diff --git a/CMake/LofarPackageList.cmake b/CMake/LofarPackageList.cmake index cd479ca772b7230b45edf29a8d097c40092c16ca..c4155b40bfbc5da819df73f02f3830625a1d7a4d 100644 --- a/CMake/LofarPackageList.cmake +++ b/CMake/LofarPackageList.cmake @@ -145,7 +145,6 @@ if(NOT DEFINED LOFAR_PACKAGE_LIST_INCLUDED) set(OTB_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/OTB) set(OTDB_SQL_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/OTDB/sql) set(QPIDInfrastructure_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/QPIDInfrastructure) - set(Scheduler_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/Scheduler) set(SAS_Feedback_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/Feedback_Service) set(XML_generator_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/XML_generator) set(XSD_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/XSD) diff --git a/SAS/CMakeLists.txt b/SAS/CMakeLists.txt index d48706292ae1ea769ded36084354320b5bdd6b79..e9293823d63effce8605dce9ed3ad0a91c927217 100644 --- a/SAS/CMakeLists.txt +++ b/SAS/CMakeLists.txt @@ -4,7 +4,6 @@ lofar_add_package(OTDB) lofar_add_package(OTB) lofar_add_package(OTDB_SQL OTDB/sql) lofar_add_package(QPIDInfrastructure) -lofar_add_package(Scheduler) lofar_add_package(SAS_Feedback Feedback_Service) lofar_add_package(XML_generator) lofar_add_package(SpecificationServices) diff --git a/SAS/Scheduler/CMakeLists.txt b/SAS/Scheduler/CMakeLists.txt deleted file mode 100644 index 02184e19d1c2ed114ff5e3bc54e0bd9f26c0094e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# $Id$ - -lofar_package(Scheduler 1.0) - -# Search for Qt4 and setup CMake environment for it -IF(BUILD_DOCUMENTATION) - find_package(Qt4 COMPONENTS QtCore QtGui QtSql QtTest) - IF(NOT Qt4_FOUND) - message(WARNING "Removed REQUIRED option while looking for package 'Qt4' because BUILD_DOCUMENTATION=${BUILD_DOCUMENTATION}. This allows cmake to continue configuring so you could make the doc, but building the code might not be possible.") - ENDIF() -ELSE() - find_package(Qt4 COMPONENTS QtCore QtGui QtSql QtTest REQUIRED) -ENDIF(BUILD_DOCUMENTATION) - -IF(Qt4_FOUND) - include(${QT_USE_FILE}) - - # Add current source- and binary directory to include path - set(CMAKE_INCLUDE_CURRENT_DIR ON) - - add_subdirectory(src) - add_subdirectory(test) -ENDIF(Qt4_FOUND) diff --git a/SAS/Scheduler/doc/package.dox b/SAS/Scheduler/doc/package.dox deleted file mode 100644 index c9a9a9415b7762779620ff1483bc033e793c8e1c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/doc/package.dox +++ /dev/null @@ -1,6 +0,0 @@ -/** - -\ingroup SAS -\defgroup Scheduler Scheduler -\ref scheduler -*/ diff --git a/SAS/Scheduler/doc/scheduler.md b/SAS/Scheduler/doc/scheduler.md deleted file mode 100644 index c7452c9f393eeb545694f3e9adb97fc17c65f8ae..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/doc/scheduler.md +++ /dev/null @@ -1,93 +0,0 @@ -# Scheduler {#scheduler} - -*This page provides the template for documenting software modules, where modules can be for example a library, service, -or an application.* - -*In order to use this template, copy its source (it is written in Markdown language) and edit it accordingy. Feel free to -remove any explanatory text written in Italic like this text, but in case some subject is not applicable to your module: -consider not removing its header, but add a rationale about why it is not applicable instead.* - -## GENERAL - -### Description -- *What does it do?* -- *Why is it needed?* - -### Author/Owner - -### Overview -- *Add a diagram* -- *Add a link to the overview diagram* -- *Add a link in the overview diagram to link back to this documentation*. - -- - - - -## DEVELOPMENT - -### Analyses -*Add non-technical information and functional considerations here, like user requirements and links to minutes of -meetings with stakeholders.* - -### Design -*Add technical considerations and design choices here* - -### Source Code -- *Add a link to svn (trunk).* -- *Add a link to (generated?) source code documentation.* - -### Testing -- *How do you run unit tests?* -- *How do you run integration tests?* -- *Add a link to Jenkins jobs (if available)* - -### Build & Deploy -- *Add a link to general instructions or describe specifics here.* -- *Add a link to Jenkins jobs (if available)* - -- - - - -## OPERATIONS - -### Configuration -- *Where is the configuration file?* -- *What are the configuration options?* - -### Log Files -- *Where are the log files?* - -### Runtime -- *Where does it run? (which user@machine)* -- *How do I run it? (user documentation? examples? commandline parameters?)* -- *Other considerations? (what happens elsewhere when I start or stop it?)* - -### Interfaces (API) -- *Describe interfaces to other applications (REST API? http requests? Messagebus?)* -- *Other communication (user? import/export?)* - -### Files/Databases -- *Which databases are used?* -- *Which files are used?* - -### Dependencies -- *To/from other applications?* -- *Files?* -- *Network locations?* -- *Other?* - -### Security -- *Special privileges needed?* -- *User login?* -- *Certificates needed?* -- *Other considerations?* - -- - - - -## ADDITIONAL INFORMATION - -### User Documentation - -*e.g. Please refer to URL X for the User Documentation* - -### Operations Documentation - -*e.g. Please refer to URL X for Operations Documentation* diff --git a/SAS/Scheduler/scripts/calendar.inc.php b/SAS/Scheduler/scripts/calendar.inc.php deleted file mode 100644 index 5c315f21180fbd1f849c65b51f796b0d64c76983..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/scripts/calendar.inc.php +++ /dev/null @@ -1,350 +0,0 @@ -<? -/* - +-------------------------------------------------------------------+ - | H T M L - C A L E N D A R (v2.11) | - | | - | Copyright Gerd Tentler www.gerd-tentler.de/tools | - | Created: May 27, 2003 Last modified: Nov. 29, 2009 | - +-------------------------------------------------------------------+ - | This program may be used and hosted free of charge by anyone for | - | personal purpose as long as this copyright notice remains intact. | - | | - | Obtain permission before selling the code for this program or | - | hosting this software on a commercial website or redistributing | - | this software over the Internet or in any other medium. In all | - | cases copyright must remain intact. | - +-------------------------------------------------------------------+ - - EXAMPLE #1: $myCal = new CALENDAR(); - echo $myCal->create(); - - EXAMPLE #2: $myCal = new CALENDAR(2004, 12); - echo $myCal->create(); - - EXAMPLE #3: $myCal = new CALENDAR(); - $myCal->year = 2004; - $myCal->month = 12; - echo $myCal->create(); - - Returns HTML code -========================================================================================================== -*/ - error_reporting(E_WARNING); -// $cal_ID = 0; - - class CALENDAR { -//======================================================================================================== -// Configuration -//======================================================================================================== - var $tFontFace = 'Arial, Helvetica'; // title: font family (CSS-spec, e.g. "Arial, Helvetica") - var $tFontSize = 14; // title: font size (pixels) - var $tFontColor = '#FFFFFF'; // title: font color - var $tBGColor = '#304B90'; // title: background color - - var $hFontFace = 'Arial, Helvetica'; // heading: font family (CSS-spec, e.g. "Arial, Helvetica") - var $hFontSize = 12; // heading: font size (pixels) - var $hFontColor = '#FFFFFF'; // heading: font color - var $hBGColor = '#304B90'; // heading: background color - - var $dFontFace = 'Arial, Helvetica'; // days: font family (CSS-spec, e.g. "Arial, Helvetica") - var $dFontSize = 14; // days: font size (pixels) - var $dFontColor = '#000000'; // days: font color - var $dBGColor = '#FFFFFF'; // days: background color - - var $wFontFace = 'Arial, Helvetica'; // weeks: font family (CSS-spec, e.g. "Arial, Helvetica") - var $wFontSize = 12; // weeks: font size (pixels) - var $wFontColor = '#FFFFFF'; // weeks: font color - var $wBGColorSchedule = '#347C17'; // weeks: background color if has week schedule (green) - var $wBGColor = '#C11B17'; // weeks: background color (red) - - var $saFontColor = '#0000D0'; // Saturdays: font color - var $saBGColor = '#F6F6FF'; // Saturdays: background color - - var $suFontColor = '#D00000'; // Sundays: font color - var $suBGColor = '#FFF0F0'; // Sundays: background color - - var $tdBorderColor = '#FF0000'; // today: border color - - var $borderColor = '#304B90'; // border color - var $hilightColor = '#FFFF00'; // hilight color (works only in combination with link) - - var $link = ''; // page to link to when day is clicked - var $offset = 1; // week start: 0 - 6 (0 = Saturday, 1 = Sunday, 2 = Monday ...) - var $weekNumbers = true; // view week numbers: true = yes, false = no - -//-------------------------------------------------------------------------------------------------------- -// You should change these variables only if you want to translate them into your language: -//-------------------------------------------------------------------------------------------------------- - // weekdays: must start with Saturday because January 1st of year 1 was a Saturday - var $weekdays = array('Sa', 'Su', 'Mo', 'Tu', 'We', 'Th', 'Fr'); - - // months: must start with January - var $months = array('January', 'February', 'March', 'April', 'May', 'June', - 'July', 'August', 'September', 'October', 'November', 'December'); - // error messages - var $error = array('Year must be 1 - 3999!', 'Month must be 1 - 12!'); - -//-------------------------------------------------------------------------------------------------------- -// Don't change from here: -//-------------------------------------------------------------------------------------------------------- - var $year, $month, $size; - var $mDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - var $specDays = array(); - -//======================================================================================================== -// Functions -//======================================================================================================== - function CALENDAR($year = '', $month = '', $week = '') { - if($year == '' && $month == '') { - $year = date('Y'); - $month = date('n'); - } - else if($year != '' && $month == '') $month = 1; - $this->year = (int) $year; - $this->month = (int) $month; - $this->week = (int) $week; - } - - function set_styles() { -// global $cal_ID; - -// $cal_ID++; - $html = '<style> .cssTitle { '; - if($this->tFontFace) $html .= 'font-family: ' . $this->tFontFace . '; '; - if($this->tFontSize) $html .= 'font-size: ' . $this->tFontSize . 'px; '; - if($this->tFontColor) $html .= 'color: ' . $this->tFontColor . '; '; - if($this->tBGColor) $html .= 'background-color: ' . $this->tBGColor . '; '; - $html .= '} .cssHeading { '; - if($this->hFontFace) $html .= 'font-family: ' . $this->hFontFace . '; '; - if($this->hFontSize) $html .= 'font-size: ' . $this->hFontSize . 'px; '; - if($this->hFontColor) $html .= 'color: ' . $this->hFontColor . '; '; - if($this->hBGColor) $html .= 'background-color: ' . $this->hBGColor . '; '; - $html .= '} .cssDays { '; - if($this->dFontFace) $html .= 'font-family: ' . $this->dFontFace . '; '; - if($this->dFontSize) $html .= 'font-size: ' . $this->dFontSize . 'px; '; - if($this->dFontColor) $html .= 'color: ' . $this->dFontColor . '; '; - // if($this->dBGColor) $html .= 'background-color: ' . $this->dBGColor . '; '; - $html .= '} .cssWeeks { '; - if($this->wFontFace) $html .= 'font-family: ' . $this->wFontFace . '; '; - if($this->wFontSize) $html .= 'font-size: ' . $this->wFontSize . 'px; '; - if($this->wFontColor) $html .= 'color: ' . $this->wFontColor . '; '; - if($this->wBGColor) $html .= 'background-color: ' . $this->wBGColor . '; '; - $html .= '} .cssWeeksSchedule { '; - if($this->wFontFace) $html .= 'font-family: ' . $this->wFontFace . '; '; - if($this->wFontSize) $html .= 'font-size: ' . $this->wFontSize . 'px; '; - if($this->wFontColor) $html .= 'color: ' . $this->wFontColor . '; '; - if($this->wBGColorSchedule) $html .= 'background-color: ' . $this->wBGColorSchedule . '; '; - $html .= '} .cssSaturdays { '; - if($this->dFontFace) $html .= 'font-family: ' . $this->dFontFace . '; '; - if($this->dFontSize) $html .= 'font-size: ' . $this->dFontSize . 'px; '; - if($this->saFontColor) $html .= 'color: ' . $this->saFontColor . '; '; - // if($this->saBGColor) $html .= 'background-color: ' . $this->saBGColor . '; '; - $html .= '} .cssSundays { '; - if($this->dFontFace) $html .= 'font-family: ' . $this->dFontFace . '; '; - if($this->dFontSize) $html .= 'font-size: ' . $this->dFontSize . 'px; '; - if($this->suFontColor) $html .= 'color: ' . $this->suFontColor . '; '; - // if($this->suBGColor) $html .= 'background-color: ' . $this->suBGColor . '; '; - $html .= '} .cssHilight { '; - if($this->dFontFace) $html .= 'font-family: ' . $this->dFontFace . '; '; - if($this->dFontSize) $html .= 'font-size: ' . $this->dFontSize . 'px; '; - if($this->dFontColor) $html .= 'color: ' . $this->dFontColor . '; '; - if($this->hilightColor) $html .= 'background-color: ' . $this->hilightColor . '; '; - $html .= '} .cssHilightRow { '; - if($this->dFontFace) $html .= 'font-family: ' . $this->dFontFace . '; '; - if($this->dFontSize) $html .= 'font-size: ' . $this->dFontSize . 'px; '; - if($this->dFontColor) $html .= 'color: ' . $this->dFontColor . '; '; - if($this->hilightColor) $html .= 'background-color: ' . $this->hilightColor . '; '; - $html .= 'cursor: default; '; - $html .= '} </style>'; - - return $html; - } - - function leap_year($year) { - return (!($year % 4) && ($year < 1582 || $year % 100 || !($year % 400))) ? true : false; - } - - function get_weekday($year, $days) { - $a = $days; - if($year) $a += ($year - 1) * 365; - for($i = 1; $i < $year; $i++) if($this->leap_year($i)) $a++; - if($year > 1582 || ($year == 1582 && $days >= 277)) $a -= 10; - if($a) $a = ($a - $this->offset) % 7; - else if($this->offset) $a += 7 - $this->offset; - - return $a; - } - - function get_week($year, $days) { - $firstWDay = $this->get_weekday($year, 0); - return floor(($days + $firstWDay) / 7) + ($firstWDay <= 3); - } - - function table_cell($content, $class, $date = '', $style = '') { -// global $cal_ID; - - $size = round($this->size * 1.5); - $html = '<td align=center width=' . $size . ' class="' . $class . '"'; - - if($content != ' ' && stristr($class, 'day')) { - $link = $this->link; - - if($this->specDays[$content]) { - if($this->specDays[$content][0]) { - $style .= 'background-color:' . $this->specDays[$content][0] . ';'; - } - if($this->specDays[$content][1]) { - $html .= ' title="' . $this->specDays[$content][1] . '"'; - } - if($this->specDays[$content][2]) $link = $this->specDays[$content][2]; - } - if($link) { - $link .= strstr($link, '?') ? "&date=$date" : "?date=$date"; - $html .= ' onMouseOver="this.className=\'cssHilight\'"'; - $html .= ' onMouseOut="this.className=\'' . $class . '\'"'; - $html .= ' onClick="document.location.href=\'' . $link . '\'"'; - } - } - if($style) $html .= ' style="' . $style . '"'; - $html .= '>' . $content . '</td>'; - - return $html; - } - - function table_head($content) { -// global $cal_ID; - - $cols = $this->weekNumbers ? 8 : 7; - $html = '<tr><td colspan=' . $cols . ' class="cssTitle" align=center><b>' . - $content . '</b></td></tr><tr>'; - for($i = 0; $i < count($this->weekdays); $i++) { - $ind = ($i + $this->offset) % 7; - $wDay = $this->weekdays[$ind]; - $html .= $this->table_cell($wDay, 'cssHeading'); - } - if($this->weekNumbers) $html .= $this->table_cell(' ', 'cssHeading'); - $html .= '</tr>'; - - return $html; - } - - function viewEvent($from, $to, $color, $title, $link = '') { - if($from > $to) return; - if($from < 1 || $from > 31) return; - if($to < 1 || $to > 31) return; - - while($from <= $to) { - $this->specDays[$from] = array($color, $title, $link); - $from++; - } - } - - function create() { -// global $cal_ID; - - $this->size = ($this->hFontSize > $this->dFontSize) ? $this->hFontSize : $this->dFontSize; - if($this->wFontSize > $this->size) $this->size = $this->wFontSize; - - list($curYear, $curMonth, $curDay) = explode('-', date('Y-m-d')); - - if($this->year < 1 || $this->year > 3999) $html = '<b>' . $this->error[0] . '</b>'; - else if($this->month < 1 || $this->month > 12) $html = '<b>' . $this->error[1] . '</b>'; - else { - $this->mDays[1] = $this->leap_year($this->year) ? 29 : 28; - for($i = $days = 0; $i < $this->month - 1; $i++) $days += $this->mDays[$i]; - - $start = $this->get_weekday($this->year, $days); - $stop = $this->mDays[$this->month-1]; - - // $html = $this->set_styles(); - $html = '<table border="0" cellspacing="0" cellpadding="0"><tr>'; - $html .= '<td>'; - $html .= '<table border="0" cellspacing="1" cellpadding="3">'; - $title = htmlentities($this->months[$this->month-1]) . ' ' . $this->year; - $html .= $this->table_head($title); - $daycount = 1; - - if(($this->year == $curYear) && ($this->month == $curMonth)) $inThisMonth = true; - else $inThisMonth = false; - - if($this->weekNumbers || $this->week) $weekNr = $this->get_week($this->year, $days); - - while($daycount <= $stop) { - if($this->week && $this->week != $weekNr) { - $daycount += 7; - $weekNr++; - continue; - } - $html .= '<tr'; // start of a week row -// // check if week html file exists - if ($this->selectedWeek == -1) { // if no week was specified set selected week equal to first week of this month - $this->selectedWeek = $weekNr; - $html .= ' style="background-color:#6698FF"'; // ;border-color:#C11B17; - } - else if ($weekNr == $this->selectedWeek) { // highlight the selected week - $html .= ' style="background-color:#6698FF"'; // ;border-color:#C11B17; - } - - $schedule_week_file = $this->year . "/week_" . $weekNr . ".html"; - - if (is_file($schedule_week_file)) { - $has_week_schedule = 1; - $html .= ' onMouseOver="this.className=\'cssHilightRow\'"'; - $html .= ' onMouseOut="this.className=\'cssDays\'"'; - $html .= ' onClick="document.location.href=\'' . $_SERVER['PHP_SELF'] . '?week=' . $weekNr . - '&year=' . $this->year . '&month=' . $this->month . '\'"'; - } - else { - $has_week_schedule = 0; - } - $html .= '>'; - - for($i = $wdays = 0; $i <= 6; $i++) { - $ind = ($i + $this->offset) % 7; - if($ind == 0) $class = 'cssSaturdays'; - else if($ind == 1) $class = 'cssSundays'; - else $class = 'cssDays'; - - $style = ''; - $date = $this->year . '-' . $this->month . '-' . $daycount; - - if(($daycount == 1 && $i < $start) || $daycount > $stop) $content = ' '; - else { - $content = $daycount; - if($inThisMonth && $daycount == $curDay) { - $style = 'padding:0px;border:3px solid ' . $this->tdBorderColor . ';'; - } - else if($this->year == 1582 && $this->month == 10 && $daycount == 4) $daycount = 14; - $daycount++; - $wdays++; - } - $html .= $this->table_cell($content, $class, $date, $style); - } - - if($this->weekNumbers) { - if(!$weekNr) { - if($this->year == 1) $content = ' '; - else if($this->year == 1583) $content = 52; - else $content = $this->get_week($this->year - 1, 365); - } - else if($this->month == 12 && $weekNr >= 52 && $wdays < 4) $content = 1; - else $content = $weekNr; - - if ($has_week_schedule == 1) { - $cssWeekStyle = 'cssWeeksSchedule'; - } - else { - $cssWeekStyle = 'cssWeeks'; - } - - $html .= $this->table_cell($content, $cssWeekStyle); - $weekNr++; - } - $html .= '</tr>'; - } - $html .= '</table></td></tr></table>'; - } - return $html; - } - } -?> diff --git a/SAS/Scheduler/scripts/schedule.php b/SAS/Scheduler/scripts/schedule.php deleted file mode 100644 index 2aa710b83a03955a65ac8e7eac73ef8033a78159..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/scripts/schedule.php +++ /dev/null @@ -1,275 +0,0 @@ -<?php -// Date in the past -header("Expires: Fri, 30 Oct 1998 14:19:41 GMT"); -// always modified -header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); -// HTTP/1.1 -header("cache-Control: no-store, no-cache, must-revalidate"); -header("cache-Control: post-check=0, pre-check=0", false); -// HTTP/1.0 -header("Pragma: no-cache"); - -?> - -<!DOCTYPE HTML> -<?php -include('calendar.inc.php'); - -$current_year = date('Y'); -$current_month = date('n'); -$current_week = date('W'); -$month_names = array("January","February","March","April","May","June","July","August","September","October","November","December"); - -if (isset($_GET["week"]) & !empty($_GET["week"])) { - if ($_GET["week"] >= 1 & $_GET["week"] <= 53) { - $URL_week = $_GET["week"]; - } -} -if (isset($_GET["month"]) & !empty($_GET["month"])) { - if ($_GET["month"] >= 1 & $_GET["month"] <= 12) { - $URL_month = $_GET["month"]; - } -} -if (isset($_GET["year"]) & !empty($_GET["year"])) { - $URL_year = $_GET["year"]; -} - -if (isset($URL_year)) { $selected_year = $URL_year; } else { $selected_year = $current_year; } -if (isset($URL_month)) { $selected_month = $URL_month; } else { $selected_month = $current_month; } -if (isset($URL_week)) { - $selected_week = $URL_week; - // create the calendar - $cal = new CALENDAR($selected_year, $selected_month); - $cal->offset = 2; - $cal->weekNumbers = 1; - $cal->tFontSize = 11; - $cal->hFontSize = 9; - $cal->dFontSize = 9; - $cal->wFontSize = 9; - $cal->selectedWeek = $selected_week; - $html_calendar_code = $cal->create(); -} -else if (isset($URL_month)) { // no week specified but month is specified -> select first week of this month (later on) - if ($selected_month > 0 & $selected_month < 13) { - // create the calendar - $cal = new CALENDAR($selected_year, $selected_month); - $cal->offset = 2; - $cal->weekNumbers = 1; - $cal->tFontSize = 11; - $cal->hFontSize = 9; - $cal->dFontSize = 9; - $cal->wFontSize = 9; - $cal->selectedWeek = -1; - $html_calendar_code = $cal->create(); - - $selected_week = $cal->selectedWeek; // make selected week equal to first week of the selected month - } -} -else { // select current week - $selected_week = intval($current_week); - // create the calendar - $cal = new CALENDAR($selected_year, $selected_month); - $cal->offset = 2; - $cal->weekNumbers = 1; - $cal->tFontSize = 11; - $cal->hFontSize = 9; - $cal->dFontSize = 9; - $cal->wFontSize = 9; - $cal->selectedWeek = $selected_week; - $html_calendar_code = $cal->create(); -} -?> - -<HTML> -<HEAD> -<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE; NO-STORE"> -<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> -<META HTTP-EQUIV="EXPIRES" CONTENT="-1"> -<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8"> -<META NAME="KEYWORDS" CONTENT="LOFAR, LOFAR schedule, LOFAR Scheduler, ASTRON, LOFAR observations, Astronomy"> -<META NAME="ROBOTS" CONTENT="INDEX,NOFOLLOW,NOARCHIVE"> - -<?php -echo "<LINK rel=\"stylesheet\" href=\"../css/mainstyle.css\" type=\"text/css\">\n"; -echo $cal->set_styles(); -echo "\n<TITLE>\nLOFAR Schedule for week " . $selected_week . " (" . $selected_year . ")\n</TITLE>\n"; -?> -</HEAD> -<BODY> - -<div id="dhtmltooltip"></div> - -<script type="text/javascript"> - -var offsetxpoint=-60 //Customize x offset of tooltip -var offsetypoint=20 //Customize y offset of tooltip -var ie=document.all -var ns6=document.getElementById && !document.all -var enabletip=false -if (ie||ns6) -var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "" - -function ietruebody(){ -return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body -} - -function ddrivetip(thetext, thecolor, thewidth){ -if (ns6||ie){ -if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px" -if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor -tipobj.innerHTML=thetext -enabletip=true -return false -} -} - -function positiontip(e){ -if (enabletip){ -var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft; -var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop; -//Find out how close the mouse is to the corner of the window -var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20 -var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20 - -var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000 - -//if the horizontal distance isn't enough to accomodate the width of the context menu -if (rightedge<tipobj.offsetWidth) -//move the horizontal position of the menu to the left by it's width -tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px" -else if (curX<leftedge) -tipobj.style.left="5px" -else -//position the horizontal position of the menu where the mouse is positioned -tipobj.style.left=curX+offsetxpoint+"px" - -//same concept with the vertical position -if (bottomedge<tipobj.offsetHeight) -tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px" -else -tipobj.style.top=curY+offsetypoint+"px" -tipobj.style.visibility="visible" -} -} - -function hideddrivetip(){ -if (ns6||ie){ -enabletip=false -tipobj.style.visibility="hidden" -tipobj.style.left="-1000px" -tipobj.style.backgroundColor='' -tipobj.style.width='' -} -} - -document.onmousemove=positiontip - -</script> - -<DIV class="style_container"> -<DIV id="MainHeader"></DIV> - - -<?php -echo "<DIV style='position: absolute; left: 400px; top: 125px; font-weight: bold; font-size: 18px;'>"; -echo "LOFAR Schedule for week " . $selected_week . " (" . $selected_year . ")"; - -echo "</DIV>\n<DIV ID='ScheduleArea'>\n<DIV id='calendar' style='position: absolute; left: 925px; top: 170px; width: 170px;'>\n"; - -// first find out which years are available by examining available year directories -$dir = './'; -$year_dirs = scandir($dir); -foreach ($year_dirs as $i => $value) { - if (!(is_dir($value)) | (strlen($value) != 4)) { // only accept 4 digits year directory - unset($year_dirs[$i]); - } - } - - if (!empty($year_dirs)) { - // month dropdown list - echo "<FORM STYLE='float: left;' METHOD='get' ACTION='"; - echo $_SERVER['PHP_SELF']; - echo "'>\n<SELECT NAME='month' onchange='this.form.submit()'>\n"; - foreach ($month_names as $i => $month_name) { - echo "<OPTION VALUE='"; - echo $i+1; - echo "'"; - if ($i+1 == $selected_month) { - echo " SELECTED"; - } - echo ">"; - echo $month_name; - echo "</OPTION>\n"; - } - echo "</SELECT>\n"; - // year pulldown list - echo "<SELECT NAME='year' onchange='this.form.submit()'>\n"; - foreach ($year_dirs as $i => $year_nr) { - echo "<OPTION VALUE='"; - echo $year_nr; - echo "'"; - if ($year_nr == $selected_year) { - echo " SELECTED"; - } - echo ">"; - echo $year_nr; - echo "</OPTION>\n"; - } - echo "</SELECT>\n"; - echo "</FORM><BR><BR>\n"; - - $sel_week = sprintf("%02d", $selected_week); // make sure we have two digits for the weeknumber otherwise strtotime fails - $prev_week_time = strtotime($selected_year . "W" . $sel_week . " -1 week"); - $next_week_time = strtotime($selected_year . "W" . $sel_week . " +1 week"); - // next: the intval is done to make sure we don't pad a single digit weeknumber with a 0 - $prev_week = intval(date("W", $prev_week_time)); - $next_week = intval(date("W", $next_week_time)); - $prev_week_month = date("n" , $prev_week_time); - $next_week_month = date("n" , $next_week_time); - $prev_week_year = date("Y" , $prev_week_time); - $next_week_year = date("Y" , $next_week_time); - - echo "<A href='" . $_SERVER['PHP_SELF'] . "?week=" . $prev_week . "&year=" . $prev_week_year . "&month=" . $prev_week_month . "'><<</A>\n \n"; - echo "<A href='" . $_SERVER['PHP_SELF'] . "?week=" . intval(date('W')) . "&year=" . $current_year . "&month=" . $current_month . "'>today</A>\n \n"; - echo "<A href='" . $_SERVER['PHP_SELF'] . "?week=" . $next_week . "&year=" . $next_week_year . "&month=" . $next_week_month . "'>>></A>\n"; - } - else { // no data available - echo "No data available\n"; - } - - echo $html_calendar_code; - - ?> - </DIV> - <?php - // add the selected week schedule - // echo "<DIV ID='schedule' style='position: absolute; top: 150px; width: 920px;'>"; - echo "<BR>"; - $schedule = $selected_year . "/week_" . $selected_week . ".html"; - /* DEBUG CODE - echo "selected week: " . $selected_week . "<BR>" . - "selected month: " . $selected_month . "<BR>" . - "selected year: " . $selected_year . "<BR>" . - "URL_week: " . $URL_week . "<BR>" . - "URL_month: " . $URL_month . "<BR>" . - "URL_year: " . $URL_year . "<BR>" . - "previous week: " . $prev_week . "<BR>" . - "next week: " . $next_week . "<BR>"; - */ - if (is_file($schedule)) { - include ($schedule); - } - else { - echo "<BR><p style='padding-left:20px; font-weight:bold; color:red;'>Week " . $selected_week . " (" . $selected_year . ") has not been published yet</p>"; - } - echo "</DIV>"; - ?> - </DIV> - </BODY> - <HEAD> - <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE; NO-STORE"> - <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> - <META HTTP-EQUIV="EXPIRES" CONTENT="-1"> - </HEAD> - </HTML> - diff --git a/SAS/Scheduler/src/.default_settings.set b/SAS/Scheduler/src/.default_settings.set deleted file mode 100644 index a41c0d18f3036dd25feaaa075818ccaaaaf21cab..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/.default_settings.set and /dev/null differ diff --git a/SAS/Scheduler/src/Angle.cpp b/SAS/Scheduler/src/Angle.cpp deleted file mode 100644 index 60647fb517bb2ec38d2b704cb9d9766a117b3a64..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Angle.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Angle.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 31-mrt-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Angle.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "Angle.h" -#include "lofar_utils.h" -#include <cmath> -#include <sstream> -#include <algorithm> -#include <iomanip> // for std::setprecision() -#include <limits> - -using std::min; -using std::max; -using std::stringstream; - -const char * ANGLE_PAIRS[END_ANGLE_PAIRS] = {"radians", "dec.degrees", "(HMS,DMS)", "(DMS,DMS)"}; - -Angle::Angle() -: itsRadianValue(0.0), itsDegreeValue(0.0) -{ - itsDMSvalue.degrees = 0; - itsDMSvalue.minutes = 0; - itsDMSvalue.seconds = 0.0; - itsHMSvalue.hours = 0; - itsHMSvalue.minutes = 0; - itsHMSvalue.seconds = 0.0; - setHMSstring(); - setDMSstring(); -} - -Angle::~Angle() { - // TODO Auto-generated destructor stub -} - -bool Angle::operator==(const Angle & right) const { - return fabs(this->itsRadianValue - right.itsRadianValue) < std::numeric_limits<double>::epsilon(); -} - -bool Angle::operator!=(const Angle & right) const { - return !(*this == right); -} - -/* -std::istream& operator>> (std::istream &in, Angle &angle) { - read_primitive<double>(in, angle.itsRadianValue); - read_primitive<double>(in, angle.itsDegreeValue); - // hmsvalue - read_primitive<unsigned>(in, angle.itsHMSvalue.hours); - read_primitive<unsigned>(in, angle.itsHMSvalue.minutes); - read_primitive<double>(in, angle.itsHMSvalue.seconds); - // dms value - read_primitive<int>(in, angle.itsDMSvalue.degrees); - read_primitive<unsigned>(in, angle.itsDMSvalue.minutes); - read_primitive<double>(in, angle.itsDMSvalue.seconds); - - read_string(in, angle.itsHMSstr); - read_string(in, angle.itsDMSstr); - - return in; -} - -std::ostream& operator<< (std::ostream &out, const Angle &angle) { - write_primitive<double>(out, angle.itsRadianValue); - write_primitive<double>(out, angle.itsDegreeValue); - // hmsvalue - write_primitive<unsigned>(out, angle.itsHMSvalue.hours); - write_primitive<unsigned>(out, angle.itsHMSvalue.minutes); - write_primitive<double>(out, angle.itsHMSvalue.seconds); - // dms value - write_primitive<int>(out, angle.itsDMSvalue.degrees); - write_primitive<unsigned>(out, angle.itsDMSvalue.minutes); - write_primitive<double>(out, angle.itsDMSvalue.seconds); - - write_string(out, angle.itsHMSstr); - write_string(out, angle.itsDMSstr); - - return out; -} -*/ -QDataStream& operator>> (QDataStream &in, Angle &angle) { - in >> angle.itsRadianValue - >> angle.itsDegreeValue - // hmsvalue - >> angle.itsHMSvalue.hours - >> angle.itsHMSvalue.minutes - >> angle.itsHMSvalue.seconds - // dms value - >> angle.itsDMSvalue.degrees - >> angle.itsDMSvalue.minutes - >> angle.itsDMSvalue.seconds - - >> angle.itsHMSstr - >> angle.itsDMSstr; - - return in; -} - -QDataStream& operator<< (QDataStream &out, const Angle &angle) { - out << angle.itsRadianValue - << angle.itsDegreeValue - // hmsvalue - << angle.itsHMSvalue.hours - << angle.itsHMSvalue.minutes - << angle.itsHMSvalue.seconds - // dms value - << angle.itsDMSvalue.degrees - << angle.itsDMSvalue.minutes - << angle.itsDMSvalue.seconds - - << angle.itsHMSstr - << angle.itsDMSstr; - - return out; -} - -bool Angle::setHMSangleStr(const std::string &HMSstring) { - int p1, p2; - p1 = HMSstring.find_first_of(':'); // typically = 3 - p2 = HMSstring.find_first_of(':', p1+1) + p1 - min(p1,2); //typ = 6 - int hours = string2Int(HMSstring.substr(0, p1)); - short sign = (hours < 0) ? -1 : 1; - if (hours >= 24) - return false; - int minutes = sign * string2Int(HMSstring.substr(p1+1,p2-p1-1)); - if (minutes >= 60) - return false; - double seconds = string2Double(HMSstring.substr(p2+1)); - if (seconds > 59.9999999999999999) - return false; - - itsHMSvalue.hours = hours; - itsHMSvalue.minutes = minutes; - itsHMSvalue.seconds = seconds; - setHMSstring(); - // calculate degrees value - calcDegreesfromHMS(); - // calculate radian value - itsRadianValue = itsDegreeValue * GRAD2RAD; - // calculate DMS value - calcDMSfromDegrees(); - return true; -} - -bool Angle::setDMSangleStr(const std::string &DMSstring) { - int p1, p2; - p1 = DMSstring.find_first_of(':'); - p2 = DMSstring.find_first_of(':', p1+1) + p1 - min(p1,3); - int degrees = string2Int(DMSstring.substr(0, p1)); - short sign = (degrees < 0) ? -1 : 1; - int minutes = sign * string2Int(DMSstring.substr(p1+1,p2-p1-1)); - if (minutes >= 60) - return false; - double seconds = sign * string2Double(DMSstring.substr(p2+1)); - if (seconds > 59.9999999999999999) - return false; - - itsDMSvalue.degrees = degrees; - itsDMSvalue.minutes = minutes; - itsDMSvalue.seconds = seconds; - - setDMSstring(); - // calculate degrees value - calcDegreesfromDMS(); - // calculate radian value - itsRadianValue = itsDegreeValue * GRAD2RAD; - // calculate DMS value - calcHMSfromDegrees(); - return true; -} - -void Angle::setRadianAngle(const double &rad) { - itsRadianValue = fmod(rad, TWO_PI); // put radians in the range of [0,2Pi> - // now calculate the other angle value units - // decimal degrees - itsDegreeValue = itsRadianValue * RAD2GRAD; - // HMS - calcHMSfromDegrees(); - // DMS - calcDMSfromDegrees(); -} - -void Angle::setDegreeAngle(const double °) { - itsDegreeValue = fmod(deg, 360.0); // put degrees in the range of [0,360> - // now calculate the other angle value units - // decimal degrees - itsRadianValue = itsDegreeValue * GRAD2RAD; - // HMS - calcHMSfromDegrees(); - // DMS - calcDMSfromDegrees(); -} - -bool Angle::setHMSangle(const Angle::hms & HMS) { - if ((HMS.hours >= 24) | (HMS.minutes >= 60) | (HMS.seconds > 59.999999999999999)) { - return false; - } - itsHMSvalue = HMS; - setHMSstring(); - // decimal degrees - calcDegreesfromHMS(); - // radians - itsRadianValue = itsDegreeValue * GRAD2RAD; - // DMS - calcDMSfromDegrees(); - return true; -} - -bool Angle::setDMSangle(const Angle::dms & dms) { - if ((dms.minutes >= 60) | (dms.seconds > 59.99999999999999)) { - return false; - } - itsDMSvalue = dms; - setDMSstring(); - // decimal degrees - calcDegreesfromDMS(); - // radians - itsRadianValue = itsDegreeValue *GRAD2RAD; - // HMS - calcHMSfromDegrees(); - return true; -} - -void Angle::setHMSstring(void) { - stringstream sstr; - sstr << std::fixed << std::setprecision(7) << (qint16)itsHMSvalue.hours << ":" << (qint16)itsHMSvalue.minutes << ":" << itsHMSvalue.seconds; - itsHMSstr = sstr.str(); -} - -void Angle::setDMSstring(void) { - stringstream sstr; - sstr << std::fixed << std::setprecision(7) << (qint16)itsDMSvalue.degrees << ":" << (qint16)itsDMSvalue.minutes << ":" << itsDMSvalue.seconds; - itsDMSstr = sstr.str(); -} - -void Angle::calcHMSfromDegrees(void) { - double dTemp = itsDegreeValue / 15.0; - itsHMSvalue.hours = static_cast<int>(dTemp); - dTemp -= itsHMSvalue.hours; // remainder - dTemp = dTemp * 60; // minutes - itsHMSvalue.minutes = static_cast<int>(dTemp); - dTemp -= itsHMSvalue.minutes; - itsHMSvalue.seconds = dTemp * 60; // seconds - setHMSstring(); -} - -void Angle::calcDegreesfromHMS(void) { - itsDegreeValue = (static_cast<double>(itsHMSvalue.hours) / 24) * 360 + - (static_cast<double>(itsHMSvalue.minutes) / 60) * 15 + - (itsHMSvalue.seconds / 60) * 0.25; -} - -void Angle::calcDegreesfromDMS(void) { - itsDegreeValue = itsDMSvalue.degrees + - static_cast<double>(itsDMSvalue.minutes) / 60 + - itsDMSvalue.seconds / 3600; -} - -void Angle::calcDMSfromDegrees(void) { - itsDMSvalue.degrees = static_cast<int>(itsDegreeValue); - double dTemp = itsDegreeValue - itsDMSvalue.degrees; // the floating point remainder degrees - if (dTemp < 0) dTemp *= -1; // positive values - itsDMSvalue.minutes = static_cast<int>(dTemp = dTemp * 60); // convert remainder to minutes - dTemp -= itsDMSvalue.minutes; // subtract whole minutes - itsDMSvalue.seconds = dTemp * 60; // convert remainder to seconds - setDMSstring(); -} - -void Angle::clear(void) { - itsRadianValue = 0.0f; - itsDegreeValue = 0.0f; - itsHMSvalue.hours = 0; - itsHMSvalue.minutes = 0; - itsHMSvalue.seconds = 0.0f; - itsDMSvalue.degrees = 0; - itsDMSvalue.minutes = 0; - itsDMSvalue.seconds = 0.0f; - setHMSstring(); - setDMSstring(); -} - -/* -void Angle::radianToHMS(void) { - -} - -void Angle::radianToDegree(void) { - -} - -void Angle::radianToDMs(void) { - -} -*/ -/* puts a large angle in the correct range 0 - 360 degrees */ -/* -double Angle::range_degrees (const double &angle) { - double temp; - double range; - - if (angle >= 0.0 && angle < 360.0) - return(angle); - - temp = static_cast<int>(angle / 360); - - if ( angle < 0.0 ) - temp --; - - temp *= 360; - range = angle - temp; - return (range); -} -*/ diff --git a/SAS/Scheduler/src/Angle.h b/SAS/Scheduler/src/Angle.h deleted file mode 100644 index 6ef9a4bb2398efa474ee7a6fe98f85897d44cc36..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Angle.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Angle.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 31-mrt-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Angle.h $ - * - */ - -#ifndef ANGLE_H_ -#define ANGLE_H_ - -#include <string> -#include <QDataStream> - -enum angleUnits { - ANGLE_UNITS_HMS, - ANGLE_UNITS_DMS, - ANGLE_UNITS_DEG, - ANGLE_UNITS_RAD, - END_ANGLE_UNITS -}; - -enum anglePairs { - ANGLE_PAIRS_RADIANS, - ANGLE_PAIRS_DECIMAL_DEGREES, - ANGLE_PAIRS_HMS_DMS, - ANGLE_PAIRS_DMS_DMS, - END_ANGLE_PAIRS -}; - -extern const char * ANGLE_PAIRS[END_ANGLE_PAIRS]; - -class Angle { - - struct hms { - qint8 hours; - qint8 minutes; - double seconds; - }; - - struct dms { - qint16 degrees; - qint8 minutes; - double seconds; - }; - -public: - Angle(); - virtual ~Angle(); - - bool operator==(const Angle & right) const; - bool operator!=(const Angle & right) const; - -// friend std::ostream& operator<< (std::ostream &out, const Angle &angle); // used for writing data to binary file -// friend std::istream& operator>> (std::istream &in, Angle &angle); // used for reading data from binary file - friend QDataStream& operator<< (QDataStream &out, const Angle &angle); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, Angle &angle); // used for reading data from binary file - - // set this angle with a radian input value and then calculate the other angle units - void setRadianAngle(const double &rad); - void setDegreeAngle(const double °); - bool setHMSangle(const hms & HMS); - bool setHMSangleStr(const std::string &HMSstring); - bool setDMSangle(const dms & dms); - bool setDMSangleStr(const std::string &DMSstring); - void clear(void); - - const double &radian(void) const {return itsRadianValue;} - const double °ree(void) const {return itsDegreeValue;} - const hms &HMS(void) const {return itsHMSvalue;} - const dms &DMS(void) const {return itsDMSvalue;} - const std::string &HMSstring(void) const {return itsHMSstr;} - const std::string &DMSstring(void) const {return itsDMSstr;} - -private: - // convert a angle unit as string to another unit as string -// std::string Angle::convertAngle(const std::string& valueStr, angleUnits oldUnits, angleUnits newUnit); - // convert a decimal degree angle to hours minutes and seconds -// void radianToHMS(void); -// void radianToDegree(void); -// void radianToDMs(void); - void setHMSstring(void); - void setDMSstring(void); - void calcHMSfromDegrees(void); // helper function to calculate HMS from degree value - void calcDegreesfromHMS(void); // helper function to calculate degrees from HMS value - void calcDegreesfromDMS(void); // helper function to calculate degrees from DMS value - void calcDMSfromDegrees(void); // helper function to calculate DMS from degrees value - -private: - double itsRadianValue; - double itsDegreeValue; - hms itsHMSvalue; - dms itsDMSvalue; - std::string itsHMSstr, itsDMSstr; -}; - -#endif /* ANGLE_H_ */ - - diff --git a/SAS/Scheduler/src/CMakeLists.txt b/SAS/Scheduler/src/CMakeLists.txt deleted file mode 100644 index 5a1229fcca2445632d9611265c28f719c5d203bd..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/CMakeLists.txt +++ /dev/null @@ -1,169 +0,0 @@ -# $Id$ - -# Create symbolic link to include directory. -execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR}/include/${PACKAGE_NAME}) - -set(scheduler_SRCS - Angle.cpp - astrodate.cpp - astrodatetime.cpp - astrotime.cpp - blocksize.cpp - calibrationpipeline.cpp - CheckBox.cpp - ComboBox.cpp - conflictdialog.cpp - Controller.cpp - DataHandler.cpp - DataMonitorConnection.cpp - dataslotdialog.cpp - DataTreeWidgetItem.cpp - DateEdit.cpp - DateTimeEdit.cpp - debug_lofar.cpp - demixingsettings.cpp - DigitalBeam.cpp - digitalbeamdialog.cpp - doublespinbox.cpp - FileUtils.cpp - GraphicCurrentTimeLine.cpp - GraphicResourceScene.cpp - GraphicStationTaskLine.cpp - graphicstoragescene.cpp - GraphicStorageTimeLine.cpp - GraphicTask.cpp - GraphicTimeLine.cpp - imagingpipeline.cpp - LineEdit.cpp - ListWidget.cpp - lofar_utils.cpp - longbaselinepipeline.cpp - neighboursolution.cpp - observation.cpp - OTDBnode.cpp - OTDBtree.cpp - parsettreeviewer.cpp - pipeline.cpp - publishdialog.cpp - pulsarpipeline.cpp - qlofardatamodel.cpp - redistributetasksdialog.cpp - sasconnectdialog.cpp - SASConnection.cpp - sasprogressdialog.cpp - sasstatusdialog.cpp - sasuploaddialog.cpp - Scheduler.cpp - schedulerdatablock.cpp - schedulerdata.cpp - schedulergui.cpp - schedulerLib.cpp - schedulersettings.cpp - schedulesettingsdialog.cpp - scheduletabledelegate.cpp - shifttasksdialog.cpp - signalhandler.cpp - SpinBox.cpp - statehistorydialog.cpp - station.cpp - stationlistwidget.cpp - stationtask.cpp - stationtreewidget.cpp - Storage.cpp - StorageNode.cpp - tablecolumnselectdialog.cpp - tableview.cpp - taskcopydialog.cpp - task.cpp - taskdialog.cpp - taskstorage.cpp - thrashbin.cpp - TiedArrayBeam.cpp - tiedarraybeamdialog.cpp - TimeEdit.cpp) - -set(scheduler_MOC_HDRS - CheckBox.h - ComboBox.h - conflictdialog.h - Controller.h - dataslotdialog.h - DateEdit.h - DateTimeEdit.h - digitalbeamdialog.h - doublespinbox.h - GraphicResourceScene.h - graphicstoragescene.h - GraphicTask.h - LineEdit.h - ListWidget.h - parsettreeviewer.h - publishdialog.h - qlofardatamodel.h - redistributetasksdialog.h - sasconnectdialog.h - sasprogressdialog.h - sasstatusdialog.h - sasuploaddialog.h - schedulergui.h - Scheduler.h - schedulesettingsdialog.h - scheduletabledelegate.h - shifttasksdialog.h - signalhandler.h - SpinBox.h - statehistorydialog.h - stationlistwidget.h - stationtreewidget.h - tablecolumnselectdialog.h - tableview.h - taskcopydialog.h - taskdialog.h - thrashbin.h - tiedarraybeamdialog.h - TimeEdit.h) - -set(scheduler_UIS - conflictdialog.ui - dataslotdialog.ui - digitalbeamdialog.ui - graphicstoragescene.ui - parsettreeviewer.ui - publishdialog.ui - redistributetasksdialog.ui - sasconnectdialog.ui - sasprogressdialog.ui - sasstatusdialog.ui - sasuploaddialog.ui - schedulergui.ui - schedulesettingsdialog.ui - shifttasksdialog.ui - statehistorydialog.ui - stationlistwidget.ui - stationtreewidget.ui - tablecolumnselectdialog.ui - taskcopydialog.ui - taskdialog.ui - thrashbin.ui - tiedarraybeamdialog.ui) - -set(scheduler_RCS - scheduler_resources.qrc) - -qt4_wrap_cpp(scheduler_MOC_SRCS ${scheduler_MOC_HDRS}) -qt4_wrap_ui(scheduler_UI_HDRS ${scheduler_UIS}) -qt4_add_resources(scheduler_RC_SRCS ${scheduler_RCS}) - -lofar_add_library(lofar_scheduler - ${scheduler_SRCS} - ${scheduler_MOC_SRCS} - ${scheduler_UI_HDRS}) - -target_link_libraries(lofar_scheduler ${QT_LIBRARIES}) - -lofar_add_bin_program(scheduler - main.cpp - ${scheduler_RC_SRCS}) - diff --git a/SAS/Scheduler/src/CMakeLists.txt.build_without_lofar_cmake b/SAS/Scheduler/src/CMakeLists.txt.build_without_lofar_cmake deleted file mode 100644 index a78e14a803643e2f92f61bd59783cb1ee9dcd4b3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/CMakeLists.txt.build_without_lofar_cmake +++ /dev/null @@ -1,123 +0,0 @@ -cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR) - -project(Scheduler) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(CMAKE_VERSION VERSION_LESS "3.7.0") - set(CMAKE_INCLUDE_CURRENT_DIR ON) -endif() - -find_package(Qt5 COMPONENTS Core Sql Widgets Gui REQUIRED) - -include_directories(AFTER .) - -add_library(LOFAR_Scheduler - Angle.cpp - astrodate.cpp - astrodatetime.cpp - astrotime.cpp - blocksize.cpp - calibrationpipeline.cpp - CheckBox.cpp - ComboBox.cpp - conflictdialog.cpp - Controller.cpp - DataHandler.cpp - DataMonitorConnection.cpp - dataslotdialog.cpp - DataTreeWidgetItem.cpp - DateEdit.cpp - DateTimeEdit.cpp - debug_lofar.cpp - demixingsettings.cpp - DigitalBeam.cpp - digitalbeamdialog.cpp - doublespinbox.cpp - FileUtils.cpp - GraphicCurrentTimeLine.cpp - GraphicResourceScene.cpp - GraphicStationTaskLine.cpp - graphicstoragescene.cpp - GraphicStorageTimeLine.cpp - GraphicTask.cpp - GraphicTimeLine.cpp - imagingpipeline.cpp - LineEdit.cpp - ListWidget.cpp - lofar_utils.cpp - longbaselinepipeline.cpp - neighboursolution.cpp - observation.cpp - OTDBnode.cpp - OTDBtree.cpp - parsettreeviewer.cpp - pipeline.cpp - publishdialog.cpp - pulsarpipeline.cpp - qlofardatamodel.cpp - redistributetasksdialog.cpp - sasconnectdialog.cpp - SASConnection.cpp - sasprogressdialog.cpp - sasstatusdialog.cpp - sasuploaddialog.cpp - Scheduler.cpp - schedulerdatablock.cpp - schedulerdata.cpp - schedulergui.cpp - schedulerLib.cpp - schedulersettings.cpp - schedulesettingsdialog.cpp - scheduletabledelegate.cpp - shifttasksdialog.cpp - signalhandler.cpp - SpinBox.cpp - statehistorydialog.cpp - station.cpp - stationlistwidget.cpp - stationtask.cpp - stationtreewidget.cpp - Storage.cpp - StorageNode.cpp - tablecolumnselectdialog.cpp - tableview.cpp - taskcopydialog.cpp - task.cpp - taskdialog.cpp - taskstorage.cpp - thrashbin.cpp - TiedArrayBeam.cpp - tiedarraybeamdialog.cpp - TimeEdit.cpp - conflictdialog.ui - dataslotdialog.ui - digitalbeamdialog.ui - graphicstoragescene.ui - parsettreeviewer.ui - publishdialog.ui - redistributetasksdialog.ui - sasconnectdialog.ui - sasprogressdialog.ui - sasstatusdialog.ui - sasuploaddialog.ui - schedulergui.ui - schedulesettingsdialog.ui - shifttasksdialog.ui - statehistorydialog.ui - stationlistwidget.ui - stationtreewidget.ui - tablecolumnselectdialog.ui - taskcopydialog.ui - taskdialog.ui - thrashbin.ui - tiedarraybeamdialog.ui - scheduler_resources.qrc -) - -target_link_libraries(LOFAR_Scheduler Qt::Core Qt::Sql Qt::Gui Qt::Widgets) - -add_executable(scheduler main.cpp) -target_link_libraries(scheduler LOFAR_Scheduler Qt::Core Qt::Sql Qt::Gui Qt::Widgets) diff --git a/SAS/Scheduler/src/CheckBox.cpp b/SAS/Scheduler/src/CheckBox.cpp deleted file mode 100644 index 26663397239976bb344b13eb4e253eba41631ce7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/CheckBox.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * CheckBox.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 16-jun-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/CheckBox.cpp $ - * - */ - -#include "CheckBox.h" - -CheckBox::CheckBox(QWidget *parent) - : QCheckBox(parent) -{ - itsPreviousCheckState = checkState(); -} - -CheckBox::~CheckBox() -{ - -} - -void CheckBox::setCheckState(Qt::CheckState state) { - this->blockSignals(true); - QCheckBox::setCheckState(state); - itsPreviousCheckState = state; - this->blockSignals(false); -} - -void CheckBox::setChecked(bool checked) { - this->blockSignals(true); - setTristate(false); - QCheckBox::setChecked(checked); - itsPreviousCheckState = checkState(); - this->blockSignals(false); -} - - -void CheckBox::setUndefined(bool tristate = true) { - this->blockSignals(true); - if (tristate) { - itsPreviousCheckState = checkState(); - setTristate(true); - } - else { - setTristate(false); - setChecked(itsPreviousCheckState); - } - this->blockSignals(false); -} diff --git a/SAS/Scheduler/src/CheckBox.h b/SAS/Scheduler/src/CheckBox.h deleted file mode 100644 index f1e741db32afad68405efd78c2887928ba903f23..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/CheckBox.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * CheckBox.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 16-jun-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/CheckBox.h $ - * - */ - -#ifndef CHECKBOX_H -#define CHECKBOX_H - -#include "lofar_scheduler.h" -#include <QCheckBox> - -class CheckBox : public QCheckBox -{ - Q_OBJECT - -public: - CheckBox(QWidget *parent = 0); - ~CheckBox(); - - void setCheckState(Qt::CheckState state); - void setChecked(bool checked); - void setUndefined(bool tristate); - inline bool isUndefined(void) {return isTristate();} - bool hasBeenChanged(void) const { - if (itsPreviousCheckState != checkState()) return true; - else if (itsPreviousCheckState == Qt::PartiallyChecked && !isTristate()) return true; - else return false; - } - void resetChangeDetect(void) { itsPreviousCheckState = checkState(); } - -//protected: -// void focusInEvent(QFocusEvent*); -// void focusOutEvent(QFocusEvent*); - -//protected slots: -// void checkValueChange(void); -private: - Qt::CheckState itsPreviousCheckState; -}; - -#endif // CHECKBOX_H diff --git a/SAS/Scheduler/src/ComboBox.cpp b/SAS/Scheduler/src/ComboBox.cpp deleted file mode 100644 index 2d467472a4977361cc0024f155c0d69af6fb9938..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/ComboBox.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ComboBox.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/ComboBox.cpp $ - * - */ - -#include "ComboBox.h" -#include "lofar_scheduler.h" -#include <QFocusEvent> - -ComboBox::ComboBox(QWidget *parent) - : QComboBox(parent), itsUndefined(false) -{ - QObject::connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(checkIndexChange(int))); -} - -ComboBox::~ComboBox() { -} - -void ComboBox::setFromString(const QString &str) { - this->blockSignals(true); - int i(0); - while (i < count()) { - if (itemText(i).compare(str) == 0) { - QComboBox::setCurrentIndex(i); - itsPreviousIndex = currentIndex(); - itsUndefined = false; - if (itemText(count()-1).compare(MULTIPLE_VALUE_TEXT) == 0) { - removeItem(count()-1); - } - this->blockSignals(false); - return; - } - else ++i; - } - this->blockSignals(false); -} - - -void ComboBox::setUndefined(bool enabled, bool removeUndefined) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - if (itemText(count()-1).compare(MULTIPLE_VALUE_TEXT) != 0) { - addItem(MULTIPLE_VALUE_TEXT); - } - QComboBox::setCurrentIndex(count()-1); - itsPreviousIndex = -1; - } - else { - if (removeUndefined) { - if (itemText(count()-1).compare(MULTIPLE_VALUE_TEXT) == 0) { - removeItem(count()-1); - } - } - QComboBox::setCurrentIndex(itsPreviousIndex); - } - this->blockSignals(false); -} - -void ComboBox::focusOutEvent(QFocusEvent* event) -{ - checkIndexChange(currentIndex()); - QComboBox::focusOutEvent(event); -} - -void ComboBox::checkIndexChange(int newIndex) { - if (itsUndefined) { - if (itsPreviousIndex == newIndex) { - blockSignals(true); - QComboBox::setCurrentIndex(count()-1); - blockSignals(false); - } - else { - itsUndefined = false; - } - itsPreviousIndex = currentIndex(); - } -} diff --git a/SAS/Scheduler/src/ComboBox.h b/SAS/Scheduler/src/ComboBox.h deleted file mode 100644 index 568dab8a2f2c366dcc6ef67db4b79081fb223448..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/ComboBox.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ComboBox.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/ComboBox.h $ - * - */ - -#include <QComboBox> -#include <QString> - -#ifndef COMBOBOX_H_ -#define COMBOBOX_H_ - -class ComboBox : public QComboBox { - - Q_OBJECT - -public: - ComboBox(QWidget *parent); - virtual ~ComboBox(); - - void setCurrentIndex(int index, bool removeUndefined = true) { - itsPreviousIndex = index; setUndefined(false, removeUndefined); - } - void setFromString(const QString &t); - void setUndefined(bool enabled = true, bool removeUndefined = true); - bool isUndefined(void) const {return itsUndefined;} - bool hasBeenChanged(void) const { - return ((itsPreviousIndex != -1) && (itsPreviousIndex != currentIndex())); - } // -1 == MIXED, hasBeenChanged should then return false - void resetChangeDetect(void) { itsPreviousIndex = currentIndex(); } - -protected: - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkIndexChange(int); - -private: - bool itsUndefined; - int itsPreviousIndex; -}; - -#endif /* COMBOBOX_H_ */ diff --git a/SAS/Scheduler/src/Controller.cpp b/SAS/Scheduler/src/Controller.cpp deleted file mode 100644 index d3471434a6a213253c43e82a38fb3574db952965..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Controller.cpp +++ /dev/null @@ -1,5677 +0,0 @@ -/* - * Controller.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * First creation : 4-feb-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Controller.cpp $ - * - */ - -//#define HAVE_BOOST - -#include "Controller.h" -#include <iostream> -#include <sstream> -#include <fstream> -#include "lofar_scheduler.h" -#include "schedulergui.h" -#include "Scheduler.h" -#include "schedulersettings.h" -#include "GraphicResourceScene.h" -#include "conflictdialog.h" -#include "taskcopydialog.h" -#include "DigitalBeam.h" -#include "pipeline.h" -#include <QMessageBox> -#include <QDateTime> -#include <QString> -#include <string> -#include <vector> -#include <cmath> -#include <limits> -#ifdef HAS_SAS_CONNECTION -#include "SASConnection.h" -#endif -#include "DataMonitorConnection.h" - -extern QString currentUser; - -using std::string; -using std::cout; -using std::endl; -using std::vector; -using std::pair; - -#define STORE_UNDO false -#define STORE_REDO true - -SchedulerSettings Controller::theSchedulerSettings = SchedulerSettings(); -unsigned Controller::itsFileVersion = 0; - -Controller::Controller(QApplication &app) : - possiblySaveMessageBox(0), application(&app), gui(0), - itsSettingsDialog(0), itsConflictDialog(0) -{ - itsAutoPublishAllowed = currentUser == "lofarsys" ? true : false; -#if defined Q_OS_WINDOWS || _DEBUG_ - itsAutoPublishAllowed = true; -#endif - theSchedulerSettings.setAutoPublish(itsAutoPublishAllowed); - - Controller::theSchedulerSettings.setController(this); - - gui = new SchedulerGUI(this); - itsSettingsDialog = new ScheduleSettingsDialog(this); - itsConflictDialog = new ConflictDialog(this); -#ifdef HAS_SAS_CONNECTION - itsSASConnection = new SASConnection(this); - itsSASConnection->setLastDownloadDate(QDateTime(Controller::theSchedulerSettings.getEarliestSchedulingDay().toQDate())); -#endif - // connection to the Data Monitor - itsDMConnection = new DataMonitorConnection(this); - itsDataHandler = new DataHandler(this); - itsDataHandler->setFileName(""); - loadProgramPreferences(); - connectSignals(); - vector<std::string> headers; - for (unsigned i = 0; i < NR_DATA_HEADERS; ++i) { - headers.push_back(std::string(DATA_HEADERS[i])); - } - data.setDataHeaders(headers); - gui->newTable(data); - gui->setEnableScheduleMenuItems(true); - gui->setEnableTaskListMenuItems(true); -// gui->setExistingProjects(theSchedulerSettings.getCampaignList()); - scheduler.setData(data); -} - -Controller::~Controller() { - if (itsSettingsDialog) delete itsSettingsDialog; - if (itsConflictDialog) delete itsConflictDialog; - if (itsSASConnection) delete itsSASConnection; - if (itsDMConnection) delete itsDMConnection; - if (gui) delete gui; - if (itsDataHandler) delete itsDataHandler; - - if (possiblySaveMessageBox) delete possiblySaveMessageBox; -} - -#ifdef DEBUG_SCHEDULER - void Controller::printSelectedTasks(const std::string &callerName) const { - std::cout << callerName << ", currently selected tasks:" << std::endl; - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - std::cout << *it << ","; - } - std::cout << std::endl; - } - -#endif - -void Controller::setSaveRequired(bool save_required) { - if (save_required) { - data.setChangesMadeFlag(); - } - else { - data.clearChangesMadeFlag(); - data.clearUploadRequiredFlag(); - } - gui->setSaveRequired(save_required); -} - -void Controller::loadProgramPreferences(void) { - if (itsDataHandler->loadProgramPreferences()) { - if (Controller::theSchedulerSettings.getLoadDefaultSettingsOnStartUp()) { - updateGUIafterSettingsLoad(); - } - } -} - -void Controller::connectSignals(void) -{ -//#if defined Q_OS_WIN || _DEBUG_ - gui->connect(gui->getSchedulerGUIClass().action_Save_default_settings, SIGNAL(triggered()), this, SLOT(saveDefaultSettings())); - gui->getSchedulerGUIClass().action_Save_default_settings->setEnabled(true); -//#else -// gui->getSchedulerGUIClass().action_Save_default_settings->setEnabled(false); -//#endif - - // subscribe to signals from the gui-> - gui->connect(gui->getSchedulerGUIClass().action_New_schedule, SIGNAL(triggered()), this, SLOT(newSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_Save_schedule, SIGNAL(triggered()), this, SLOT(saveSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_Save_schedule_as, SIGNAL(triggered()), this, SLOT(saveScheduleAs())); - gui->connect(gui->getSchedulerGUIClass().action_Open_Schedule, SIGNAL(triggered()), this, SLOT(openSchedule())); -// gui->connect(gui->getSchedulerGUIClass().action_Open_task_list, SIGNAL(triggered()), this, SLOT(openTaskList())); - gui->connect(gui->getSchedulerGUIClass().action_Save_task_list, SIGNAL(triggered()), this, SLOT(saveTaskListAs())); - gui->connect(gui->getSchedulerGUIClass().action_Close_schedule, SIGNAL(triggered()), this, SLOT(closeSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_Create_initial_schedule, SIGNAL(triggered()), this, SLOT(createInitialSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_Optimize_schedule, SIGNAL(triggered()), this, SLOT(optimizeSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_Schedule_Settings, SIGNAL(triggered()), this, SLOT(openSettingsDialog())); - gui->connect(gui->getSchedulerGUIClass().action_Save_settings, SIGNAL(triggered()), this, SLOT(saveSettings())); - gui->connect(gui->getSchedulerGUIClass().action_Load_settings, SIGNAL(triggered()), this, SLOT(loadSettings())); - gui->connect(gui->getSchedulerGUIClass().actionLoad_default_settings, SIGNAL(triggered()), this, SLOT(loadDefaultSettings())); - gui->connect(gui->getSchedulerGUIClass().action_Balance_schedule, SIGNAL(triggered()), this, SLOT(balanceSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_Quit, SIGNAL(triggered()), this, SLOT(quit())); - gui->connect(gui->getSchedulerGUIClass().action_Assign_resources, SIGNAL(triggered()), this, SLOT(assignResources())); - gui->connect(gui, SIGNAL(quitApp()), this, SLOT(quit())); - gui->connect(gui, SIGNAL(tableSortChanged()), this, SLOT(tableSortingChanged())); - gui->connect(gui->getSchedulerGUIClass().action_Add_task, SIGNAL(triggered()), this, SLOT(addTask())); -// gui->connect(gui->getSchedulerGUIClass().action_Add_reservation, SIGNAL(triggered()), this, SLOT(addReservation())); - gui->connect(gui->getSchedulerGUIClass().action_Delete_task, SIGNAL(triggered()), this, SLOT(deleteSelectedTasks())); - gui->connect(gui->getSchedulerGUIClass().action_Undo, SIGNAL(triggered()), this, SLOT(undo())); - gui->connect(gui->getSchedulerGUIClass().action_Redo, SIGNAL(triggered()), this, SLOT(redo())); - gui->connect(gui->getTableDelegate(), SIGNAL(tableItemChanged(unsigned, data_headers, const QVariant &, const QModelIndex &)), this, SLOT(applyTableItemChange(unsigned, data_headers, const QVariant &, const QModelIndex &))); - gui->connect(itsSettingsDialog, SIGNAL(actionSaveSettings()), this, SLOT(closeSettingsDialog())); - scheduler.connect(&scheduler, SIGNAL(optimizeIterationFinished(unsigned)), this, SLOT(updateStatusBarOptimize(unsigned))); -// gui->scene()->connect(gui->scene(), SIGNAL(taskRescheduleRequest(unsigned, AstroDateTime, bool)), this, SLOT(moveTaskRequest(unsigned, const AstroDateTime &))); -// gui->taskDialog()->connect(gui->taskDialog(), SIGNAL(taskChanged(Task &, bool)), this, SLOT(updateTask(Task &, bool))); -// gui->taskDialog()->connect(gui->taskDialog(), SIGNAL(abortTask(unsigned int)), this, SLOT(abortTask(unsigned int))); -// gui->taskDialog()->connect(gui->taskDialog(), SIGNAL(addNewTask(const Task &)), this, SLOT(createTask(const Task &))); -// gui->taskDialog()->connect(gui->taskDialog(), SIGNAL(addNewReservation(const Task &)), this, SLOT(createReservation(const Task &))); -// gui->taskDialog()->connect(gui->taskDialog(), SIGNAL(checkPredecessor(unsigned)), this, SLOT(checkPredecessor(unsigned))); -// gui->connect(gui->getSchedulerGUIClass().action_Align_left, SIGNAL(triggered()), this, SLOT(alignLeft())); -// thrash bin connections - gui->connect(gui->getSchedulerGUIClass().action_Thrashcan, SIGNAL(triggered()), this, SLOT(showThrashBin())); - itsThrashBin.connect(&itsThrashBin, SIGNAL(restoreTasksRequest(const std::vector<unsigned> &)), this, SLOT(restoreTasks(const std::vector<unsigned> &))); - itsThrashBin.connect(&itsThrashBin, SIGNAL(thrashBinIsEmpty()), this, SLOT(thrashBinEmpty())); - itsThrashBin.connect(&itsThrashBin, SIGNAL(thrashBinContainsItems()), this, SLOT(thrashBinNotEmpty())); - itsThrashBin.connect(&itsThrashBin, SIGNAL(destroyTasks(std::vector<unsigned>)), this, SLOT(doDestroyTasks(std::vector<unsigned>))); - -#ifdef HAS_SAS_CONNECTION - gui->connect(gui->getSchedulerGUIClass().action_DownloadSASSchedule, SIGNAL(triggered()), this, SLOT(downloadSASSchedule())); - gui->connect(gui->getSchedulerGUIClass().action_SyncSASSchedule, SIGNAL(triggered()), this, SLOT(InitSynchronizeSASSchedule())); - gui->connect(gui->getSchedulerGUIClass().actionCheck_SAS_status, SIGNAL(triggered()), this, SLOT(checkSASStatus())); -#endif - -} - -const AstroDateTime &Controller::now(void) { - QDateTime currentTime = QDateTime::currentDateTimeUtc(); - itsTimeNow = AstroDateTime(currentTime.date().day(), currentTime.date().month(), currentTime.date().year(), - currentTime.time().hour(), currentTime.time().minute(), currentTime.time().second()); - return itsTimeNow; -} - -#ifdef HAS_SAS_CONNECTION - -void Controller::checkSASStatus(void) const { - itsSASConnection->checkSASStatus(); -} - -void Controller::setSASConnectionSettings(const QString &username, const QString &password, const QString &DBname, const QString &hostname) { - Controller::theSchedulerSettings.setSASConnectionSettings(username, password, DBname, hostname); -} - - -void Controller::downloadSASSchedule(void) { - //TODO: when downloading the running schedule we discard the data that is possibly in the scheduler already. - // ask the user (if there are tasks in the schedule) if he wants to proceed and discard these. - // Next question: which schedule settings to use? (time span of schedule, which stations are defined? etc) - // Answers: scheduler settings: use the settings that are already loaded into the scheduler - // if tasks from SAS contain stations that are not defined, then these tasks will be unscheduled and marked with an error. - // we have to run checkTasks() to look for possible errors in the downloaded tasks. - if (data.getUploadRequired()) { - if (QMessageBox::question(0, tr("Confirm discard changes"), - tr("Changes were made to the schedule. By downloading the schedule again those changes will be discarded.\nDo you want to continue with the download?"), - QMessageBox::Ok, - QMessageBox::Cancel) == QMessageBox::Cancel) { - return; - } - } - storeScheduleUndo(QObject::tr("Download SAS schedule")); - if (checkSASSettings()) { - gui->setStatusText("Now downloading running schedule from SAS..."); - itsSASConnection->init(theSchedulerSettings.getSASUserName(), - theSchedulerSettings.getSASPassword(), - theSchedulerSettings.getSASDatabase(), - theSchedulerSettings.getSASHostName()); -// itsSASConnection.init("postgres", "", "jong", "127.0.0.1"); - int result = itsSASConnection->connect(); - if (result == 0) { - // clear the current schedule - cleanup(true); -// usedTaskIDs = itsSASConnection->getUsedSASTaskIDs(); // we have to do this before any task is created or downloaded - if (itsSASConnection->downloadAllSASTasks()) { // this will call mergeDownloadedSASTasks -// data.setSASUsedTaskIDs(itsSASConnection->getUsedSASTaskIDs()); - gui->setStatusText("Download of running schedule from SAS completed"); - } - } - else if (result == -1) { - deleteLastStoredUndo(); - QApplication::beep(); - QMessageBox::critical(0, tr("No connection to SAS"), - tr("Could not connect to SAS database.\nPlease check SAS connection settings.\n\nError:") + itsSASConnection->lastConnectionError()); - - gui->setStatusText("Error: Could not connect to SAS"); - } - else if (result == -2) { - deleteLastStoredUndo(); - QApplication::beep(); - QMessageBox::warning(0, tr("No write permissions to SAS database"), - tr("You don't have write permissions to the SAS database.\n Please check the SAS user name and password")); - gui->setStatusText("Error: No write permissions to SAS database"); - } - } -} - -void Controller::autoPublish(void) { - std::pair<AstroDate, AstroDate> publishRange(itsSASConnection->getUploadedDateRange()); - if (publishRange.first.isSet()) { - const AstroDate &today(itsTimeNow.date()); - if (publishRange.first < today) publishRange.first = today; // don't auto publish the past - - unsigned day = publishRange.first.getDayOfTheWeek(); - AstroDate monday = publishRange.first.subtractDays(day); // monday of current week - scheduleWeekVector publishWeeks; - publishWeeks.push_back(std::pair<unsigned, AstroDate>(monday.getWeek(), monday)); - - while (publishRange.second >= monday.addDays(7)) { - monday = monday.addDays(7); // next week has to be included in publish - publishWeeks.push_back(std::pair<unsigned, AstroDate>(monday.getWeek(), monday)); - } - - QStringList weekNrStr; - for (scheduleWeekVector::const_iterator pit = publishWeeks.begin(); pit != publishWeeks.end(); ++pit) { - weekNrStr += QString::number(pit->first); - } - itsSASConnection->progressDialog().addText("Publishing week numbers:" + weekNrStr.join(QChar(','))); - gui->publish(publishWeeks); - } -} - -void Controller::InitSynchronizeSASSchedule(void) { - if ((data.getNrTasks() > 0) || (itsSASConnection->nrTaskToDeleteFromSAS())) { - int result; - if (checkSASSettings()) { - gui->setStatusText("Now synchronizing schedule with SAS..."); - itsSASConnection->showProgressUploadDialog(); - itsSASConnection->progressDialog().addText("Checking and assigning resources..."); - result = assignResources(false); - if (result == 0) { // resource assignment went ok - itsSASConnection->progressDialog().addText("Resource assignment OK."); - result = itsSASConnection->connect(); - if (result == 0) { - // initialize the upload to SAS dialog - itsSASConnection->startSynchronizeProcedure(data); - } - else if (result == -1) { // could not connect to SAS database - QApplication::beep(); - QString errStr(tr("Could not connect to SAS database.\nPlease check SAS connection settings.\n") + - tr("host:") + theSchedulerSettings.getSASHostName() + tr(", database:") + theSchedulerSettings.getSASDatabase() + tr(", username:") + theSchedulerSettings.getSASUserName() + - "\nError:" + itsSASConnection->lastConnectionError()); - QMessageBox::critical(0, tr("No connection to SAS"), errStr); - itsSASConnection->progressDialog().addError(errStr); - itsSASConnection->progressDialog().enableClose(); - gui->setStatusText("Error: Could not connect to SAS"); - } - else if (result == -2) { - QApplication::beep(); - QMessageBox::warning(0, tr("No write permissions to SAS database"), - tr("You don't have write permissions to the SAS database.\n Please check the SAS user name and password")); - gui->setStatusText("Error: No write permissions to SAS database"); - } - } - else { - itsSASConnection->closeProgressUploadDialog(); - gui->clearStatusText(); - } - } - } - else { - QMessageBox::warning(0, tr("Empty schedule cannot be uploaded"), tr("The schedule doesn't contain any tasks.\nAn empty schedule cannot be uploaded to SAS.")); - } -} - -void Controller::commitScheduleToSAS(void) { - if (itsSASConnection->commitScheduleToSAS(data)) { - // auto publish - if (itsSASConnection->autoPublish()) { - itsSASConnection->progressDialog().addText("Now starting the automatic publish of the schedule to the web-server"); - autoPublish(); - } - - data.clearUploadRequiredFlag(); - cleanup(true, false); - mergeDownloadedSASTasks(); - gui->setStatusText(tr("schedule was successfully uploaded to SAS database")); - itsSASConnection->addProgressInfo(tr("The new schedule was successfully uploaded to the SAS database")); - } - else { - gui->setStatusText(tr("Error Uploading schedule to SAS")); - QMessageBox::critical(0, tr("Error uploading schedule to SAS"), tr("The schedule could not correctly be uploaded to the SAS database")); - } - gui->writeTableData(data); -} - -// ask user if he wants to overwrite existing tasks -// arguments to this function will be set according to the answers -// return value is true when user wants to continue, false if cancel was clicked -bool Controller::askOverWriteExistingTask(bool &overwrite, bool &forAll, unsigned taskID, const QString &taskName) { - QMessageBox questionBox(QMessageBox::Question,tr("Confirm overwrite existing task"),"Task " + QString::number(taskID) + - ", '" + taskName +"' already exist.\nDo you want to overwrite this task?"); - QAbstractButton *overWriteButton = questionBox.addButton(tr("Overwrite"), QMessageBox::ActionRole); - QAbstractButton *overWriteAllButton = questionBox.addButton(tr("Overwrite all"), QMessageBox::ActionRole); - QAbstractButton *keepButton = questionBox.addButton(tr("Keep current"), QMessageBox::ActionRole); - QAbstractButton *keepAllButton = questionBox.addButton(tr("Keep all"), QMessageBox::ActionRole); - QAbstractButton *CancelDownloadButton = questionBox.addButton(tr("Cancel Download"), QMessageBox::ActionRole); - questionBox.exec(); - if (questionBox.clickedButton() == overWriteButton) { - overwrite = true; - forAll = false; - return true; - } - else if (questionBox.clickedButton() == overWriteAllButton) { - overwrite = true; - forAll = true; - return true; - } - else if (questionBox.clickedButton() == keepButton) { - overwrite = false; - forAll = false; - return true; - } - else if (questionBox.clickedButton() == keepAllButton) { - overwrite = false; - forAll = true; - return true; - } - else if (questionBox.clickedButton() == CancelDownloadButton) { - return false; - } - return false; -} - - -void Controller::mergeDownloadedSASTasks(void) { - const SAStasks &sasTasks = itsSASConnection->SASTasks(); - Task::task_status status; - vector<Task *> newPipelines; - - unsigned taskID; - for (SAStasks::const_iterator it = sasTasks.begin(); it != sasTasks.end(); ++it) { - taskID = it->second->getID(); - Task *pTask(0); - Observation *pObs = dynamic_cast<Observation *>(it->second); - StationTask *pStat(0); - Pipeline *pPipe(0); - if (pObs) { - pTask = data.newObservation(taskID, OVERRIDE_SAS_TASKIDS); - pTask->clone(pObs); // clones the properties from pObs into the newly created observation pointed to by pTask - pTask->calculateDataFiles(); - } - else if ((pStat = dynamic_cast<StationTask *>(it->second))) { - pTask = data.newReservation(taskID, OVERRIDE_SAS_TASKIDS); - pTask->clone(pStat); - } - else if ((pPipe = dynamic_cast<Pipeline *>(it->second))) { - pTask = data.newPipeline(taskID, pPipe->pipelinetype(), OVERRIDE_SAS_TASKIDS); - pTask->clone(pPipe); - newPipelines.push_back(pTask); - } - else { - debugWarn("sis", "Controller::mergeDownloadedSASTasks: task:", taskID, " is of unknown type. Skipping."); - continue; - } - - if (pTask) { - // copy all properties from itsSasTasks -// *pTask = *it->second; - // pTask->setID(taskID); // set the ID again to the ID of the newly created task - status = pTask->getStatus(); - - if ((status == Task::SCHEDULED) || (status == Task::PRESCHEDULED)) { - if (pTask->isStationTask()) { - if (data.checkStationConflicts(static_cast<StationTask *>(pTask))) { - if (data.scheduleTask(pTask)) { - pTask->setStatus(status); - } - } - else { // there is a conflict of stations in use - pTask->setStatus(Task::CONFLICT); - } - } - else { - if (data.scheduleTask(pTask)) { - pTask->setStatus(status); - } - } - } - else if ((status >= Task::STARTING) && (status <= Task::COMPLETING)) { - if (data.scheduleTask(pTask)) { - pTask->setStatus(status); - } - } - else if (status >= Task::FINISHED) { - data.moveTaskToInactive(pTask->getID()); - } - } - } - - // go by all pipelines to update their input files, because these are dependent on other tasks - for (std::vector<Task *>::const_iterator nit = newPipelines.begin(); nit != newPipelines.end(); ++nit) { - setInputFilesForPipeline(*nit); - static_cast<Pipeline *>(*nit)->calculateDataFiles(); - } - - data.checkStatusChanges(); // check all task in the scheduler for status changes and moves the tasks to the correct map - if (!data.checkTasksForErrors()) { - itsSASConnection->addProgressError("Errors were detected in some of the downloaded tasks. Please check and correct were necessary."); - } - updateGraphicTasks(); - gui->writeTableData(data); - gui->updateProjectsFilter(Controller::theSchedulerSettings.getCampaignList()); - updateStatusBar(); - setSaveRequired(true); - data.clearUploadRequiredFlag(); -} - - -bool Controller::checkSASSettings(void) { - if (theSchedulerSettings.getSASUserName().isEmpty()) { - QMessageBox::critical(0, tr("SAS user name not specified"), - tr("SAS user name is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - else if (theSchedulerSettings.getSASPassword().isEmpty()) { - QMessageBox::critical(0, tr("SAS password not set"), - tr("SAS password is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - else if (theSchedulerSettings.getSASDatabase().isEmpty()) { - QMessageBox::critical(0, tr("SAS database name not specified"), - tr("SAS database name is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - else if (theSchedulerSettings.getSASHostName().isEmpty()) { - QMessageBox::critical(0, tr("SAS host name not specified"), - tr("SAS host name is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - - return true; -} - -int Controller::checkSASconnection(const QString &username, const QString &password, const QString &DBname, const QString &hostname) { - return itsSASConnection->testConnect(username, password, DBname, hostname); -} - -QString Controller::lastSASError(void) const { - return itsSASConnection->lastConnectionError(); -} - -#endif // HAS_SAS_CONNECTION -/* -void Controller::checkPredecessor(unsigned predecessor_id) const { - if (data.predecessorExists(predecessor_id)) { - gui->taskDialog()->updatePredecessor(true); - } - else { - gui->taskDialog()->updatePredecessor(false); - } -} -*/ -void Controller::newSchedule(void) { - if (closeSchedule()) { - gui->newTable(data); - gui->setEnableScheduleMenuItems(true); - itsDataHandler->setFileName(""); - } -} - -void Controller::balanceSchedule(void) { - QMessageBox::warning(0, tr("Function not implemented"), - tr("Balance schedule function not yet implemented")); - return; - - if (data.getNrTasks()) { - // TODO: implement balance schedule - - - } - else { - QMessageBox::warning(gui, tr("No tasks defined"), - tr("There are no tasks defined. Cannot balance an empty schedule."),tr("Close")); - } -} - -void Controller::addTask(void) { -// unsigned newTaskID = data.getNewTaskID(); -// storeTaskUndo(newTaskID, QString("Add task ") + QString::number(newTaskID), true); // when second argument is set to true it means, when undo is applied delete the task - gui->addTaskDialog(data.getNewTaskID()); -} - -//void Controller::addReservation(void) { -// gui->addReservationDialog(data.getNewTaskID()); -//} - - -// createTask return value: 0 - task created, -1 task not created, 1 task created but has conflict/error -bool Controller::createTask(const Task &task) { - bool bResult(true); - unsigned task_id(task.getID()); - Task::task_status status = task.getStatus(); - Task *new_task = cloneTask(&task); - if (new_task) { - // predecessor existence checks - if (task.hasPredecessors()) { - const IDvector &predecessors(task.getPredecessors()); - for (IDvector::const_iterator prit = predecessors.begin(); prit != predecessors.end(); ++prit) { - if (getTask(prit->second, prit->first) == 0) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task has non existing predecessors")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText("The task has non-existing predecessors\nThe task cannot be created before this error is resolved"); - warningBox.exec(); - bResult = false; - } - } - } - if (bResult && (status == Task::SCHEDULED || status == Task::PRESCHEDULED)) { -// do (PRE)SCHEDULE checks - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(new_task); - if (errCode.first >= SCHEDULED_TOO_EARLY) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task has critical problems")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be created before this problem is resolved"); - warningBox.exec(); - bResult = false; - } - else { - if (errCode.first == USER_WARNING) { - if (QMessageBox::question(gui, tr("Warning"), - errCode.second + "\nDo you want to continue?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - bResult = false; - } - } - } - } - itsSelectedTasks.clear(); - itsSelectedTasks.push_back(task_id); - gui->selectRows(itsSelectedTasks); - } - else { // could not clone task - bResult = false; - } - - if (bResult) { - storeTaskUndo(task_id, QString("Add task ") + QString::number(task_id), true); // when second argument is set to true it means, when undo is applied delete the task - setSaveRequired(true); - data.addTask(new_task, false); - if (status == Task::SCHEDULED) { - if (doScheduleChecks(new_task)) { - data.scheduleTask(new_task); - } - } - else { // PRESCHEDULED - data.scheduleTask(new_task); - new_task->setStatus(Task::PRESCHEDULED); - } - gui->addTask(new_task); - updateStatusBar(); - } - - return bResult; -} - -bool Controller::createReservation(const Task *reservation) { - int reservation_id = reservation->getID(); - Task *new_reservation = data.newReservation(reservation_id); - if (new_reservation) { - storeTaskUndo(reservation_id, QString("Add reservation ") + QString::number(reservation_id), true); // when second argument is set to true it means, when undo is applied delete the reservation - setSaveRequired(true); - *new_reservation = *reservation; - data.addUsedTaskID(reservation_id); - - Task::task_status status = reservation->getStatus(); - if (status == Task::SCHEDULED || status == Task::PRESCHEDULED) { -// do (PRE)SCHEDULE checks - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(new_reservation); - if (errCode.first == TASK_CONFLICT) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Reservation has conflicts with other tasks")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe reservation cannot be created before this error/conflict is resolved"); - warningBox.exec(); - data.deleteTask(new_reservation->getID()); - deleteLastStoredUndo(); - return false; - } - else { - if (status == Task::SCHEDULED) { - if (doScheduleChecks(new_reservation)) { - data.scheduleTask(new_reservation); - } - } - else { // PRESCHEDULED - data.scheduleTask(new_reservation); - new_reservation->setStatus(Task::PRESCHEDULED); - } - gui->addTask(new_reservation); - updateStatusBar(); - } - } - itsSelectedTasks.clear(); - itsSelectedTasks.push_back(reservation_id); - gui->selectRows(itsSelectedTasks); - return true; - } - - return false; -} - -void Controller::createPipeline(const Pipeline *pipeline) { - Task *pTask = cloneTask(pipeline); - data.addTask(pTask,false); - unsigned task_id(pTask->getID()); - storeTaskUndo(task_id, QString("Add Pipeline ") + QString::number(task_id), true); // when second argument is set to true it means, when undo is applied delete the pipeline - setSaveRequired(true); - gui->addTask(pTask); - updateStatusBar(); - itsSelectedTasks.clear(); - itsSelectedTasks.push_back(task_id); - gui->selectRows(itsSelectedTasks); -} - -// expungeTask: deletes a task from the scheduler without undo and without it being added to the deletedTasks list -// used by SASconnection when a task was externally deleted from SAS -void Controller::expungeTask(unsigned treeID) { - const Task *pTask(data.getTask(treeID, ID_SAS)); - if (pTask) { - unsigned taskID(pTask->getID()); - gui->deleteTaskFromGUI(taskID); - data.deleteTask(taskID); - updateStatusBar(); - } -} - -// deletes a single task -void Controller::deleteTask(unsigned taskID) { - Task *delTask(data.deleteTask(taskID, ID_SCHEDULER, false)); - - if (delTask) { - QString undo_text = "Delete task " + QString::number(taskID); - itsUndoType.push_back(undoTypeVector::value_type(UNDO_DELETE_TASKS, std::pair<QString, vector<unsigned> >(undo_text, itsSelectedTasks ))); - gui->addUndo(undo_text); - - vector<Task *> deletedTasks; - deletedTasks.push_back(delTask); - gui->deleteTaskFromGUI(taskID); - - int treeID(delTask->getSASTreeID()); - if (treeID) - itsSASConnection->addToTreesToDelete(treeID, taskID); - - itsThrashBin.addTasks(deletedTasks); - itsDeletedTasks.push_back(deletedTasks); - gui->setFullThrashIcon(); - clearRedoStack(); - //set status string - gui->setStatusText(QString("Deleted task " + QString::number(taskID))); - updateStatusBar(); - itsSelectedTasks.clear(); - setSaveRequired(true); - } -} - - -// deletes selected tasks -void Controller::deleteSelectedTasks(void) { - if (!itsSelectedTasks.empty()) { - if (QMessageBox::question(0, tr("Delete task(s)"), - tr("Are you sure you want to delete the selected task(s)?"), - QMessageBox::Ok, - QMessageBox::Cancel) == QMessageBox::Ok) { - if (itsSelectedTasks.size() == 1) { - QString undo_text = "Delete task " + QString::number(itsSelectedTasks.front()); - itsUndoType.push_back(undoTypeVector::value_type(UNDO_DELETE_TASKS, - std::pair<QString, vector<unsigned> > - (undo_text, itsSelectedTasks ))); - gui->addUndo(undo_text); - - } - else { - QString taskIDs; - for (vector<unsigned>::iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - taskIDs.append(QString::number(*it) + ","); - } - taskIDs.remove(taskIDs.length()-1,1); // removes the last comma - QString undo_text = "Delete tasks " + taskIDs; - // itsUndoType.push_back(std::pair<undo_type, QString>(UNDO_DELETE_TASKS, undo_text)); - itsUndoType.push_back(undoTypeVector::value_type(UNDO_DELETE_TASKS, - std::pair<QString, vector<unsigned> > - (undo_text, itsSelectedTasks ))); - - gui->addUndo(undo_text); - } - vector<Task *> deletedTasks; - unsigned treeID; - - // *** CAUTION ! *** - // have to block signals from GUI otherwise it will send signals when deleting graphicTasks from its view, - // (i.e. it will generate signal selectionChanged which in turn is coupled to SLOT graphicResourceScene::handleRubberBandSelection() - // which will indirectly alter (clear) the selection from the Controller while the following FOR loop is still active - gui->scene()->blockSignals(true); - for (vector<unsigned>::iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { // do the actual deletion - Task *delTask(data.deleteTask(*it, ID_SCHEDULER, false)); - if (delTask) { - deletedTasks.push_back(delTask); - treeID = delTask->getSASTreeID(); - if (treeID) { - itsSASConnection->addToTreesToDelete(treeID, *it); - } - gui->deleteTaskFromGUI(*it); // will cause signals to be generated if we don't block them (see remark just before FOR loop) - } - } - gui->scene()->blockSignals(false); - - if (!deletedTasks.empty()) { - itsThrashBin.addTasks(deletedTasks); - itsDeletedTasks.push_back(deletedTasks); - gui->setFullThrashIcon(); - } - clearRedoStack(); - //set status string - std::string statStr = "Deleted "; - statStr += int2String(itsSelectedTasks.size()) += " task(s)"; - gui->setStatusText(statStr.c_str()); - updateStatusBar(); - itsSelectedTasks.clear(); - setSaveRequired(true); - } - } -} - -void Controller::restoreTasks(const vector<unsigned> &tasksToRestore) { - vector<unsigned> success; - for (vector<unsigned>::const_iterator it = tasksToRestore.begin(); it != tasksToRestore.end(); ++it) { - if (unDelete(*it)) { - success.push_back(*it); - } - } - if (!success.empty()) { - itsThrashBin.removeRestoredTasks(success); - } - updateStatusBar(); -} - -void Controller::openMoveTasksDialog(void) { - gui->openMoveTasksDialog(); -} - -void Controller::moveSelectedTasksRequest(unsigned task_id, const AstroDateTime &new_start_time) { - const Task *pTask(data.getTask(task_id)); - AstroTime shift = pTask->getScheduledStart().timeDifference(new_start_time); - moveType typeOfMove = new_start_time < pTask->getScheduledStart() ? MOVE_LEFT : MOVE_RIGHT; - moveSelectedTasks(shift, typeOfMove); -} - -bool Controller::moveTasks(const std::map<unsigned, AstroDateTime> &startTimes) { - storeScheduleUndo("Moving task(s)"); - std::map<unsigned, std::pair<Task *, Task::task_status> > movedTasks; - std::vector<const Task *> updateTableTasks; - std::vector<unsigned> updateGraphicTasks; - - // unschedule all tasks that are going to be moved so that they don't conflict with each other when doing the move - // check the status of all tasks to be moved if above PRESCHEDULED then abort the move - for (std::map<unsigned, AstroDateTime>::const_iterator it = startTimes.begin(); it != startTimes.end(); ++it) { - Task *pTask(data.getTaskForChange(it->first)); - if (pTask) { - updateTableTasks.push_back(pTask); - if (pTask->getStatus() <= Task::PRESCHEDULED) { - movedTasks[it->first] = std::pair<Task *, Task::task_status>(pTask, pTask->getStatus()); - data.unscheduleTask(it->first); - } - else { - // status higher than PRESCHEDULED -> abort move - undo(false); - return false; - } - } - } - // try to move the tasks (one by one) - // if the task that is going to be moved has status PRESCHEDULED then check if moveTask returns conflicting tasks, if yes then abort the move and undo - // if no conflicting tasks were returned for this task move then directly schedule the task at the new time - // if the task has state lower than PRESCHEDULED (e.g. UNSCHEDULED) then the conflicting tasks returned by moveTask can be ignored. Just continue with the move - - for (std::map<unsigned, std::pair<Task *, Task::task_status> >::const_iterator it = movedTasks.begin(); it != movedTasks.end(); ++it) { - Task *pTask = it->second.first; - const AstroDateTime &startTime = startTimes.find(it->first)->second; - if (pTask->isPipeline()) { - pTask->setScheduledStart(startTime); - pTask->setStatus(it->second.second); - } - else { - // try to move the task - if (it->second.second == Task::PRESCHEDULED) { - std::vector<unsigned> conflictingTasks = data.moveTask(pTask, startTime, false); - if (!conflictingTasks.empty()) { - undo(false); - QString confstr = Vector2StringList(conflictingTasks); - QMessageBox::warning(gui, tr("Move not possible"), - "Moving task " + QString::number(it->first) + " conflicts with task(s): " + confstr, tr("Close")); - return false; - } - else { - updateGraphicTasks.push_back(it->first); - // schedule the task at the new time - data.scheduleTask(pTask); - pTask->setStatus(it->second.second); - } - } - else { - pTask->setScheduledStart(startTime); - pTask->setStatus(it->second.second); - } - } - } - - if (!updateTableTasks.empty()) { - gui->updateTableTasksScheduleTimes(updateTableTasks); - } - for (std::vector<unsigned>::const_iterator it = updateGraphicTasks.begin(); it != updateGraphicTasks.end(); ++it) { - gui->updateGraphicTask(*it); - } - - setSaveRequired(true); - return true; -} - -bool Controller::moveSelectedTasks(const AstroDateTime &date_time, moveType move_type) { - if (!itsSelectedTasks.empty()) { - storeScheduleUndo("Moving task(s)"); - AstroDateTime new_start; - std::vector<std::pair<Task *, Task::task_status> > tasks; - for (vector<unsigned>::iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - Task *pTask(data.getTaskForChange(*it)); - if (pTask) { - if (pTask->getStatus() <= Task::PRESCHEDULED) { - tasks.push_back(std::vector<std::pair<Task *, Task::task_status> >::value_type(pTask, pTask->getStatus())); - if (pTask->isScheduled()) { - data.unscheduleTask(*it); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - } - } - } - else { - QMessageBox::warning(gui, tr("Move not possible"), - "Some tasks have a status above PRESCHEDULED.\nMoving tasks above PRESCHEDULED is not possible.\nMove is canceled.", tr("Close")); - undo(false); - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - return false; - } - } - } - - AstroDateTime timenow = now() + Controller::theSchedulerSettings.getMinimumTimeBetweenTasks(); - - if ((move_type == MOVE_LEFT) || (move_type == MOVE_RIGHT)) { // these are relative moves so interpret only the time part of date_time (as a relative time) - for (std::vector<std::pair<Task *, Task::task_status> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - switch (move_type) { - case MOVE_LEFT: - new_start = it->first->getScheduledStart() - date_time.time(); - break; - default: // MOVE_RIGHT - new_start = it->first->getScheduledStart() + date_time.time(); - break; - } - if (it->first->isObservation() && new_start <= timenow) { - undo(false); - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - QMessageBox::warning(gui, tr("Move not possible"), - "Observations cannot be scheduled before now.\nStart time would be too early.\nMove is canceled.", tr("Close")); - return false; - } - std::vector<unsigned> conflictingTasks = data.moveTask(it->first, new_start, false); - if (!conflictingTasks.empty()) { - unsigned taskID(it->first->getID()); - undo(false); // dangerous! it also changes all pointers such as pTask - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - QString confstr = Vector2StringList(conflictingTasks); - QMessageBox::warning(gui, tr("Move not possible"), - "Moving task " + QString::number(taskID) + " conflicts with task(s): " + confstr + "\nMove is canceled.", tr("Close")); - return false; - } - } - } - else if (move_type == MOVE_TO_START) { // shift to absolute specified time - AstroDateTime earliestStartTime = tasks.front().first->getScheduledStart(); - for (std::vector<std::pair<Task *, Task::task_status> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - if (it->first->getScheduledStart() < earliestStartTime) { - earliestStartTime = it->first->getScheduledStart(); - } - } - - AstroDateTime newFirstTime(date_time); - AstroTime dif; - bool left_right; - if (earliestStartTime < newFirstTime) { // shift right - dif = newFirstTime - earliestStartTime; - left_right = true; - - } - else { // shift left - dif = earliestStartTime - newFirstTime; - left_right = false; - } - - for (std::vector<std::pair<Task *, Task::task_status> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - if (left_right) { - new_start = it->first->getScheduledStart() + dif; - } - else { - new_start = it->first->getScheduledStart() - dif; - } - - if (it->first->isObservation() && new_start <= timenow) { - undo(false); - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - QMessageBox::warning(gui, tr("Move not possible"), - "Observations cannot be scheduled before now.\nStart time would be too early.\nMove is canceled.", tr("Close")); - return false; - } - - std::vector<unsigned> conflictingTasks = data.moveTask(it->first, new_start, false); - if (!conflictingTasks.empty()) { - unsigned taskID(it->first->getID()); - undo(false); // dangerous! it also changes all pointers such as pTask - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - QString confstr = Vector2StringList(conflictingTasks); - QMessageBox::warning(gui, tr("Move not possible"), - "Moving task " + QString::number(taskID) + " conflicts with task(s): " + confstr + "\nMove is canceled.", tr("Close")); - return false; - } - } - } - else { // MOVE_TO_CENTER - AstroDateTime earliestStartTime = tasks.front().first->getScheduledStart(); - AstroDateTime latestEndTime = tasks.front().first->getScheduledEnd(); - for (std::vector<std::pair<Task *, Task::task_status> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - if (it->first->isObservation()) { // only look at observations to determine the shift for a CENTER = LST move - if (it->first->getScheduledStart() < earliestStartTime) { - earliestStartTime = it->first->getScheduledStart(); - } - if (it->first->getScheduledEnd() > latestEndTime) { - latestEndTime = it->first->getScheduledEnd(); - } - } - } - - AstroDateTime newCenterTime(date_time); - AstroDateTime oldCenterTime((latestEndTime.toJulian() + earliestStartTime.toJulian()) / 2); - AstroTime dif = newCenterTime - oldCenterTime; - - for (std::vector<std::pair<Task *, Task::task_status> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - new_start = it->first->getScheduledStart() + dif; - - if (it->first->isObservation() && new_start <= timenow) { - undo(false); - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - QMessageBox::warning(gui, tr("Move not possible"), - "Observations cannot be scheduled before now.\nStart time would be too early.\nMove is canceled.", tr("Close")); - return false; - } - - std::vector<unsigned> conflictingTasks = data.moveTask(it->first, new_start, false); - if (!conflictingTasks.empty()) { - unsigned taskID(it->first->getID()); - undo(false); // dangerous! it also changes all pointers such as pTask - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - QString confstr = Vector2StringList(conflictingTasks); - QMessageBox::warning(gui, tr("Move not possible"), - "Moving task " + QString::number(taskID) + " conflicts with task(s): " + confstr, tr("Close")); - return false; - } - } - } - - // reschedule the unscheduled moved tasks - for (std::vector<std::pair<Task *, Task::task_status> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - if (it->second == Task::PRESCHEDULED) { - data.scheduleTask(it->first); - } - it->first->setStatus(it->second); - gui->updateTableTaskScheduleTimes(*(it->first)); - gui->updateGraphicTask(it->first->getID()); - } - setSaveRequired(true); - } - return true; -} - -int Controller::getSelectedObservationsTimeSpan(void) const { - bool isSet(false); - AstroDateTime earliestStartTime, latestEndTime; - if (!itsSelectedTasks.empty()) { - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin()+1; it != itsSelectedTasks.end(); ++it) { - const Task *pTask(data.getTask(*it)); - if (pTask) { - if (pTask->isObservation()/* && pTask->getScheduledStart().isSet()*/) { - if (!isSet) { - earliestStartTime = pTask->getScheduledStart(); - latestEndTime = pTask->getScheduledEnd(); - isSet = true; - } - else { - if (pTask->getScheduledStart() < earliestStartTime) { - earliestStartTime = pTask->getScheduledStart(); - } - if (pTask->getScheduledEnd() > latestEndTime) { - latestEndTime = pTask->getScheduledEnd(); - } - } - } - } - } - } - if (isSet) { - return (latestEndTime - earliestStartTime).totalSeconds(); - } - else return 0; -} - -/* -void Controller::alignLeft(void) { - storeScheduleUndo(tr("Align left")); - data.alignLeft(); - gui->writeTableData(data); - updateGraphicTasks(); - gui->setStatusText(tr("Align left finished")); - setSaveRequired(true); -} -*/ -void Controller::showThrashBin(void) { - itsThrashBin.show(); -} - -void Controller::doDestroyTasks(vector<unsigned> destroyTasks) { - bool taskDestroyed; - vector<unsigned> destroyedTasks; - for (vector<unsigned>::const_iterator dit = destroyTasks.begin(); dit != destroyTasks.end(); ++dit) { - taskDestroyed = false; - for (deletedTasksVector::iterator it = itsDeletedTasks.begin(); it != itsDeletedTasks.end(); ++it) { - for (vector<Task *>::iterator tit = it->begin(); tit != it->end(); ++tit) { - if ((*tit)->getID() == *dit) { - destroyedTasks.push_back(*dit); - debugInfo("si", "destroying task: ", *dit); - delete *tit; - it->erase(tit); - taskDestroyed = true; - break; - } - } - if (taskDestroyed) - break; // goes to the next task that has to be destroyed - } - } - // update the deleted tasks undo stack - bool taskFound; - for (vector<unsigned>::const_iterator dit = destroyedTasks.begin(); dit != destroyedTasks.end(); ++dit) { - taskFound = false; - for (undoTypeVector::iterator it = itsUndoType.begin(); it != itsUndoType.end(); ++it) { - if (it->first == UNDO_DELETE_TASKS) { - for (vector<unsigned>::iterator vit = it->second.second.begin(); vit != it->second.second.end(); ++vit) { - if (*vit == *dit) { - it->second.second.erase(vit); - if (it->second.second.empty()) { // this undo step has no tasks left, remove it from the undo stack - gui->removeUndo(it->second.first); - itsUndoType.erase(it); - } - taskFound = true; - break; - } - } - if (taskFound) break; - } - } - } - gui->setStatusText(tr("Tasks were destroyed")); -} - -void Controller::updateGUIafterSettingsLoad(void) { - // new stations could be defined, update the task objects to use the new station IDs generated - data.updateTasksStationIDs(); - data.updateStations(); // create stations if any where loaded from the default settings - data.checkTasksForErrors(); // re-check tasks because stations may have been removed or added - gui->updateTaskDialogStations(); - gui->updateGraphicStations(); - updateGraphicTasks(); - gui->writeTableData(data); - gui->updateSasDatabaseName(); - updateStatusBar(); - gui->initPublishDialog(); // initialize the publish dialog with the correct week numbers - gui->setExistingProjects(theSchedulerSettings.getCampaignList()); - gui->setTestMode(theSchedulerSettings.getIsTestEnvironment()); -} - -void Controller::refreshGUIafterMultiEdit(void) { - data.checkTasksForErrors(); // re-check tasks because stations may have been removed or added - updateGraphicTasks(); - gui->writeTableData(data); - updateStatusBar(); -} - -bool Controller::updateProjects(void) { - if (checkSASSettings()) { - gui->setStatusText("fetching project list from SAS..."); - itsSASConnection->init(theSchedulerSettings.getSASUserName(), - theSchedulerSettings.getSASPassword(), - theSchedulerSettings.getSASDatabase(), - theSchedulerSettings.getSASHostName()); - int result = itsSASConnection->connect(); - if (result == 0) { - if (itsSASConnection->getCampaignsFromSAS()) { // stores the campaigns in theSchedulerSettings - gui->setExistingProjects(theSchedulerSettings.getCampaignList()); - return true; - } - else { - QMessageBox::critical(0, tr("No connection to SAS"), - tr("Could not fetch the project list from SAS database ") + theSchedulerSettings.getSASDatabase()); - } - } - else if (result == -1) { - QMessageBox::critical(0, tr("No connection to SAS"), - tr("Could not connect to SAS database ") + theSchedulerSettings.getSASDatabase() - + tr("\n Please check SAS connection settings.\n\nError:") - + itsSASConnection->lastConnectionError()); - gui->setStatusText("Error: Could not connect to SAS"); - } - } - else { - std::cerr << "no SAS connection" << std::endl; - } - return false; -} - -void Controller::saveSettings(void) { - QString filename = gui->fileDialog(tr("Save Settings"), "set", tr("Settings files (*.set)"),1); - if (!filename.isEmpty()) { - if (itsDataHandler->saveSettings(filename)) - { - //set status string - std::string statStr = "Settings saved to file "; - statStr += filename.toStdString(); - gui->setStatusText(statStr.c_str()); - } - else { - //set status string - std::string statStr = "Failed to save settings to file "; - statStr += filename.toStdString(); - gui->setStatusText(statStr.c_str()); - } - } -} - -void Controller::saveDefaultSettings(void) { - if (itsDataHandler->saveSettings(PROGRAM_DEFAULT_SETTINGS_FILENAME)) { - QDir working_dir(QDir::currentPath()); - if (working_dir.exists("WinSCP")) { // if winscp exists then we assume this is the control room pc which is a windows machine and has winSCP dir in the scheduler path - if (QMessageBox::question(gui, tr("Upload default settings to central scheduler?"), - tr("Default settings have been saved.\n\nAlso upload these default settings to the central scheduler on sas001?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - QProcess proc; - QStringList args; -// std::string working_dir_str(QDir::toNativeSeparators(QDir::currentPath()).toStdString()); - QString curPath(QDir::toNativeSeparators(QDir::currentPath())); - args << "/privatekey=\"C:\\Scheduler\\pksas.ppk\" /script=" << curPath + "\\upload_default_settings.txt"; - proc.start("\\WinSCP\\WinSCP.com", args); - proc.waitForFinished(-1); -// string systemCmd(working_dir_str + "\\WinSCP\\WinSCP.com /privatekey=\"C:\\Scheduler\\pksas.ppk\" /script=" + working_dir_str + "\\upload_default_settings.txt"); -// std::system(systemCmd.c_str()); // upload .default_settings.set file to sas server - } - } - else { - QMessageBox::information(gui,"saved default settings", tr("Default settings have been saved.")); - } - } - else { - QMessageBox::critical(gui,"default settings could not be saved", tr("ERROR: Default settings could not be saved.")); - } -} - -void Controller::loadDefaultSettings(void) { - QMessageBox msgBox; - - if (itsDataHandler->loadSettings(PROGRAM_DEFAULT_SETTINGS_FILENAME)) { - updateGUIafterSettingsLoad(); - msgBox.setText(tr("Default settings have been loaded.")); - } else { - msgBox.setText(tr("ERROR: Default settings could not be loaded.")); - } - msgBox.exec(); -} - -void Controller::loadSettings(void) { - QString filename = gui->fileDialog(tr("Load Settings"), "set", tr("Settings files (*.set)")); - if (!filename.isEmpty()) { - if (itsDataHandler->loadSettings(filename)) { - updateGUIafterSettingsLoad(); - gui->setStatusText("Settings loaded"); - } - } -} - -void Controller::optimizeSchedule(void) { - if (data.getNrTasks()) { - gui->setProgressBarMaximum(Controller::theSchedulerSettings.getMaxNrOptimizations()); - gui->setStatusText("Optimize in progress"); - storeScheduleUndo(QObject::tr("Optimize schedule")); - // data.create_undo_level(); - // data.setSaveRequired(true); - // registerChange(SCHEDULER_DATA_BLOCK_CHANGE); - int result = scheduler.optimize(); - // data.checkPredecessors(); // check time limits on predecessor tasks - if (result == 0) { - debugInfo("s", "Optimization finished."); - } else if (result == 1) { - debugInfo("s", "Optimization finished, user accepted penalty was reached."); - } else if (result == 2) { - debugInfo("s", "Optimization finished, the maximum number of iterations was reached."); - } else if (result == 3) { - debugInfo("s", "Optimization finished, there are no more scheduled tasks that may be changed"); - } - gui->writeTableData(data); - updateGraphicTasks(); - gui->setStatusText("Optimization finished"); - gui->disableProgressBar(); - debugInfo("si", "Penalty obtained: ", data.getPenalty()); - debugInfo("si", "# of successfully scheduled tasks: ", data.getNrScheduled()); - setSaveRequired(true); - } - else { - QMessageBox::warning(gui, tr("No tasks defined"), - tr("There are no tasks defined. Cannot optimize an empty schedule."),tr("Close")); - } -} - -void Controller::updateStatusBar(void) { gui->updateStatusBar(data.getNrScheduled(), data.getNrUnscheduled(), - data.getNrInactive(), data.getNrReservations(), data.nrOfErrorTasks(), data.getNrPipelines()); -} - -void Controller::updateStatusBarOptimize(unsigned optimize_iteration) { - gui->updateStatusBar(data.getNrScheduled(), data.getNrUnscheduled(), - data.getNrInactive(), data.getNrReservations(), data.nrOfErrorTasks(), optimize_iteration); -} - -void Controller::applyTableItemChange(unsigned taskID, data_headers property, const QVariant &value, const QModelIndex &index) { - checkTableItem(index); - Task *pTask = data.getTaskForChange(taskID); - Task::task_status status(pTask->getStatus()); - - // create undo - storeTaskUndo(taskID, QString("Task ") + QString::number(taskID) + " " + DATA_HEADERS[property] + " change"); - - if (index.column() == TASK_STATUS) { // user is trying to change the status, don't apply status just yet, first do the preschedule checks - QString newstatus(value.toString()); - if ((newstatus == task_states_str[Task::PRESCHEDULED]) || (newstatus == task_states_str[Task::SCHEDULED])) { - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(pTask); - if (errCode.first == BEAM_DURATION_DIFFERENT) { - if (QMessageBox::question(gui, tr("Beam duration different"), - errCode.second.replace('$','\n') + "\nDo you still want to set the task to " + newstatus + "?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - // don't apply the status change - deleteLastStoredUndo(); - return; - } - else { - applyTaskPropertyChange(taskID, property, value, STORE_UNDO); // apply the status change - updateStatusBar(); - } - } - else if (errCode.first == USER_WARNING) { - if (QMessageBox::question(gui, tr("Warning"), - errCode.second + "\nDo you still want to set the task to " + newstatus + "?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - deleteLastStoredUndo(); - return; - } - } - - else if (errCode.first == SCHEDULED_TOO_EARLY) { - QMessageBox::warning(gui, tr("Start time too early"), - QString("Error: ") + errCode.second.replace('$','\n') + "\n\nThe change will not be applied!"); - // don't apply the status change -> undo the change - deleteLastStoredUndo(); - } - else if (errCode.first >= TASK_CONFLICT) { - if (pTask->isScheduled()) { - data.unscheduleTask(taskID); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - } - if (errCode.first == TASK_CONFLICT) { - pTask->setStatus(Task::CONFLICT); - } - else { - pTask->setStatus(Task::ERROR); - } - updateStatusBar(); - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task has errors/conflicts")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to (PRE)SCHEDULED before the problem is resolved"); - warningBox.exec(); - } - else { - applyTaskPropertyChange(taskID, property, value, STORE_UNDO); // apply the status change - updateStatusBar(); - } - } - else { - applyTaskPropertyChange(taskID, property, value, STORE_UNDO); // apply the change - } - } - // for changes made in the table other than status changes - else { - // do the preschedule checks after the change has been applied - // If there is an error ask the user if he still wants to apply the change, - // if he wants to apply the change the task should be set to error state - // if not undo the last stored undo - - applyTaskPropertyChange(taskID, property, value, STORE_UNDO); // apply the change regarding if error or not - Task *pTask = data.getTaskForChange(taskID); - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(pTask); - if (errCode.first == BEAM_DURATION_DIFFERENT) { - QMessageBox::warning(gui, tr("Beam duration different"), errCode.second.replace('$','\n'), QMessageBox::Ok); - } - else if (errCode.first == USER_WARNING) { - if (QMessageBox::question(gui, tr("Warning"), - errCode.second + "\nDo you still want to apply the change?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - undo(false); - } - } - else if (errCode.first == SCHEDULED_TOO_EARLY) { - QMessageBox::warning(gui, tr("Start time too early"), - QString("Error: ") + errCode.second.replace('$','\n') + "\n\nThe change will not be applied!"); - // don't apply the status change -> undo the change - undo(false); - } - else if (errCode.first >= TASK_CONFLICT) { - if (QMessageBox::question(gui, tr("Task has errors/conflicts"), - QString("Error: ") + errCode.second.replace('$','\n') + "\n\nIf the change is applied the task will get the ERROR/CONFLICT status.\nDo you still want to apply the change?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - // don't apply the status change -> undo the change - undo(false); - } - else { - data.unscheduleTask(taskID); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - if (errCode.first == TASK_CONFLICT) { - pTask->setStatus(Task::CONFLICT); - } - else { - pTask->setStatus(Task::ERROR); - } - updateStatusBar(); - } - } - } - } - gui->updateTask(pTask); - setSaveRequired(true); -} - -void Controller::tableSortingChanged(void) { - gui->setErrorCells(data.getErrorTasks()); -} - -void Controller::checkTableItem(const QModelIndex &index) { - switch (index.column()) { - case TASK_TYPE: // task type - case TASK_NAME: - case PROJECT_ID: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - break; -/* - case PREDECESSORS: // predecessor ID - if (index.model()->data(index).toString().isEmpty()) { - gui->clearErrorIndex(index); // mark cell as repaired because it is an empty cell - } - else { - if (data.predecessorExists(index.model()->data(index).toUInt())) // if the predecessor exists - gui->clearErrorIndex(index); // mark cell as repaired - else - gui->addErrorIndex(index); // mark cell as error - } - break; -*/ - case PRIORITY: // priority - break; - case STATION_ID: // station IDs - if (checkStationList(index.model()->data(index).toString().toStdString())) { - gui->clearErrorIndex(index); - } else { - gui->addErrorIndex(index); - } - break; - case STORAGE_SIZE: // storage - case ANTENNA_MODE: // antenna mode - case FILTER_TYPE: // filter type - case CLOCK_FREQUENCY: // clock frequencies - case FIXED_DAY: // fixed day and time (1/0) - case FIXED_TIME: - case TASK_STATUS: // task status - case NR_OF_SUBBANDS: // number of subbands (spinbox) - case NIGHT_TIME_WEIGHT_FACTOR: // night time weight factor (spinbox) - break; -// case PRED_MIN_TIME_DIF: // time edit -// case PRED_MAX_TIME_DIF: - case TASK_DURATION: // duration - break; - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: - break; - case FIRST_POSSIBLE_DATE: // date edit - case LAST_POSSIBLE_DATE: - break; - case PLANNED_START: // date-time edit - case PLANNED_END: - break; - } -} - -bool Controller::checkStationList(const std::string & stations) const { - size_t p = 0, i = 0; - if (!stations.empty()) { - while (true) { - i = stations.find(';', p); - if (i != std::string::npos) { - if (!(theSchedulerSettings.stationExist(stations.substr(p, i-p)))) { - return false; - } - } - else { // extract last station and exit loop - if (!(theSchedulerSettings.stationExist(stations.substr(p, stations.size()-p)))) { - return false; - } - else return true; - } - p = i + 1; - } - } else return true; // no error in empty list - return true; -} - -void Controller::storeTaskUndo(unsigned taskID, const QString &undo_action, bool delete_task) { -// itsUndoType.push_back(std::pair<undo_type, QString>(UNDO_COMPLETE_TASK, undo_action)); - - //std::pair<undo_type, std::pair<QString, std::vector<unsigned> > > - - itsUndoType.push_back(undoTypeVector::value_type(UNDO_COMPLETE_TASK, - std::pair<QString, vector<unsigned> >( undo_action, vector<unsigned>() ) )); - - - if (delete_task) { - itsTaskUndoStack.push_back(taskUndoStack::value_type(taskID, new Task(0)) ); - } - else { - itsTaskUndoStack.push_back(taskUndoStack::value_type(taskID, cloneTask(data.getTask(taskID))) ); - } - gui->addUndo(undo_action); -} - -void Controller::storeTaskPropertyUndo(unsigned taskID, data_headers property, const QVariant &value) { - QString undo_text("Task " + QString::number(taskID) + " " + DATA_HEADERS[property] + " change"); - itsUndoType.push_back(undoTypeVector::value_type(UNDO_TASK_PROPERTY, - std::pair<QString, vector<unsigned> >( undo_text, vector<unsigned>() ) )); - itsTaskPropertyUndoStack.push_back(taskPropertyUndoStack::value_type (taskID, - std::pair<data_headers, QVariant>(property, value))); - gui->addUndo(undo_text); - setSaveRequired(true); -} - -void Controller::storeScheduleUndo(const QString &undo_action) { -// itsUndoType.push_back(std::pair<undo_type, QString>(UNDO_SCHEDULER_DATA_BLOCK, undo_action)); - itsUndoType.push_back(undoTypeVector::value_type(UNDO_SCHEDULER_DATA_BLOCK, - std::pair<QString, vector<unsigned> > - ( undo_action, vector<unsigned>() ) )); - data.create_undo_level(); - gui->addUndo(undo_action); -} - -void Controller::deleteLastStoredUndo(void) { - if (!itsUndoType.empty()) { - undo_type ut = itsUndoType.back().first; - itsUndoType.pop_back(); - if (ut == UNDO_COMPLETE_TASK) { - delete itsTaskUndoStack.back().second; - itsTaskUndoStack.pop_back(); - } - else if (ut == UNDO_SCHEDULER_DATA_BLOCK) { - data.deleteLastStoredUndo(); - } - else if (ut == UNDO_TASK_PROPERTY) { - itsTaskPropertyUndoStack.pop_back(); - } - } - gui->removeLastUndo(); -} - -void Controller::applyTaskPropertyChange(unsigned taskID, data_headers property, const QVariant &value, bool undo_redo) { - QVariant taskValue; - Task *pTask = data.getTaskForChange(taskID); - - Task::task_status currentStatus, newStatus; - switch (property) { - case TASK_ID: - case SAS_ID: - return; - case TASK_NAME: - taskValue = QString(pTask->getTaskName()); - pTask->setTaskName(value.toString().toStdString()); - break; - case TASK_DESCRIPTION: - taskValue = QString(pTask->SASTree().description().c_str()); - pTask->setTaskDescription(value.toString().toStdString()); - break; - case PROJECT_ID: - taskValue = QString(pTask->getProjectName()); - pTask->setProjectName(value.toString().toStdString()); - break; - case CONTACT_NAME: - taskValue = QString(pTask->getContactName()); - pTask->setContactName(value.toString().toStdString()); - break; - case CONTACT_PHONE: - taskValue = QString(pTask->getContactPhone()); - pTask->setContactPhone(value.toString().toStdString()); - break; - case CONTACT_EMAIL: - taskValue = QString(pTask->getContactEmail()); - pTask->setContactEmail(value.toString().toStdString()); - break; -// case TASK_TYPE: -// taskValue = QString(pTask->getTypeStr()); -// pTask->setType(value.toString().toStdString()); -// break; - case PREDECESSORS: - taskValue = pTask->getPredecessorsString(); - pTask->setPredecessors(value.toString()); - break; - case PRED_MIN_TIME_DIF: - taskValue = QString(pTask->getPredecessorMinTimeDif().toString().c_str()); - pTask->setPredecessorMinTimeDif(AstroTime(value.toString())); - break; - case PRED_MAX_TIME_DIF: - taskValue = QString(pTask->getPredecessorMaxTimeDif().toString().c_str()); - pTask->setPredecessorMaxTimeDif(value.toString()); - break; - case PRIORITY: - taskValue = pTask->getPriority(); - pTask->setPriority(value.toDouble()); - break; - case FIRST_POSSIBLE_DATE: - taskValue = QString(pTask->getWindowFirstDay().toString().c_str()); - pTask->setWindowFirstDay(value.toString()); - break; - case LAST_POSSIBLE_DATE: - taskValue = QString(pTask->getWindowLastDay().toString().c_str()); - pTask->setWindowLastDay(value.toString()); - break; - case WINDOW_MINIMUM_TIME: - taskValue = QString(pTask->getWindowMinTime().toString().c_str()); - pTask->setWindowMinTime(value.toString()); - break; - case WINDOW_MAXIMUM_TIME: - taskValue = QString(pTask->getWindowMaxTime().toString().c_str()); - pTask->setWindowMaxTime(value.toString()); - break; - case TASK_DURATION: - taskValue = QString(pTask->getDuration().toString().c_str()); -// pTask->setDuration(value.toString().toStdString()); - data.changeTaskDuration(taskID, value.toString()); -// pTask->storage()->recalculateCheck(); - break; - case PLANNED_START: - taskValue = QString(pTask->getScheduledStart().toString().c_str()); -// pTask->setScheduledStart(value.toString().toStdString()); - data.changeTaskStartTime(taskID, value.toString()); - break; - case PLANNED_END: - taskValue = QString(pTask->getScheduledEnd().toString().c_str()); -// pTask->setScheduledEnd(value.toString().toStdString()); - data.changeTaskEndTime(taskID, value.toString()); -// pTask->recalculateCheck(); - break; - case FIXED_DAY: - taskValue = pTask->getFixedDay(); - pTask->setFixDay(value.toBool()); - break; - case FIXED_TIME: - taskValue = pTask->getFixedTime(); - pTask->setFixTime(value.toBool()); - break; - case TASK_STATUS: - taskValue = QString(pTask->getStatusStr()); - newStatus = taskStatusFromString(value.toString().toStdString()); - if (pTask->isScheduled()) { // currently scheduled? - if ( (newStatus < Task::PRESCHEDULED) || (newStatus == Task::OBSOLETE) ) { // not scheduled anymore? - data.unscheduleTask(pTask->getID()); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - pTask->setStatus(newStatus); - } - else if (newStatus == Task::SCHEDULED) { - if (doScheduleChecks(pTask)) { - pTask->setStatus(newStatus); - } - } - else { - pTask->setStatus(newStatus); - } - } - else { // currently task is not scheduled - if (pTask->getStatus() == Task::ERROR) { - if (!data.checkTask(pTask)) { // task still has errors? - // TODO: mark the error cell with gui->addErrorIndex(index) - QMessageBox::critical(gui, tr("Task has errors"), - tr("The task still has errors. Cannot change its status."),tr("Close")); - QApplication::beep(); - return; - } - } - if (newStatus == Task::PRESCHEDULED) { - if (!pTask->isPipeline()) { - data.scheduleTask(pTask); - } - pTask->setStatus(Task::PRESCHEDULED); - } - else if (newStatus == Task::SCHEDULED) { - if (doScheduleChecks(pTask)) { - if (!pTask->isPipeline()) { - data.scheduleTask(pTask); - } - else { - pTask->setStatus(Task::SCHEDULED); - } - } - } - else if ((newStatus == Task::STARTING) || (newStatus == Task::ACTIVE)) { - data.scheduleTask(pTask); - pTask->setStatus(newStatus); - } - else { - pTask->setStatus(newStatus); - } - } - updateStatusBar(); - break; - case UNSCHEDULED_REASON: - break; - case STORAGE_SIZE: - break; - case _END_DATA_HEADER_ENUM_: - break; - default: - break; - } - - if (pTask->isStationTask()) { - StationTask *pStationTask = static_cast<StationTask *>(pTask); // no expensive dynamic_cast needed because we know it is a StationTask - - switch (property) { - case FILTER_TYPE: - taskValue = QString(pStationTask->getFilterTypeStr()); - pStationTask->setFilterType(value.toString().toStdString()); - break; - case ANTENNA_MODE: - taskValue = QString(pStationTask->getAntennaModeStr()); - pStationTask->setAntennaMode(value.toString().toStdString()); - break; - case STATION_ID: - taskValue = QString(pStationTask->getStationNamesStr().c_str()); - currentStatus = pStationTask->getStatus(); - if (pStationTask->isScheduled()) { - data.unscheduleTask(taskID); - pStationTask->setStations(value.toString(),';'); - pStationTask->clearAllStorageConflicts(); - if (pStationTask->hasStorage()) { - pStationTask->storage()->unAssignStorage(); - pStationTask->storage()->generateFileList(); - } - data.scheduleTask(pStationTask); - pStationTask->setStatus(currentStatus); - } - else { - pStationTask->setStations(value.toString(),';'); - } -// pStationTask->recalculateCheck(); - break; - case CLOCK_FREQUENCY: - taskValue = QString(pStationTask->getStationClockStr()); - pStationTask->setStationClock(value.toString().toStdString()); -// pStationTask->recalculateCheck(); - break; - default: - break; - } - - if (pStationTask->isObservation()) { - Observation *pObs = static_cast<Observation *>(pStationTask); - switch (property) { - case NIGHT_TIME_WEIGHT_FACTOR: - taskValue = pObs->getNightTimeWeightFactor(); - pObs->setNightTimeWeightFactor(value.toUInt()); - break; - default: - break; - } - } - - } - - if (undo_redo) { - itsTaskPropertyRedoStack.push_back(taskPropertyUndoStack::value_type (pTask->getID(), - std::pair<data_headers, QVariant>(property, taskValue))); - } - else { - itsTaskPropertyUndoStack.push_back(taskPropertyUndoStack::value_type (pTask->getID(), - std::pair<data_headers, QVariant>(property, taskValue))); - } - setSaveRequired(true); -} - -void Controller::undo(bool store_redo) { - if (!itsUndoType.empty()) { - QApplication::setOverrideCursor(Qt::WaitCursor); - undoTypeVector::value_type undo_data = itsUndoType.back(); - itsUndoType.pop_back(); - if (store_redo) { - itsRedoType.push_back(undo_data); - } - if (undo_data.first == UNDO_TASK_PROPERTY) { - taskPropertyUndoStack::value_type val = itsTaskPropertyUndoStack.back(); - itsTaskPropertyUndoStack.pop_back(); - applyTaskPropertyChange(val.first, val.second.first, val.second.second, store_redo); - gui->updateTableTask(data.getTask(val.first)); - gui->updateGraphicTask(val.first); - //set status string - gui->setStatusText("Task " + QString::number(val.first) + DATA_HEADERS[val.second.first] + " change undone"); - } - else if (undo_data.first == UNDO_COMPLETE_TASK) { - taskUndoStack::value_type val = itsTaskUndoStack.back(); // val contains the task as it was before the action that has to be undone was applied - itsTaskUndoStack.pop_back(); // remove task from undo stack - if (val.second->getID()) { // if task is non-zero then this is not a delete action - Task *task = data.getTaskForChange(val.first); // contains current task properties that will be undone - if (task) { // task could have been deleted before this undo step in which case we would have a null pointer exception - if (store_redo) { - itsTaskRedoStack.push_back(taskUndoStack::value_type (val.first, cloneTask(task))); // stores current properties in redo stack - } - Task::task_status current_state = task->getStatus(); // the current state - Task::task_status prev_state = val.second->getStatus(); // the state before the change was applied that is now being undone - task->clone(val.second); // copy the previous task values to the existing task - if (!task->isPipeline()) { - if ( (prev_state >= Task::FINISHED) && (current_state >= Task::PRESCHEDULED) && (current_state < Task::FINISHED)) { // go from a scheduled to an inactive state - data.unscheduleTask(task->getID()); - task->setStatus(prev_state); - data.moveTaskToInactive(task->getID()); - } - else if ((prev_state >= Task::PRESCHEDULED) && (prev_state < Task::FINISHED) && (current_state < Task::PRESCHEDULED)) { // go from an unscheduled to a scheduled state - data.scheduleTask(task); - task->setStatus(prev_state); - } - else if ((prev_state < Task::PRESCHEDULED) && (current_state >= Task::PRESCHEDULED) && (current_state < Task::FINISHED)) { // go from a scheduled to an unscheduled state - data.unscheduleTask(task->getID()); - task->setStatus(prev_state); - } - } - updateStatusBar(); - gui->updateTask(task); - } - else { - gui->removeLastUndo(); - gui->setStatusText("Changes to task " + QString::number(val.first) + " could not be undone because it was destroyed"); - delete val.second; // release memory of task that came from undo stack - return; - } - } - else { // when task ID is zero it means delete task (it was added to undo stack by the add task function) - Task *task = data.getTaskForChange(val.first); - if (store_redo) { - itsTaskRedoStack.push_back(taskUndoStack::value_type (0, cloneTask(task))); - } - gui->deleteTaskFromGUI(val.first); - data.deleteTask(val.first); - updateStatusBar(); - } - delete val.second; // release memory from undo task - //set status string - gui->setStatusText("Task " + QString::number(val.first) + " change undone"); - } - else if (undo_data.first == UNDO_SCHEDULER_DATA_BLOCK) { - if (data.undo(store_redo)) { // schedule undo - data.checkTasksForErrors(); - gui->writeTableData(data); - updateGraphicTasks(); - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - updateStatusBar(); - gui->setStatusText("Schedule changes undone"); - } - else { - gui->setStatusText("No more schedule changes to undo"); - debugWarn("s", "No more data undo levels"); - } - } - else if (undo_data.first == UNDO_DELETE_TASKS) { // undo deletion of tasks - if (!itsDeletedTasks.empty()) { - vector<Task *> &deletedTasks = itsDeletedTasks.back(); - unsigned task_id; - vector<unsigned> taskIDvec; - Task::task_status status; - for (vector<Task *>::iterator it = deletedTasks.begin(); it != deletedTasks.end(); ++it) { - task_id = (*it)->getID(); - taskIDvec.push_back(task_id); - status = (*it)->getStatus(); - data.addTask(*it, false); - if ((*it)->isScheduled()) { - data.scheduleTask(*it); - (*it)->setStatus(status); - } - else if (status >= Task::FINISHED) { - data.moveTaskToInactive(task_id); - } - gui->addTask(*it); - itsSASConnection->removeFromSASTaskToDelete((*it)->getSASTreeID()); - } - itsThrashBin.removeRestoredTasks(taskIDvec); - itsDeletedTasks.pop_back(); - if (store_redo) { - itsDeletedTasksRedoStack.push_back(taskIDvec); - } - updateStatusBar(); - } - } - gui->undo(store_redo); - } - if (itsUndoType.empty()) { - setSaveRequired(false); - } - QApplication::restoreOverrideCursor(); -} - -void Controller::redo(void) { - if (!itsRedoType.empty()) { - QApplication::setOverrideCursor(Qt::WaitCursor); - undoTypeVector::value_type redo_data = itsRedoType.back(); - itsRedoType.pop_back(); - itsUndoType.push_back(redo_data); - if (redo_data.first == UNDO_TASK_PROPERTY) { - taskPropertyUndoStack::value_type val = itsTaskPropertyRedoStack.back(); - itsTaskPropertyRedoStack.pop_back(); - applyTaskPropertyChange(val.first, val.second.first, val.second.second, STORE_UNDO); - gui->updateTableTask(data.getTask(val.first)); - gui->updateGraphicTask(val.first); - //set status string - gui->setStatusText("Task " + QString::number(val.first) + DATA_HEADERS[val.second.first] + " change redone"); - } - else if (redo_data.first == UNDO_COMPLETE_TASK) { - taskUndoStack::value_type val = itsTaskRedoStack.back(); - itsTaskRedoStack.pop_back(); - if (val.first) { // when task ID is not zero the task exist - Task *task = data.getTaskForChange(val.first); - if (task) { - itsTaskUndoStack.push_back(taskUndoStack::value_type (val.first, cloneTask(task))); - Task::task_status current_state = task->getStatus(); // the current state of the task - Task::task_status new_state = val.second->getStatus(); // the state before the undo was applied - task->clone(val.second); // copy the previous ('undone') task values to the existing task - if (!task->isPipeline()) { - if ((new_state >= Task::FINISHED) && (current_state >= Task::PRESCHEDULED) && (current_state < Task::FINISHED)) { // go from scheduled to an inactive state - data.unscheduleTask(task->getID()); - task->setStatus(new_state); - data.moveTaskToInactive(task->getID()); - } - else if ((new_state >= Task::PRESCHEDULED) && (new_state < Task::FINISHED) && (current_state < Task::PRESCHEDULED)) { // go from an unscheduled to a scheduled state - data.scheduleTask(task); - task->setStatus(current_state); - } - else if ((new_state < Task::PRESCHEDULED) && (current_state >= Task::PRESCHEDULED) && (current_state < Task::FINISHED)) { // go from a scheduled to an unscheduled state - data.unscheduleTask(task->getID()); - task->setStatus(new_state); - } - else if ((new_state >= Task::PRESCHEDULED) && (new_state < Task::FINISHED) && (current_state >= Task::FINISHED)) { // go from an inactive to a scheduled state - data.scheduleTask(task); // we need to reschedule the task because the state changed from an inactive to active - task->setStatus(new_state); - } - } - updateStatusBar(); - gui->updateTask(task); - } - delete val.second; // release memory of undo task - } - else { // special case: add the previously deleted task - Task *pTask = val.second; - if (!data.addTask(pTask)) { - Task::task_status status(pTask->getStatus()); - if (!pTask->isPipeline() && pTask->isScheduled()) { // we need to schedule the task again if it was scheduled before it got deleted - data.scheduleTask(pTask); - pTask->setStatus(status); - } - itsTaskUndoStack.push_back(taskUndoStack::value_type (pTask->getID(), new Task(0))); - gui->addTask(pTask); - } - else { - qDebug() << "Controller::redo : task cannot be re-added : ID:" << pTask->getID(); - } - } - //set status string - gui->setStatusText("Task " + QString::number(val.first) + " change redone"); - updateStatusBar(); - } - else if (redo_data.first == UNDO_SCHEDULER_DATA_BLOCK) { - if (data.redo()) { // schedule undo - data.checkTasksForErrors(); - gui->writeTableData(data); - updateGraphicTasks(); - gui->selectTasks(itsSelectedTasks); // re-select the selected tasks - updateStatusBar(); - gui->setStatusText("Schedule changes redone"); - } - else { - gui->setStatusText("No more schedule changes to redo"); - debugWarn("s", "No more data redo levels"); - } - } - else if (redo_data.first == UNDO_DELETE_TASKS) { // redo deletion of tasks - if (!itsDeletedTasksRedoStack.empty()) { - vector<Task *> deletedTasks; - vector<unsigned> &taskIDvec = itsDeletedTasksRedoStack.back(); - gui->scene()->blockSignals(true); - unsigned treeID; - for (vector<unsigned>::iterator it = taskIDvec.begin(); it != taskIDvec.end(); ++it) { - Task *delTask(data.deleteTask(*it, ID_SCHEDULER, false)); - if (delTask) { - deletedTasks.push_back(delTask); - treeID = delTask->getSASTreeID(); - if (treeID) { - itsSASConnection->addToTreesToDelete(treeID, *it); - } - gui->deleteTaskFromGUI(*it); // will cause signals to be generated if we don't block them (see remark just before FOR loop) - } - else { - debugWarn("si","Redo delete: could not find task: ", *it); // should never occur - } - } - gui->scene()->blockSignals(false); - if (!deletedTasks.empty()) { - itsDeletedTasks.push_back(deletedTasks); - itsThrashBin.addTasks(deletedTasks); - gui->setFullThrashIcon(); - } - itsDeletedTasksRedoStack.pop_back(); - updateStatusBar(); - } - } - gui->redo(); - setSaveRequired(true); - } - QApplication::restoreOverrideCursor(); -} - -void Controller::quit() -{ - itsSASConnection->disconnect(); - if (possiblySave()) - { - itsDataHandler->saveProgramPreferences(); - application->quit(); - } -} - -bool Controller::checkSettings() const { - return true; -} - -// Dialogbox asking for saving of schedule project -int Controller::possiblySaveDialog() -{ - - // Save the pointer to the message box to allow sending signals from - // outside threads (testing) - possiblySaveMessageBox = new QMessageBox(); - QMessageBox *possiblySaveMessageBox = new QMessageBox(); - possiblySaveMessageBox->setWindowTitle( tr("Save schedule project") ); - possiblySaveMessageBox->setText( tr("Schedule project contains unsaved changes\nDo you want to save the schedule project?") ); - possiblySaveMessageBox->setStandardButtons( QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel); - possiblySaveMessageBox->setDefaultButton( QMessageBox::Save); - possiblySaveMessageBox->setEscapeButton( QMessageBox::Cancel); - - // execute and wait - return possiblySaveMessageBox->exec(); -} - -// check if data needs to be saved before cleaning up data -// returns true if data saving went OK or when no data needs to be saved. -// returns false if user decided to cancel the save or something else went wrong -// with saving the data. -// TODO: The return value of this function mixes error state and selected choices. -bool Controller::possiblySave() -{ - // check in SchedulingData if save required - if (!data.getSaveRequired() ) - return true; - - // ask user if he wants to save project file - int answer = possiblySaveDialog(); - - // If user answered no or cancel we can exit with true exit state ( no error - if (answer == QMessageBox::No) - return true; - - if (answer == QMessageBox::Cancel) - return false; - - // If save is selected attempt save If this fails return false - if (answer == QMessageBox::Save && saveSchedule()) - return true; - else// default return is false - return false; -} - - -void Controller::cleanup(bool keepUndo, bool cleanSasConnection) { - itsSelectedTasks.clear(); - gui->clearTasks(); - if (cleanSasConnection) { - itsSASConnection->cleanup(); - } - data.cleanup(); - if (!keepUndo) { - clearUndoRedoStack(); - } -// gui->updateGraphicStations(); - gui->cleanup(); - gui->newTable(data); - itsThrashBin.emptyThrashBin(); - gui->setEmptyThrashIcon(); - setSaveRequired(false); -} - -void Controller::clearUndoRedoStack(void) { - itsTaskPropertyUndoStack.clear(); - itsTaskPropertyRedoStack.clear(); - for (taskUndoStack::iterator uit = itsTaskUndoStack.begin(); uit != itsTaskUndoStack.end(); ++uit) delete uit->second; - itsTaskUndoStack.clear(); - for (taskUndoStack::iterator rit = itsTaskRedoStack.begin(); rit != itsTaskRedoStack.end(); ++rit) delete rit->second; - itsTaskRedoStack.clear(); - itsUndoType.clear(); - itsRedoType.clear(); - gui->clearUndoRedo(); -} - -void Controller::clearRedoStack(void) { - itsTaskPropertyRedoStack.clear(); - for (taskUndoStack::iterator rit = itsTaskRedoStack.begin(); rit != itsTaskRedoStack.end(); ++rit) delete rit->second; - itsTaskRedoStack.clear(); - itsRedoType.clear(); - gui->clearRedo(); -} - -/* -void Controller::openTaskList(void) -{ - if (possiblySave()) { - QString filename = gui->openTaskFileDialog(); - if (!filename.isEmpty()) { - cleanup(); - if(itsDataHandler->readCSVFile(filename, data)) - { - scheduler.setData(data); - gui->writeTableData(data); - gui->setCurrentFileName(filename); - gui->setEnableTaskListMenuItems(true); - } - } - } -} -*/ - -void Controller::saveTaskListAs(void) { - bool saveAll(true); - std::vector<const Task *> tasks; - std::vector<unsigned> selectedTaskIDs(gui->getSelectedRowsTaskIDs()); - if (!selectedTaskIDs.empty()) { - QMessageBox msgBox; - msgBox.setText("Do you want to export all tasks or only the selection?"); - QPushButton *selectionButton = msgBox.addButton("Selection", QMessageBox::NoRole); - QPushButton *allButton = msgBox.addButton("All", QMessageBox::YesRole); - msgBox.setDefaultButton(allButton); - msgBox.setIcon(QMessageBox::Question); - msgBox.exec(); - if (msgBox.clickedButton() == selectionButton) { - saveAll = false; - for (std::vector<unsigned>::const_iterator it = selectedTaskIDs.begin(); it != selectedTaskIDs.end(); ++it) { - tasks.push_back(data.getTask(*it)); - } - } - } - if (saveAll) { - std::vector<unsigned> taskIDs(gui->getShownTaskIDs()); - for (std::vector<unsigned>::const_iterator it = taskIDs.begin(); it != taskIDs.end(); ++it) { - tasks.push_back(data.getTask(*it)); - } - } - QString filename = gui->saveTaskFileDialog(); - if (!filename.isEmpty()) { - itsDataHandler->writeCSVFile(filename, tasks); - } -} - -bool Controller::saveScheduleAs(void) { - QString filename = gui->saveProjectDialog(); - if (!filename.isEmpty()) { - return saveSchedule(filename); - } - else return false; -} - -bool Controller::saveSchedule(QString filename) { - if (filename.isEmpty()) { - filename = itsDataHandler->getFileName(); - } - if (filename.isEmpty()) { - QString filename = gui->saveProjectDialog(); - if (!filename.isEmpty()) { - bool result = itsDataHandler->saveSchedule(filename, data); - if (result) { - //set status string - QString statStr = "Schedule saved to " + filename; - gui->setStatusText(statStr); - gui->setCurrentFileName(filename); - setSaveRequired(false); - return true; - } - return result; - } - else return false; - } - else { - if (itsDataHandler->saveSchedule(filename, data)) { - QString statStr = "Schedule saved to " + filename; - gui->setStatusText(statStr); - gui->setCurrentFileName(filename); - setSaveRequired(false); - return true; - } - else return false; - } -} - -void Controller::openSchedule(void) { - if (possiblySave()) { - QString filename = gui->openProjectDialog(); - if (!filename.isEmpty()) { - QApplication::setOverrideCursor(Qt::WaitCursor); - cleanup(); - if(itsDataHandler->openSchedule(filename, data)) { - scheduler.setData(data); - gui->newTable(data); - gui->updateProjectsFilter(Controller::theSchedulerSettings.getCampaignList()); - gui->setCurrentFileName(filename); - gui->updateSceneTimeSpan(); - gui->updateTaskDialogStations(); - gui->updateGraphicStations(); - updateGraphicTasks(); - gui->setEnableScheduleMenuItems(true); - gui->initPublishDialog(); // initialize the publish dialog with the correct week numbers - //set status string - QString statStr = "Schedule loaded from " + filename; - gui->setStatusText(statStr); - updateStatusBar(); - } - QApplication::restoreOverrideCursor(); - } - } -} - -bool Controller::closeSchedule(void) { - if (possiblySave()) { - cleanup(); - gui->clearCurrentFileName(); - gui->setEnableScheduleMenuItems(false); - updateStatusBar(); - gui->setStatusText("Ready"); - return true; - } - else return false; -} - -void Controller::openSettingsDialog(void) { - itsSettingsDialog->show(); -} - -void Controller::closeSettingsDialog() { - if (checkSettings()) { - theSchedulerSettings.updateSettings(itsSettingsDialog); - scheduler.updateSettings(); - itsSettingsDialog->close(); - itsSASConnection->setAutoPublishEnabled(theSchedulerSettings.getAutoPublish()); - updateGUIafterSettingsLoad(); - emit schedulerSettingsChanged(); - } -} - -bool Controller::connectToDataMonitor(void) { - bool bResult(true); - if (!itsDMConnection->isOpen()) { - QMessageBox mb(QMessageBox::Information, "Please wait for connection to data monitor", - "Trying to connect to the data monitor.\n Please wait."); - mb.show(); - QApplication::setOverrideCursor(Qt::WaitCursor); - QCoreApplication::processEvents(); // force update to paint dialog - - if (itsDMConnection->init(theSchedulerSettings.getDMUserName(), - theSchedulerSettings.getDMPassword(), - theSchedulerSettings.getDMDatabase(), - theSchedulerSettings.getDMHostName())) { - if (itsDMConnection->connect()) { - itsDMConnection->updateStorageNodes(); - itsSettingsDialog->updateStorageNodeInfoTree(itsDMConnection->getStorageNodes(), itsDMConnection->getStates(), itsDMConnection->getHostPartitions()); - mb.hide(); - } - else { - bResult = false; - } - } - else { - bResult = false; - } - QApplication::restoreOverrideCursor(); - } - else { - bResult = false; - } - - gui->setDataMonitorConnectionButton(bResult); - return bResult; -} - -void Controller::disconnectDataMonitor(void) { - itsDMConnection->disconnect(); - gui->setDataMonitorConnectionButton(false); -} - -bool Controller::isDataMonitorConnected(void) const { - bool isConnected(itsDMConnection->isOpen()); - gui->setDataMonitorConnectionButton(isConnected); - return isConnected; -} - -int Controller::refreshStorageNodesInfo(bool doConnectToDM) { - if (doConnectToDM) { - if (itsDMConnection->isOpen()) { - // if (connectToDataMonitor()) { - if (itsDMConnection->updateStorageNodes()) { - // update the storage node information used for scheduling (wich is stored in the datablock) - // update the storage node information in the scheduler settings information used at startup of scheduler to fill the settingsdialog with last known storage nodes - data.initStorage(); // also clears all task claims on the storage nodes - // show the updated storage node information in the settings dialog - itsSettingsDialog->updateStorageNodeInfoTree(itsDMConnection->getStorageNodes(), itsDMConnection->getStates(), itsDMConnection->getHostPartitions()); - return 0; // OK - } - else return 1; // not connected to data monitor - } - else { // not yet connected to the data monitor - if (connectToDataMonitor()) { - if (itsDMConnection->updateStorageNodes()) { - // update the storage node information used for scheduling (wich is stored in the datablock) - // update the storage node information in the scheduler settings information used at startup of scheduler to fill the settingsdialog with last known storage nodes - data.initStorage(); // also clears all task claims on the storage nodes - // show the updated storage node information in the settings dialog - itsSettingsDialog->updateStorageNodeInfoTree(itsDMConnection->getStorageNodes(), itsDMConnection->getStates(), itsDMConnection->getHostPartitions()); - return 0; // OK - } - else return 1; // not connected to data monitor - } - else { - QMessageBox msgBox; - msgBox.setText("Could not connect to the data monitor."); - msgBox.setInformativeText("Do you want to continue?"); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::Yes); - int ret = msgBox.exec(); - if (ret == QMessageBox::Yes) { - data.initStorage(); // also clears all task claims on the storage nodes - itsSettingsDialog->updateStorageNodeInfoTree(itsDMConnection->getStorageNodes(), itsDMConnection->getStates(), itsDMConnection->getHostPartitions()); - return 0; // OK, user didn't want to connect to data monitor but does want to continue - } - else { - itsSettingsDialog->stopStorageWaitCursor(); - return 1; // not connected to data monitor - } - } - } - } - else { - data.initStorage(); // also clears all task claims on the storage nodes - itsSettingsDialog->updateStorageNodeInfoTree(itsDMConnection->getStorageNodes(), itsDMConnection->getStates(), itsDMConnection->getHostPartitions()); - return 0; - } -} - -void Controller::createInitialSchedule(void) -{ - if (data.getNrTasks()) { - gui->setStatusText("Creating Initial schedule"); - data.checkTasksForErrors(); - gui->writeTableData(data); - const errorTasksMap &errorTasks = data.getErrorTasks(); - if (!errorTasks.empty()) { - gui->setErrorCells(errorTasks); - QMessageBox mb("Error(s) in task(s)", - "The marked task properties have errors!\nDo you want to continue?\n Tasks with errors will get error status and will not be scheduled", - QMessageBox::Warning, - QMessageBox::Yes, - QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, - QMessageBox::NoButton); - const QRect &gui_pos = gui->geometry(); - mb.setGeometry(gui_pos.x()+gui_pos.width()/3, gui_pos.y()+gui_pos.height()/3, mb.width(), mb.height()); - int answer = mb.exec(); - if (answer == QMessageBox::Yes) { - data.markErrorTasksStatus(); // changes the error tasks status to ERROR - } - else { - return; - } - }// no new (unmarked) error tasks were found, it's save to continue - storeScheduleUndo(QObject::tr("Create initial schedule")); - scheduler.createStartSchedule(); - setSaveRequired(true); - gui->setEnableScheduleMenuItems(true); - - // update views - gui->writeTableData(data); - updateGraphicTasks(); - gui->setStatusText("Initial schedule created"); - updateStatusBar(); - } - else { - QMessageBox::warning(gui, tr("No tasks defined"), - tr("There are no tasks defined. Cannot create a start schedule."),tr("Close")); - } -} - -void Controller::start() -{ - // create scheduling data storage - gui->show(); // shows the GUI -} - -void Controller::fixTaskErrors() { - errorTasksMap tasks = data.getErrorTasks(); - gui->setErrorCells(tasks); - if (!tasks.empty()) { - - QMessageBox mb("Error(s) in task(s)", - "The marked task properties have errors!\nDo you want to Continue?\n Tasks with errors will get error status and skipped from further calculation", - QMessageBox::Warning, - QMessageBox::Yes, - QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, - QMessageBox::NoButton); - const QRect &gui_pos = gui->geometry(); - mb.setGeometry(gui_pos.x()+gui_pos.width()/3, gui_pos.y()+gui_pos.height()/3, mb.width(), mb.height()); - int answer = mb.exec(); - if (answer == QMessageBox::Yes) { - } - } -} - -/* -void Controller::tryRescheduleTask(unsigned task_id, AstroDateTime start_time) { - // check if multiple tasks are selected, if so try to 'shift' them all - if (multipleSelected()) { - const Task *pTask(data.getTask(task_id)); - AstroDateTime new_start; - AstroTime dif = pTask->getScheduledStart().timeDifference(start_time); - bool negative = start_time < pTask->getScheduledStart() ? true : false; - storeScheduleUndo("Reschedule of multiple tasks"); - bool save_required(true); - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - const Task *task(data.getTask(*it)); - if (negative) { - new_start = task->getScheduledStart() - dif; - } - else { - new_start = task->getScheduledStart() + dif; - } - if (!scheduler.tryRescheduleTask(*it, new_start)) { - undo(); - deleteLastStoredUndo(); - save_required = false; - break; - } - } - setSaveRequired(save_required); - } - else { - // TODO: check if the move of the task is not beyond the predecessor limits (if the task has predecessors) - storeTaskUndo(task_id, QString("Reschedule task ") + QString::number(task_id)); - if (scheduler.tryRescheduleTask(task_id, start_time)) { - setSaveRequired(true); - } - else { - deleteLastStoredUndo(); - } - } - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - gui->updateTask(*it,Task::OBSERVATION); - } -} -*/ - -void Controller::rescheduleTask(unsigned task_id, AstroDateTime new_start) { - const Task *pTask = data.getTask(task_id); - if ( (new_start >= pTask->getFirstPossibleDateTime()) & (new_start <= pTask->getLastPossibleDateTime()) ) { - storeTaskUndo(task_id, QString("Reschedule aborted task ") + QString::number(task_id)); - if (scheduler.rescheduleAbortedTask(task_id, new_start)) { - setSaveRequired(true); - gui->updateTask(pTask); - updateStatusBar(); - } - else { - deleteLastStoredUndo(); - } - } - else { - QMessageBox::warning(0, tr("Cannot reschedule task"), - tr("Could not reschedule the task.\nThe task's scheduling window (first possible date, last possible date) does not allow the task to be scheduled in the future.")); - QApplication::beep(); - } -} - -void Controller::rescheduleAbortedTask(unsigned task_id, AstroDateTime new_start) { - if (new_start.isSet()) { - rescheduleTask(task_id,new_start); - } - else { // reschedule the task at now - const AstroDateTime &timenow(now()); - if ((timenow >= Controller::theSchedulerSettings.getEarliestSchedulingDay()) | (timenow <= Controller::theSchedulerSettings.getLatestSchedulingDay())) { - rescheduleTask(task_id,timenow + Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); - } - else { - QMessageBox::warning(0, tr("Cannot reschedule task"), - tr("The current time is outside of the defined scheduling range.\nTasks can only be scheduled in the future.")); - QApplication::beep(); - } - } -} - -void Controller::showTaskDialog(unsigned taskID, tabIndex tab) const { - const Task *pTask = data.getTask(taskID); - if (pTask) { - gui->showTaskDialog(pTask, tab); - } - else { - QMessageBox::critical(gui,QObject::tr("Could not find task"), QObject::tr("Could not find task:") + QString::number(taskID)); - } -} - -void Controller::showTaskStateHistory(unsigned taskID) { - const Task *pTask = data.getTask(taskID); - if (pTask) { - int treeID(pTask->getSASTreeID()); - if (treeID != 0) { - itsSASConnection->showTaskStateHistory(treeID); - } - else { - QMessageBox::warning(0,QObject::tr("No history for new task"), QObject::tr("This seems to be a new task which is not in the SAS database yet")); - } - } -} - -void Controller::openSASTreeViewer(int treeID) const { - QString parsetTree(itsSASConnection->getTreeParset(treeID)); - OTDBtree otdb_tree(itsSASConnection->getTreeInfo(treeID)); - if (!parsetTree.isEmpty()) { - gui->parsetTreeView(parsetTree, otdb_tree); - } - else { - QMessageBox::warning(0, tr("Empty tree parset returned"), - tr("SAS could not create a tree parset for tree ") + QString::number(treeID)); - QApplication::beep(); - } -} - -void Controller::openMetaDataViewer(int treeID) const { - QString metaData(itsSASConnection->getMetaData(treeID)); - if (!metaData.isEmpty()) { - gui->parsetTreeView(metaData); - } - else { - QMessageBox::warning(0, tr("No meta-data available"), - tr("No meta-data is available for tree ") + QString::number(treeID)); - QApplication::beep(); - } -} - - -bool Controller::checkPredecessorsExistence(const IDvector &predecessors) const { - for (IDvector::const_iterator prit = predecessors.begin(); prit != predecessors.end(); ++prit) { - if (getTask(prit->second, prit->first) == 0) { - return false; - } - } - return true; -} - -bool Controller::updatePipelineTask(Task *task, bool createUndo) { - unsigned task_id = task->getID(); - - Task *pTask = data.getPipelineForChange(task_id); // a pointer to the task to change - if (pTask) { - - if (createUndo) { - storeTaskUndo(task_id, QString("Changes to pipeline task ") + QString::number(task_id)); - } - - // predecessor existence checks - if (task->hasPredecessors()) { - if (!checkPredecessorsExistence(task->getPredecessors())) { - if (QMessageBox::question(gui->taskDialog(), tr("Task has non existing predecessors"), - "The task has non-existing predecessors\nIf you continue the task status will be set to ERROR.\nDo you want to continue?", - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::No) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - else { - pTask->clone(task); - pTask->calculateDataFiles(); - pTask->setStatus(Task::ERROR); - pTask->setReason(unscheduled_reason_str[PREDECESSOR_NOT_FOUND]); - gui->updateTask(pTask); - gui->taskDialog()->updateStatus(Task::ERROR); - setSaveRequired(true); - return true; - } - } - } - - Task::task_status prevState(pTask->getStatus()), new_status(task->getStatus()); - - if (new_status <= Task::PRESCHEDULED) { - - // now check what needs to be changed and then apply the change - if (new_status == Task::PRESCHEDULED) { // task is just changed to a scheduled state - task->clearReason(); - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(task); - if (errCode.first == BEAM_DURATION_DIFFERENT) { - if (QMessageBox::question(gui->taskDialog(), tr("Beam duration different from observation duration"), - errCode.second.replace('$','\n') + tr("\nDo you want to continue?"), - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::No) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - } - else if (errCode.first != 0) { // the task has an error - if (QMessageBox::question(gui->taskDialog(), tr("Task has errors"), - errCode.second.replace('$','\n') + tr("\nIf you continue the task status will be set to ERROR.\nDo you want to continue?"), - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::No) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - else { - pTask->clone(task); - if ((prevState >= Task::PRESCHEDULED) && (prevState <= Task::ACTIVE)) { - data.unscheduleTask(task_id); - pTask->clearAllStorageConflicts(); - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - pTask->setStatus(Task::ERROR); - gui->taskDialog()->updateStatus(Task::ERROR); - setSaveRequired(true); - return true; - } - } - pTask->clone(task); - pTask->calculateDataFiles(); - data.scheduleTask(pTask); - pTask->setStatus(Task::PRESCHEDULED); - } - else if (new_status == Task::SCHEDULED) { - task->clearReason(); - pTask->clone(task); - pTask->calculateDataFiles(); - if (doScheduleChecks(pTask)) { - data.scheduleTask(pTask); - } - else { - pTask->setStatus(prevState); - } - } - else if (prevState == Task::ERROR) { // previously task had error, currently it is not (pre)scheduled - pTask->clone(task); - data.checkTask(pTask); - } - else { - pTask->clone(task); - } - - // upload the ON_HOLD status directly to SAS. If not possible (e.g. no connection) issue warning - if ((new_status == Task::ON_HOLD) && (prevState != Task::ON_HOLD)) { - setTaskOnHold(task_id, false); - } - - gui->updateTask(pTask); - setSaveRequired(true); - return true; - } - else return false; // may not be edited if status is above SCHEDULED - } - else { - debugErr("sis", "Controller::updatePipelineTask: task:", task_id, " not found"); - return false; - } -} - -// updateTask returns true if the task was updated and false otherwise -bool Controller::updateTask(Task *task, bool createUndo) { // task contains the new attributes of the task that need to be changed - unsigned task_id = task->getID(); - Task *pTask = data.getTaskForChange(task_id); // a pointer to the task to change - if (pTask) { - Task::task_status prev_status(pTask->getStatus()), new_status(task->getStatus()); - // check status of task. if status <= SCHEDULED then the task may be edited otherwise don't allow changes - if (prev_status <= Task::SCHEDULED) { - // create an undo level for the changes - if (new_status == Task::SCHEDULED && !doScheduleChecks(task)) { - return false; - } - if (createUndo) { - storeTaskUndo(task_id, QString("Changes to task ") + QString::number(task_id)); - } - - // check if (PRE)SCHEDULE checks need to be done - if ((new_status == Task::PRESCHEDULED) || (new_status == Task::SCHEDULED)) { - // new status is one of the scheduled states? - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(task); - if (errCode.first == BEAM_DURATION_DIFFERENT) { - if (QMessageBox::question(gui->taskDialog(), tr("Beam duration different from observation duration"), - errCode.second.replace('$','\n') + tr("\nDo you want to continue?"), - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::No) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - } - else if (errCode.first == USER_WARNING) { - if (QMessageBox::question(gui, tr("Warning"), - errCode.second + "\nDo you want to continue?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - } - - else if (errCode.first != NO_ERROR) { // the task has an error - if (QMessageBox::question(gui->taskDialog(), tr("Task has errors/conflict"), - errCode.second.replace('$','\n') + tr("\nIf you continue the task status will be set to ERROR/CONFLICT.\nDo you want to continue?"), - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::No) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - else { - pTask->clone(task); - pTask->calculateDataFiles(); - if ((prev_status >= Task::PRESCHEDULED) && (prev_status <= Task::ACTIVE)) { - data.unscheduleTask(task_id); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - } - if (errCode.first == TASK_CONFLICT) { - pTask->setStatus(Task::CONFLICT); - gui->taskDialog()->updateStatus(Task::CONFLICT); - } - else { - pTask->setStatus(Task::ERROR); - gui->taskDialog()->updateStatus(Task::ERROR); - } - gui->updateTask(pTask); - setSaveRequired(true); - return true; - } - } - if (new_status == Task::SCHEDULED) { - if (!doScheduleChecks(task)) { - if (createUndo) deleteLastStoredUndo(); - return false; - } - } - } - - // now check what needs to change and apply the change - - // TODO: When a task is put on SCHEDULED then ScheduleTask should be called. This function checks a.o. if storage is assigned correctly. - // if storage is not assigned correctly the task doesn't get its new state SCHEDULED. - // it should then be put back on its original state and the last stored undo information should be removed - - if ((prev_status >= Task::PRESCHEDULED) && (prev_status <= Task::ACTIVE)) { // if task was scheduled on stations - if (!task->isScheduled()) { // task is not scheduled anymore - data.unscheduleTask(task_id); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - } - else if (pTask->isStationTask() && task->isStationTask()) { - StationTask *pt(static_cast<StationTask *>(pTask)); - StationTask *po(static_cast<StationTask *>(task)); - if (pt->getStations() != po->getStations()) { // task is still scheduled but its stations were changed (unschedule and reschedule to update the stations bookkeeping) - data.unscheduleTask(task_id); - pt->setStations(po->getStations()); // set the new stations - if (new_status == Task::SCHEDULED) { - if (doScheduleChecks(pt)) { - data.scheduleTask(pt); - } - } - else { - data.scheduleTask(pt); - pt->setStatus(new_status); - } - } - } - else if ((pTask->getScheduledStart() != task->getScheduledStart()) || - (pTask->getScheduledEnd() != task->getScheduledEnd()) || - (pTask->getDuration() != task->getDuration())) { // still scheduled but its scheduling times were changed - data.changeTaskSchedule(task_id, task->getScheduledStart(), task->getScheduledEnd()); - } - pTask->clone(task); - } - else if ((new_status == Task::PRESCHEDULED) || (new_status == Task::SCHEDULED)) { // task is just changed to a scheduled state - task->clearReason(); - pTask->clone(task); - if (new_status == Task::SCHEDULED) { - if (doScheduleChecks(pTask)) { - data.scheduleTask(pTask); - } - } - else { - data.scheduleTask(pTask); - pTask->setStatus(new_status); - } - } - else if (prev_status == Task::ERROR) { // previously task had error, currently it is not (pre)scheduled - pTask->clone(task); - data.checkTask(pTask); - } - else { - pTask->clone(task); - } - pTask->calculateDataFiles(); - - // upload the on hold status directly to SAS. If not possible (e.g. no connection) issue warning - if ((new_status == Task::ON_HOLD) && (prev_status != Task::ON_HOLD)) { - setTaskOnHold(task_id, false); - } - - gui->updateTask(pTask); - updateStatusBar(); - setSaveRequired(true); - return true; - } - else return false; // may not be edited if status above SCHEDULED - } - else { - debugErr("sis", "Controller::updateTask: task:", task_id, " not found"); - return false; - } -} - -// synchronizeTask updates externally (i.e. OTDB) modified tasks in the scheduler -// parameter task holds the updated task -// if the task already exists in the scheduler then update its properties, -// if it does not yet exist then create it -void Controller::synchronizeTask(const Task *pTask) { - unsigned treeID(pTask->getSASTreeID()), taskID(pTask->getID()); - Task::task_status state(pTask->getStatus()); - - data.deleteTask(treeID, ID_SAS); // unschedules and deletes the existing task - - // create a new copyt of the task to add to the scheduler's datablock - Task *pClone = cloneTask(pTask); - - // Add the task to the unscheduled tasks, dont check if the ID is free becuase it could just be an update of a scheudler task already in memory - if (pClone->isStationTask()) { - data.addTask(pClone, false); - if (state >= Task::PRESCHEDULED && state <= Task::SCHEDULED) { - data.scheduleTask(pClone); - pClone->setStatus(state); - } - if (state >= Task::FINISHED) { - data.moveTaskToInactive(taskID); - } - } - else if (pClone->isPipeline()) { - Pipeline *pPipe(static_cast<Pipeline *>(pClone)); - data.addTask(pPipe, false); // adds the task to the unscheduled tasks - setInputFilesForPipeline(pPipe); - pPipe->calculateDataFiles(); - if (state >= Task::PRESCHEDULED && state <= Task::SCHEDULED) { - data.scheduleTask(pPipe); - pPipe->setStatus(state); - } - } - - gui->updateTask(pClone); - updateStatusBar(); -} - -/* -void Controller::synchronizeTask(const Task &task) { - unsigned treeID(task.getSASTreeID()), taskID(task.getID()); - Task::task_status state(task.getStatus()); - Task *schedulerTask = data.getTaskForChange(treeID, ID_SAS); - if (schedulerTask) { - Task::task_status prev_status(schedulerTask->getStatus()); - - if ((prev_status >= Task::PRESCHEDULED) && (prev_status <= Task::ACTIVE)) { // if task was scheduled on stations - data.unscheduleTask(taskID); - } - if (prev_status >= Task::FINISHED && state < Task::FINISHED) { - Task *pTask(data.moveTaskFromInactive(taskID)); - if (pTask) { - schedulerTask = pTask; - } - } - - taskID = schedulerTask->getID(); - *schedulerTask = task; // THIS DOES NOT WORK FOR DERIVED CLASSES BECAUSE THEIR PROPERTIES ARE NOT COPIED (ONLY THE BASE CLASS PROPERTIES ARE COPIED THROUGH BASE POINTERS!!!) - schedulerTask->setID(taskID); - } - else { // task not found in scheduler , create it now - if (task.isPipeline()) { - schedulerTask = data.newPipeline(taskID, static_cast<const Pipeline &>(task).pipelinetype(), OVERRIDE_SAS_TASKIDS); // this should always succeed because OVERRIDE_SAS_TASKIDS is true - if (schedulerTask) { - taskID = schedulerTask->getID(); - *schedulerTask = task; - schedulerTask->setID(taskID); - setInputFilesForPipeline(schedulerTask); - schedulerTask->calculateDataFiles(); - } - else { - std::cerr << "Controller::synchronizeTask: Could not create Pipeline task for tree:" << treeID << std::endl; - return; - } - } - else { // TODO: Also tasks of type SYSTEM are for the moment created here to prevent SEGFAULTs. But it should maybe be created in another way than with newTask? - schedulerTask = data.newTask(taskID, OVERRIDE_SAS_TASKIDS); // this should always succeed because OVERRIDE_SAS_TASKIDS is true - if (schedulerTask) { - taskID = schedulerTask->getID(); - *schedulerTask = task; - schedulerTask->setID(taskID); - } - else { - std::cerr << "Controller::synchronizeTask: Could not create task for tree:" << treeID << std::endl; - return; - } - } - } - - if (task.isScheduled()) { - data.scheduleTask(schedulerTask); - Task *pTask = data.getTaskForChange(taskID); - pTask->setStatus(task.getStatus()); - } - else { - if (state >= Task::FINISHED) { - data.moveTaskToInactive(taskID); - } - } - - gui->updateTask(treeID, ID_SAS, task.getType()); - updateStatusBar(); -} -*/ - -/* -void Controller::abortTask(unsigned int taskID) { - Task *pTask = data.getScheduledTaskForChange(taskID); - if (pTask) { - Task::task_status status = pTask->getStatus(); - if ((status == Task::ACTIVE) | (status == Task::STARTING) | (status == Task::SCHEDULED)) { - QString taskStr = tr("Aborting task (") + QString::number(taskID) + ") " + pTask->getTaskName() + ", SAS_ID:" + QString::number(pTask->getSASTreeID()); - if (QMessageBox::question(0, taskStr, - taskStr + "\n" + tr("The abort will be instantaneously committed to SAS.\nThe abort cannot be undone.\nDo you really want to abort the task?"), - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::Yes) { - if (itsSASConnection->abortTask(pTask->getSASTreeID())) { - pTask->setStatus(Task::ABORTED); - data.moveTaskToInactive(taskID); - gui->updateTask(taskID); - updateStatusBar(); - } - else { - QMessageBox::critical(0, tr("Could not abort the task"), - tr("Could not abort the task. Probably the task is not in the ACTIVE or STARTING state")); - } - } - } - } -} -*/ - -const char *Controller::getReservationName(unsigned reservation_id) const { - const Task *pRes = data.getReservation(reservation_id); - if (pRes) return pRes->getTaskName(); - else return 0; -} - -std::pair<unscheduled_reasons, QString> Controller::doPreScheduleChecks(Task *task) { - // only add checks to this function that really should block the task from being (pre)scheduled - std::pair<unscheduled_reasons, QString> error; - error.first = NO_ERROR; - - // check for zero duration - if (!task->getDuration().isSet()) { - task->setReason(unscheduled_reason_str[ZERO_DURATION]); - error.first = ZERO_DURATION; - error.second = unscheduled_reason_str[ZERO_DURATION]; - return error; - } - - // start time not set - if (!task->getScheduledStart().isSet()) { - task->setReason(unscheduled_reason_str[START_TIME_NOT_SET]); - error.first = START_TIME_NOT_SET; - error.second = unscheduled_reason_str[START_TIME_NOT_SET]; - return error; - } - // stop time not set - if (!task->getScheduledEnd().isSet()) { - task->setReason(unscheduled_reason_str[END_TIME_NOT_SET]); - error.first = END_TIME_NOT_SET; - error.second = unscheduled_reason_str[END_TIME_NOT_SET]; - return error; - } - - QDateTime currentTime = QDateTime::currentDateTimeUtc(); - AstroDateTime now = AstroDateTime(currentTime.date().day(), currentTime.date().month(), currentTime.date().year(), - currentTime.time().hour(), currentTime.time().minute(), currentTime.time().second()); - const AstroTime &minTime(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); - if (task->isObservation() || task->isPipeline()) { - if (task->getScheduledStart() < now + minTime) { - task->setReason(unscheduled_reason_str[SCHEDULED_TOO_EARLY]); - error.first = SCHEDULED_TOO_EARLY; - error.second = unscheduled_reason_str[SCHEDULED_TOO_EARLY]; - return error; - } - } - - error = checkPredecessorDependencies(task, Task::PRESCHEDULED); - if (error.first != NO_ERROR) { - task->setReason(unscheduled_reason_str[error.first]); - return error; - } - - if (task->isObservation()) { - Observation *pObs(static_cast<Observation *>(task)); - // check for unspecified antenna mode - if (pObs->getAntennaMode() == UNSPECIFIED_ANTENNA_MODE) { - pObs->setReason(unscheduled_reason_str[ANTENNA_MODE_UNSPECIFIED]); - error.first = ANTENNA_MODE_UNSPECIFIED; - error.second = unscheduled_reason_str[ANTENNA_MODE_UNSPECIFIED]; - return error; - } - // check for unspecified clock - if (pObs->getStationClock() == UNSPECIFIED_CLOCK) { - pObs->setReason(unscheduled_reason_str[UNSPECIFIED_CLOCK]); - error.first = CLOCK_FREQUENCY_UNSPECIFIED; - error.second = unscheduled_reason_str[CLOCK_FREQUENCY_UNSPECIFIED]; - return error; - } - // check for unspecified filter - if (pObs->getFilterType() == UNSPECIFIED_FILTER) { - pObs->setReason(unscheduled_reason_str[UNSPECIFIED_FILTER]); - error.first = FILTER_TYPE_UNSPECIFIED; - error.second = unscheduled_reason_str[FILTER_TYPE_UNSPECIFIED]; - return error; - } - // check for incompatible antenna mode and filter type - if (QString(pObs->getAntennaModeStr()).left(3) != QString(pObs->getFilterTypeStr()).left(3)) { - pObs->setReason(unscheduled_reason_str[INCOMPATIBLE_ANTENNA_AND_FILTER]); - error.first = INCOMPATIBLE_ANTENNA_AND_FILTER; - error.second = unscheduled_reason_str[INCOMPATIBLE_ANTENNA_AND_FILTER]; - return error; - } - // check for incompatible station clock and filter settings - station_clock clock(pObs->getStationClock()); - station_filter_type filter(pObs->getFilterType()); - if ((clock != UNSPECIFIED_CLOCK) & (filter != UNSPECIFIED_FILTER)) { - if ((clock == clock_160Mhz) & ((filter == LBA_10_70) | (filter == LBA_30_70) | (filter == HBA_170_230))) { /* compatible 160MHz */ } - else if ((clock == clock_200Mhz) & ((filter == LBA_10_90) | (filter == LBA_30_90) | (filter == HBA_110_190) | (filter == HBA_210_250))) { /* compatible 200MHz */ } - else { - pObs->setReason(unscheduled_reason_str[INCOMPATIBLE_CLOCK_AND_FILTER]); - error.first = INCOMPATIBLE_CLOCK_AND_FILTER; - error.second = unscheduled_reason_str[INCOMPATIBLE_CLOCK_AND_FILTER]; - return error; - } - } - // check for empty station list - if (pObs->getStations().empty()) { - pObs->setReason(unscheduled_reason_str[NO_STATIONS_DEFINED]); - error.first = NO_STATIONS_DEFINED; - error.second = unscheduled_reason_str[NO_STATIONS_DEFINED]; - return error; - } - - // check for forbidden station combinations and empty station list / non-existing stations - unscheduled_reasons reason = data.checkTaskStations(pObs); - if (reason != NO_ERROR) { - error.first = reason; - error.second = pObs->getReason().c_str(); - return error; - } - - // check for empty subband lists in digital beams - int i = 0; - bool showRelativeCoordWarning(false); - const std::map<unsigned, DigitalBeam> &digiBeams = pObs->getDigitalBeams(); - for (std::map<unsigned, DigitalBeam>::const_iterator it = digiBeams.begin(); it != digiBeams.end(); ++it) { - if (it->second.nrSubbands() == 0) { - pObs->setReason(unscheduled_reason_str[EMPTY_SUBBAND_LIST]); - error.first = EMPTY_SUBBAND_LIST; - error.second = QString(unscheduled_reason_str[EMPTY_SUBBAND_LIST]) + " for beam " + QString::number(i); - return error; - } - // check for relative TAB coordinates (if 0,0 is specified than most likely the user did not change the angles to absolute coordinates yet) - if (!showRelativeCoordWarning) { - const std::map<unsigned, TiedArrayBeam> &Tabs(it->second.tiedArrayBeams()); - for (std::map<unsigned, TiedArrayBeam>::const_iterator tabit = Tabs.begin(); tabit != Tabs.end(); ++tabit) { - if (tabit->second.isCoherent() && tabit->second.angle1() < std::numeric_limits<double>::epsilon() && tabit->second.angle2() < std::numeric_limits<double>::epsilon()) { - showRelativeCoordWarning = true; - break; - } - } - } - ++i; - } - - // check the total number of subbands - unsigned short nrSubbands(pObs->getNrOfSubbands()); - switch (pObs->getBitMode()) { -/* - case 2: - if (nrSubbands > MAX_DATASLOTS_2_BITS) { - pObs->setReason(unscheduled_reason_str[TOO_MANY_SUBBANDS]); - error.first = TOO_MANY_SUBBANDS; - error.second = unscheduled_reason_str[TOO_MANY_SUBBANDS] + "\nFor 2 bits mode only " + QString::number(MAX_DATASLOTS_2_BITS) + " subbands are allowed"; - return error; - } - break; -*/ - case 4: - if (nrSubbands > MAX_DATASLOTS_4_BITS) { - pObs->setReason(unscheduled_reason_str[TOO_MANY_SUBBANDS]); - error.first = TOO_MANY_SUBBANDS; - error.second = QString(unscheduled_reason_str[TOO_MANY_SUBBANDS]) + "\nFor 4 bits mode only " + QString::number(MAX_DATASLOTS_4_BITS) + " subbands are allowed"; - return error; - } - break; - case 8: - if (nrSubbands > MAX_DATASLOTS_8_BITS) { - pObs->setReason(unscheduled_reason_str[TOO_MANY_SUBBANDS]); - error.first = TOO_MANY_SUBBANDS; - error.second = QString(unscheduled_reason_str[TOO_MANY_SUBBANDS]) + "\nFor 8 bits mode only " + QString::number(MAX_DATASLOTS_8_BITS) + " subbands are allowed"; - return error; - } - break; - case 16: - if (nrSubbands > MAX_DATASLOTS_16_BITS) { - pObs->setReason(unscheduled_reason_str[TOO_MANY_SUBBANDS]); - error.first = TOO_MANY_SUBBANDS; - error.second = QString(unscheduled_reason_str[TOO_MANY_SUBBANDS]) + "\nFor 16 bits mode only " + QString::number(MAX_DATASLOTS_16_BITS) + " subbands are allowed"; - return error; - } - break; - default: // unknown bit mode - pObs->setReason(unscheduled_reason_str[UNKNOWN_BITMODE]); - error.first = UNKNOWN_BITMODE; - error.second = unscheduled_reason_str[UNKNOWN_BITMODE]; - return error; - } - - // check beam duration difference from observation duration - QString beamDurStr; - const AstroTime &duration(pObs->getDuration()); - for (std::map<unsigned, DigitalBeam>::const_iterator it = digiBeams.begin(); it != digiBeams.end(); ++it) { - if ((it->second.duration().totalSeconds() > 0) && (it->second.duration() != duration)) { - beamDurStr += QString(it->second.target().c_str()) + "(" + it->second.duration().toString().c_str() + ")\n"; - } - } - const Observation::RTCPsettings &rtcp(pObs->getRTCPsettings()); - TaskStorage::enableDataProdukts odp(pObs->storage()->getOutputDataProductsEnabled()); - - if ((odp.coherentStokes || odp.incoherentStokes /*|| odp.complexVoltages*/) && !rtcp.flysEye && (pObs->totalNrTABs() == 0)) { - error.first = NO_TABS_DEFINED; - error.second = unscheduled_reason_str[NO_TABS_DEFINED]; - pObs->setReason(unscheduled_reason_str[NO_TABS_DEFINED]); - return error; - } - - if (odp.incoherentStokes && (pObs->nrIncoherentTABs() == 0)) { - error.first = NO_INCOHERENT_TABS_DEFINED; - error.second = unscheduled_reason_str[NO_INCOHERENT_TABS_DEFINED]; - pObs->setReason(unscheduled_reason_str[NO_INCOHERENT_TABS_DEFINED]); - return error; - } - - if (odp.coherentStokes && (pObs->nrCoherentTABs() == 0) && (pObs->nrTABrings() == 0) && !rtcp.flysEye) { - error.first = NO_COHERENT_TABS_DEFINED; - error.second = unscheduled_reason_str[NO_COHERENT_TABS_DEFINED]; - pObs->setReason(unscheduled_reason_str[NO_COHERENT_TABS_DEFINED]); - return error; - } - - /* NOT FOR COBALT - if (odp.coherentStokes && (rtcp.coherentChannelsPerSubband != 0)) { - if (fmod((double)rtcp.channelsPerSubband, rtcp.coherentChannelsPerSubband) > 0) { - error.first = WRONG_CHANNEL_COLLAPSE; - error.second = "Channels per subband must be integer multiple or equal to coherent channels per subband"; - pObs->setReason(unscheduled_reason_str[WRONG_CHANNEL_COLLAPSE]); - return error; - } - } - */ - - if (odp.coherentStokes && rtcp.coherentChannelsPerSubband == 0) { - error.first = WRONG_CHANNEL_COLLAPSE; - error.second = "coherent channels per subband setting may not be zero"; - pObs->setReason("coherent channels per subband setting may not be zero"); - return error; - } - - /* NOT FOR COBALT - if (odp.incoherentStokes && (rtcp.incoherentChannelsPerSubband != 0)) { - if (fmod((double)rtcp.channelsPerSubband, rtcp.incoherentChannelsPerSubband) > 0) { - error.first = WRONG_CHANNEL_COLLAPSE; - error.second = "Channels per subband must be integer multiple or equal to incoherent channels per subband"; - pObs->setReason(unscheduled_reason_str[WRONG_CHANNEL_COLLAPSE]); - return error; - } - } - */ - - if (odp.incoherentStokes && rtcp.incoherentChannelsPerSubband == 0) { - error.first = WRONG_CHANNEL_COLLAPSE; - error.second = "incoherent channels per subband setting may not be zero"; - pObs->setReason("incoherent channels per subband setting may not be zero"); - return error; - } - - if ((!odp.incoherentStokes) && (!odp.coherentStokes) && (!odp.correlated)) { - error.first = NO_DATA_OUTPUT_SELECTED; - error.second = unscheduled_reason_str[NO_DATA_OUTPUT_SELECTED]; - pObs->setReason(unscheduled_reason_str[NO_DATA_OUTPUT_SELECTED]); - return error; - } - - - // check for conflicts with overlapping tasks - if (!data.checkStationConflicts(pObs)) { - error.first = TASK_CONFLICT; - error.second = pObs->getReason().c_str(); - return error; - } - - if (pObs->getReservation() != 0) { - std::pair<bool, std::pair<QString, Observation> > result(doReservationChecks(pObs, pObs->getReservation())); - if (result.first) { - error.first = NOT_COMPATIBLE_WITH_RESERVATION; - error.second = result.second.first; - return error; - } - } - - // (non severe tests) such as beamduration test should be the last test (user is still allowed to set the task to PRESCHEDULED - if (!beamDurStr.isEmpty()) { - error.first = BEAM_DURATION_DIFFERENT; - error.second = QString(unscheduled_reason_str[BEAM_DURATION_DIFFERENT]) + " (" + duration.toString().c_str() + ") for beam:\n" + beamDurStr; - return error; - } - - if (showRelativeCoordWarning) { - error.first = USER_WARNING; - error.second = "(0.0, 0.0) TAB coordinates detected. Did you forget to specify the TABs in absolute coordinates?"; - } - - - } // END if task->isObservation() - else if (task->isStationTask()) { // e.g. MAINTENANCE or RESERVATION - StationTask *psTask(static_cast<StationTask *>(task)); - // check for conflicts with overlapping tasks - if (!data.checkStationConflicts(psTask)) { - error.first = TASK_CONFLICT; - error.second = psTask->getReason().c_str(); - return error; - } - } - else if (task->isPipeline()) { // PIPELINE checks here - Pipeline *pPipe(static_cast<Pipeline *>(task)); - itsSASConnection->translateMomPredecessors(pPipe->getPredecessorsForChange()); - - // check demixing and averaging settings - // demix freq step should be multiple of (averaging freq step) - // same for demix time step and averaging time step - // but this should only lead to error when demixing is actually done - if (pPipe->isCalibrationPipeline()) { - CalibrationPipeline *pCalPipe(static_cast<CalibrationPipeline *>(pPipe)); - if (pCalPipe->demixingEnabled()) { - const DemixingSettings &demixing(pCalPipe->demixingSettings()); - // TODO: see Redmine issue #4923. The check if there are sources to demix cannot be used yet. - // the demix freq step and time step still need checking because the demixer will always be started in the pipeline and throw an assertion if these are wrong - // needs fixing in the pipeline first. - if ((demixing.freqStep() != 0) && (demixing.timeStep() != 0)) { - if ((demixing.demixFreqStep() % demixing.freqStep() != 0) || (demixing.demixTimeStep() % demixing.timeStep() != 0)) { - error.first = INCOMPATIBLE_DEMIX_SETTINGS; - error.second = unscheduled_reason_str[INCOMPATIBLE_DEMIX_SETTINGS]; - task->setReason(unscheduled_reason_str[INCOMPATIBLE_DEMIX_SETTINGS]); - return error; - } - } - else { - error.first = INCOMPATIBLE_DEMIX_SETTINGS; - error.second = unscheduled_reason_str[INCOMPATIBLE_DEMIX_SETTINGS]; - task->setReason(unscheduled_reason_str[INCOMPATIBLE_DEMIX_SETTINGS]); - return error; - } - - // check for unknown demix sources - const QStringList &demix_src = theSchedulerSettings.getDemixSources(); - QStringList dsra(demixing.demixAlways().split(",", QString::SkipEmptyParts)); - QStringList dsri(demixing.demixIfNeeded().split(",", QString::SkipEmptyParts)); - QStringList invalid_srcs; - foreach (const QString &src, dsra) { - if (!demix_src.contains(src)) { - invalid_srcs.append(src); - } - } - foreach (const QString &src, dsri) { - if (!demix_src.contains(src)) { - invalid_srcs.append(src); - } - } - if (!invalid_srcs.isEmpty()) { - error.first = UNKNOWN_DEMIX_SOURCE; - error.second = QString("Unknown demix sources specified:") + invalid_srcs.join(","); - task->setReason(error.second.toStdString()); - return error; - } - } - } - - // TODO: setInputFilesForPipeline should probably not be done here. Only set the input files when a task is downloaded from SAS or when it is just loaded from disk - // now the enabled flags (user selection) gets reset by calling setInputFilesForPipeline which is also a bug. This should not be the case - error = setInputFilesForPipeline(pPipe); - - //WK code commented out -// if (pPipe->isCalibrationPipeline() && -// !task->storage()->getEqualityInputOutputProducts()) -// { -// error.first = INPUT_OUTPUT_LOCATION_MISMATCH1; -// error.second = unscheduled_reason_str[INPUT_OUTPUT_LOCATION_MISMATCH2]; -// return error; -// } - - - if (error.first != NO_ERROR) return error; - } - - if (error.first == NO_ERROR) { - if (task->hasStorage()) { - task->calculateDataFiles(); - task->storage()->generateFileList(); - } - } - // Check here if the input output locations are the same - // Check added due to #8174 -// if (task->isPipeline()) -// { -// // TODO: This is incredibly ugly!!! -// Pipeline *pipeline = dynamic_cast<Pipeline *>(task); -// -// if (pipeline->isCalibrationPipeline() && -// !task->storage()->getEqualityInputOutputProducts()) -// { -// error.first = INPUT_OUTPUT_LOCATION_MISMATCH2; -// error.second = unscheduled_reason_str[INPUT_OUTPUT_LOCATION_MISMATCH2]; -// return error; -// } -// } - - // if we arrrive here no errors in the task - task->clearReason(); - - return error; -} - -std::pair<unscheduled_reasons, QString> Controller::checkPredecessorDependencies(const Task *pTask, Task::task_status newState) const { - // check predecessors statuses. They must have at least PRESCHEDULED state - std::pair<unscheduled_reasons, QString> error; - const IDvector &predecessorIDs(pTask->getPredecessors()); - if (!predecessorIDs.empty()) { - Task::task_status predState; - // check if all predecessors are equal or beyond the SCHEDULED status, if not this task may not yet be scheduled - const Task *predTask; - for (IDvector::const_iterator predit = predecessorIDs.begin(); predit != predecessorIDs.end(); ++ predit) { - predTask = data.getTask(predit->second, predit->first); - if (predTask) { - predState = predTask->getStatus(); - if ((predState < newState) || (predState > Task::ABORTED)) { - error.first = PREDECESSOR_UNSCHEDULED; - error.second = "The task cannot be scheduled because not all its predecessors are (pre)scheduled..aborted.\nThe predecessors may not have a lower state."; - return error; // not all predecessors in correct state, cannot schedule the current task - } - else if (pTask->getScheduledStart() < predTask->getRealEnd() + theSchedulerSettings.getMinimumTimeBetweenTasks()) { - error.first = TOO_CLOSE_OR_BEFORE_PREDECESSOR; - error.second = "The start time is before or too close to the predecessor task " + QString::number(predTask->getID()); - return error; // not all predecessors in correct state, cannot schedule the current task - } - } - else { - error.first = PREDECESSOR_NOT_FOUND; - error.second = QString("The task cannot be scheduled because the predecessor ") + QString::number(predit->second) + " could not be found"; - return error; // one of the predecessors could not be found - } - } - } - return error; -} - - -// doReservationChecks checks if the task is compatible with the reservation specified in the task -// returns pair<bool, Task>; bool is true -> changes needed, new compatible Task with changes is returned as second part of pair -// if bool is false means task is already compatible and no changes are needed or the reservation was not found -std::pair<bool, std::pair<QString, Observation> > Controller::doReservationChecks(const Observation *orgObs, unsigned reservationID) { - std::pair<bool, std::pair<QString, Observation> > returnValue; - returnValue.first = false; - returnValue.second.second.clone(orgObs); - Observation &compatibleTask(returnValue.second.second); - QString &msg(returnValue.second.first); - - if (reservationID) { - const StationTask *reservation = data.getReservation(reservationID); - if (reservation) { - msg = "The following changes are needed to make the task compatible with the reservation:\n"; - // check if task is no longer than the reservation - const AstroTime &reservationDuration(reservation->getDuration()); - if (orgObs->getDuration() > reservationDuration) { - compatibleTask.setDuration(reservationDuration); // shorten task - msg += QString("- task duration shortened to ") + reservationDuration.toString().c_str() +"\n"; - returnValue.first = true; - } - if (orgObs->isStationTask()) { - // check if the stations of the task are a subset of the reserved stations - const taskStationsMap &stations = orgObs->getStations(); - const taskStationsMap &resStations = reservation->getStations(); - std::vector<std::string> newStations; - bool stationsChanged(false); - QString removedStations("- removed stations:"); - for (taskStationsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - if (resStations.find(it->first) != resStations.end()) { - newStations.push_back(it->first); - } - else { - removedStations += QString(it->first.c_str()) + " "; - stationsChanged = true; - } - } - compatibleTask.setStations(newStations); - - if (stationsChanged) { - msg += removedStations += "\n"; - returnValue.first = true; - } - - // check if antenna settings are the same - if ((reservation->getAntennaMode() != UNSPECIFIED_ANTENNA_MODE) && (orgObs->getAntennaMode() != reservation->getAntennaMode())) { - compatibleTask.setAntennaMode(reservation->getAntennaMode()); - msg += QString("- antenna mode changed from ") + orgObs->getAntennaModeStr() + " to " + compatibleTask.getAntennaModeStr() + "\n"; - returnValue.first = true; - } - if ((reservation->getStationClock() != UNSPECIFIED_CLOCK) && (orgObs->getStationClock() != reservation->getStationClock())) { - compatibleTask.setStationClock(reservation->getStationClock()); - msg += QString("- station clock changed from ") + orgObs->getStationClockStr() + " to " + compatibleTask.getStationClockStr() + "\n"; - returnValue.first = true; - } - if ((reservation->getFilterType() != UNSPECIFIED_FILTER) && (orgObs->getFilterType() != reservation->getFilterType())) { - compatibleTask.setFilterType(reservation->getFilterType()); - msg += QString("- station filter changed from ") + orgObs->getFilterTypeStr() + " to " + compatibleTask.getFilterTypeStr() + "\n"; - returnValue.first = true; - } - } - - - // check the scheduled times of the task and if needed find new schedule times within reservation - - const AstroDateTime &scheduledStart = orgObs->getScheduledStart(); - const AstroDateTime &resStart = reservation->getScheduledStart(); - const AstroDateTime &resEnd = reservation->getScheduledEnd(); - if ((scheduledStart < resStart) || (scheduledStart > resEnd)) { - AstroDateTime start(resStart); - data.findFirstOpportunity(orgObs, start, reservationID); - compatibleTask.setScheduledStart(start); - msg += QString("- scheduled start changed from ") + - orgObs->getScheduledStart().toString().c_str() + - " to " + compatibleTask.getScheduledStart().toString().c_str() + "\n"; - returnValue.first = true; - } - // minimum and maximum time window - if ((orgObs->getWindowFirstDay() < resStart) || (orgObs->getWindowFirstDay() > resEnd)) { - compatibleTask.setWindowFirstDay(resStart); - msg += QString("- first possible date changed from ") + - orgObs->getWindowFirstDay().toString().c_str() + - " to " + compatibleTask.getWindowFirstDay().toString().c_str() + "\n"; - returnValue.first = true; - } - if ((orgObs->getWindowLastDay() < resStart) || (orgObs->getWindowLastDay() > resEnd)) { - compatibleTask.setWindowLastDay(resEnd); - msg += QString("- last possible date changed from ") + - orgObs->getWindowLastDay().toString().c_str() + - " to " + compatibleTask.getWindowLastDay().toString().c_str() + "\n"; - returnValue.first = true; - } - if (orgObs->getWindowMinTime() < resStart.getTime()) { - compatibleTask.setWindowMinTime(resStart.getTime()); - msg += QString("- first possible time changed from ") + - orgObs->getWindowMinTime().toString().c_str() + - " to " + compatibleTask.getWindowMinTime().toString().c_str() + "\n"; - returnValue.first = true; - } - if (orgObs->getWindowMaxTime() < resEnd.getTime()) { - compatibleTask.setWindowMaxTime(resEnd.getTime()); - msg += QString("- last possible time changed from ") + - orgObs->getWindowMaxTime().toString().c_str() + - " to " + compatibleTask.getWindowMaxTime().toString().c_str() + "\n"; - returnValue.first = true; - } - } - else { - debugWarn("sis","reservation with ID:", reservationID, " not found!"); - } - } - return returnValue; -} - - -void Controller::multiEditSelectedTasks(void) { - bool showReservationWarning(false), showScheduledWarning(false); - std::vector<Task *> selectedTasks; - Task *pTask; - for (std::vector<unsigned>::iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - pTask = data.getTaskForChange(*it); - if (pTask) { - if (pTask->getType() != Task::RESERVATION) { - if (pTask->getStatus() <= Task::PRESCHEDULED) { - selectedTasks.push_back(pTask); - } - else { - showScheduledWarning = true; - } - } - else { - showReservationWarning = true; - } - } - } - if (showReservationWarning || showScheduledWarning) { - if (!selectedTasks.empty()) { - if (QMessageBox::question(gui, tr("Some tasks cannot be edited"), - tr("Tasks with status SCHEDULED and above and reservations cannot be (multi)edited.\n These tasks will be de-selected. Do you want to continue?"), - QMessageBox::Yes, - QMessageBox::No) == QMessageBox::Yes) { - std::vector<unsigned> newSelection; - for (std::vector<Task *>::const_iterator it = selectedTasks.begin(); it != selectedTasks.end(); ++it) { - newSelection.push_back((*it)->getID()); - } - selectTasks(newSelection); // sets the new selection (without reservations) - if (!selectedTasks.empty()) { - gui->multiEditTasks(selectedTasks); - return; - } - } - else return; // do not continue - } - else { - QMessageBox::warning(gui, tr("None of the selected tasks can be edited"), - tr("Tasks with status SCHEDULED and above and reservations cannot be (multi)edited.\n There are no other tasks left in the selection that can be (multi-)edited")); - return; - } - } - if (!selectedTasks.empty()) { - gui->multiEditTasks(selectedTasks); - return; - } - else { - QMessageBox::warning(0, tr("Not tasks to multi-edit"), - tr("No tasks remain for multi-edit.")); - QApplication::beep(); - } -} - -void Controller::selectCurrentTaskGroups(selector_types type) { - if (!itsSelectedTasks.empty()) { - QApplication::setOverrideCursor(Qt::WaitCursor); - std::vector<unsigned> groups; - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - const Task *pTask(data.getTask(*it)); - if (pTask) { - unsigned group(pTask->getGroupID()); - if (group != 0) { - if (find(groups.begin(), groups.end(), group) == groups.end()) { - groups.push_back(group); - } - } - } - } - std::vector<unsigned> tasksToSelect; - for (std::vector<unsigned>::const_iterator groupIt = groups.begin(); groupIt != groups.end(); ++groupIt) { - std::vector<unsigned> groupTasks(data.tasksInGroup(*groupIt, type)); - tasksToSelect.insert(tasksToSelect.end(), groupTasks.begin(), groupTasks.end()); - } - if (!tasksToSelect.empty()) { - selectTasks(tasksToSelect); - QApplication::restoreOverrideCursor(); - } - else { - QApplication::restoreOverrideCursor(); - QMessageBox::information(gui, "No tasks to select", "No tasks of this type could be found to select"); - } - } -} - - -void Controller::selectTask(unsigned taskID, bool singleSelection, bool selectRows, bool tableClick) { - if (singleSelection) { - itsSelectedTasks.clear(); - gui->selectTask(taskID, singleSelection, selectRows, tableClick); - itsSelectedTasks.push_back(taskID); - } - else { - if (find(itsSelectedTasks.begin(), itsSelectedTasks.end(), taskID) == itsSelectedTasks.end()) { // not already selected? - gui->selectTask(taskID, singleSelection, selectRows, tableClick); - itsSelectedTasks.push_back(taskID); - } - } -} - -void Controller::deselectTask(unsigned taskID, bool singleSelection, bool selectRows) { - std::vector<unsigned>::iterator it = find(itsSelectedTasks.begin(), itsSelectedTasks.end(), taskID); - if (it != itsSelectedTasks.end()) { // is it currently selected? - gui->deselectTask(taskID, singleSelection, selectRows); - itsSelectedTasks.erase(it); - } -} - -void Controller::selectTasks(const std::vector<unsigned> &taskIDs) { - itsSelectedTasks.clear(); - for (std::vector<unsigned>::const_iterator it = taskIDs.begin(); it != taskIDs.end(); ++it) { - if ((find(itsSelectedTasks.begin(), itsSelectedTasks.end(), *it)) == itsSelectedTasks.end()) { - itsSelectedTasks.push_back(*it); - } - } - gui->selectTasks(itsSelectedTasks); -} - -bool Controller::isSelected(unsigned taskID) { - return (find(itsSelectedTasks.begin(), itsSelectedTasks.end(), taskID) != itsSelectedTasks.end()); -} - -void Controller::deselectAllTasks(void) { - itsSelectedTasks.clear(); - gui->clearSelection(); -} - -bool Controller::isDeleted(unsigned taskID) const { - for (deletedTasksVector::const_iterator it = itsDeletedTasks.begin(); it != itsDeletedTasks.end(); ++it) { - for (vector<Task *>::const_iterator tit = it->begin(); tit != it->end(); ++tit) { - if ((*tit)->getID() == taskID) return true; - } - } - return false; -} - - -bool Controller::unDelete(unsigned taskID) { - for (deletedTasksVector::iterator it = itsDeletedTasks.begin(); it != itsDeletedTasks.end(); ++it) { - for (vector<Task *>::iterator tit = it->begin(); tit != it->end(); ++tit) { - if ((*tit)->getID() == taskID) { // found the task - Task::task_status status((*tit)->getStatus()); - data.addTask(*tit, false); - if ((*tit)->isScheduled()) { - data.scheduleTask(*tit); - (*tit)->setStatus(status); - } - else if (status >= Task::FINISHED) { - data.moveTaskToInactive(taskID); - } - gui->addTask(*tit); - itsSASConnection->removeFromSASTaskToDelete((*tit)->getSASTreeID()); - it->erase(tit); // deletes the task from the deletedTasksVector - - // update the undo info so that it doesn't try to undo the deletion of this task again - for (undoTypeVector::iterator uit = itsUndoType.begin(); uit != itsUndoType.end(); ++uit) { - if (uit->first == UNDO_DELETE_TASKS) { - for (vector<unsigned>::iterator vit = uit->second.second.begin(); vit != uit->second.second.end(); ++vit) { - if (*vit == taskID) { - uit->second.second.erase(vit); - if (uit->second.second.empty()) { // this undo step has no tasks left, remove it from the undo stack - gui->removeUndo(uit->second.first); - itsUndoType.erase(uit); - } - return true; - } - } - } - } - } - } - } - return false; -} - -void Controller::unscheduleSelectedTasks(void) { - if (!itsSelectedTasks.empty()) { - storeScheduleUndo(QObject::tr("unschedule task(s)")); - Task *pTask; - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - if (data.unscheduleTask(*it)) { - pTask = data.getTaskForChange(*it); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - gui->removeTaskFromScene(*it); - gui->updateTableTask(pTask); - updateStatusBar(); - } - } - } -} - -void Controller::setSelectedTasksOnHold(void) { - if (!itsSelectedTasks.empty()) { - bool undo_needed(false), warning(false); - storeScheduleUndo(QObject::tr("set (multiple) task(s) on hold")); - Task::task_status status; - Task *pTask; - std::vector<int> SAStrees; - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - pTask = data.getTaskForChange(*it); - status = pTask->getStatus(); - if (status <= Task::SCHEDULED) { - if (!((status == Task::UNSCHEDULED) || (status == Task::ERROR))) { - data.unscheduleTask(*it); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - gui->removeTaskFromScene(*it); - } - undo_needed = true; - pTask->setStatus(Task::ON_HOLD); - gui->updateTableTask(pTask); - SAStrees.push_back(pTask->getSASTreeID()); - } - else warning = true; - } - if (!undo_needed) { - deleteLastStoredUndo(); - } - else { - updateStatusBar(); - if (QMessageBox::question(gui, tr("Directly upload to SAS"), - tr("Do you want to upload the ON_HOLD status directly to SAS?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - if (!itsSASConnection->setTasksOnHold(SAStrees)) { - QMessageBox::warning(0, tr("Could not update the states in SAS"), - tr("Could not update the states in SAS database. Maybe there is a connection error?")); - } - } - } - if (warning) { - QMessageBox::warning(0, tr("Some task(s) could not be set on hold"), - tr("Only tasks that have the status UNSCHEDULED or (PRE)SCHEDULED or ERROR can be put on hold")); - QApplication::beep(); - } - } -} - -bool Controller::setTaskOnHold(unsigned taskID, bool store_undo) { - Task *pTask = data.getTaskForChange(taskID); - Task::task_status status = pTask->getStatus(); - if (status <= Task::SCHEDULED) { - if (store_undo) { - storeTaskPropertyUndo(taskID, TASK_STATUS, QString(pTask->getStatusStr())); - } - if (!((status == Task::UNSCHEDULED) || (status == Task::ERROR))) { - data.unscheduleTask(taskID); - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - gui->removeTaskFromScene(taskID); - } - pTask->setStatus(Task::ON_HOLD); - gui->updateTableTask(pTask); - updateStatusBar(); - if (QMessageBox::question(gui, tr("Directly upload to SAS"), - tr("Do you want to upload the ON_HOLD status directly to SAS?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - if (!itsSASConnection->setTaskOnHold(pTask->getSASTreeID())) { - QMessageBox::warning(0, tr("Could not set the state in SAS"), - tr("Could put the task ON_HOLD in the SAS database. Maybe there is a connection error?")); - } - } - return true; - } - else { - QMessageBox::warning(0, tr("Cannot put the task on hold"), - tr("Task with status: ") + pTask->getStatusStr() + tr(" cannot be put ON_HOLD")); - QApplication::beep(); - return false; - } -} - -void Controller::copyTask(unsigned int taskID) { - bool undo_necessary(false); - TaskCopyDialog *copyDialog = new TaskCopyDialog(gui); - int nrCopies = copyDialog->exec(); - AstroDateTime startTime(copyDialog->getStartTime()); - const AstroTime &timeStep(copyDialog->getTimeStep()); - const Task::task_status newState(copyDialog->getTaskState()); - bool applyNewStartTime = startTime.isSet() ? true : false; - bool applyTimeStep = timeStep.isSet() ? true : false; - - if (nrCopies) { - std::vector<unsigned int> newTasks; - storeScheduleUndo("create copy(s) of task " + QString::number(taskID)); - const Task *pTask(data.getTask(taskID)); - if (pTask) { - unsigned int newTaskID; - Task *newTask(0); - Observation *obs(0); - Pipeline *pipe(0); - for (int copy = 0; copy < nrCopies; ++copy) { - newTaskID = data.getNewTaskID(); - newTask = cloneTask(pTask); - newTask->setID(newTaskID); - data.addTask(newTask, false); - newTasks.push_back(newTaskID); - if (applyNewStartTime) { - if (applyTimeStep & (copy > 0)) { - startTime += timeStep + newTask->getDuration(); - } - newTask->setScheduledStart(startTime); - } - newTask->resetRealTimes(); - obs = dynamic_cast<Observation *>(newTask); - if (obs) { - obs->resetBeamDurations(); - obs->clearDataSlots(); - } - newTask->setOriginalTreeID(theSchedulerSettings.getSASDefaultTreeID(newTask)); - newTask->setSASTreeID(0); - newTask->setMoMID(0); - newTask->setTaskName(std::string("(copy of) ") + newTask->getTaskName()); - if (newTask->hasStorage()) { - newTask->storage()->clearStorageCheckResults(); - newTask->storage()->unAssignStorage(); - } - newTask->clearAllConflicts(); - newTask->clearReason(); - newTask->clearPenalty(); - pipe = dynamic_cast<Pipeline *>(newTask); - if (pipe) { - setInputFilesForPipeline(pipe); - } - if (newTask->hasStorage()) { - newTask->calculateDataFiles(); - } - if (newState == Task::PRESCHEDULED) { - std::pair<unscheduled_reasons, QString> errCode(doPreScheduleChecks(newTask)); - if (errCode.first == BEAM_DURATION_DIFFERENT) { - if (QMessageBox::question(gui, tr("Beam duration different"), - errCode.second.replace('$','\n') + "\nDo you want to maximize the beam durations (Recommended)", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - static_cast<Observation *>(newTask)->resetBeamDurations(); - } - data.scheduleTask(newTask); - newTask->setStatus(Task::PRESCHEDULED); - } - else if (errCode.first == USER_WARNING) { - if (QMessageBox::question(gui, tr("Warning"), - errCode.second + "\nDo you want to continue?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - deleteLastStoredUndo(); - return; - } - data.scheduleTask(newTask); - newTask->setStatus(Task::PRESCHEDULED); - } - else if (errCode.first == NO_ERROR) { - data.scheduleTask(newTask); - newTask->setStatus(Task::PRESCHEDULED); - } - else if (errCode.first == TASK_CONFLICT) { - newTask->setStatus(Task::CONFLICT); - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task has conflict")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to PRESCHEDULED before the problem is resolved"); - warningBox.exec(); - } - else if (errCode.first > TASK_CONFLICT) { - newTask->setStatus(Task::ERROR); - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task has critical errors")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to PRESCHEDULED before the problem is resolved"); - warningBox.exec(); - } - } - else { - newTask->setStatus(Task::UNSCHEDULED); - } - gui->addTask(newTask); - } - } - - if (undo_necessary) { - gui->sortTable(); - selectTasks(newTasks); - updateStatusBar(); - setSaveRequired(true); - } - else { - deleteLastStoredUndo(); - } - updateStatusBar(); - } - delete copyDialog; -} - -// setInputFilesForPipeline checks if the task has dependencies on data products from predecessor tasks -// then gets the data product information and checks and sets the correct info for these dependencies in the task -// These dependencies have to be checked and set before a task is set to SCHEDULED -std::pair<unscheduled_reasons, QString> Controller::setInputFilesForPipeline(Task *pPipe) { - std::pair<unscheduled_reasons, QString> error; - std::vector<const Task *> predecessors; - const IDvector &predecessorIDs(pPipe->getPredecessors()); - if (!predecessorIDs.empty()) { - // collect all predecessor tasks in a vector for faster searching - const Task *predTask; - for (IDvector::const_iterator predit = predecessorIDs.begin(); predit != predecessorIDs.end(); ++ predit) { - predTask = data.getTask(predit->second, predit->first); - if (predTask) { - predecessors.push_back(predTask); - } - else { - error.first = PREDECESSOR_NOT_FOUND; - error.second = QString("The predecessor task ") + QString::number(predit->second) + " could not be found."; - return error; // one of the predecessors could not be found - } - } - - // task has predecessors, check all input data products identifications of this task and search the - // output data products of the predecessors for matching identifications - // if a match is found then copy the corresponding filenames and location arrays into the inputDataProduct of this task - // if no match then error condition data product not found in predecessor(s) tasks, task cannot be scheduled - std::map<dataProductTypes, TaskStorage::inputDataProduct> &inputDataProducts(pPipe->storage()->getInputDataProductsForChange()); - - int idxIt; - bool foundit; - std::map<dataProductTypes, TaskStorage::outputDataProduct>::const_iterator pit; - QString sapstr; - QStringList locations, filenames; - std::vector<bool> skipVec; - bool resetSkipVector, SyncSkipWithPredecessor; - - for (dataProductTypes dpType = _BEGIN_DATA_PRODUCTS_ENUM_; dpType < _END_DATA_PRODUCTS_ENUM_-1; dpType = dataProductTypes(dpType + 1)) { - if (pPipe->storage()->isInputDataProduktEnabled(dpType)) { // is this input data product type enabled? - TaskStorage::inputDataProduct &dp = inputDataProducts[dpType]; // also creates the record in the inputDataProducts map if it doesn't exist yet - resetSkipVector = (dp.skip.empty() ); // the skip vector should only be synchronized with the predecessor skip vector the first time (i.e. when it is not yet set) - - for (QStringList::const_iterator identit = dp.identifications.begin(); identit != dp.identifications.end(); ++identit) { - foundit = false; - for (std::vector<const Task *>::const_iterator predit = predecessors.begin(); predit != predecessors.end(); ++predit) { - if ((*predit)->hasStorage()) { - const TaskStorage *predStorage((*predit)->storage()); - const std::map<dataProductTypes, TaskStorage::outputDataProduct> &pred_output(predStorage->getOutputDataProducts()); - pit = pred_output.find(dpType); - if (pit != pred_output.end()) { - idxIt = pit->second.identifications.indexOf(*identit); - if (idxIt != -1) { // found? - if (true /*Used to contain code for CEP2/CEP4 checks*/) { - // copy the filenames and locations pointed to by this identification to the input data product list of this task - if (pit->second.filenames.size() == pit->second.locations.size()) { - if ((dpType == DP_CORRELATED_UV) || (dpType == DP_COHERENT_STOKES) || (dpType == DP_INCOHERENT_STOKES)) { // for these data product types copy only the files that have the corresponding SAP - const QString &identification(pit->second.identifications.at(idxIt)); - int i(identification.indexOf(".SAP")); - if (i != -1) { // does it contain a reference to a specific SAP? - sapstr = identification.mid(i+1, identification.indexOf('.',i+1) - i - 1); - SyncSkipWithPredecessor = (pit->second.skip.size() == (unsigned)pit->second.filenames.size()); - for (int i = 0; i < pit->second.filenames.size(); ++ i) { - const QString &filename(pit->second.filenames.at(i)); - if (filename.contains(sapstr)) { - filenames.push_back(filename); - locations.push_back(pit->second.locations.at(i)); - if (resetSkipVector) { - if (SyncSkipWithPredecessor) { - skipVec.push_back(pit->second.skip.at(i)); - } - else { - skipVec.push_back(false); - } - } - } - } - } - else { // no specific SAP specified in identification, just copy all files - filenames += pit->second.filenames; - locations += pit->second.locations; - if (resetSkipVector) { - if (pit->second.skip.size() == (unsigned)pit->second.filenames.size()) { - skipVec.insert(skipVec.end(), pit->second.skip.begin(), pit->second.skip.end()); - } - else { - skipVec.assign(filenames.size(), false); - } - } - } - } - else { // for all other data product types copy all files - filenames += pit->second.filenames; - locations += pit->second.locations; - if (resetSkipVector) { - if (pit->second.skip.size() == (unsigned)pit->second.filenames.size()) { - skipVec.insert(skipVec.end(), pit->second.skip.begin(), pit->second.skip.end()); - } - else { - skipVec.assign(filenames.size(), false); - } - } - } - // also set the input file size - const std::pair<double, unsigned> &outputSizes(predStorage->getOutputFileSizes(dpType)); - pPipe->storage()->setInputFileSizes(dpType, std::pair<double, unsigned>(outputSizes.first, filenames.size())); - - // Pulsar Pipeline: for Stokes register the polarization type in the pipeline - // which is needed to determine the number of output files for the pulsar pipeline - PulsarPipeline *pPulsarPipe = dynamic_cast<PulsarPipeline *>(pPipe); - if (pPulsarPipe && (*predit)->isObservation()) { - const Observation *predObs(static_cast<const Observation *>(*predit)); - pPulsarPipe->setCoherentType(predObs->getRTCPsettings().coherentType); - pPulsarPipe->setIncoherentType(predObs->getRTCPsettings().incoherentType); - } - } - else { - std::cerr << "filenames and locations array of task: " << (*predit)->getID() << " for data product: " << DATA_PRODUCTS[dpType] << " are not equal in length!" << std::endl; - } - foundit = true; - break; // breaks out of predecessor search loop for the current identification - } - } - } - } - } - if (!foundit) { - // one of the identifications was not found in any of the predecessor tasks - // this is an error, scheduling of this task cannot continue - error.first = INPUT_DATA_PRODUCT_NOT_FOUND; - error.second = QString("The task cannot be scheduled because the ") + DATA_PRODUCTS[dpType] + " input data product with identification:" + *identit + " could not be found in its predecessor tasks.\nAre all predecessor tasks correctly defined for this task?"; - return error; // identification not found - } - } - dp.filenames = filenames; - dp.locations = locations; - if (!resetSkipVector) { - if (dp.skip.size() != (unsigned)dp.filenames.size()) { - dp.skip.assign(dp.filenames.size(), false); - } - } - else { - dp.skip = skipVec; - } - filenames.clear(); - locations.clear(); - skipVec.clear(); - } - } - } - else { - error.first = INPUT_DATA_PRODUCT_NOT_FOUND; - error.second = QString("The task cannot be scheduled because it doesn't have a predecessor defined"); - return error; - } - - return error; -} - -bool Controller::doScheduleChecks(Task *pTask) { - // check if all output data products have storage assigned to them, if not don't allow to set the task to SCHEDULED - if (pTask->hasStorage()) { - if (!pTask->storage()->checkStorageAssigned()) { - QMessageBox::warning(gui, tr("Cannot schedule the task"), - tr("The task cannot be scheduled because some of its output data products do not have storage assigned.\nFirst assign resources to the task in the PRESCHEDULED state.")); - return false; // no storage assigned to (some) data products - } - } - - std::pair<unscheduled_reasons, QString> result = checkPredecessorDependencies(pTask, Task::SCHEDULED); - if (result.first != NO_ERROR) { - QMessageBox::warning(gui, tr("Cannot schedule the task"),result.second); - return false; - } - -//WK code commented out -// if (pTask->isPipeline()) -// { -// // TODO: This is incredibly ugly!!! -// Pipeline *pipeline = dynamic_cast<Pipeline *>(pTask); -// if (pipeline->isCalibrationPipeline() && -// !pTask->storage()->getEqualityInputOutputProducts()) -// { -// QMessageBox::warning(gui, -// tr("Error during scheduling") -// ,tr("Task input and output are different, #8174, LOC3. Retry assigning resources")); -// return false; -// } -// } - - return true; -} - -void Controller::copySelectedTasks(void) { - if (!itsSelectedTasks.empty()) { - bool undo_necessary(false); - TaskCopyDialog *copyDialog = new TaskCopyDialog(gui); - int nrCopies = copyDialog->exec(); - AstroDateTime startTime(copyDialog->getStartTime()); - const AstroTime &timeStep(copyDialog->getTimeStep()); - const Task::task_status newState(copyDialog->getTaskState()); - bool applyNewStartTime = startTime.isSet() ? true : false; - - // first sort the selected tasks on start time - const Task *pTask(0); - std::vector<const Task *> sortedTasks; - for (vector<unsigned>::iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - pTask = data.getTask(*it); - if (pTask) { - sortedTasks.push_back(pTask); - } - } - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - - if (nrCopies) { - std::vector<unsigned int> newTasks; - storeScheduleUndo("create copies of multiple tasks"); - Task *newTask(0); - unsigned int newTaskID; - AstroDateTime firstTaskStart(sortedTasks.front()->getScheduledStart()); - AstroTime shift(startTime - sortedTasks.front()->getScheduledStart()); // the shift from the original start of the first task to the new start time of the first task - for (int copy = 0; copy < nrCopies; ++copy) { - for (vector<const Task *>::iterator it = sortedTasks.begin(); it != sortedTasks.end(); ++it) { - const AstroDateTime &origTaskStartTime((*it)->getScheduledStart()); - newTask = cloneTask(*it); - newTaskID = data.getNewTaskID(); - newTask->setID(newTaskID); - if (data.addTask(newTask, false)) { - newTasks.push_back(newTaskID); - if (applyNewStartTime) { - newTask->setScheduledStart(origTaskStartTime + shift); - } - int defaultTreeID(theSchedulerSettings.getSASDefaultTreeID(newTask)); - if (defaultTreeID != newTask->getOriginalTreeID()) { - newTask->setOriginalTreeID(defaultTreeID); - } - newTask->resetRealTimes(); - newTask->setSASTreeID(0); - newTask->setMoMID(0); - newTask->setTaskName(std::string("(copy of) ") + newTask->getTaskName()); - if (newTask->hasStorage()) { - newTask->storage()->unAssignStorage(); - newTask->storage()->clearStorageCheckResults(); - } - if (newTask->isObservation()) { - Observation *pObs(static_cast<Observation *>(newTask)); - pObs->resetBeamDurations(); - pObs->clearDataSlots(); - } - newTask->clearAllConflicts(); - newTask->clearReason(); - newTask->clearPenalty(); - newTask->calculateDataFiles(); - undo_necessary = true; - if (newState == Task::PRESCHEDULED) { - data.scheduleTask(newTask); - newTask->setStatus(newState); - } - else { - newTask->setStatus(Task::UNSCHEDULED); - } - gui->addTask(newTask); - } - } - shift = newTask->getScheduledEnd() + timeStep - firstTaskStart; - if (!undo_necessary) { - deleteLastStoredUndo(); - } - } - // after all copying is done: - if (undo_necessary) { - selectTasks(newTasks); - updateStatusBar(); - setSaveRequired(true); - } - else { - deleteLastStoredUndo(); - } - } - } -} - -bool Controller::unscheduleTask(unsigned taskID) { - Task *pTask = data.getTaskForChange(taskID); - if (pTask) { - storeTaskPropertyUndo(taskID,TASK_STATUS, QString(pTask->getStatusStr())); - if (data.unscheduleTask(taskID)) { - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - } - if (pTask->isStationTask()) { - gui->removeTaskFromScene(taskID); - } - gui->updateTableTask(pTask); - updateStatusBar(); - return true; - } - else { - deleteLastStoredUndo(); - return false; - } - } - else return false; -} - -void Controller::scheduleTask(unsigned taskID, Task::task_status new_status) { - Task *pTask = data.getTaskForChange(taskID); - Task::task_status current_status(pTask->getStatus()); - - if (new_status == Task::PRESCHEDULED) { - if ((current_status < Task::PRESCHEDULED) || (current_status == Task::SCHEDULED)) { - std::pair<unscheduled_reasons, QString> errCode = doPreScheduleChecks(pTask); - if (errCode.first == NOT_COMPATIBLE_WITH_RESERVATION) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task does not meet reservation constraints")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to PRESCHEDULED before the conflict is resolved"); - warningBox.exec(); - gui->updateTask(pTask); - return; - } - if (errCode.first == BEAM_DURATION_DIFFERENT) { - if (QMessageBox::question(gui, tr("Beam duration different"), - errCode.second.replace('$','\n') + "\nDo you still want to set the task to PRESCHEDULED?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - // don't apply the status change - return; - } - } - else if (errCode.first == USER_WARNING) { - if (QMessageBox::question(gui, tr("Warning"), - errCode.second + "\nDo you want to continue?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { - return; - } - } - else if (errCode.first == TASK_CONFLICT) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task has conflicts with other tasks")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to PRESCHEDULED before the conflict is resolved"); - warningBox.exec(); - pTask->setStatus(Task::CONFLICT); - gui->updateTask(pTask); - return; - } - else if (errCode.first == SCHEDULED_TOO_EARLY) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task is scheduled too early")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to PRESCHEDULED"); - warningBox.exec(); - gui->updateTask(pTask); - return; - } - else if (errCode.first > TASK_CONFLICT) { - if (pTask->isScheduled()) { - if (!pTask->isPipeline()) { - data.unscheduleTask(taskID); - } - pTask->clearAllStorageConflicts(); - if (pTask->hasStorage()) { - pTask->storage()->unAssignStorage(); - pTask->storage()->generateFileList(); - } - pTask->setStatus(Task::ERROR); - gui->updateTask(pTask); - updateStatusBar(); - } - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task contains error(s)")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Cancel"), QMessageBox::NoRole); - warningBox.setText(errCode.second.replace('$','\n') + "\nThe task cannot be set to (PRE)SCHEDULED before the error is resolved"); - warningBox.exec(); - gui->updateTask(pTask); - return; - } - storeTaskPropertyUndo(taskID, TASK_STATUS, QString(pTask->getStatusStr())); - if (!pTask->isPipeline()) { // pipelines do not have to be unscheduled first - data.unscheduleTask(taskID); - if (data.scheduleTask(pTask)) { - pTask->setStatus(Task::PRESCHEDULED); - } - } - else { // for pipeline - pTask->setStatus(Task::PRESCHEDULED); - } - gui->updateTask(pTask); - } - else { - QMessageBox::warning(0, tr("Cannot set the task to PRESCHEDULED"), - tr("The task can only be set PRESCHEDULED when the current status is below PRESCHEDULED or the status is SCHEDULED.")); - QApplication::beep(); - } - } - else if (new_status == Task::SCHEDULED) { - Task::task_type type(pTask->getType()); - if (current_status == Task::PRESCHEDULED) { - if (doScheduleChecks(pTask)) { - storeTaskUndo(taskID, "Set task " + QString::number(taskID) + " to SCHEDULED"); - if (type != Task::PIPELINE) { - data.unscheduleTask(taskID); - } - data.scheduleTask(pTask); - } - gui->updateTask(pTask); - } - else { - QMessageBox::warning(0, tr("Could not set the task to SCHEDULED"), - tr("Tasks can only be set SCHEDULED when their current task status is PRESCHEDULED.")); - QApplication::beep(); - } - } -} - -void Controller::scheduleSelectedTasks(Task::task_status new_status) { - bool warn(false), undo_needed(false); - std::vector<Task *> sortedTasks; - for (std::vector<unsigned>::const_iterator it = itsSelectedTasks.begin(); it != itsSelectedTasks.end(); ++it) { - Task *pTask = data.getTaskForChange(*it); - sortedTasks.push_back(pTask); - } - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - Task::task_status current_status; - if (new_status == Task::SCHEDULED) { - storeScheduleUndo("Set multiple tasks on SCHEDULED"); - for (std::vector<Task *>::const_iterator tit = sortedTasks.begin(); tit != sortedTasks.end(); ++tit) { - Task::task_type type((*tit)->getType()); - current_status = (*tit)->getStatus(); - if ((current_status == Task::PRESCHEDULED) && (new_status == Task::SCHEDULED)) { - if (doScheduleChecks((*tit))) { - if (type != Task::PIPELINE) { - data.unscheduleTask((*tit)->getID()); - } - data.scheduleTask((*tit)); - undo_needed = true; - gui->updateTask(*tit); - } - } - else if (current_status == new_status) { } // nop - else warn = true; - } - if (!undo_needed) { - deleteLastStoredUndo(); - } - if (warn) { - QMessageBox::warning(0, tr("Could not set some tasks to SCHEDULED"), - tr("Tasks can only be set SCHEDULED when their current task status is PRESCHEDULED.")); - QApplication::beep(); - } - } - else { - storeScheduleUndo("Set multiple tasks on PRESCHEDULED"); - bool apply_prescheduled, early_warning(false), error_warning(false), conflict_warning(false), apply_all_beam_duration_diffs(false), - ignore_all_rel_coord_warnings(false); - for (std::vector<Task *>::const_iterator tit = sortedTasks.begin(); tit != sortedTasks.end(); ++tit) { - apply_prescheduled = false; - Task::task_type type((*tit)->getType()); - unsigned taskID = (*tit)->getID(); - Task::task_status current_status((*tit)->getStatus()); - if ((current_status < Task::PRESCHEDULED) || (current_status == Task::SCHEDULED)) { - std::pair<unscheduled_reasons, QString> errCode(doPreScheduleChecks(*tit)); - if (errCode.first == NO_ERROR) { - apply_prescheduled = true; - } - else if (errCode.first == BEAM_DURATION_DIFFERENT) { - if (apply_all_beam_duration_diffs) apply_prescheduled = true; - else { - int choice(QMessageBox::question(gui, tr("Beam duration different"), - errCode.second.replace('$','\n') + "\nDo you still want to set the task to PRESCHEDULED?", - QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No, QMessageBox::Yes)); - if (choice == QMessageBox::No) { - // don't apply the status change - } - else if (choice == QMessageBox::YesToAll) { - apply_all_beam_duration_diffs = true; - apply_prescheduled = true; - } - else apply_prescheduled = true; - } - } - else if (errCode.first == USER_WARNING) { - if (ignore_all_rel_coord_warnings) apply_prescheduled = true; - else { - int choice(QMessageBox::question(gui, tr("Warning"), - errCode.second.replace('$','\n') + "\nDo you still want to set the task to PRESCHEDULED?", - QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No, QMessageBox::Yes)); - if (choice == QMessageBox::No) { - // don't apply the status change - } - else if (choice == QMessageBox::YesToAll) { - ignore_all_rel_coord_warnings = true; - apply_prescheduled = true; - } - } - } - else if (errCode.first == SCHEDULED_TOO_EARLY) { - if ((*tit)->isScheduled()) { - (*tit)->clearAllStorageConflicts(); - if ((*tit)->hasStorage()) { - (*tit)->storage()->unAssignStorage(); - (*tit)->storage()->generateFileList(); - } - data.unscheduleTask(taskID); - gui->updateTask(*tit); - } - early_warning = true; - } - else if (errCode.first == TASK_CONFLICT) { - if ((*tit)->isScheduled()) { - (*tit)->clearAllStorageConflicts(); - if ((*tit)->hasStorage()) { - (*tit)->storage()->unAssignStorage(); - (*tit)->storage()->generateFileList(); - } - data.unscheduleTask(taskID); - gui->updateTask(*tit); - } - (*tit)->setStatus(Task::CONFLICT); - conflict_warning = true; - // don't apply the status change - } - else if (errCode.first > TASK_CONFLICT) { - if ((*tit)->isScheduled()) { - (*tit)->clearAllStorageConflicts(); - if ((*tit)->hasStorage()) { - (*tit)->storage()->unAssignStorage(); - (*tit)->storage()->generateFileList(); - } - data.unscheduleTask(taskID); - gui->updateTask(*tit); - } - (*tit)->setStatus(Task::ERROR); - error_warning = true; - // don't apply the status change - } - else apply_prescheduled = true; - - if (apply_prescheduled) { - if (type != Task::PIPELINE) { - if ((*tit)->isScheduled()) { - data.unscheduleTask(taskID); - } - } - data.scheduleTask((*tit)); - (*tit)->setStatus(Task::PRESCHEDULED); - undo_needed = true; - } - gui->updateTask(*tit); - } - else if (current_status == Task::PRESCHEDULED) { } // nop - else warn = true; - } - - if (early_warning) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task(s) scheduled too early")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText("One or more task(s) are scheduled too early or too close to now.\nCheck start time(s) of these tasks before setting them to (PRE)SCHEDULED"); - warningBox.exec(); - } - if (conflict_warning) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task(s) with conflicts")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText("One or more task(s) are conflicting with other tasks.\nThese task(s) cannot be set to (PRE)SCHEDULED before the conflict is resolved"); - warningBox.exec(); - } - if (error_warning) { - QMessageBox warningBox(gui); - warningBox.setWindowTitle(tr("Task(s) with errors")); - warningBox.setIcon(QMessageBox::Critical); - warningBox.addButton(tr("Ok"), QMessageBox::NoRole); - warningBox.setText("One or more task(s) have errors.\nThese task(s) cannot be set to (PRE)SCHEDULED before these errors are resolved"); - warningBox.exec(); - } - - if (!undo_needed) { - deleteLastStoredUndo(); - } - else { - updateStatusBar(); - } - if (warn) { - QMessageBox::warning(0, tr("Could not set some tasks to PRESCHEDULED"), - tr("Tasks can only be set PRESCHEDULED when their current task status is below PRESCHEDULED or the status is SCHEDULED.")); - QApplication::beep(); - } - } -} - - -bool Controller::checkEarlyTasksStatus(void) { - bool bResult(true); - // first check the actual status of tasks that have a start time less than now + minimum_time_between_observations - // if the status is still (PRE)SCHEDULED then this is a conflict - // if the status changed in the mean time then download the task again from SAS and update in the scheduler - std::vector<Task *> tasks(data.getScheduledTasksVector()); - std::vector<Pipeline *> pipelines(data.getScheduledPipelinesVector()); - tasks.insert(tasks.end(), pipelines.begin(), pipelines.end()); // add pipelines - int treeID; - for (std::vector<Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - if ((*it)->getScheduledStart() <= now()) { - if ( (*it)->isPipeline()) { - continue; //Pipelines on CEP4: we don't care as SLURM sorts it out. - } - treeID = (*it)->getSASTreeID(); - if ((itsSASConnection->connect() == 0) && (treeID != 0)) { // only do the sas check for apparently too early tasks that are already in SAS , not for new tasks - Task::task_status status(itsSASConnection->getTaskStatus(treeID)); - AstroDateTime start(itsSASConnection->getScheduledStartTime(treeID)); - if (status < Task::STARTING && start.isSet()) { // *** the task has not been started yet (nor is it running or finished or aborted), this is a too early task now - // set conflict - if ((*it)->hasStorage()) { - (*it)->storage()->clearStorageCheckResults(); - (*it)->storage()->unAssignStorage(); - } - (*it)->setConflict(CONFLICT_STORAGE_TIME_TOO_EARLY); - itsConflictDialog->addConflict(*it, CONFLICT_STORAGE_TIME_TOO_EARLY); - bResult = false; - } - } - else { // this is a new task with a too early start time, that is a conflict - if ((*it)->hasStorage()) { - (*it)->storage()->clearStorageCheckResults(); - (*it)->storage()->unAssignStorage(); - } - (*it)->setConflict(CONFLICT_STORAGE_TIME_TOO_EARLY); - itsConflictDialog->addConflict(*it, CONFLICT_STORAGE_TIME_TOO_EARLY); - bResult = false; - } - } - } - return bResult; -} - -int Controller::assignResources(bool showResult) { - int retVal(0); - itsConflictDialog->clearAllConflicts(); - // first check the actual status of tasks that have a start time less than now + minimum_time_between_observations - // if the status is still (PRE)SCHEDULED then this is a conflict - // if the status changed in the mean time then download the task again from SAS and update in the scheduler - if (!checkEarlyTasksStatus()) { - retVal = 2; // some tasks are scheduled too early - } - - if (retVal == 0) { - int ret = 0; //Data Monitor does not exist any more refreshStorageNodesInfo(); - // ret: - // 0: refresh ok - // 1: no connection to data monitor don't continue - // 2: user clicked cancel when asked to connect to the data monitor - - if (ret == 0) { // refresh ok - if (false /*Used to contain code for CEP2/CEP4 checks*/) { - retVal = 3; // storage resource assignment conflicts detected - } - } - else if (ret == 2) { // user clicked cancel when asked to connect to the data monitor - return -1; - } - else retVal = ret; - - if ((retVal != 1) & (!calculateDataSlots())) { - retVal = 4; // data slots conflict detected - } - } - - switch (retVal) { - case 0: - if (showResult) { - QMessageBox::information(gui,tr("Resource assignment ok"),tr("Resources are successfully assigned to all future prescheduled and scheduled tasks")); - } - break; - case 1: - //Used to contain DataMonitor code - break; - case 2: - QMessageBox::warning(gui,tr("Resource assignment conflicts detected"),tr("Some task(s) are scheduled in the past!\nStart time needs to be at least 3 minutes after now")); - itsConflictDialog->show(); - break; - case 3: - QMessageBox::warning(gui,tr("Resource assignment conflicts detected"),tr("A storage resource conflict was detected!")); - itsConflictDialog->show(); - break; - case 4: - QMessageBox::warning(gui,tr("Resource assignment conflicts detected"),tr("A dataslot resource conflict was detected!")); - itsConflictDialog->show(); - break; - } - - return retVal; -} - - -bool Controller::calculateDataSlots(void) { - // TODO calculate the data slots for all OBSERVATION tasks (RESERVATION should reserve a number of data slots) - // the number of data slots for a task are equal to the total number of subbands that are requested. - bool bResult(true); - - // steps: - // 1) get a list of pointers all future scheduled tasks (status prescheduled or scheduled) - const std::vector<Observation *> tasks = data.getFutureObservationsSortStartTime(); - // clear all assigned data slots for these tasks - for (std::vector<Observation *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - if ((*it)->getStatus() == Task::PRESCHEDULED) { // tasks with SCHEDULED status keep their assigned resources - (*it)->clearDataSlots(); - (*it)->clearConflict(CONFLICT_BITMODE); - (*it)->clearConflict(CONFLICT_OUT_OF_DATASLOTS); - } - } - - std::vector<unsigned> overlappingTasks; - std::map<unsigned short, unsigned> upperDataSlotUsed; // key = RSP board number, value contains the maximum dataslotnr that is currently taken - stationDataSlotMap newDataSlots; // the newly assigned dataslot ranges for a task (first = RSP board, second = range of dataslots) - unsigned short bitMode; - unsigned nrOfSubbands; - bool bitModeConflict, outOfDataSlots; - - // for each task, do: - for (std::vector<Observation *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - // get bit mode for this task (parallel tasks on the same stations should have same bit mode - bitModeConflict = false; - outOfDataSlots = false; - bitMode = (*it)->getBitMode(); - nrOfSubbands = (*it)->getNrOfSubbands(); - // 3) for each station assigned to the task find out which are the parallel tasks - const std::map<std::string, unsigned> &stations = (*it)->getStations(); - for (std::map<std::string, unsigned>::const_iterator statit = stations.begin(); statit != stations.end(); ++statit) { - newDataSlots.clear(); - upperDataSlotUsed.clear(); - const Station *station = data.getStation(statit->second); - if (station) { - overlappingTasks = station->getTaskswithinTimeSpan((*it)->getScheduledStart(), (*it)->getScheduledEnd()); - // 4) for each parallel task on this station make a note of the used data slots - for (std::vector<unsigned>::const_iterator otit = overlappingTasks.begin(); otit != overlappingTasks.end(); ++otit) { - if (*otit != (*it)->getID()) { // Station::getOverlappingTasks also returns the current task which obviously always overlaps with itself (exclude this task) - StationTask *parallelTask = data.getScheduledTask(*otit); // the next overlapping task on this station - if (parallelTask) { - if (!bitModeConflict) { // if the current task already has a bit mode conflict - // check that bit mode is the same for parallel tasks - if (parallelTask->isObservation()) { - Observation *parallelObs(static_cast<Observation *>(parallelTask)); - if (parallelObs->getBitMode() == bitMode) { - const stationDataSlotMap & dataSlots = parallelTask->getStationDataSlots(statit->second); - if (!dataSlots.empty()) { // are the data slots set for this station in this task? - // iterate over the RSP boards - for (unsigned short RSPBoard = 0; RSPBoard <= 3; ++ RSPBoard) { - stationDataSlotMap::const_iterator dsit = dataSlots.find(RSPBoard); - if (dsit != dataSlots.end()) { - // the parallel task already uses some of the dataslots on this RSP board - // take a note of the maximum occupied data slot number on this board - upperDataSlotUsed[RSPBoard] = std::max(upperDataSlotUsed[RSPBoard], dsit->second.second); - } - } - } - } - else { // there is a bit mode conflict for this task and the parallel task - (*it)->setConflict(CONFLICT_BITMODE); - parallelObs->setConflict(CONFLICT_BITMODE); - itsConflictDialog->addDataSlotConflict(*it, CONFLICT_BITMODE, statit->first, parallelObs->getID()); - bitModeConflict = true; - bResult = false; - } - } - } - else { - parallelTask->setConflict(CONFLICT_BITMODE); - } - } - } - } - - // 2d) for every station in the task assign N free dataslots (where N equals the total number of subbands for this task) - if (!bitModeConflict && !outOfDataSlots) { - unsigned maxDataSlotNr = (*it)->getNrOfDataslotsPerRSPboard()-1; - - // assign free dataslots - std::map<unsigned short, unsigned>::const_iterator udit; // used dataslot iterator - unsigned subbandsLeft(nrOfSubbands); - unsigned maxNrToAssign; - while (subbandsLeft && !outOfDataSlots) { - for (unsigned short RSPBoard = 0; RSPBoard <= 3; ++ RSPBoard) { - udit = upperDataSlotUsed.find(RSPBoard); - if (udit == upperDataSlotUsed.end()) { // board is completely free - maxNrToAssign = std::min(subbandsLeft-1, (unsigned)maxDataSlotNr); - newDataSlots[RSPBoard] = std::pair<unsigned, unsigned>(0, maxNrToAssign); - subbandsLeft -= (maxNrToAssign+1); - } - else { // board is partially taken - // udit->second = maximum data slot occupied on the RSP board - if (udit->second < maxDataSlotNr) { - maxNrToAssign = std::min(udit->second + subbandsLeft, (unsigned)maxDataSlotNr); // the maximum dataslot number that can be assigned on this board - newDataSlots[RSPBoard] = std::pair<unsigned, unsigned>(udit->second+1, maxNrToAssign); // the range of dataslots that will be assigned to this task on this board - subbandsLeft -= (maxNrToAssign - udit->second); // the number of subbands that still have to be assigned to the task - } - else if (RSPBoard == 3) outOfDataSlots = true; - } - if (subbandsLeft == 0) break; // w're done for this station - } - if (subbandsLeft > 0) { - outOfDataSlots = true; - break; - } - } - if (!outOfDataSlots) { - (*it)->assignDataSlots(statit->second, newDataSlots); // TODO: we have to set the list for every antenna field (stations) in the task!!! -// std::cout << "assigning data slots to task: " << (*it)->getID() << ", for station:" << statit->first << std::endl; -// for (stationDataSlotMap::const_iterator vit = newDataSlots.begin(); vit != newDataSlots.end(); ++vit) { -// std::cout << "RSPBoard:" << vit->first << ", data slots:" << vit->second.first << ".." << vit->second.second << std::endl; -// } - } - else { - (*it)->setConflict(CONFLICT_OUT_OF_DATASLOTS); - itsConflictDialog->addDataSlotConflict(*it, CONFLICT_OUT_OF_DATASLOTS, statit->first); - bResult = false; - } - } - } - } - // 2e) get the next scheduled task and redo steps 2b,c,d until at end of scheduled tasks - } - return bResult; -} - - -/*bool Controller::assignManualStorageToTask(Task *pTask) { - if (pTask->hasStorage()) { - TaskStorage *taskStorage(pTask->storage()); - // check and when possible assign the task's manually requested resources - const storageMap &locations(taskStorage->getStorageLocations()); - //check if the minimum required number of nodes is assigned - std::map<dataProductTypes, int> minNodes(taskStorage->getMinimumNrOfStorageNodes()); - storageMap::const_iterator sit; - for (std::map<dataProductTypes, int>::const_iterator it = minNodes.begin(); it != minNodes.end(); ++it) { - sit = locations.find(it->first); - if (sit != locations.end()) { - if (sit->second.size() < static_cast<unsigned>(it->second)) { - pTask->setConflict(CONFLICT_STORAGE_MINIMUM_NODES); - taskStorage->setOutputDataProductAssigned(it->first, false); - // add the conflict to the conflicts dialog - itsConflictDialog->addStorageConflict(pTask, it->first, CONFLICT_STORAGE_MINIMUM_NODES); - return false; - } - } - } - - std::vector<storageResult> result = data.addStorageToTask(pTask, locations); - if (result.empty()) { // no conflicts? - // clear the task's storage conflicts - pTask->clearAllStorageConflicts(); - taskStorage->clearStorageCheckResults(); - return true; - } - else { - taskStorage->setStorageCheckResult(result); - for (std::vector<storageResult>::const_iterator confit = result.begin(); confit != result.end(); ++confit) { - pTask->setConflict(confit->conflict); - taskStorage->setOutputDataProductAssigned(confit->dataProductType, false); - // add the conflict to the conflicts dialog - itsConflictDialog->addStorageConflict(pTask, confit->dataProductType, confit->conflict, confit->storageNodeID, confit->storageRaidID); - } - return false; - } - } - else return true; -}*/ - - -/*bool Controller::assignStorageToTask(Task *pTask) { - bool bResult(true); - if (pTask->hasStorage()) { - TaskStorage *taskStorage(pTask->storage()); - data.removeStorageForTask(pTask->getID()); - taskStorage->unAssignStorage(); - taskStorage->clearStorageCheckResults(); - const dataFileMap &dataFileSizes = taskStorage->getOutputFileSizes(); - if (dataFileSizes.empty()) { - itsConflictDialog->addStorageConflict(pTask, DP_UNKNOWN_TYPE, CONFLICT_STORAGE_NO_DATA); - return false; - } - - double singleFileBW; - unsigned nrFiles, minNrOfNodes, nrFilesPerNode; - - if (pTask->isPipeline()) { - Pipeline *pipe = static_cast<Pipeline *>(pTask); - setInputFilesForPipeline(pipe); - // for pipelines typically the input node is also the output node except for imaging pipeline and skyImage (skyImkages get merged together) - const storageMap &inputLocations(taskStorage->getInputStorageLocations()); - std::vector<storageResult> scResultTotal; - for (dataFileMap::const_iterator dpit = dataFileSizes.begin(); dpit != dataFileSizes.end(); ++dpit) { // output number of files and file sizes - if (dpit->first == DP_SKY_IMAGE) { // for sky image files may be merged to a single node - // TODO: for imaging pipeline write distribution scheme (merge skyImages to one node for each image) - } - else if (dpit->first == DP_PULSAR) { - storageVector combinedStorage; - - storageMap::const_iterator iit = inputLocations.find(DP_COHERENT_STOKES); - if (iit != inputLocations.end()) { - combinedStorage.insert( combinedStorage.end(), iit->second.begin(), iit->second.end() ); - } - iit = inputLocations.find(DP_INCOHERENT_STOKES); - if (iit != inputLocations.end()) { - combinedStorage.insert( combinedStorage.end(), iit->second.begin(), iit->second.end() ); - } - - if (!combinedStorage.empty()) { - std::vector<storageResult> scResult = data.addStorageToTask(pipe, dpit->first, combinedStorage, false); - scResultTotal.insert(scResultTotal.end(), scResult.begin(), scResult.end()); - } - else bResult = false; // no input data for task - } - else { - // get the locations used for the input data product from which this output data product type is generated - // for the moment this typically will be DP_CORRELATED_UV - storageMap::const_iterator iit = inputLocations.find(DP_CORRELATED_UV); - if (iit != inputLocations.end()) { - std::vector<storageResult> scResult = data.addStorageToTask(pipe, dpit->first, iit->second, false); - scResultTotal.insert(scResultTotal.end(), scResult.begin(), scResult.end()); - } - else bResult = false; // storage locations for input data product type not found - } - } - if (scResultTotal.empty()) { // no conflicts? - // clear the task's storage conflicts - pipe->clearAllStorageConflicts(); - taskStorage->clearStorageCheckResults(); - bResult = true; - } - else { - taskStorage->setStorageCheckResult(scResultTotal); - for (std::vector<storageResult>::const_iterator confit = scResultTotal.begin(); confit != scResultTotal.end(); ++confit) { - pTask->setConflict(confit->conflict); - taskStorage->setOutputDataProductAssigned(confit->dataProductType, false); - // add the conflict to the conflicts dialog - itsConflictDialog->addStorageConflict(pTask, confit->dataProductType, confit->conflict, confit->storageNodeID, confit->storageRaidID); - } - bResult = false; - } - } - else { // for observations and other non-pipeline tasks - std::map<dataProductTypes, int> minimumNrNodes = taskStorage->getMinimumNrOfStorageNodes(); - sortMode sort_mode; - std::vector<int> emptyVec; - std::vector<int> &preferred_nodes = emptyVec; - std::vector<int> extra_nodes, usable_storage_nodes(itsDMConnection->getUsableStorageNodeIDs()); // all existing storage node IDs - - // the distribution algorithm used - const storageNodeDistribution &distribution(theSchedulerSettings.getStorageDistribution()); - if (distribution == STORAGE_DISTRIBUTION_FLAT_USAGE) { - sort_mode = SORT_USAGE; - } - else if (distribution == STORAGE_DISTIBUTION_LEAST_FRAGMENTED) { - sort_mode = SORT_SIZE; - } - else sort_mode = SORT_NONE; - - // storage node selection by preferred project nodes? - storage_selection_mode mode(taskStorage->getStorageSelectionMode()); - bool project_preferred_nodes; - if ((mode == STORAGE_MODE_MAXIMUM_PROJECT_PREFERRED) || (mode == STORAGE_MODE_MINIMUM_PROJECT_PREFERRED)) project_preferred_nodes = true; - else project_preferred_nodes = false; - - const preferredDataProductStorageMap &pdps(theSchedulerSettings.getPreferredDataProductStorage()); - const preferredProjectStorageMap &pps(theSchedulerSettings.getPreferredProjectStorage()); - int project_id(theSchedulerSettings.getCampaignInfo(pTask->getProjectName()).id); - - preferredDataProductStorageMap::const_iterator pnit; - preferredProjectStorageMap::const_iterator ppit; - - // *********************************************************************** - // ******************* SEARCH FOR SUITABLE LOCATIONS ********************* - // *********************************************************************** - - // STEP2: search storageLocations for all dataProducts in sequence according to individual file size (large to small) of the dataProduct (i.e. sequence of sortedDataFiles) - - if (project_preferred_nodes) { - ppit = pps.find(project_id); - if (ppit != pps.end()) { - if (ppit->second.empty()) { - preferred_nodes = usable_storage_nodes; - } - else { - preferred_nodes = ppit->second; - for (std::vector<int>::const_iterator asit = usable_storage_nodes.begin(); asit != usable_storage_nodes.end(); ++asit) { - if (std::find(preferred_nodes.begin(), preferred_nodes.end(), *asit) == preferred_nodes.end()) { - extra_nodes.push_back(*asit); - } - } - } - } - else { - preferred_nodes = usable_storage_nodes; - } - } - - dataFileMap::const_iterator dfit; - for (std::map<dataProductTypes, int>::const_iterator dpit = minimumNrNodes.begin(); dpit != minimumNrNodes.end(); ++dpit) { - if (!project_preferred_nodes) { - // data type preferred nodes - pnit = pdps.find(dpit->first); // are there preferred storage nodes for this data product type specified? - if (pnit != pdps.end()) { - if (pnit->second.empty()) { - preferred_nodes = usable_storage_nodes; - } - preferred_nodes = pnit->second; - for (std::vector<int>::const_iterator asit = usable_storage_nodes.begin(); asit != usable_storage_nodes.end(); ++asit) { - if (std::find(preferred_nodes.begin(), preferred_nodes.end(), *asit) == preferred_nodes.end()) { - extra_nodes.push_back(*asit); - } - } - } - else { - preferred_nodes = usable_storage_nodes; - } - } - - if (dpit->second == -1) { // the bandwidth required for a single file of this dataproduct exceeds the single storage node network bandwidth - if (pTask->getOutputDataproductCluster() != "CEP4") { - pTask->setConflict(CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH); - itsConflictDialog->addStorageConflict(pTask, dpit->first, CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH); - bResult = false; - break; - } - } - // get number of available nodes - unsigned nrOfAvailableNodes(Controller::theSchedulerSettings.getNrOfStorageNodesAvailable()); - if (nrOfAvailableNodes == 0) { - pTask->setConflict(CONFLICT_STORAGE_NO_NODES); - itsConflictDialog->addStorageConflict(pTask, dpit->first, CONFLICT_STORAGE_NO_NODES); - return false; // no sense in continuing when no storage nodes are available - } - - minNrOfNodes = dpit->second; // the minimum number of storage nodes REQUIRED for this data product - dfit = dataFileSizes.find(dpit->first); - storageLocationOptions preferred_locations, extra_locations; - bool found_sufficient_nodes(false); - if (dfit != dataFileSizes.end()) { - nrFiles = dfit->second.second; // dataFileSizes.at(dpit->first).second; - unsigned minNrFilesPerNode = static_cast<unsigned>(ceil((float)nrFiles / nrOfAvailableNodes)); // the minimum number of files that have to be written to one storage node if all available nodes are used - unsigned maxNrFilesPerNode = static_cast<unsigned>(floor((float)nrFiles / minNrOfNodes)); // the maximum number of files that can be written to one storage node according to bandwidth limitations - nrFilesPerNode = minNrFilesPerNode; - singleFileBW = dfit->second.first / (double) pTask->getDuration().totalSeconds() * 8; // kbit/sec - - // calculate the mininum number of files that have to fit on one storage node - if (nrOfAvailableNodes >= minNrOfNodes) { - if (minNrFilesPerNode <= maxNrFilesPerNode) { - while (!found_sufficient_nodes) { - preferred_locations = data.getStorageLocationOptions(dpit->first, pTask->getScheduledStart(), pTask->getScheduledEnd(), dfit->second.first, singleFileBW, nrFilesPerNode, sort_mode, preferred_nodes); - if (preferred_locations.size() <= minNrOfNodes) { - extra_locations = data.getStorageLocationOptions(dpit->first, pTask->getScheduledStart(), pTask->getScheduledEnd(), dfit->second.first, singleFileBW, nrFilesPerNode, sort_mode, extra_nodes); - if (((preferred_locations.size() + extra_locations.size()) * nrFilesPerNode >= nrFiles) && (preferred_locations.size() + extra_locations.size() >= minNrOfNodes)) { - found_sufficient_nodes = true; - break; - } - } - else { - if (preferred_locations.size() * nrFilesPerNode >= nrFiles) { - found_sufficient_nodes = true; - break; - } - } - if (++nrFilesPerNode > maxNrFilesPerNode) { // nr files per node too high will exceed bandwidth to node - break; - } - } - if (!found_sufficient_nodes) { - if (pTask->getOutputDataproductCluster() != "CEP4") { - taskStorage->setStorageCheckResult(data.getLastStorageCheckResult()); - pTask->setConflict(CONFLICT_STORAGE_NO_OPTIONS); - itsConflictDialog->addStorageConflict(pTask, dpit->first, CONFLICT_STORAGE_NO_OPTIONS); - bResult = false; - break; - } - } - } - else { - if (pTask->getOutputDataproductCluster() != "CEP4") { - pTask->setConflict(CONFLICT_STORAGE_TOO_FEW_NODES); - itsConflictDialog->addStorageConflict(pTask, dpit->first, CONFLICT_STORAGE_TOO_FEW_NODES); - bResult = false; - break; - } - } - - if (bResult) { - // *********************************************************************** - // ************* DISTRIBUTION OF DATA OVER STORAGE NODES ***************** - // *********************************************************************** - // use the maximum number of suitable storage nodes (= suitable_locations.size()) - bool sufficient_locations(false); - storageVector locations; - unsigned maxFilesToNodes(MAX_UNSIGNED); - - if ((mode == STORAGE_MODE_MAXIMUM_DATA_TYPE_PREFERRED) || (mode == STORAGE_MODE_MAXIMUM_PROJECT_PREFERRED)) { - for (storageLocationOptions::const_iterator sit = preferred_locations.begin(); sit != preferred_locations.end(); ++sit) { // iterate over available locations - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { // iterates over the raids - locations.push_back(storageVector::value_type(sit->first, nsit->raidID)); // use only the first raid option of each storage node available - // also determine the maximum number of files that can be written to a single suitable node, needed to determine the minimum number of extra (non-preferred) nodes needed in addition to the preferred nodes - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); - if (locations.size() * nrFilesPerNode >= nrFiles) { - sufficient_locations = true; - break; // don't assign more storage nodes than the number of files written - } - } - if (sufficient_locations) break; - } - if (!sufficient_locations && (locations.size() < minNrOfNodes)) { // do we need extra locations (non preferred nodes)? If so, use as few as possible of these - for (storageLocationOptions::const_iterator sit = extra_locations.begin(); sit != extra_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { - locations.push_back(storageVector::value_type(sit->first, nsit->raidID)); - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); - if ((locations.size() * maxFilesToNodes >= nrFiles) & (locations.size() >= minNrOfNodes)) { - sufficient_locations = true; - break; // don't assign more storage nodes than the number of files written - } - } - if (sufficient_locations) break; - } - } - } - - - else if ((mode == STORAGE_MODE_MINIMUM_DATA_TYPE_PREFERRED) || (mode == STORAGE_MODE_MINIMUM_PROJECT_PREFERRED)) { - bool inserted(false); - vector<std::pair<int, storageOption> > smallest_vec; // first = node ID - for (storageLocationOptions::const_iterator sit = preferred_locations.begin(); sit != preferred_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); // determine the maximum number of files that can be written to a single suitable node - for (vector<std::pair<int, storageOption> >::iterator ssit = smallest_vec.begin(); ssit != smallest_vec.end(); ++ssit) { - if (nsit->remainingSpacekB < ssit->second.remainingSpacekB) { // sort according to free space in smallest_vec - smallest_vec.insert(ssit, std::pair<int, storageOption>(sit->first, *nsit)); // insert the smallest free space raid arrays in smallest_vec - inserted = true; - break; - } - } - if (!inserted) { - smallest_vec.push_back(std::pair<int, storageOption>(sit->first, *nsit)); // put at the end (it's has the largest free space up to now) - break; // only one raid array per node here - } - } - if (smallest_vec.size() * nrFilesPerNode >= nrFiles) { - sufficient_locations = true; - break; // don't assign more storage nodes than the number of files written - } - } - - if (!sufficient_locations) { // do we need extra locations (non preferred nodes)? If so, use as few as possible of these - for (storageLocationOptions::const_iterator sit = extra_locations.begin(); sit != extra_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); - for (vector<std::pair<int, storageOption> >::iterator ssit = smallest_vec.begin(); ssit != smallest_vec.end(); ++ssit) { - if (nsit->remainingSpacekB < ssit->second.remainingSpacekB) { // sort according to free space in smallest_vec - smallest_vec.insert(ssit, std::pair<int, storageOption>(sit->first, *nsit)); // insert the smallest free space raid arrays in smallest_vec - inserted = true; - break; - } - } - if (!inserted) { - smallest_vec.push_back(std::pair<int, storageOption>(sit->first, *nsit)); // put at the end (it has the largest free space up to now) - break; // only one raid array per node here - } - } - if ((smallest_vec.size() * maxFilesToNodes >= nrFiles) & (smallest_vec.size() >= minNrOfNodes)) { - break; // don't assign more storage nodes than the number of files written - } - } - } - for (unsigned i = 0; i < minNrOfNodes; ++i) { - locations.push_back(pair<int,int>(smallest_vec.at(i).first, smallest_vec.at(i).second.raidID)); - } - } - - // report the storage to the storage nodes which will also set the storage in the task - data.addStorageToTask(pTask, dpit->first, locations, true); - } - } - else { - if (pTask->getOutputDataproductCluster() != "CEP4") { - pTask->setConflict(CONFLICT_STORAGE_TOO_FEW_NODES); - itsConflictDialog->addStorageConflict(pTask, dpit->first, CONFLICT_STORAGE_TOO_FEW_NODES); - bResult = false; - break; - } - } - } - } - } - } - return bResult; -}*/ - -/*bool Controller::assignGroupedStorage(void) { // not for manual assignment of storage - bool bResult(true); - std::map<unsigned, std::vector<Task *> > groupedTasks = data.getGroupedTasks(Task::PRESCHEDULED); - - std::vector<unsigned> emptyGroups; - if (!groupedTasks.empty()) { - std::vector<Task *> subGroupTasks; - TaskStorage *tStorage; - for (std::map<unsigned, std::vector<Task *> >::iterator groupIt = groupedTasks.begin(); groupIt != groupedTasks.end(); ++groupIt) { - for (std::vector<Task *>::const_iterator taskit = groupIt->second.begin(); taskit != groupIt->second.end(); ++taskit) { - if ((*taskit)->hasStorage()) { - tStorage = (*taskit)->storage(); - if (tStorage->getStorageSelectionMode() != STORAGE_MODE_MANUAL) { // don't assign grouped storage to tasks that have manual storage assignment - data.removeStorageForTask((*taskit)->getID()); - tStorage->unAssignStorage(); - tStorage->clearStorageCheckResults(); - (*taskit)->clearAllStorageConflicts(); - subGroupTasks.push_back(*taskit); - } - } - } - if (subGroupTasks.empty()) { - emptyGroups.push_back(groupIt->first); - } - else { - groupIt->second = subGroupTasks; // removes all 'manual storage' tasks - subGroupTasks.clear(); - } - } - // remove groups that have no tasks with automatic storage assignment left - for (std::vector<unsigned>::const_iterator eit = emptyGroups.begin(); eit != emptyGroups.end(); ++eit) { - groupedTasks.erase(*eit); - } - if (groupedTasks.empty()) return bResult; // if nothing left return - - // get number of available storage nodes - unsigned nrOfAvailableNodes(Controller::theSchedulerSettings.getNrOfStorageNodesAvailable()); - if (nrOfAvailableNodes > 0) { - sortMode sort_mode; - - // the distribution algorithm used - const storageNodeDistribution &distribution(theSchedulerSettings.getStorageDistribution()); - if (distribution == STORAGE_DISTRIBUTION_FLAT_USAGE) { - sort_mode = SORT_USAGE; - } - else if (distribution == STORAGE_DISTIBUTION_LEAST_FRAGMENTED) { - sort_mode = SORT_SIZE; - } - else sort_mode = SORT_NONE; - - const preferredDataProductStorageMap &pdps(theSchedulerSettings.getPreferredDataProductStorage()); - const preferredProjectStorageMap &pps(theSchedulerSettings.getPreferredProjectStorage()); - std::vector<int> extra_nodes, usable_storage_nodes(itsDMConnection->getUsableStorageNodeIDs()); // all existing storage node IDs - - - //determine grouped tasks combined storage needs and settings - dataFileMap combinedOutput; - storage_selection_mode mode; - std::map<dataProductTypes, int> combinedMinimumNrNodes; - std::map<dataProductTypes, double> maxSingleFileBW; - std::map<dataProductTypes, double>::iterator bwit; - dataFileMap::iterator dfit; - std::map<dataProductTypes, int>::iterator mit; - int project_id(0); - std::pair<unscheduled_reasons, QString> error; - for (std::map<unsigned, std::vector<Task *> >::const_iterator groupIt = groupedTasks.begin(); groupIt != groupedTasks.end(); ++groupIt) { // 2 - combinedOutput.clear(); - combinedMinimumNrNodes.clear(); - if (!groupIt->second.empty()) { - mode = groupIt->second.front()->storage()->getStorageSelectionMode(); - project_id = theSchedulerSettings.getCampaignInfo(groupIt->second.front()->getProjectName()).id; // should be the same for all tasks within group (no check done) - for (std::vector<Task *>::const_iterator taskit = groupIt->second.begin(); taskit != groupIt->second.end(); ++taskit) { // 3 - TaskStorage *task_storage((*taskit)->storage()); - if ((*taskit)->isPipeline()) { - Pipeline *pipe(static_cast<Pipeline *>(*taskit)); - error = setInputFilesForPipeline(pipe); - if (error.first == NO_ERROR) { - pipe->calculateDataFiles(); - const storageMap &inputStorageLocations(task_storage->getInputStorageLocations()); - storageMap::const_iterator inpcorit = inputStorageLocations.find(DP_CORRELATED_UV); - if (inpcorit != inputStorageLocations.end()) { - if (task_storage->isOutputDataProduktEnabled(DP_INSTRUMENT_MODEL)) { // set output storage nodes equal to input storage nodes for these type of data products - std::vector<storageResult> result = data.addStorageToTask(pipe, DP_INSTRUMENT_MODEL, inpcorit->second, false); - if (!result.empty()) { - for (std::vector<storageResult>::const_iterator sit = result.begin(); sit != result.end(); ++sit) { - if (sit->conflict != CONFLICT_NO_CONFLICT) { - itsConflictDialog->addStorageConflict(pipe, sit->dataProductType, sit->conflict); - } - pipe->setConflict(sit->conflict); - } - bResult = false; - } - } - if (task_storage->isOutputDataProduktEnabled(DP_CORRELATED_UV)) { - - // inpcorit->second bevat alle storage nodes, dus ook die van de eerdere SAPs waardoor - // dit dataprodukt de storage nodes van SAP000 van de input krijgt en niet die van SAP001 - std::vector<storageResult> result = data.addStorageToTask(pipe, DP_CORRELATED_UV, inpcorit->second, false); - if (!result.empty()) { - for (std::vector<storageResult>::const_iterator sit = result.begin(); sit != result.end(); ++sit) { - if (sit->conflict != CONFLICT_NO_CONFLICT) { - itsConflictDialog->addStorageConflict(pipe, sit->dataProductType, sit->conflict); - } - pipe->setConflict(sit->conflict); - } - bResult = false; - } - } - - task_storage->generateFileList(); - } - } - } - - double taskDuration((*taskit)->getDuration().totalSeconds() * 8); - const dataFileMap &dataFileSizes = task_storage->getOutputFileSizes(); - if (task_storage->getStorageSelectionMode() != mode) { - itsConflictDialog->addConflict(*taskit, CONFLICT_GROUP_STORAGE_MODE_DIFFERENT); - bResult = false; - } - if (!dataFileSizes.empty()) { - // summing individual file size for same data product types - for (dataFileMap::const_iterator dit = dataFileSizes.begin(); dit != dataFileSizes.end(); ++dit) { // 4 - if ((*taskit)->isObservation() || ((dit->first != DP_INSTRUMENT_MODEL) && (dit->first != DP_CORRELATED_UV))) { // skip this for instrument model and correlated, which is already set above - dfit = combinedOutput.find(dit->first); - if (dfit != combinedOutput.end()) { - dfit->second.first += dit->second.first; - - } - else { - combinedOutput[dit->first] = std::pair<double, unsigned>(dit->second.first, dit->second.second); - } - //determine the maximum single file bandwidth for each data product type in the group of tasks - double currentBW = dit->second.first / taskDuration; // kbit/sec - bwit = maxSingleFileBW.find(dit->first); - if (bwit != maxSingleFileBW.end()) { - bwit->second = std::max(bwit->second, currentBW); - } - else { - maxSingleFileBW[dit->first] = currentBW; - } - } - } - // determining the overall minimum number of nodes needed for each data product type - std::map<dataProductTypes, int> minimumNrnodes = task_storage->getMinimumNrOfStorageNodes(); - for (std::map<dataProductTypes, int>::const_iterator minit = minimumNrnodes.begin(); minit != minimumNrnodes.end(); ++minit) { - if ((*taskit)->isObservation() || ((minit->first != DP_INSTRUMENT_MODEL) && (minit->first != DP_CORRELATED_UV))) { // skip for instrument model and correlated,they have been set - if (minit->second == -1) { - if ((*taskit)->getOutputDataproductCluster() != "CEP4") { - (*taskit)->setConflict(CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH); - itsConflictDialog->addStorageConflict((*taskit), minit->first, CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH); - bResult = false; - } - } - else { - mit = combinedMinimumNrNodes.find(minit->first); - if (mit != combinedMinimumNrNodes.end()) { - mit->second = std::max(mit->second, minit->second); - } - else { - combinedMinimumNrNodes[minit->first] = minit->second; - } - } - } - } - } - else { - itsConflictDialog->addConflict(*taskit, CONFLICT_STORAGE_NO_DATA); - bResult = false; - } - } // END 3 - } - else { - std::cout << "Controller::assignGroupedStorage: Warning: trying to assign storage to group:" << groupIt->first << " in which there are no tasks" << std::endl; - continue; - } - - if (bResult) { // only do the actual group storage assignment if no conflicts are found - - if (!combinedOutput.empty()) { - - // storage node selection by preferred project nodes? - // storage_selection_mode mode(pTask->getStorageSelectionMode()); - bool project_preferred_nodes; - if ((mode == STORAGE_MODE_MAXIMUM_PROJECT_PREFERRED) || (mode == STORAGE_MODE_MINIMUM_PROJECT_PREFERRED)) project_preferred_nodes = true; - else project_preferred_nodes = false; - - - // double singleFileBW; - unsigned nrFiles(0), minNrOfNodes(0), nrFilesPerNode(0); - - std::vector<int> preferred_nodes;// = emptyVec; - - - // *********************************************************************** - // ******************* SEARCH FOR SUITABLE LOCATIONS ********************* - // *********************************************************************** - - // STEP2: search storageLocations for all dataProducts in sequence according to individual file size (large to small) of the dataProduct (i.e. sequence of sortedDataFiles) - - preferredDataProductStorageMap::const_iterator pnit; - preferredProjectStorageMap::const_iterator ppit; - - if (project_preferred_nodes) { - ppit = pps.find(project_id); - if (ppit != pps.end()) { - if (ppit->second.empty()) { - preferred_nodes = usable_storage_nodes; - } - else { - preferred_nodes = ppit->second; - for (std::vector<int>::const_iterator asit = usable_storage_nodes.begin(); asit != usable_storage_nodes.end(); ++asit) { - if (std::find(preferred_nodes.begin(), preferred_nodes.end(), *asit) == preferred_nodes.end()) { - extra_nodes.push_back(*asit); - } - } - } - } - else { - preferred_nodes = usable_storage_nodes; - } - } - - storageLocationOptions preferred_locations, extra_locations, common_pref_locations, common_extra_locations; - for (std::map<dataProductTypes, int>::const_iterator dpit = combinedMinimumNrNodes.begin(); dpit != combinedMinimumNrNodes.end(); ++dpit) { // 5 - for (std::vector<Task *>::const_iterator taskit = groupIt->second.begin(); taskit != groupIt->second.end(); ++taskit) { //6 - - if (!project_preferred_nodes) { - pnit = pdps.find(dpit->first); // are there preferred storage nodes for this data product type specified? - if (pnit != pdps.end()) { - if (pnit->second.empty()) { - preferred_nodes = usable_storage_nodes; - } - else { - preferred_nodes = pnit->second; - for (std::vector<int>::const_iterator asit = usable_storage_nodes.begin(); asit != usable_storage_nodes.end(); ++asit) { - if (std::find(preferred_nodes.begin(), preferred_nodes.end(), *asit) == preferred_nodes.end()) { - extra_nodes.push_back(*asit); - } - } - } - } - else { - preferred_nodes = usable_storage_nodes; - } - } - - // now search for storage locations using the combined storage requirements (only search ones, not for all tasks separately, - // final check will be done when really assigning the storage to each grouped task - minNrOfNodes = dpit->second; // the minimum number of storage nodes REQUIRED for this data product - dfit = combinedOutput.find(dpit->first); - bwit = maxSingleFileBW.find(dpit->first); - if (dfit != combinedOutput.end()) { - nrFiles = dfit->second.second; - unsigned minNrFilesPerNode = static_cast<unsigned>(ceil((float)nrFiles / nrOfAvailableNodes)); // the minimum number of files the selected nodes should be able to hold - unsigned maxNrFilesPerNode = static_cast<unsigned>(floor((float)nrFiles / minNrOfNodes)); // the maximum number of files that can be written to one storage node according to bandwidth limitations - nrFilesPerNode = minNrFilesPerNode; - - // calculate the minimum number of files that have to fit on one storage node - if (nrOfAvailableNodes >= minNrOfNodes) { - if (minNrFilesPerNode <= maxNrFilesPerNode) { - preferred_locations = data.getStorageLocationOptions(dpit->first, (*taskit)->getScheduledStart(), (*taskit)->getScheduledEnd(), dfit->second.first, bwit->second, nrFilesPerNode, sort_mode, preferred_nodes); - extra_locations = data.getStorageLocationOptions(dpit->first, (*taskit)->getScheduledStart(), (*taskit)->getScheduledEnd(), dfit->second.first, bwit->second, nrFilesPerNode, sort_mode, extra_nodes); - - if (preferred_locations.size() + extra_locations.size() >= minNrOfNodes) { - - preferred_nodes.clear(); - extra_nodes.clear(); - for (storageLocationOptions::const_iterator cpit = preferred_locations.begin(); cpit != preferred_locations.end(); ++cpit) { - preferred_nodes.push_back(cpit->first); - } - for (storageLocationOptions::const_iterator cpit = extra_locations.begin(); cpit != extra_locations.end(); ++cpit) { - extra_nodes.push_back(cpit->first); - } - - if (preferred_nodes.empty() && extra_nodes.empty()) { - (*taskit)->setConflict(CONFLICT_STORAGE_NO_OPTIONS); - itsConflictDialog->addStorageConflict((*taskit), dpit->first, CONFLICT_STORAGE_NO_OPTIONS); - bResult = false; - break; - } - - if (nrFilesPerNode > maxNrFilesPerNode) { // nr files per node too high will exceed bandwidth to node - if ((*taskit)->getOutputDataproductCluster() != "CEP4") { - (*taskit)->setConflict(CONFLICT_STORAGE_EXCEEDS_BANDWIDTH); - itsConflictDialog->addStorageConflict((*taskit), dpit->first, CONFLICT_STORAGE_EXCEEDS_BANDWIDTH); - bResult = false; - break; - } - } - } - else { - if ((*taskit)->getOutputDataproductCluster() != "CEP4") { - (*taskit)->setConflict(CONFLICT_STORAGE_MINIMUM_NODES); - itsConflictDialog->addStorageConflict((*taskit), dpit->first, CONFLICT_STORAGE_MINIMUM_NODES); - bResult = false; - break; - } - } - } - else { - if ((*taskit)->getOutputDataproductCluster() != "CEP4") { - (*taskit)->setConflict(CONFLICT_STORAGE_EXCEEDS_BANDWIDTH); - itsConflictDialog->addStorageConflict((*taskit), dpit->first, CONFLICT_STORAGE_EXCEEDS_BANDWIDTH); - bResult = false; - break; - } - } - } - else { - if ((*taskit)->getOutputDataproductCluster() != "CEP4") { - (*taskit)->setConflict(CONFLICT_STORAGE_TOO_FEW_NODES); - itsConflictDialog->addStorageConflict((*taskit), dpit->first, CONFLICT_STORAGE_TOO_FEW_NODES); - bResult = false; - break; - } - } - } - - - if (bResult) { - // check which nodes they have in common, assign common nodes with checking! - // *********************************************************************** - // ************* DISTRIBUTION OF DATA OVER STORAGE NODES ***************** - // *********************************************************************** - // use the maximum number of suitable storage nodes (= suitable_locations.size()) - // only keep the locations that are common to all tasks for this data product - if (taskit == groupIt->second.begin()) { // for first task search, keep all options - common_pref_locations = preferred_locations; - common_extra_locations = extra_locations; - } - else { - storageLocationOptions new_common_pref_locations, new_common_extra_locations; - for (storageLocationOptions::const_iterator sit = common_pref_locations.begin(); sit != common_pref_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { // iterates over the raids - if (storageLocationsContains(preferred_locations, sit->first, nsit->raidID)) { - new_common_pref_locations.push_back(*sit); - } - } - } - common_pref_locations = new_common_pref_locations; - for (storageLocationOptions::const_iterator sit = common_extra_locations.begin(); sit != common_extra_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { // iterates over the raids - if (storageLocationsContains(extra_locations, sit->first, nsit->raidID)) { - new_common_extra_locations.push_back(*sit); - } - } - } - common_extra_locations = new_common_extra_locations; - } - } - } // 6, end of search for all task in this group for the current data product - - - unsigned maxFilesToNodes(MAX_UNSIGNED); - storageVector locations; - - bool sufficient_locations(false); - // select enough locations from the common location solutions - if ((mode == STORAGE_MODE_MAXIMUM_DATA_TYPE_PREFERRED) || (mode == STORAGE_MODE_MAXIMUM_PROJECT_PREFERRED)) { - for (storageLocationOptions::const_iterator sit = common_pref_locations.begin(); sit != common_pref_locations.end(); ++sit) { // iterate over available locations - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { // iterates over the raids - locations.push_back(storageVector::value_type(sit->first, nsit->raidID)); // use only the first raid option of each storage node available - // also determine the maximum number of files that can be written to a single suitable node, needed to determine the minimum number of extra (non-preferred) nodes needed in addition to the preferred nodes - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); - if (locations.size() * nrFilesPerNode >= nrFiles) { - sufficient_locations = true; - // break; // don't assign more storage nodes than the number of files written - } - - } - // if (sufficient_locations) break; - } - if (!sufficient_locations && (locations.size() < minNrOfNodes)) { // do we need extra locations (non preferred nodes)? If so, use as few as possible of these - for (storageLocationOptions::const_iterator sit = common_extra_locations.begin(); sit != common_extra_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { - locations.push_back(storageVector::value_type(sit->first, nsit->raidID)); - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); - if ((locations.size() * maxFilesToNodes >= nrFiles) && (locations.size() >= minNrOfNodes)) { - sufficient_locations = true; - break; // don't assign more storage nodes than the number of files written - } - } - if (sufficient_locations) break; - } - } - } - else if ((mode == STORAGE_MODE_MINIMUM_DATA_TYPE_PREFERRED) || (mode == STORAGE_MODE_MINIMUM_PROJECT_PREFERRED)) { - bool inserted(false); - vector<std::pair<int, storageOption> > smallest_vec; // first = node ID - for (storageLocationOptions::const_iterator sit = common_pref_locations.begin(); sit != common_pref_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); // determine the maximum number of files that can be written to a single suitable node - for (vector<std::pair<int, storageOption> >::iterator ssit = smallest_vec.begin(); ssit != smallest_vec.end(); ++ssit) { - if (nsit->remainingSpacekB < ssit->second.remainingSpacekB) { // sort according to free space in smallest_vec - smallest_vec.insert(ssit, std::pair<int, storageOption>(sit->first, *nsit)); // insert the smallest free space raid arrays in smallest_vec - inserted = true; - break; - } - } - if (!inserted) { - smallest_vec.push_back(std::pair<int, storageOption>(sit->first, *nsit)); // put at the end (it's has the largest free space up to now) - break; // only one raid array per node here - } - } - if (smallest_vec.size() * nrFilesPerNode >= nrFiles) { - sufficient_locations = true; - break; // don't assign more storage nodes than the number of files written - } - } - - if (!sufficient_locations && (locations.size() < minNrOfNodes)) { // do we need extra locations (non preferred nodes)? If so, use as few as possible of these - for (storageLocationOptions::const_iterator sit = common_extra_locations.begin(); sit != common_extra_locations.end(); ++sit) { - for (nodeStorageOptions::const_iterator nsit = sit->second.begin(); nsit != sit->second.end(); ++nsit) { - maxFilesToNodes = std::min(maxFilesToNodes, nsit->nrUnits); - for (vector<std::pair<int, storageOption> >::iterator ssit = smallest_vec.begin(); ssit != smallest_vec.end(); ++ssit) { - if (nsit->remainingSpacekB < ssit->second.remainingSpacekB) { // sort according to free space in smallest_vec - smallest_vec.insert(ssit, std::pair<int, storageOption>(sit->first, *nsit)); // insert the smallest free space raid arrays in smallest_vec - inserted = true; - break; - } - } - if (!inserted) { - smallest_vec.push_back(std::pair<int, storageOption>(sit->first, *nsit)); // put at the end (it has the largest free space up to now) - break; // only one raid array per node here - } - } - if ((smallest_vec.size() * maxFilesToNodes >= nrFiles) & (smallest_vec.size() >= minNrOfNodes)) { - break; // don't assign more storage nodes than the number of files written - } - } - } - for (unsigned i = 0; i < minNrOfNodes; ++i) { - locations.push_back(pair<int,int>(smallest_vec.at(i).first, smallest_vec.at(i).second.raidID)); - } - } - - // finally assign the common storage locations for this data product to all tasks in the group and check if the result is ok (i.e. no conflicts) - for (std::vector<Task *>::const_iterator taskit = groupIt->second.begin(); taskit != groupIt->second.end(); ++taskit) { // 7 - if ((*taskit)->storage()->isOutputDataProduktEnabled(dpit->first)) { - std::vector<storageResult> result = data.addStorageToTask(*taskit, dpit->first, locations, false); - if (!result.empty()) { - for (std::vector<storageResult>::const_iterator sit = result.begin(); sit != result.end(); ++sit) { - if (sit->conflict != CONFLICT_NO_CONFLICT) { - itsConflictDialog->addStorageConflict(*taskit, sit->dataProductType, sit->conflict); - } - (*taskit)->setConflict(sit->conflict); - } - bResult = false; - } - } - } // END 7 - } // 5 - for (std::vector<Task *>::const_iterator taskit = groupIt->second.begin(); taskit != groupIt->second.end(); ++taskit) { - if ((*taskit)->isPipeline()) { - Pipeline *pipe(static_cast<Pipeline *>(*taskit)); - setInputFilesForPipeline(pipe); - // we have to re-assign the storage for the pipeline because the predecessor (observation or pipeline) might have changed in the previous loop - for (dataProductTypes dp = _BEGIN_DATA_PRODUCTS_ENUM_; dp < _END_DATA_PRODUCTS_ENUM_; dp = dataProductTypes(dp + 1)) { - if (dp != DP_SKY_IMAGE && pipe->storage()->isOutputDataProduktEnabled(dp)) { // for SKY_IMAGE input nodes are not equal to output nodes - const storageMap &inputStorageLocations(pipe->storage()->getInputStorageLocations()); - storageMap::const_iterator inpcorit = inputStorageLocations.find(DP_CORRELATED_UV); - if (inpcorit != inputStorageLocations.end()) { - data.addStorageToTask(*taskit, dp, inpcorit->second, false); - } - } - } - } - (*taskit)->storage()->generateFileList(); - } - - } - } - } // END for loop over individual groups - } - else return false; // no storage nodes available - } - - return bResult; -}*/ - - -/*bool Controller::assignStorageResources(Task *task) { - bool bResult(true); - // if (refreshStorageNodesInfo()) { - if (task) { - // assign storage only to the specified task - - gui->updateTaskDialog(task); // update task dialog if it shows the current task (needed for the storage tree to show the conflict info) - } - else { - data.clearStorageClaims(); - // assign storage resources to all SCHEDULED tasks - // step 1: iterate over all scheduled tasks and try to re-assign storage to these tasks according to their storage claims already set - // check the user assigned resources. If insufficient storage is assigned notify user and ask how to continue. - // (options are: let me change/add resources for this task, ignore and continue (in which case the task is left on prescheduled status and its conflicts are updated, - // and the last option is abort assigning resources. - const std::vector<Task *> scheduledTasks = data.getScheduledTasksSortStartTime(); - std::vector<storageResult> res; - const AstroTime &minTime(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); - - TaskStorage *tStorage(0); - for (std::vector<Task *>::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - tStorage = (*it)->storage(); - if (tStorage) { - if ((*it)->getScheduledStart() >= now() + minTime) { // TODO time needs to be after a minimum time after now (minimum time needs to be added to settingsdialog) - res = data.addStorageToTask(*it, tStorage->getStorageLocations()); - if (res.empty()) { - (*it)->clearAllStorageConflicts(); - } - else { - for (std::vector<storageResult>::const_iterator scit = res.begin(); scit != res.end(); ++scit) { - itsConflictDialog->addStorageConflict(*it, scit->dataProductType, scit->conflict, scit->storageNodeID, scit->storageRaidID); - } - bResult = false; // tasks with status SCHEDULED should have storage assigned already and will only be checked if storage resources are still ok - } - } - } - } - - // now try to do the same for prescheduled tasks - const std::vector<Task *> preScheduledTasks = data.getPreScheduledTasksSortStartTime(); - for (std::vector<Task *>::const_iterator it = preScheduledTasks.begin(); it != preScheduledTasks.end(); ++it) { - tStorage = (*it)->storage(); - if (tStorage) { - if ((*it)->getScheduledStart() >= now() + minTime) { // TODO time needs to be after a minimum time after now (minimum time needs to be added to settingsdialog) - storage_selection_mode mode(tStorage->getStorageSelectionMode()); - if (mode == STORAGE_MODE_MANUAL) { // both for observations and pipelines - if (assignManualStorageToTask(*it)) { - (*it)->clearAllStorageConflicts(); - } - else bResult = false; - tStorage->generateFileList(); - } - else if ((*it)->getGroupID() == 0) { // grouped observations are assigned resources together in automatic storage selection modes - if (!assignStorageToTask(*it)) - bResult = false; - (*it)->clearAllStorageConflicts(); - tStorage->generateFileList(); - } - } - } - } - } - - - // now assign storage to grouped OBSERVATIONS - // observations in the same group get the same storage nodes per subband for correlated data - // the actual assignment for tasks with automatic selected storage (non manual) is done later on. - - if (!assignGroupedStorage()) bResult = false; - - gui->updateTaskDialog(); // update task dialog (needed for the storage tree to show the conflict info) - return bResult; -}*/ - diff --git a/SAS/Scheduler/src/Controller.h b/SAS/Scheduler/src/Controller.h deleted file mode 100644 index b33812173b73bf5849a4dfe66356712998b4ed4b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Controller.h +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Controller.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 4-feb-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Controller.h $ - * - */ - - -#ifndef CONTROLLER_H_ -#define CONTROLLER_H_ - -#include <QMessageBox> -#include <vector> -#include <string> -#include "lofar_scheduler.h" -#include "task.h" -#include "Scheduler.h" -#include "schedulerdata.h" -#include "schedulergui.h" -#include "schedulesettingsdialog.h" -#include "DataHandler.h" -#include "schedulersettings.h" -#include "thrashbin.h" -#include "astrodatetime.h" -#include "OTDBtree.h" -#include "Storage.h" -#include "SASConnection.h" -#include "shifttasksdialog.h" -// todo ( This could be added in the project file, as a compiler option) -//#ifdef SCHEDULER_TEST -#include "signalhandler.h" -//#endif - -class Thrashbin; -class AstroDateTime; -class DataMonitorConnection; -class ConflictDialog; -class QTableWidgetItem; -class StationTask; - -enum undo_type { - UNDO_TASK_PROPERTY, - UNDO_COMPLETE_TASK, - UNDO_SCHEDULER_DATA_BLOCK, - UNDO_DELETE_TASKS -}; - -typedef std::vector<std::pair<unsigned, std::pair<data_headers, QVariant> > > taskPropertyUndoStack; -typedef std::vector<std::pair<unsigned, Task *> > taskUndoStack; -typedef std::vector<std::vector<Task *> > deletedTasksVector; -typedef std::vector<std::pair<undo_type, std::pair<QString, std::vector<unsigned> > > > undoTypeVector; - -class Controller : public QObject -{ - Q_OBJECT -//todo -//#ifdef SCHEDULER_TEST - friend class SignalHandler; -//#endif -public: - Controller(QApplication &app); - virtual ~Controller(); - - // interface members to SchedulerGUI - void start(void); // show the SchedulerGUI -// unsigned getCurrentUndoLevel(void) const {return current_undo_level;}; - bool fixTasks(); - const Task *getScheduledTask(unsigned taskID) const {return data.getScheduledTask(taskID);} - const Task *getInactiveTask(unsigned taskID) const {return data.getInactiveTask(taskID);} - const Task *getUnscheduledTask(unsigned taskID) const {return data.getUnscheduledTask(taskID);} - const Task *getTask(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return data.getTask(taskID, IDtype);} - const StationTask *getStationTask(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return data.getStationTask(taskID, IDtype);} - const Observation *getObservation(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return data.getObservation(taskID, IDtype);} - const CalibrationPipeline *getCalibrationPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return data.getCalibrationPipeline(taskID, IDtype);} - const ImagingPipeline *getImagingPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return data.getImagingPipeline(taskID, IDtype);} - const PulsarPipeline *getPulsarPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return data.getPulsarPipeline(taskID, IDtype);} - unsigned getNewTaskID(void) const {return data.getNewTaskID();} -// void loadScheduleTable(void); // load the schedule table - const char *getReservationName(unsigned reservation_id) const; - const reservationsMap &getReservations(void) const {return data.getReservations();} - std::pair<bool, std::pair<QString, Observation> > doReservationChecks(const Observation *orgObs, unsigned reservationID); - // checks the task for errors that prevent it from being scheduled - // returns pair<unscheduled_reasons, string> with the first error found in the task (unscheduled_reasons error code, string = error) - // if the int value returned = 0 then no errors were detected -// std::pair<unscheduled_reasons, QString> doPreScheduleChecks(const Task &task) const; - std::pair<unscheduled_reasons, QString> doPreScheduleChecks(Task *task); - std::pair<unscheduled_reasons, QString> setInputFilesForPipeline(Task *pPipe); - void updateStatusBar(void); - // undo redo interface functions - void storeTaskPropertyUndo(unsigned taskID, data_headers property, const QVariant &value); - void storeTaskUndo(unsigned taskID, const QString &undo_action, bool delete_task = false); - void storeScheduleUndo(const QString &undo_action); - void deleteLastStoredUndo(void); // removes the last added undo level - - void moveSelectedTasksRequest(unsigned task_id, const AstroDateTime &new_start_time); - bool moveSelectedTasks(const AstroDateTime &time, moveType move_type); - bool moveTasks(const std::map<unsigned, AstroDateTime> &startTimes); - void deselectAllTasks(void); - void copySelectedTasks(void); - void copyTask(unsigned int taskID); -// void addSelectedTask(unsigned taskID); - void selectTasks(const std::vector<unsigned> &taskIDs); // selects multiple tasks - void setSelectedTasks(const std::vector<unsigned> &taskIDs) {itsSelectedTasks = taskIDs;} // only sets the selected tasks, does not actually perform a selection in GUI - void setSelectedTask(unsigned taskID) {itsSelectedTasks.clear(); itsSelectedTasks.push_back(taskID);} // only sets the selected task, does not actually perform a selection in GUI - bool isSelected(unsigned taskID); - void selectTask(unsigned taskID, bool singleSelection, bool selectRows = true, bool tableClick = false); - void selectCurrentTaskGroups(selector_types type = SEL_ALL_TASKS); - void deselectTask(unsigned taskID, bool singleSelection, bool selectRows = true); - bool multipleSelected(void) const {return itsSelectedTasks.size() > 1;} - unsigned lastSelectedTask(void) {if(!itsSelectedTasks.empty()) {return itsSelectedTasks.back();} else {return 0;}} - const std::vector<unsigned> &selectedTasks(void) const {return itsSelectedTasks;} - const std::map<std::string, std::vector<Task *> > getPublishTasks(const AstroDateTime &start, const AstroDateTime &end) const {return data.getPublishTasks(start,end);} - const campaignMap &getCampaignList(void) const {return theSchedulerSettings.getCampaignList();} // returns the campaign (project) list - void setSaveRequired(bool); - bool isDeleted(unsigned taskID) const; // check if task was deleted from schedule - bool unDelete(unsigned taskID); // un-deletes a previously deleted task (this could cause conflicts with other tasks!) - void mergeDownloadedSASTasks(void); // used by SAS connection to initiate the creation of the downloaded SAS tasks into the scheduler -// const Task *createSASErrorTask(const OTDBtree& SAS_tree, unsigned task_id = 0); // creates a new unscheduled task with some properties set by the erronneus SAS task tree. - QString getSasDatabaseName(void) const {return theSchedulerSettings.getSASDatabase();} - - void unscheduleSelectedTasks(void); - void setSelectedTasksOnHold(void); - - void setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts) { - itsDMConnection->setAllowedStorageHosts(allowedStorageHosts); - data.setAllowedStorageHosts(allowedStorageHosts);} - - void showTaskDialog(unsigned taskID, tabIndex tab = TAB_SCHEDULE) const; - void openMoveTasksDialog(void); - - // following used by graphicTask objects - bool unscheduleTask(unsigned taskID); - void scheduleTask(unsigned taskID, Task::task_status status); - void scheduleSelectedTasks(Task::task_status new_status); - bool setTaskOnHold(unsigned taskID, bool store_undo = true); - void rescheduleAbortedTask(unsigned task_id, AstroDateTime new_start = 0); - void expungeTask(unsigned treeID); - void deleteTask(unsigned taskID); - void showTaskStateHistory(unsigned taskID); - void openSASTreeViewer(int treeID) const; - void openMetaDataViewer(int treeID) const; - - // storage settings - int refreshStorageNodesInfo(bool doConnectToDM = true); // refreshes the storage nodes availability and capacity info in the settingsdialog - bool isDataMonitorConnected(void) const; - void setDataMonitorConnectionButton(bool enable) {gui->setDataMonitorConnectionButton(enable);} - const storageHostsMap &getStorageNodes(void) const {return itsDMConnection->getStorageNodes();} - const statesMap &getStorageNodesStates(void) const {return itsDMConnection->getStates();} - size_t getNrOfStorageNodesAvailable(void) const {return itsDMConnection->getNrOfStorageNodesAvailable();} - const hostPartitionsMap &getStoragePartitions(void) const {return itsDMConnection->getHostPartitions();} - int getStorageRaidID(int node_id, const std::string &raidName) const {return itsDMConnection->getStorageRaidID(node_id, raidName);} -// const dataPathsMap &getStorageNodesDataPaths(void) const {return itsDMConnection->getDataPaths();} - std::string getStorageNodeName(int node_id) const {return itsDMConnection->getStorageNodeName(node_id);} - std::string getStorageRaidName(int node_id, int raid_id) const {return itsDMConnection->getStorageRaidName(node_id, raid_id);} - int getStorageNodeID(const std::string &name) const {return itsDMConnection->getStorageNodeID(name);} -// const std::string &getStorageNodeStatusStr(int node_id) const; -// unsigned long getStorageNodeSpaceRemaining(int node_id, unsigned short partition_id) const {return itsDMConnection->getStorageNodeSpaceRemaining(node_id, partition_id);} -// const statesMap &getStates(void) const {return states;} -// const dataPathsMap &getDataPaths(void) const {return itsDMConnection->getDataPaths();} - void setStorageNodes(const storageHostsMap &nodes) {itsDMConnection->setStorageNodes(nodes);} - void setStoragePartitions(const hostPartitionsMap &partitions) {itsDMConnection->setStoragePartitions(partitions);} - const AstroDateTime &now(void); // returns the current UTC time - bool connectToDataMonitor(void); - void disconnectDataMonitor(void); - bool updateProjects(void); // fetches the updates project (campaign) list from SAS and updates the GUI accordingly - void multiEditSelectedTasks(void); // opens the multi-edit taskdialiog with the cumulative properties of all selected tasks - void refreshGUIafterMultiEdit(void); - void synchronizeTask(const Task *pTask); // updates a single existing task after it has been downloaded again - bool updateTask(Task *, bool createUndo); - bool updatePipelineTask(Task *task, bool createUndo); - bool createTask(const Task &task); - bool createReservation(const Task *reservation); - void createPipeline(const Pipeline *pipeline); - std::vector<DefaultTemplate> getDefaultTemplatesFromSAS(void) {return itsSASConnection->getDefaultTemplates();} - void defaultTemplatesUpdated(void) {gui->loadProcessTypes();} - void setStatusText(const char *text) {gui->setStatusText(text);} - void clearStatusText(void) {gui->clearStatusText();} - int getSelectedObservationsTimeSpan(void) const; - void setAutoPublish(bool enabled) {theSchedulerSettings.setAutoPublish(enabled);} - bool autoPublishAllowed(void) {return itsAutoPublishAllowed;} - -#ifdef DEBUG_SCHEDULER - void printSelectedTasks(const std::string &callerName) const; -#endif - - // resource assignment -// bool assignStorageResources(Task *task = 0); - bool calculateDataSlots(void); - - -#ifdef HAS_SAS_CONNECTION - QString lastSASError(void) const; - bool checkSASSettings(void); - int checkSASconnection(const QString &username, const QString &password, const QString &DBname, const QString &hostname); - void setSASConnectionSettings(const QString &username, const QString &password, const QString &DBname, const QString &hostname); - void commitScheduleToSAS(void); -#endif - -private: - bool doScheduleChecks(Task *); - std::pair<unscheduled_reasons, QString> checkPredecessorDependencies(const Task *, Task::task_status newState) const; - void updateGraphicTasks(void) {gui->updateGraphicTasks(data.getScheduledTasks(), data.getReservations(), data.getInactiveTasks());} - void connectSignals(void); // connect the signals from the SchedulerGUI to the Scheduler - void loadProgramPreferences(void); - void clearUndoRedoStack(void); - void clearRedoStack(void); - void checkTableItem(const QModelIndex &index); // checks the value of the table item index. Used after changes were made to a table cell - bool possiblySave(); // check if things need to be saved and then cleans up the data - int possiblySaveDialog(); - void cleanup(bool keepUndo = false, bool cleanSasConnection = true); // does the actual cleaning - bool checkStationList(const std::string & stations) const; // return true if all stations mentioned in the string stations actually exist - bool checkSettings() const; - bool applyGUITableChanges(bool askContinue); - void updateGUIafterSettingsLoad(void); - void applyTaskPropertyChange(unsigned taskID, data_headers property, const QVariant &value, bool undo_redo); - // updates the undo stack looking for deleted tasks that have been destroyed - void updateDeletedTasksUndo(void); - bool askOverWriteExistingTask(bool &overwrite, bool &forAll, unsigned taskID, const QString &taskName); -// bool dataMonitorInitRequired(void); // checks to see if data monitor init is required -// bool assignManualStorageToTask(Task *pTask); -// bool assignGroupedStorage(void); -// bool assignMinimumStorageToTask(Task *pTask); -// bool assignStorageToTask(Task *pTask); - void rescheduleTask(unsigned task_id, AstroDateTime new_start); - // checkEarlyTasksStatus: checks the current status of too early tasks in the SAS database and updates the tasks in the scheduler if the status was changed in SAS - // returns false if any too early task was found which is still (PRE)SCHEDULED - bool checkEarlyTasksStatus(void); - bool checkPredecessorsExistence(const IDvector &predecessors) const; - void autoPublish(void); - -signals: - void schedulerSettingsChanged(void); - -public slots: - void quit(void); // exit Scheduler application after some checks - void deleteSelectedTasks(void); -// void abortTask(unsigned int taskID); - -private slots: - void tableSortingChanged(void); // the sorting column and/or order was changed -// void openTaskList(void); // handles the open task list event - void saveTaskListAs(void); // handles the save task list as event - bool saveSchedule(QString filename = ""); - bool saveScheduleAs(void); - void openSchedule(void); - bool closeSchedule(void); - void saveSettings(void); - void saveDefaultSettings(void); - void loadSettings(void); - void loadDefaultSettings(void); - void closeSettingsDialog(void); - void openSettingsDialog(void); // opens the settings dialog - void createInitialSchedule(void); // creates the start schedule - void undo(bool store_redo = true); - void redo(void); - void optimizeSchedule(void); - void applyTableItemChange(unsigned, data_headers, const QVariant &, const QModelIndex &); // keep track of all changes to the schedule table made by the user - void fixTaskErrors(void); - void updateStatusBarOptimize(unsigned); -// void tryRescheduleTask(unsigned, AstroDateTime); -// void alignLeft(void); - void showThrashBin(void); - void thrashBinEmpty(void) const {gui->setEmptyThrashIcon();} - void thrashBinNotEmpty(void) const {gui->setFullThrashIcon();} - void doDestroyTasks(std::vector<unsigned>); - void restoreTasks(const std::vector<unsigned> &tasksToRestore); - void addTask(void); -// void addReservation(void); -// void checkPredecessor(unsigned) const; - void balanceSchedule(void); - void newSchedule(void); - int assignResources(bool showResult = true); - -#ifdef HAS_SAS_CONNECTION - void downloadSASSchedule(void); - void InitSynchronizeSASSchedule(void); - void checkSASStatus(void) const; -#endif - -public: - static SchedulerSettings theSchedulerSettings; // everyone can access these settings - static unsigned itsFileVersion; // used for storing the last read input file version - -private: - QMessageBox *possiblySaveMessageBox; - QApplication *application; - Scheduler scheduler; - SchedulerGUI *gui; - ScheduleSettingsDialog *itsSettingsDialog; - ConflictDialog *itsConflictDialog; - SchedulerData data; - DataHandler *itsDataHandler; - - AstroDateTime itsTimeNow; - std::vector<unsigned> itsSelectedTasks; - Thrashbin itsThrashBin; - -#ifdef HAS_SAS_CONNECTION - // connection to SAS database - SASConnection *itsSASConnection; -#endif - - DataMonitorConnection *itsDMConnection; - - // undo items - undoTypeVector itsUndoType; - undoTypeVector itsRedoType; - taskPropertyUndoStack itsTaskPropertyUndoStack; - taskPropertyUndoStack itsTaskPropertyRedoStack; - taskUndoStack itsTaskUndoStack; - taskUndoStack itsTaskRedoStack; - deletedTasksVector itsDeletedTasks; - std::vector<std::vector<unsigned> > itsDeletedTasksRedoStack; - - bool itsAutoPublishAllowed; -}; - -#endif /* CONTROLLER_H_ */ - diff --git a/SAS/Scheduler/src/DataHandler.cpp b/SAS/Scheduler/src/DataHandler.cpp deleted file mode 100644 index 195d4bfe844d69d1d86ef397911c2a325801ef5d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DataHandler.cpp +++ /dev/null @@ -1,568 +0,0 @@ -/* - * DataHandler.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 5-feb-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DataHandler.cpp $ - * - */ - -#include "DataHandler.h" -#include <iostream> -#include <fstream> -#include <string> -#include <sstream> -#include <map> -#include <algorithm> -#include "astrotime.h" -#include "astrodatetime.h" -#include "task.h" -#include "schedulerdatablock.h" -#include "Controller.h" -#include "station.h" -#include "lofar_scheduler.h" -#include "pipeline.h" -#include "calibrationpipeline.h" -#include "imagingpipeline.h" -#include "pulsarpipeline.h" -using std::string; -using std::cout; -using std::cerr; -using std::endl; -using std::ifstream; -using std::ofstream; -using std::stringstream; -using std::vector; -using std::map; - -DataHandler::DataHandler(const Controller *controller) -: itsController(controller) -{ -} - -DataHandler::~DataHandler() -{ -} - -void DataHandler::checkTask(Task *task) { - bool bResult = false; - if (!(task->getWindowFirstDay().isSet())) { - if (!(task->getWindowLastDay().isSet())) { - if (!(task->getWindowMinTime().isSet())) { - if (!(task->getWindowMaxTime().isSet())) { - bResult = true; - } - } - } - } - if (!bResult) { - task->setStatus(Task::ERROR); - task->setReason("incomplete specification"); - } -} - -/* -bool DataHandler::readCSVFile(const QString &filename, SchedulerData &data) -{ - if (!filename.isEmpty()) - { - ifstream file(filename.toStdString().c_str()); - if (file) { - Task *pt(0); - char buf[50]; - char buf2[500]; - string line; - int bsize = sizeof(buf); - stringstream sstr; - // variables needed to create a task: - unsigned int tid=0, pid=0, clock=0, ngt_time_wght=0, uVal(0); - int task_status_int = -1, task_mode_int = -1, iVal(0); - string target, status, strdt, task_mode_str; - double priority = 0.0f; - bool bool_value; - processSubTypes subType = PST_UNKNOWN; - - while (!file.eof()) { - tid=0; pid=0; clock=0; ngt_time_wght=0; - iVal = 0; - uVal = 0; - target = ""; status = ""; strdt = ""; - priority = 0.0f; - // read taskID - file.getline(buf, bsize, ','); - - // if this is a commented line '#' then skip it - if (buf[0] == '#') { getline(file, line); continue; } - //else { file.getline(buf, bsize, ','); } - - sstr.str(""); - sstr.clear(); - sstr << buf; - sstr >> tid; - if (tid == 0) { // tid == 0 means we are probably at the end of the file now - continue; - } - - // read task type - getline(file, strdt, ','); - string subtypestr; - getline(file, subtypestr, ','); - - if (strdt != "") { - Task::task_type type = taskTypeFromString(strdt); - switch (type) { - case Task::OBSERVATION: - pt = data.newObservation(tid); - if (!pt) { - cerr << "Creating new observaton failed because task ID: " << tid << " already exists." << endl; - file.getline(buf2, sizeof(buf2)); // skip this line - continue; - } - break; - case Task::PIPELINE: - subType = stringToProcessSubType(subtypestr.c_str()); - switch (subType) { - case PST_AVERAGING_PIPELINE: - case PST_CALIBRATION_PIPELINE: - pt = data.newCalibrationPipeline(tid, false); - break; - case PST_IMAGING_PIPELINE: - case PST_MSSS_IMAGING_PIPELINE: - pt = data.newImagingPipeline(tid, false); - break; - case PST_PULSAR_PIPELINE: - pt = data.newPulsarPipeline(tid, false); - break; - default: - pt = data.newPipeline(tid, false); - break; - } - if (!pt) { - cerr << "Creating new pipeline failed because task ID: " << tid << " already exists." << endl; - file.getline(buf2, sizeof(buf2)); // skip this line - continue; - } - break; - case Task::RESERVATION: - break; - case Task::MAINTENANCE: - break; - case Task::SYSTEM: - break; - default: - cerr << "Unknown task type for task ID: " << tid << " . Skipping." << endl; - file.getline(buf2, sizeof(buf2)); // skip this line - continue; - } - if (!pt) { - cerr << "Creating new task failed because task ID: " << tid << " already exists." << endl; - file.getline(buf2, sizeof(buf2)); // skip this line - continue; - } - } - else { - cerr << "Could not read task type for task ID: " << tid << ". Skipping." << endl; - file.getline(buf2, sizeof(buf2)); // skip this line - continue; - } - - // read SAS ID - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> iVal; - pt->setSASTreeID(iVal); - - // read MoM ID - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> iVal; - pt->setMoMID(iVal); - - // read Group ID - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> uVal; - pt->setGroupID(uVal); - - // read project name - getline(file, strdt, ','); - if (strdt != "") { - pt->setProjectName(strdt); - } - // read task name - getline(file, strdt, ','); - if (strdt != "") { - pt->setTaskName(strdt); - } - // read contact name - getline(file, strdt, ','); - if (strdt != "") { - pt->setContactName(strdt); - } - // read contact phone - getline(file, strdt, ','); - if (strdt != "") { - pt->setContactPhone(strdt); - } - // read contact e-mail - getline(file, strdt, ','); - if (strdt != "") { - pt->setContactEmail(strdt); - } - // read Predecessor ID - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> pid; - if (pid) { - // read predecessor minimum time difference - getline(file, strdt,','); - // read predecessor maximum time difference - getline(file, strdt,','); - pt->addPredecessor(pid); - } - else { - getline(file, strdt,','); - getline(file, strdt,','); - } - - // read task status - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> task_status_int; - - // read task duration - getline(file, strdt, ','); - if (strdt != "") { - pt->setDuration(strdt); - } - - // read planned start - getline(file, strdt, ','); - if (strdt != "") { - pt->setScheduledStart(strdt); - } - - // read planned end - getline(file, strdt, ','); - if (strdt != "") { - pt->setScheduledEnd(strdt); - } - - // read first possible date - getline(file, strdt, ','); - if (strdt != "") { - pt->setWindowFirstDay(strdt); - } - - // read last possible date - getline(file, strdt, ','); - if (strdt != "") { - pt->setWindowLastDay(strdt); - } - - // read scheduling time window minimum time - getline(file, strdt, ','); - if (strdt != "") { - pt->setWindowMinTime(strdt); - } - - // read scheduling time window maximum time - getline(file, strdt, ','); - if (strdt != "") { - pt->setWindowMaxTime(strdt); - } - - // read fixed day boolean - bool_value = false; - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> bool_value; - pt->setFixDay(bool_value); - - // read fixed time boolean - bool_value = false; - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> bool_value; - pt->setFixTime(bool_value); - - // read priority - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> priority; - pt->setPriority(priority); - - // unscheduled reason - getline(file, strdt, ','); - if (strdt != "") { - pt->setReason(strdt); - } - - // if this is an observation - if (pt->isObservation()) { - Observation *pObs = dynamic_cast<Observation *>(pt); - // read antenna mode - task_mode_int = -1; - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> task_mode_int; - if (task_mode_int != -1) { // if task mode was specified as an integer in the file - pObs->setAntennaMode(static_cast<station_antenna_mode>(task_mode_int)); - } - else { // if task mode was specified as a string in the file - sstr.clear(); - sstr.seekp(0, std::ios::beg); - sstr >> task_mode_str; - pObs->setAntennaMode(task_mode_str); - } - // read station names - getline(file, strdt, ','); - if (strdt != "") { - pObs->setStations(strdt.c_str(),';'); - } - // read clock frequency - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> clock; - pObs->setStationClock(clock); - // read night-time weight factor - sstr.str(""); - sstr.clear(); - file.getline(buf, bsize, ','); - sstr << buf; - sstr >> ngt_time_wght; - pObs->setNightTimeWeightFactor(ngt_time_wght); - } - else { // skip to next line (task) in file - file.getline(buf2, sizeof(buf2)); // skip this line - continue; - } - // now check if this task has enough valid data to be scheduled, if not put on hold - checkTask(pt); - pt->calculateDataFiles(); - } - file.close(); - } - else { - cerr << "Could not open file " << filename.toStdString() << "." << endl; - } - return true; - } - return false; -} -*/ - -bool DataHandler::writeCSVFile(const QString &filename, const std::vector<const Task *> tasks) { - QFile file(filename); - if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { - - QTextStream out(&file); - - // write data headers - out << "# "; - for (unsigned i=0; i < NR_DATA_HEADERS; ++i) { - out << DATA_HEADERS[i] << ","; - } - out << endl; - - // write the tasks properties - for (std::vector<const Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - writeTaskToFile(out, *it); - } - - file.close(); - - debugInfo("sss","File: ", filename.toStdString().c_str(), " written correctly."); - return true; - } - else { - debugErr("sss","Cannot write to file ", filename.toStdString().c_str(), " !"); - return false; - } -} - -void DataHandler::writeTaskToFile(QTextStream &out, const Task *ptask) { - out << ptask->getID() << "," - << ptask->getTypeStr() << "," - << ptask->getSASTreeID() << "," - << ptask->getMomID() << "," - << ptask->getGroupID() << "," - << ptask->getProjectName() << "," - << QString(ptask->getTaskName()).replace(",","_").toStdString().c_str() << "," - << QString(ptask->getTaskDescription()).replace(",","_").toStdString().c_str() << "," - << ptask->getStatusStr() << "," - << QString(ptask->getContactName()).replace(",","_") << "," - << QString(ptask->getContactPhone()).replace(",","_") << "," - << ptask->getContactEmail() << "," - << ptask->getPredecessorsString(';') << "," - << ptask->getDuration().toString().c_str() << "," - << ptask->getScheduledStart().toString().c_str() << "," - << ptask->getScheduledEnd().toString().c_str() << "," - << ptask->getWindowFirstDay().toString().c_str() << "," - << ptask->getWindowLastDay().toString().c_str() << "," - << ptask->getWindowMinTime().toString().c_str() << "," - << ptask->getWindowMaxTime().toString().c_str() << "," - << ptask->getFixedDay() << "," - << ptask->getFixedTime() << "," - << ptask->getPriority(); - if (ptask->hasStorage()) { - out << "," << ptask->storage()->getTotalStoragekBytes(); - } - - if (ptask->isObservation()) { - const Observation * pObs = static_cast<const Observation *>(ptask); - out << pObs->getStationNamesStr(';').c_str() << "," << pObs->getAntennaModeStr() << "," << pObs->getStationClockStr() << "," - << pObs->getFilterTypeStr() << "," << pObs->getNrOfSubbands(); - - unsigned res_id(pObs->getReservation()); - if (res_id) { - out << itsController->getReservationName(res_id); - } - } - - out << endl; -} - -bool DataHandler::openSchedule(const QString &filename, SchedulerData &data) { - QFile file(filename); - if (file.open(QIODevice::ReadOnly)) { - QDataStream in(&file); - in >> Controller::itsFileVersion; // set the current file version read from file - std::cout << "version: " << Controller::itsFileVersion << std::endl; - bool test(Controller::theSchedulerSettings.getIsTestEnvironment()); // remember current test environment setting, should not be changed when loading a schedule from disk - in >> Controller::theSchedulerSettings >> data; - Controller::theSchedulerSettings.setIsTestEnvironment(test); - file.close(); - debugInfo("ss","Read file: ", filename.toStdString().c_str()); - itsFileName = filename; - return true; - } - else - return false; -} - -bool DataHandler::saveSchedule(const QString &filename, const SchedulerData &data) { - QFile file(filename); - if (file.open(QIODevice::WriteOnly)) { - QDataStream out(&file); - out << (quint32)FILE_WRITE_VERSION << Controller::theSchedulerSettings << data; - file.close(); - debugInfo("ss","Wrote file: ", filename.toStdString().c_str()); - itsFileName = filename; - return true; - } - else - return false; -} - -bool DataHandler::loadProgramPreferences(void) { - ifstream file; - bool loadDefaults; - file.open(PROGRAM_PREFERENCES_FILENAME, std::ios::binary); - if (file.is_open()) { - try { - read_primitive<bool>(file, loadDefaults); - Controller::theSchedulerSettings.setLoadDefaultSettingsOnStartup(loadDefaults); - } - catch (std::bad_alloc &) { - debugErr("s","preferences file corrupted, canceling reading program preferences"); - file.close(); - return false; - } - file.close(); - if (loadDefaults) { - if (loadSettings(PROGRAM_DEFAULT_SETTINGS_FILENAME)) { - return true; - } - else return false; - } - return true; - } - else - return false; -} - -bool DataHandler::saveProgramPreferences(void) { - ofstream file; - file.open(PROGRAM_PREFERENCES_FILENAME, std::ios::binary); - if (file.is_open()) { - write_primitive<bool>(file, Controller::theSchedulerSettings.getLoadDefaultSettingsOnStartUp()); - file.close(); - debugInfo("ss","Wrote preferences to file: ", PROGRAM_PREFERENCES_FILENAME); - return true; - } - else - return false; -} - -bool DataHandler::saveSettings(const QString &filename) const -{ - QFile file(filename); - if (file.open(QIODevice::WriteOnly)) - { - QDataStream out(&file); - out << (unsigned)FILE_WRITE_VERSION; - out << Controller::theSchedulerSettings; - file.close(); - debugInfo("ss","Wrote settings to file: ", (filename.toStdString().c_str())); - return true; - } - else { - debugInfo("ss","Failed to write to file: ", (filename.toStdString().c_str())); - return false; - } -} - -bool DataHandler::loadSettings(const QString &filename) { - QFile file(filename); - if (file.open(QIODevice::ReadOnly)) { - QDataStream in(&file); - try { - in >> Controller::itsFileVersion; // set the current file version read from file -// file.close(); - if (Controller::itsFileVersion != 0) { - in >> Controller::theSchedulerSettings; - } - else { - debugErr("ss","Could not read file version from settings file: ", filename.toStdString().c_str()); - return false; - } - } - catch (std::bad_alloc &) { - file.close(); - debugErr("sss","settings file: ", filename.toStdString().c_str()," corrupted, canceling reading program settings"); - return false; - } - file.close(); - debugInfo("ss","Read settings from file: ", filename.toStdString().c_str()); - return true; - } - else { - debugErr("ss","Could not open settings file: ", filename.toStdString().c_str()); - return false; - } -} diff --git a/SAS/Scheduler/src/DataHandler.h b/SAS/Scheduler/src/DataHandler.h deleted file mode 100644 index 67d44e735e0593c82649444d624562578bbb425e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DataHandler.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * DataHandler.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 5-feb-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DataHandler.h $ - * - */ - -#ifndef DATAHANDLER_H_ -#define DATAHANDLER_H_ - -#include "schedulerdata.h" - -#include <string> - -class DataHandler { -public: - DataHandler(const Controller *); - virtual ~DataHandler(); -// bool readCSVFile(const QString &filename, SchedulerData &data); // read data from a task file and load in scheduler data objects - bool writeCSVFile(const QString &filename, const std::vector<const Task *> tasks); // write the task data contained in data to a CSV file - bool openSchedule(const QString &filename, SchedulerData &data); // read a scheduling project from binary file - bool saveSchedule(const QString &filename, const SchedulerData &data); // save the scheduling project to file - void checkTask(Task *task); // checks if the task has enough parameters specified to be scheduled - bool saveSettings(const QString &filename) const; - bool loadSettings(const QString &filename); - bool loadProgramPreferences(void); - bool saveProgramPreferences(void); - - // getters - const QString &getFileName(void) const { return itsFileName; } - - // setters - void setFileName(QString const &fname) { itsFileName = fname; } - -private: - void writeTaskToFile(QTextStream &out, const Task *ptask) ; // Retrieves and writes the details of a task to file - QString itsFileName; - const Controller *itsController; -}; - -#endif /* DATAHANDLER_H_ */ diff --git a/SAS/Scheduler/src/DataMonitorConnection.cpp b/SAS/Scheduler/src/DataMonitorConnection.cpp deleted file mode 100644 index 94515669132e490cf1229df02a906ca0d98754c4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DataMonitorConnection.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* - * DataMonitorConnection.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 4-aug-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DataMonitorConnection.cpp $ - * - */ - -#include "DataMonitorConnection.h" -#include "lofar_utils.h" -#include <QSqlRecord> -#include <QSqlQuery> -#include <QVariant> -#include <QSqlResult> -#include <QSqlError> -#include <algorithm> - -DataMonitorConnection::DataMonitorConnection(Controller *controller) -: itsController(controller)/*, itsIsConnected(false)*/ { - QSqlDatabase dataMonitorDB = QSqlDatabase::addDatabase("QMYSQL","datamonitorDB"); -} - -DataMonitorConnection::~DataMonitorConnection() { - { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - if (dataMonitorDB.isValid()) { - if (dataMonitorDB.isOpen()) dataMonitorDB.close(); - } - } - QSqlDatabase::removeDatabase("datamonitorDB"); -} - -bool DataMonitorConnection::isOpen(void) const { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - if (dataMonitorDB.isOpen()) { - QSqlQuery query("SELECT * FROM states", dataMonitorDB); - if (query.next()) { - query.finish(); - return true; - } - else { - query.finish(); - return false; - } - } - else return false; - // return dataMonitorDB.isOpen(); -} - -bool DataMonitorConnection::initRequired(const QString &username, const QString &password, const QString &DBName, const QString &hostname) { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - if (username.compare(dataMonitorDB.userName()) != 0) return true; - else if (hostname.compare(dataMonitorDB.hostName()) != 0) return true; - else if (password.compare(dataMonitorDB.password()) != 0) return true; - else if (DBName.compare(dataMonitorDB.databaseName()) != 0) return true; - // if the same wrong settings where applied two times the settings are not changed but the connection should still be re-initialized to make sure the settings are checked - else return (!dataMonitorDB.isOpen()); -} - -bool DataMonitorConnection::init(const QString &username, const QString &password, const QString &DBName, const QString &hostname) { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - if (!dataMonitorDB.isValid()) { - dataMonitorDB = QSqlDatabase::addDatabase("QMYSQL","datamonitorDB"); - } - - if (dataMonitorDB.isOpen()) { - dataMonitorDB.close(); - } - - bool init_required(false); - if (username.compare(dataMonitorDB.userName()) != 0) init_required = true; - else if (hostname.compare(dataMonitorDB.hostName()) != 0) init_required = true; - else if (password.compare(dataMonitorDB.password()) != 0) init_required = true; - else if (DBName.compare(dataMonitorDB.databaseName()) != 0) init_required = true; - - if (init_required) { - dataMonitorDB.setHostName(hostname); - dataMonitorDB.setDatabaseName(DBName); - dataMonitorDB.setUserName(username); - dataMonitorDB.setPassword(password); - } - - // get all status types from database - if (dataMonitorDB.open()) { - itsStates.clear(); - QSqlQuery query("SELECT * FROM states", dataMonitorDB); - int idxId = query.record().indexOf("id"); - int idxStateName = query.record().indexOf("statename"); - while (query.next()) { - itsStates[query.value(idxId).toInt()] = query.value(idxStateName).toString().toStdString(); - } - query.finish(); - dataMonitorDB.close(); - return true; - } - return false; -} - -bool DataMonitorConnection::connect(void) { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - if (!dataMonitorDB.isValid()) { - dataMonitorDB = QSqlDatabase::addDatabase("QMYSQL","datamonitorDB"); - } - QVariant value; - if (dataMonitorDB.open()) { - return true; - } - else { - debugErr("sssssss","Could not establish a connection to the Data Monitor! Settings used:\n", - "Username: ", dataMonitorDB.userName().toStdString().c_str(), - ", database: ", dataMonitorDB.databaseName().toStdString().c_str(), - ", hostname: ", dataMonitorDB.hostName().toStdString().c_str() - ); - return false; // could not connect to SAS database - } -} -/* -bool DataMonitorConnection::isOpen(void) const { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - return dataMonitorDB.isOpen(); -} -*/ -void DataMonitorConnection::disconnect(void) { - { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - dataMonitorDB.close(); - } // dataMonitorDB needs to go out of scope before removeDatabase is called - QSqlDatabase::removeDatabase("datamonitorDB"); -} - -bool DataMonitorConnection::updateStorageNodes(void) { - QSqlDatabase dataMonitorDB = QSqlDatabase::database("datamonitorDB"); - //itsStorageNodes.clear(); - storageHostsMap itsNewStorageNodes; - itsHostPartitions.clear(); - if (dataMonitorDB.isOpen()) { - //fetch all storage nodes - StorageHost newHost; - QSqlQuery query("SELECT * FROM hosts WHERE groupid=3", dataMonitorDB); - storageHostsMap::const_iterator stit; - while (query.next()) { - newHost.itsID = query.value(query.record().indexOf("id")).toInt(); - newHost.itsName = query.value(query.record().indexOf("hostname")).toString().toStdString(); - newHost.itsStatus = query.value(query.record().indexOf("statusid")).toInt(); - // look up the host in the old host table to see if it may be used - stit = itsStorageNodes.find(newHost.itsID); - if (stit != itsStorageNodes.end()) { // host did exist before? - if (newHost.itsName == stit->second.itsName) { - newHost.itsMayBeUsed = stit->second.itsMayBeUsed; - } - else if (newHost.itsStatus == 1) { - newHost.itsMayBeUsed = true; - } - else { - newHost.itsMayBeUsed = false; - } - } - else if (newHost.itsStatus == 1) { - newHost.itsMayBeUsed = true; - } - else { - newHost.itsMayBeUsed = false; - } - itsNewStorageNodes[newHost.itsID] = newHost; - } - query.finish(); - itsStorageNodes = itsNewStorageNodes; - // now update the free space of every partition available from this storage node - int locationID; - std::string path; - std::vector<quint64> spaceVector; - dataPathsMap dataPaths; - quint64 totalSpace, claimedSpace, usedSpace, freeSpace; - for (storageHostsMap::const_iterator it = itsStorageNodes.begin(); it != itsStorageNodes.end(); ++it) { - query.exec("SELECT * FROM datapaths WHERE hostid=" + QString::number(it->first)); - while (query.next()) { // get all partitions for this node from the database - locationID = query.value(query.record().indexOf("id")).toInt(); - path = query.value(query.record().indexOf("path")).toString().toStdString(); - totalSpace = query.value(query.record().indexOf("totalspace")).toULongLong(); - usedSpace = query.value(query.record().indexOf("usedspace")).toULongLong(); - claimedSpace = query.value(query.record().indexOf("claimedspace")).toULongLong(); - spaceVector.push_back(totalSpace); - spaceVector.push_back(usedSpace); - spaceVector.push_back(claimedSpace); - if (usedSpace + claimedSpace > totalSpace) freeSpace = 0; - else freeSpace = totalSpace - usedSpace - claimedSpace; - spaceVector.push_back(freeSpace); - dataPaths[locationID] = std::pair<std::string, std::vector<quint64> >(path, spaceVector); - spaceVector.clear(); - } - itsHostPartitions[it->first] = dataPaths; - dataPaths.clear(); - query.finish(); - } - return true; - } - else return false; -} - -void DataMonitorConnection::setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts) { - std::vector<int>::const_iterator it; - storageHostsMap::iterator sit = itsStorageNodes.begin(); - while (sit != itsStorageNodes.end()) { - it = find(allowedStorageHosts.begin(),allowedStorageHosts.end(),sit->second.itsID); - if (it != allowedStorageHosts.end()) { - sit->second.itsMayBeUsed = true; - } - else { - sit->second.itsMayBeUsed = false; - } - ++sit; - } -} - -std::vector<int> DataMonitorConnection::getUsableStorageNodeIDs(void) const { - std::vector<int> nodes; - for (storageHostsMap::const_iterator it = itsStorageNodes.begin(); it != itsStorageNodes.end(); ++it) { - if (it->second.itsMayBeUsed) { - nodes.push_back(it->first); - } - } - return nodes; -} - -int DataMonitorConnection::getStorageNodeID(const std::string &name) const { - storageHostsMap::const_iterator it = itsStorageNodes.begin(); - while (it != itsStorageNodes.end()) { - if (it->second.itsName.compare(name.c_str()) == 0) return it->first; - ++it; - } - return 0; -} - -std::string DataMonitorConnection::getStorageNodeName(int node_id) const { - storageHostsMap::const_iterator it = itsStorageNodes.find(node_id); - if (it != itsStorageNodes.end()) return it->second.itsName; - else return ""; -} - -int DataMonitorConnection::getStorageRaidID(int node_id, const std::string &raidName) const { - hostPartitionsMap::const_iterator it = itsHostPartitions.find(node_id); - if (it != itsHostPartitions.end()) { - for (dataPathsMap::const_iterator dit = it->second.begin(); dit != it->second.end(); ++dit) { - if (dit->second.first.compare(raidName) == 0) return dit->first; - } - return 0; - } - else return 0; -} - -size_t DataMonitorConnection::getNrOfStorageNodesAvailable(void) const { - size_t nrAvailable(0); - for (storageHostsMap::const_iterator it = itsStorageNodes.begin(); it != itsStorageNodes.end(); ++it) { - if (it->second.itsMayBeUsed) ++nrAvailable; - } - return nrAvailable; -} - -std::string DataMonitorConnection::getStorageRaidName(int node_id, int raid_id) const { - hostPartitionsMap::const_iterator it = itsHostPartitions.find(node_id); - if (it != itsHostPartitions.end()) { - dataPathsMap::const_iterator dit = it->second.find(raid_id); - if (dit != it->second.end()) - return dit->second.first; - } - return ""; -} diff --git a/SAS/Scheduler/src/DataMonitorConnection.h b/SAS/Scheduler/src/DataMonitorConnection.h deleted file mode 100644 index 077a09e5dbc19cb1db9dcc2166c8017e5ce5bca3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DataMonitorConnection.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * DataMonitorConnection.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 4-aug-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DataMonitorConnection.h $ - * - */ - -#ifndef DATAMONITORCONNECTION_H_ -#define DATAMONITORCONNECTION_H_ - -#include <QSqlDatabase> -#include <vector> -#include <map> - -class StorageHost { -public: - std::string itsName; - quint16 itsID; - quint16 itsStatus; - bool itsMayBeUsed; -}; - -typedef std::map<int, std::string> statesMap; -// key = hostID, value: pair<hostname, status> -//typedef std::map<int, std::pair<std::string, int> > storageHostsMap; -typedef std::map<int, StorageHost> storageHostsMap; -// key = hostID, value: vector<pair<path, pair<totalspace, pair<usedspace, claimedspace>>> -//typedef std::map<int, std::vector<std::pair<QString, std::pair<unsigned long, std::pair<unsigned long, unsigned long> > > > > dataPathsMap; -// key = raid ID, value = pair<path, vector with four space componennts i.e. [0]=total, [1]=used, [2]=claimed, [3]=free -typedef std::map<int, std::pair<std::string, std::vector<quint64> > > dataPathsMap; -// key = host ID, value = vector of path IDs that belong to this host (the path IDs can be looked up in the dataPathsMap) -//typedef std::map<int, std::vector<int> > hostPartitionIDsMap; -typedef std::map<int, dataPathsMap> hostPartitionsMap; - -//#include "Controller.h" -class Controller; - -class DataMonitorConnection { -public: - DataMonitorConnection(Controller *controller); - virtual ~DataMonitorConnection(); - - bool init(const QString &username, const QString &password, const QString &DBName, const QString &hostname); - bool initRequired(const QString &username, const QString &password, const QString &DBName, const QString &hostname); - bool connect(void); -// int testConnect(const QString &username, const QString &password, const QString &DBname, const QString &hostname); - void disconnect(void); - bool isOpen(void) const; - bool updateStorageNodes(void); // gets the the storage nodes and their current status from the DM database - - const storageHostsMap &getStorageNodes(void) const {return itsStorageNodes;} - std::vector<int> getUsableStorageNodeIDs(void) const; - const statesMap &getStates(void) const {return itsStates;} - size_t getNrOfStorageNodesAvailable(void) const; -// const dataPathsMap &getDataPaths(void) const {return itsDataPaths;} - const hostPartitionsMap &getHostPartitions(void) const {return itsHostPartitions;} - int getStorageRaidID(int node_id, const std::string &raidName) const; -// long double getStorageNodeSpaceRemaining(int node_id, unsigned short partition_id) const; - int getStorageNodeID(const std::string &name) const; - std::string getStorageNodeName(int node_id) const; - std::string getStorageRaidName(int node_id, int raid_id) const; - - void setStorageNodes(const storageHostsMap &nodes) {itsStorageNodes = nodes;} - void setStoragePartitions(const hostPartitionsMap &partitions) {itsHostPartitions = partitions;} - - void setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts); - - friend class Controller; - -private: -// QSqlDatabase itsDataMonitorDB; - Controller *itsController; - statesMap itsStates; - storageHostsMap itsStorageNodes; - hostPartitionsMap itsHostPartitions; -// bool itsIsConnected; -// hostPartitionIDsMap itsHostPartitionsIDs; -// dataPathsMap itsDataPaths; -}; - -#endif /* DATAMONITORCONNECTION_H_ */ diff --git a/SAS/Scheduler/src/DataTreeWidgetItem.cpp b/SAS/Scheduler/src/DataTreeWidgetItem.cpp deleted file mode 100644 index 5435a189bb6ed2925396f641fadc0c9980f6a81a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DataTreeWidgetItem.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * qtreewidget.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Aug 23, 2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DataTreeWidgetItem.cpp $ - * - */ - -#include "DataTreeWidgetItem.h" - -DataTreeWidgetItem::DataTreeWidgetItem(QTreeWidgetItem *base) - : QTreeWidgetItem(base) -{ - // TODO Auto-generated constructor stub - -} - -DataTreeWidgetItem::~DataTreeWidgetItem() { - // TODO Auto-generated destructor stub -} - diff --git a/SAS/Scheduler/src/DataTreeWidgetItem.h b/SAS/Scheduler/src/DataTreeWidgetItem.h deleted file mode 100644 index eaaf2f3b314dad068df65c0903e8ea66d8be3416..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DataTreeWidgetItem.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * qtreewidget.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Aug 23, 2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DataTreeWidgetItem.h $ - * - */ - - -#ifndef DATATREEWIDGETITEM_H_ -#define DATATREEWIDGETITEM_H_ - -#include <qtreewidget.h> -#include "lofar_utils.h" - -class DataTreeWidgetItem: public QTreeWidgetItem { -public: - DataTreeWidgetItem(QTreeWidgetItem *base = 0); - DataTreeWidgetItem(QTreeWidget *parent, const QStringList &str) : QTreeWidgetItem(parent, str) {} - DataTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &str) : QTreeWidgetItem(parent, str) {} - - void setDataValue(quint64 value) { - setData(0,Qt::UserRole,value); - itsHumanReadableValue = humanReadableUnits(value, SIZE_UNITS).c_str(); - } - virtual ~DataTreeWidgetItem(); - - quint64 dataValue(void) const {return data(0,Qt::UserRole).toULongLong();} - QString humanReadible(void) const {return itsHumanReadableValue;} - -private: - bool operator<(const QTreeWidgetItem &other) const { - int column = treeWidget()->sortColumn(); - if (column == 1) { - return data(1,Qt::UserRole).toUInt() < other.data(1,Qt::UserRole).toUInt(); - } - else if (column == 10) { - return data(0,Qt::UserRole).toULongLong() < other.data(0,Qt::UserRole).toULongLong(); - } - else return (QTreeWidgetItem::operator <(other)); - } - -private: - QString itsHumanReadableValue; -}; - -#endif /* DATATREEWIDGETITEM_H_ */ diff --git a/SAS/Scheduler/src/DateEdit.cpp b/SAS/Scheduler/src/DateEdit.cpp deleted file mode 100644 index 46cbed42887b5d9bd719f5d7d7ebe97db31293ab..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DateEdit.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * DateEdit.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DateEdit.cpp $ - * - */ - -#include "DateEdit.h" -#include <QFocusEvent> - -DateEdit::DateEdit(QWidget *parent) - : QDateEdit(parent), itsUndefined(false) -{ - itsPreviousDate = date(); - QObject::connect(this,SIGNAL(dateChanged(const QDate &)), this, SLOT(checkDateChange(void))); -} - -DateEdit::~DateEdit() { -} - -void DateEdit::setDate(const QDate &date) { - this->blockSignals(true); - setSpecialValueText(""); - itsUndefined = false; - QDateEdit::setDate(date); - itsPreviousDate = date; - this->blockSignals(false); -} - -void DateEdit::setUndefined(bool enabled = true) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - itsPreviousDate = date(); - // NOTE: if minimum date equals the date then the special value text is shown - setSpecialValueText(MULTIPLE_VALUE_TEXT); - QDateEdit::setDate(minimumDate()); - } - else { - setSpecialValueText(""); - QDateEdit::setDate(itsPreviousDate); - } - this->blockSignals(false); -} - -void DateEdit::focusInEvent(QFocusEvent* event) -{ - this->blockSignals(true); - if (itsUndefined) { - QDateEdit::setDate(itsDefaultDate); - setSpecialValueText(""); - itsPreviousDate = date(); - } - - QDateEdit::focusInEvent(event); - this->blockSignals(false); -} - -void DateEdit::focusOutEvent(QFocusEvent* event) -{ - checkDateChange(); - QDateEdit::focusOutEvent(event); -} - -void DateEdit::checkDateChange(void) { - this->blockSignals(true); - if (itsUndefined) { - if (itsPreviousDate == date()) { // was undefined and did not change - // NOTE: if minimum date equals the date then the special value text is shown - setSpecialValueText(MULTIPLE_VALUE_TEXT); - QDateEdit::setDate(minimumDate()); - } - else { - itsUndefined = false; - setSpecialValueText(""); - } - itsPreviousDate = date(); - } - this->blockSignals(false); -} diff --git a/SAS/Scheduler/src/DateEdit.h b/SAS/Scheduler/src/DateEdit.h deleted file mode 100644 index c12481e9bcbc397f6483319321144baf0a058033..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DateEdit.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * DateEdit.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DateEdit.h $ - * - */ - -#include <QDateEdit> -#include "astrodate.h" - -#ifndef DATEEDIT_H_ -#define DATEEDIT_H_ - -class DateEdit : public QDateEdit { - - Q_OBJECT - -public: - DateEdit(QWidget *parent); - virtual ~DateEdit(); - - void setDate(const QDate &d); - void setUndefined(bool enabled); - void setDefaultDate(const AstroDate &d) {itsDefaultDate.setDate(d.getYear(),d.getMonth(),d.getDay());} - inline bool isUndefined(void) {return itsUndefined;} - inline bool hasBeenChanged(void) const {return itsPreviousDate != date();} - void resetChangeDetect(void) {itsPreviousDate = date();} - - -protected: - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkDateChange(void); - -private: - bool itsUndefined; - QDate itsPreviousDate, itsDefaultDate; -}; - -#endif /* DATEEDIT_H_ */ diff --git a/SAS/Scheduler/src/DateTimeEdit.cpp b/SAS/Scheduler/src/DateTimeEdit.cpp deleted file mode 100644 index de93a80de61765b9495f13e592086587b9ffe2a0..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DateTimeEdit.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * DateTimeEdit.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DateTimeEdit.cpp $ - * - */ - -#include "DateTimeEdit.h" -#include <QFocusEvent> -#include "astrodate.h" - -DateTimeEdit::DateTimeEdit(QWidget *parent) - : QDateTimeEdit(parent), itsUndefined(true) -{ - itsPreviousDateTime = dateTime(); - QObject::connect(this,SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(checkDateTimeChange(void))); -} - -DateTimeEdit::~DateTimeEdit() { -} - -void DateTimeEdit::setDateTime(const QDateTime &datetime) { - this->blockSignals(true); - QDateTimeEdit::setDateTime(datetime); - itsPreviousDateTime = QDateTimeEdit::dateTime(); - setSpecialValueText(""); - itsUndefined = false; - this->blockSignals(false); -} - -void DateTimeEdit::setUndefined(bool enabled) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - itsPreviousDateTime = dateTime(); - // NOTE: if minimum date equals the date then the special value text is shown - setSpecialValueText(itsSpecialValueText); - QDateTimeEdit::setDateTime(minimumDateTime()); - } - else { - setSpecialValueText(""); - QDateTimeEdit::setDateTime(itsPreviousDateTime); - } - this->blockSignals(false); -} - -void DateTimeEdit::focusInEvent(QFocusEvent* event) -{ - this->blockSignals(true); - - if (itsUndefined) { - QDateTimeEdit::setDateTime(itsDefaultDateTime); - setSpecialValueText(""); - itsPreviousDateTime = dateTime(); - } - - QDateTimeEdit::focusInEvent(event); - this->blockSignals(false); -} - -void DateTimeEdit::focusOutEvent(QFocusEvent* event) -{ - checkDateTimeChange(); - QDateTimeEdit::focusOutEvent(event); -} - -void DateTimeEdit::checkDateTimeChange(void) { - this->blockSignals(true); - if (itsUndefined) { - if (itsPreviousDateTime == dateTime()) { // was undefined and did not change -> re-apply opacity effect - // NOTE: if minimum date equals the date then the special value text is shown - setSpecialValueText(itsSpecialValueText); - QDateTimeEdit::setDateTime(minimumDateTime()); - } - else { - itsUndefined = false; - setSpecialValueText(""); - } - itsPreviousDateTime = dateTime(); - } - this->blockSignals(false); -} diff --git a/SAS/Scheduler/src/DateTimeEdit.h b/SAS/Scheduler/src/DateTimeEdit.h deleted file mode 100644 index 41ab810f469dc452a704ad7dfd791bbe78bbbfc9..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DateTimeEdit.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * DateTimeEdit.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DateTimeEdit.h $ - * - */ - -#include <QDateTimeEdit> -#include "astrodatetime.h" - -#ifndef DATETIMEEDIT_H_ -#define DATETIMEEDIT_H_ - -class DateTimeEdit : public QDateTimeEdit { - - Q_OBJECT - -public: - DateTimeEdit(QWidget *parent); - virtual ~DateTimeEdit(); - - void setDateTime(const QDateTime &datetime); - void setMultipleValue(void) {itsSpecialValueText = MULTIPLE_VALUE_TEXT; setUndefined(true);} - void setNotSetValue(void) {itsSpecialValueText = NOT_SET_TEXT; setUndefined(true);} - void setUndefined(bool enabled = true); - bool hasBeenChanged(void) const {return ((!itsUndefined) && (itsPreviousDateTime != QDateTimeEdit::dateTime()));} - void setDefaultDateTime(const AstroDateTime &dt) {itsDefaultDateTime.setDate(QDate(dt.getYear(),dt.getMonth(),dt.getDay())); - itsDefaultDateTime.setTime(QTime(dt.getHours(), dt.getMinutes(), dt.getSeconds()));} - void resetChangeDetect(void) {itsPreviousDateTime = dateTime();} - - bool isUndefined(void) {return itsUndefined;} - -protected: - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkDateTimeChange(void); - -private: - bool itsUndefined; - QString itsSpecialValueText; - QDateTime itsPreviousDateTime, itsDefaultDateTime; -}; - -#endif /* DATETIMEEDIT_H_ */ diff --git a/SAS/Scheduler/src/DigitalBeam.cpp b/SAS/Scheduler/src/DigitalBeam.cpp deleted file mode 100644 index d6a66225720584b8dae3bb152f0121b80aaba5ce..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DigitalBeam.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * DigitalBeam.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Dec 6, 2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DigitalBeam.cpp $ - * - */ - -#include "DigitalBeam.h" -#include <algorithm> -#include <math.h> - -const char * BEAM_DIRECTION_TYPES[_END_DIRECTION_TYPES] = {"J2000", "B1950", "ITRF", "HADEC","AZELGEO", "TOPO", "ICRS", "APP","GALACTIC", - "ECLIPTIC", "COMET", "MERCURY", "VENUS", "MARS", "JUPITER", "SATURN", "URANUS", "NEPTUNE", "PLUTO", "SUN", "MOON", "UNDEFINED"}; - -beamDirectionType stringToBeamDirectionType(const std::string &str) { - if (!str.empty()) { - for (short i = 0; i < DIR_TYPE_UNDEFINED; ++i) { - if (str.compare(BEAM_DIRECTION_TYPES[i]) == 0) { - return static_cast<beamDirectionType>(i); - } - } - } - return static_cast<beamDirectionType>(DIR_TYPE_UNDEFINED); -} - -DigitalBeam::~DigitalBeam() { - // TODO Auto-generated destructor stub -} - -bool DigitalBeam::addSubband(quint16 subband) { - if (std::find(itsSubbandList.begin(), itsSubbandList.end(), subband) == itsSubbandList.end()) { - itsSubbandList.push_back(subband); - return true; - } - else return false; -} - -QDataStream& operator<< (QDataStream &out, const DigitalBeam &digiBeam) { - if (out.status() == QDataStream::Ok) { - out << digiBeam.itsTarget - << digiBeam.itsAngle1 - << digiBeam.itsAngle2 - << (quint8) digiBeam.itsDirectionType - << (quint8) digiBeam.itsUnits - << digiBeam.itsDuration - << digiBeam.itsStartTime - << digiBeam.itsNrTabRings - << digiBeam.itsTabRingSize; - - // subbandList - const std::vector<unsigned> &subbandList(digiBeam.subbandList()); - out << (quint32) subbandList.size(); - for (std::vector<unsigned>::const_iterator vit = subbandList.begin(); vit != subbandList.end(); ++vit) { - out << (quint16) *vit; - } - - // tied array beams - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(digiBeam.tiedArrayBeams()); - out << (quint32) tiedArrayBeams.size(); - for (std::map<unsigned, TiedArrayBeam>::const_iterator vit = tiedArrayBeams.begin(); vit != tiedArrayBeams.end(); ++vit) { - out << vit->first << vit->second; - } - } - - return out; -} - -QDataStream& operator>> (QDataStream &in, DigitalBeam &digiBeam) { - quint16 subband; - quint8 beamDirType, units; - - in >> digiBeam.itsTarget - >> digiBeam.itsAngle1 >> digiBeam.itsAngle2 - >> beamDirType; - digiBeam.itsDirectionType = (beamDirectionType) beamDirType; - in >> units; - digiBeam.itsUnits = (anglePairs) units; - in >> digiBeam.itsDuration >> digiBeam.itsStartTime - >> digiBeam.itsNrTabRings >> digiBeam.itsTabRingSize; - - // digital beam subband list - digiBeam.itsSubbandList.clear(); - quint32 nrOfObjects; - in >> nrOfObjects; // number of subbands - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> subband; // subband number - digiBeam.itsSubbandList.push_back(subband); - } - - // tied array beams - digiBeam.itsTiedArrayBeams.clear(); - unsigned beamNr; - TiedArrayBeam tiedArrayBeam; - in >> nrOfObjects; - for (quint32 i = 0; i < nrOfObjects; ++i) { - tiedArrayBeam.clear(); - in >> beamNr >> tiedArrayBeam; - digiBeam.itsTiedArrayBeams[beamNr] = tiedArrayBeam; - } - - return in; -} - -bool DigitalBeam::operator!=(const DigitalBeam & right) const { - return ((itsTarget != right.target()) || - (itsAngle1 != right.angle1()) || - (itsAngle2 != right.angle2()) || - (itsDirectionType != right.directionType()) || - (itsNrTabRings != right.nrTABrings()) || - (fabs(itsTabRingSize - right.tabRingSize()) > std::numeric_limits<double>::epsilon()) || - (itsDuration != right.duration()) || - (itsStartTime != right.startTime()) || - (itsSubbandList != right.subbandList()) || - (itsTiedArrayBeams != right.tiedArrayBeams())); -} - -bool DigitalBeam::setSubbandList(const QString &subbands) { - bool error(false); - itsSubbandList = StringList2VectorOfUint(subbands, error); - return !error; -} - -unsigned DigitalBeam::nrIncoherentTABs(void) const { - unsigned nrIncoherent(0); - for (std::map<unsigned, TiedArrayBeam>::const_iterator it = itsTiedArrayBeams.begin(); it != itsTiedArrayBeams.end(); ++it) { - if (!it->second.isCoherent()) ++nrIncoherent; - } - return nrIncoherent; -} - -unsigned DigitalBeam::nrCoherentTABs(void) const { - unsigned nrCoherent(0); - for (std::map<unsigned, TiedArrayBeam>::const_iterator it = itsTiedArrayBeams.begin(); it != itsTiedArrayBeams.end(); ++it) { - if (it->second.isCoherent()) ++nrCoherent; - } - return nrCoherent; -} - -void DigitalBeam::clear(void) { - itsSubbandNotationChange = false; - itsTarget=""; - itsAngle1.clear(); - itsAngle2.clear(); - itsDirectionType = DIR_TYPE_J2000; - itsUnits = ANGLE_PAIRS_HMS_DMS; - itsDuration.clearTime(); - itsStartTime.clearTime(); - itsSubbandList.clear(); - itsTiedArrayBeams.clear(); -} diff --git a/SAS/Scheduler/src/DigitalBeam.h b/SAS/Scheduler/src/DigitalBeam.h deleted file mode 100644 index 6494a1916f3df3abf32d1e047d00b63406eba97f..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/DigitalBeam.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * DigitalBeam.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Dec 6, 2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/DigitalBeam.h $ - * - */ - -#ifndef DIGITALBEAM_H_ -#define DIGITALBEAM_H_ - -#include "lofar_scheduler.h" -#include "lofar_utils.h" -#include "Angle.h" -#include "astrotime.h" -#include "TiedArrayBeam.h" -#include <string> -#include <vector> - -enum beamDirectionType { - _BEGIN_DIRECTION_TYPES, - DIR_TYPE_J2000 = _BEGIN_DIRECTION_TYPES, // Right ascension & declination - DIR_TYPE_B1950, - DIR_TYPE_ITRF, - DIR_TYPE_HADEC,// hour angle + declination - DIR_TYPE_AZELGEO, // Azimuth & Elevation - DIR_TYPE_TOPO, - DIR_TYPE_ICRS, - DIR_TYPE_APP, - DIR_TYPE_GALACTIC, - DIR_TYPE_ECLIPTIC, - DIR_TYPE_COMET, - DIR_TYPE_MERCURY, - DIR_TYPE_VENUS, - DIR_TYPE_MARS, - DIR_TYPE_JUPITER, - DIR_TYPE_SATURN, - DIR_TYPE_URANUS, - DIR_TYPE_NEPTUNE, - DIR_TYPE_PLUTO, - DIR_TYPE_SUN, - DIR_TYPE_MOON, - DIR_TYPE_UNDEFINED, - _END_DIRECTION_TYPES -}; - -extern const char * BEAM_DIRECTION_TYPES[_END_DIRECTION_TYPES]; - -extern beamDirectionType stringToBeamDirectionType(const std::string &str); - -class DigitalBeam { -public: - DigitalBeam() : - itsDirectionType(DIR_TYPE_J2000), itsUnits(ANGLE_PAIRS_HMS_DMS), itsTabRingSize(0), itsNrTabRings(0), itsSubbandNotationChange(false) { } - friend QDataStream& operator<< (QDataStream &out, const DigitalBeam &digiBeam); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, DigitalBeam &digiBeam); // used for reading data from binary file - - bool operator!=(const DigitalBeam & right) const; - bool operator==(const DigitalBeam & right) const {return (!(*this != right));} - - const std::string &target(void) const {return itsTarget;} - const Angle &angle1(void) const {return itsAngle1;} - const Angle &angle2(void) const {return itsAngle2;} - beamDirectionType directionType(void) const {return itsDirectionType;} - anglePairs units(void) const {return itsUnits;} - const AstroTime &duration(void) const {return itsDuration;} - const AstroTime &startTime(void) const {return itsStartTime;} - const std::vector<unsigned> &subbandList(void) const {return itsSubbandList;} - QString subbandsStr(void) const {return Vector2StringList(itsSubbandList);} - unsigned nrSubbands(void) const {return itsSubbandList.size();} - unsigned nrManualTABs(void) const {return itsTiedArrayBeams.size();} - unsigned nrIncoherentTABs(void) const; - unsigned nrCoherentTABs(void) const; - unsigned nrTABrings(void) const {return itsNrTabRings;} - unsigned nrRingTABs(void) const {return (3 * itsNrTabRings * (itsNrTabRings + 1) + 1);} - const double &tabRingSize(void) const {return itsTabRingSize;} - int nrTabRings(void) const {return itsNrTabRings;} - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(void) const {return itsTiedArrayBeams;} - std::map<unsigned, TiedArrayBeam> &getTiedArrayBeamsForChange(void) {return itsTiedArrayBeams;} - bool subbandNotationChange(void) const {return itsSubbandNotationChange; } - - void setTarget(const std::string &target) {itsTarget = target;} - void setAngle1(const Angle &angle) {itsAngle1 = angle;} - void setAngle1Radian(const double &rad) {itsAngle1.setRadianAngle(rad);} - void setAngle1HMS(const std::string &hms) {itsAngle1.setHMSangleStr(hms);} - void setAngle1DMS(const std::string &dms) {itsAngle1.setDMSangleStr(dms);} - void setAngle1Degree(const double °rees) {itsAngle1.setDegreeAngle(degrees);} - void setAngle2(const Angle &angle) {itsAngle2 = angle;} - void setAngle2Radian(const double &rad) {itsAngle2.setRadianAngle(rad);} - void setAngle2HMS(const std::string &hms) {itsAngle2.setHMSangleStr(hms);} - void setAngle2DMS(const std::string &dms) {itsAngle2.setDMSangleStr(dms);} - void setAngle2Degree(const double °rees) {itsAngle2.setDegreeAngle(degrees);} - void setDirectionType(beamDirectionType directionType) {itsDirectionType = directionType;} - void setUnits(anglePairs units) {itsUnits = units;} - void clearDuration(void) {itsDuration.clearTime();} - void setDuration(const AstroTime &duration) {itsDuration = duration;} - void setDuration(unsigned seconds) {itsDuration = itsDuration.addSeconds(seconds);} - void setTimeStr(const QString &timeStr) {itsDuration.setTimeStr(timeStr);} - void zeroStartTime(void) {itsStartTime.clearTime();} - void setStartTime(const AstroTime &startTime) {itsStartTime = startTime;} - void setStartTime(unsigned seconds) {itsStartTime = itsStartTime.addSeconds(seconds);} - void setSubbandList(const std::vector<unsigned> &subbandList) {itsSubbandList = subbandList;} - bool setSubbandList(const QString &subbands); - void clearSubbandList(void) {itsSubbandList.clear();} - bool addSubband(quint16 subband); - void setTiedArrayBeams(const std::map<unsigned, TiedArrayBeam> &tbeams) {itsTiedArrayBeams = tbeams;} - bool addTiedArrayBeam(unsigned beamNr, const TiedArrayBeam &tiedArrayBeam) { - return itsTiedArrayBeams.insert(std::map<unsigned, TiedArrayBeam>::value_type(beamNr, tiedArrayBeam)).second; - } - void setTabRingSize(const double &tabRingSize) {itsTabRingSize = tabRingSize;} - void setNrTabRings(int nrTabRings) {itsNrTabRings = nrTabRings;} - void clear(void); - void setSubbandNotationChange(bool change) {itsSubbandNotationChange = change;} - - virtual ~DigitalBeam(); - -private: - std::string itsTarget; - Angle itsAngle1, itsAngle2; - beamDirectionType itsDirectionType; - anglePairs itsUnits; - AstroTime itsDuration, itsStartTime; - double itsTabRingSize; // itsTabRingSize and itsNrTabRings fold out in COHERENT TABs - unsigned itsNrTabRings; - std::vector<unsigned> itsSubbandList; - bool itsSubbandNotationChange; // to keep track if changes were made to the subband list string (e.g. sequence change) - std::map<unsigned, TiedArrayBeam> itsTiedArrayBeams; -}; - -#endif /* DIGITALBEAM_H_ */ diff --git a/SAS/Scheduler/src/FileUtils.cpp b/SAS/Scheduler/src/FileUtils.cpp deleted file mode 100644 index 5bd12cdc5e719ebe5ad7a88650ee1ea7d8ce9377..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/FileUtils.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * FileUtils.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 19 Apr 2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/FileUtils.cpp $ - * - */ - -#include <QDir> -#include <QFile> -#include <QFileInfo> -#include <QFileInfoList> - -#include "FileUtils.h" - -FileUtils::FileUtils() { - // TODO Auto-generated constructor stub - -} - -FileUtils::~FileUtils() { - // TODO Auto-generated destructor stub -} - -/*! - Delete a directory along with all of its contents. - - \param dirName Path of directory to remove. - \return true on success; false on error. -*/ - -bool FileUtils::removeDir(const QString &dirName) -{ - bool result = true; - QDir dir(dirName); - - if (dir.exists(dirName)) { - Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { - if (info.isDir()) { - result = removeDir(info.absoluteFilePath()); - } - else { - result = QFile::remove(info.absoluteFilePath()); - } - - if (!result) { - return result; - } - } - result = dir.rmdir(dirName); - } - - return result; -} diff --git a/SAS/Scheduler/src/FileUtils.h b/SAS/Scheduler/src/FileUtils.h deleted file mode 100644 index a821335059c3a8c2038e7a8a92cf5d551dfafa45..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/FileUtils.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * FileUtils.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 19 Apr 2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/FileUtils.h $ - * - */ - -#ifndef FILEUTILS_H_ -#define FILEUTILS_H_ - -#include <QString> - -class FileUtils { -public: - FileUtils(); - virtual ~FileUtils(); - - bool removeDir(const QString &dirName); -}; - -#endif /* FILEUTILS_H_ */ diff --git a/SAS/Scheduler/src/GraphicCurrentTimeLine.cpp b/SAS/Scheduler/src/GraphicCurrentTimeLine.cpp deleted file mode 100644 index a39f98fe115b87167a36e94267b7a7e43f69ad8f..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicCurrentTimeLine.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * GraphicCurrentTimeLine.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 15-apr-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicCurrentTimeLine.cpp $ - * - */ - -#include "GraphicCurrentTimeLine.h" -#include "GraphicResourceScene.h" -#include "lofar_scheduler.h" -#include "astrodatetime.h" -#include <QPainter> -#include "Controller.h" - -GraphicCurrentTimeLine::GraphicCurrentTimeLine(GraphicResourceScene *scene, int height) -: itsScene(scene), itsHeight(height), itsLinePen(Qt::red ,2 , Qt::DashLine), isInSchedule(false), isHidden(false) { -// updateTime(); - setZValue(4); // time line is on top of everything, tasks are at z level 1, background at 0 - itsTimeBackgroundBrush = QBrush(Qt::white, Qt::SolidPattern); - setY(20); -} - -GraphicCurrentTimeLine::~GraphicCurrentTimeLine() { - // TODO Auto-generated destructor stub -} - -void GraphicCurrentTimeLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - if (isInSchedule & (!isHidden)) { - painter->setPen(itsLinePen); - painter->drawLine(0,0,0,itsHeight); - QString UTtimeStr(itsCurrentTime.toString("hh:mm:ss") + " UT"); - painter->setBrush(itsTimeBackgroundBrush); - painter->setPen(Qt::blue); - painter->setBrush(QColor(255, 255, 255, 185)); - painter->setFont(QFont("Helvetica",9,QFont::Normal)); - // upper time display - painter->drawRect(4,6,78,23); - painter->drawText(7,18,UTtimeStr); - painter->drawText(7,28,QString(itsLST.toString(1).c_str()) + " LST"); - // lower time display -// painter->drawRect(4,itsHeight-1,52,12); -// painter->drawText(7,itsHeight + 10,timeStr); - // for test purpose: draw boundings -// QPen pen(Qt::cyan, 1); -// painter->setBrush(Qt::NoBrush); -// painter->setPen(pen); -// painter->drawRect(itsBoundings); - } -} - -void GraphicCurrentTimeLine::updateTime(const QDateTime &UTC) { - itsCurrentTime = UTC; - int JD = itsCurrentTime.date().toJulianDay() - J2000_EPOCH; - if ((JD >= Controller::theSchedulerSettings.getEarliestSchedulingDay().toJulian()) & (JD <= Controller::theSchedulerSettings.getLatestSchedulingDay().toJulian())) { - isInSchedule = true; - itsLST = AstroDateTime(itsCurrentTime).toLST(); - setPos(itsScene->time2xPos(AstroDateTime(itsCurrentTime.date().day(), itsCurrentTime.date().month(), itsCurrentTime.date().year(), - itsCurrentTime.time().hour(), itsCurrentTime.time().minute(), itsCurrentTime.time().second()) ), pos().y() ); - itsBoundings = QRectF(-1, -1, 85, itsHeight + 14); - update(itsBoundings); - } - else isInSchedule = false; -} - -AstroDateTime GraphicCurrentTimeLine::currentDateTime(void) const { - AstroDateTime now(itsCurrentTime.date().day(), itsCurrentTime.date().month(), itsCurrentTime.date().year(), - itsCurrentTime.time().hour(), itsCurrentTime.time().minute(), itsCurrentTime.time().second()); - return now; -} diff --git a/SAS/Scheduler/src/GraphicCurrentTimeLine.h b/SAS/Scheduler/src/GraphicCurrentTimeLine.h deleted file mode 100644 index 70ab1e26f60d8761f94b196a2087216ac41a9f96..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicCurrentTimeLine.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * GraphicCurrentTimeLine.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 15-apr-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicCurrentTimeLine.h $ - * - */ - -#ifndef GRAPHICCURRENTTIMELINE_H_ -#define GRAPHICCURRENTTIMELINE_H_ - -#include <QGraphicsItem> -#include <QDateTime> -#include <QPen> -#include <QBrush> -#include "astrodatetime.h" -class GraphicResourceScene; - - -class GraphicCurrentTimeLine : public QGraphicsItem { -public: - GraphicCurrentTimeLine(GraphicResourceScene *scene, int height); - virtual ~GraphicCurrentTimeLine(); - - QRectF boundingRect() const {return itsBoundings;} - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - inline void updateHeight(int height) {itsHeight = height;} - void updateTime(const QDateTime &UTC); - void redrawTime(void) {updateTime(itsCurrentTime);} - bool isWithinSchedule(void) {return isInSchedule;} - AstroDateTime currentDateTime(void) const; - void show(void) {isHidden = false;} - void hide(void) {isHidden = true;} - -private: - GraphicResourceScene *itsScene; - QRectF itsBoundings; - QDateTime itsCurrentTime; - AstroTime itsLST; - int itsHeight; - QPen itsLinePen; - QBrush itsTimeBackgroundBrush; - bool isInSchedule, isHidden; -}; - -#endif /* GRAPHICCURRENTTIMELINE_H_ */ diff --git a/SAS/Scheduler/src/GraphicResourceScene.cpp b/SAS/Scheduler/src/GraphicResourceScene.cpp deleted file mode 100644 index 1757c9e8644ff03f9f2076bffa37df0d7a5ec189..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicResourceScene.cpp +++ /dev/null @@ -1,720 +0,0 @@ -/* - * GraphicResourceScene.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 14, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicResourceScene.cpp $ - * - */ - -#include <algorithm> -#include <QPaintEngine> -#include <QGraphicsSceneMouseEvent> -#include <QGraphicsView> -#include <QScrollBar> -#include <QMessageBox> -#include <QTimer> -#include "GraphicResourceScene.h" -#include "GraphicStationTaskLine.h" -#include "GraphicTask.h" -#include "Controller.h" -#include "station.h" - -GraphicResourceScene::GraphicResourceScene(Controller *controller) - : itsParentView(0), itsController(controller), itsZoomLevel(ZM_DAY), - itsTimeLineZeroPos(70), itsTaskColorMode(Task::TASK_STATUS_COLOR_MODE), lastXPosition(0) -{ - setNewTimeSpan(); - itsTimeLine = new GraphicTimeLine(this); - this->addItem(itsTimeLine); - itsCurrentTimeLine = new GraphicCurrentTimeLine(this, 200); - this->addItem(itsCurrentTimeLine); - setSceneRect(0, 0, itsTimeLine->getWidth() + 150, 200); - connect(this, SIGNAL(selectionChanged()), this, SLOT(handleRubberBandSelection())); -} - -GraphicResourceScene::~GraphicResourceScene() { - delete itsTimeLine; - for (stationTimeLineMap::iterator it = itsStationTimeLines.begin(); it != itsStationTimeLines.end(); ++it) { - delete it->second.second; - } - for (std::map<unsigned, std::pair<QGraphicsSimpleTextItem *, QGraphicsRectItem *> >::iterator nit = itsStationNameLabels.begin(); nit != itsStationNameLabels.end(); ++ nit) { - delete nit->second.first; - delete nit->second.second; - } - delete itsCurrentTimeLine; -} - -int GraphicResourceScene::time2xPos(const AstroDateTime &date) const { - double difDays = date.toJulian() - itsStartDay.toJulian(); - if (itsZoomLevel == ZM_MONTH) { - return static_cast<int>(difDays * 5) + itsTimeLineZeroPos; // week = 35 pixels, day = 5 pixels - } - else if (itsZoomLevel == ZM_WEEK) { - return static_cast<int>(difDays * 48) + itsTimeLineZeroPos; // day = 48 pixels, hour = 2 pixels - } - else if (itsZoomLevel == ZM_DAY) { - return static_cast<int>(difDays * 120) + itsTimeLineZeroPos; // day = 120 pixels, hour = 5 pixels - } - else if (itsZoomLevel == ZM_HOUR) { - return static_cast<int>(difDays * 480) + itsTimeLineZeroPos; // day = 480 pixels, hour = 20 pixels - } - else if (itsZoomLevel == ZM_MIN) { - return static_cast<int>(difDays * 1440) + itsTimeLineZeroPos; // day = 1440 pixels, hour = 60 pixels - } - return 0; -} - - -AstroDateTime GraphicResourceScene::xPos2Time(int xpos) { - int pos = xpos - itsTimeLineZeroPos; - AstroDateTime time(itsStartDay); - switch (itsZoomLevel) { - case ZM_MONTH: // week = 35 pixels, day = 5 pixels - if (pos >= 5) { - time = time.addDays(pos / 5); - } - else if (pos <= -5) { - time = time.subtractDays(pos / 5); - } - break; - case ZM_WEEK: // day = 48 pixels, hour = 2 pixels - if (pos >= 2) { - time = time.addHours(pos / 2); - } - else if (pos <= -2) { - time = time.subtractHours(-pos / 2); - } - break; - case ZM_DAY: // day = 120 pixels, hour = 5 pixels - if (pos >= 5) { - time = time.addHours(pos / 5); - } - else if (pos <= -5) { - time = time.subtractHours(-pos / 5); - } - break; - case ZM_HOUR: // day = 480 pixels, hour = 20 pixels, 15 minutes = 5 pixels - if (pos >= 5) { - time = time.addMinutes(15 * pos / 5); - } - else if (pos <= -5) { - time = time.subtractMinutes(-15 * pos / 5); - } - break; - case ZM_MIN: // day = 1440 pixels, hour = 60 pixels, 1 minute = 1 pixel - if (pos >= 1) { - time = time.addMinutes(pos); - } - else if (pos <= -1) { - time = time.subtractMinutes(-pos); - } - break; - } - return time; -} - -void GraphicResourceScene::applyNewScheduleTimeSpan(bool centerOnSelectedTask) { - setNewTimeSpan(); - itsTimeLine->updateWidth(); - for (stationTimeLineMap::iterator it = itsStationTimeLines.begin(); it != itsStationTimeLines.end(); ++it) { - it->second.second->updateWidth(); - } - for (tasksMap::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - (*git)->updatePosition(); - } - } - - setSceneRect(0, 0, itsTimeLine->getWidth() + 150.0, itsStationTimeLines.size() * 20 + 60); - itsCurrentTimeLine->updateHeight(itsStationTimeLines.size() * 20 + 15); - itsCurrentTimeLine->redrawTime(); - - if (centerOnSelectedTask) { - if (!itsController->selectedTasks().empty()) { - tasksMap::iterator tit = itsTasks.find(itsController->lastSelectedTask()); - if (tit != itsTasks.end()) { - itsParentView->centerOn(tit->second.front()); - //tit->second.front()->ensureVisible(); - } - } - } - - update(); -} - -void GraphicResourceScene::setNewTimeSpan(void) { - itsStartDay = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - itsEndDay = Controller::theSchedulerSettings.getLatestSchedulingDay(); - - if (itsZoomLevel == ZM_MONTH) { - // set end date to the first day of the next week - unsigned week = itsEndDay.getWeek(); - while (week == itsEndDay.getWeek()) {itsEndDay = itsEndDay.addDays(1);} - // set currentDate to the first day of the current week - week = itsStartDay.getWeek(); - while (week == itsStartDay.getWeek()) {itsStartDay = itsStartDay.subtractDays(1);} - itsStartDay = itsStartDay.addDays(1); - } - else if (itsZoomLevel == ZM_WEEK) { - } - else if (itsZoomLevel == ZM_DAY) { - } - else if (itsZoomLevel == ZM_HOUR) { - } - else if (itsZoomLevel == ZM_MIN) { - } - -} - -void GraphicResourceScene::scrollToNow(void) { - itsParentView->centerOn(itsCurrentTimeLine); - itsParentView->verticalScrollBar()->setValue(0); -} - -void GraphicResourceScene::ensureTaskIsVisible(unsigned int taskID) { - tasksMap::const_iterator it = itsTasks.find(taskID); - if (it != itsTasks.end()) { - if (!(it->second.empty())) { - it->second.front()->ensureVisible(); - } - } -} - -int GraphicResourceScene::getHorizontalScrollPos(void) { - return itsParentView->horizontalScrollBar()->value(); -} - -void GraphicResourceScene::updateTimeLineYPos(void) { - int moveY(itsParentView->verticalScrollBar()->value() - static_cast<int>(itsTimeLine->y())); - itsTimeLine->moveBy(0,moveY); - itsCurrentTimeLine->moveBy(0,moveY); - QCoreApplication::processEvents(); -} - -void GraphicResourceScene::updateStationNamesXPos(void) { - int labelXpos(getHorizontalScrollPos()); - for (stationTimeLineMap::iterator it = itsStationTimeLines.begin(); it != itsStationTimeLines.end(); ++it) { - it->second.second->update(); - itsStationNameLabels[it->first].first->setX(labelXpos+30); // text - itsStationNameLabels[it->first].second->setX(labelXpos); // rectangle around text - } - QCoreApplication::processEvents(); -} - -void GraphicResourceScene::updateStationTimeLines() { - const stationNameIDMapping &stations = Controller::theSchedulerSettings.getStations(); - for (stationTimeLineMap::iterator it = itsStationTimeLines.begin(); it != itsStationTimeLines.end(); ++it) { - // CAUTION!: ALSO REMOVES THE CHILD GRAPHICS TASK OBJECTS WHILE THESE ARE NOT REMOVED FROM itsTasks tasksMap - delete it->second.second; - } - itsStationTimeLines.clear(); - for (std::map<unsigned, std::pair<QGraphicsSimpleTextItem *, QGraphicsRectItem *> >::iterator nit = itsStationNameLabels.begin(); nit != itsStationNameLabels.end(); ++ nit) { - delete nit->second.first; - delete nit->second.second; - } - itsStationNameLabels.clear(); - int StationLineYPos, labelXpos(itsTimeLineZeroPos - 40); - for (stationNameIDMapping::const_iterator it = stations.begin(); it != stations.end(); ++ it) { - // create station time line - StationLineYPos = itsStationTimeLines.size() * 20 + 40; - GraphicStationTaskLine *stationTimeLine = new GraphicStationTaskLine(this, it->second, StationLineYPos); - addItem(stationTimeLine); - // create station label - QGraphicsSimpleTextItem *stationName = new QGraphicsSimpleTextItem(it->first.c_str(), NULL); - this->addItem(stationName); - stationName->setPos(labelXpos, StationLineYPos-2); - stationName->setFont(QFont("Liberation Sans", 9, QFont::Bold)); - stationName->setZValue(10); - const QPointF &sp(stationName->pos()); - QRectF r(sp.x()-2, sp.y()-2, 9*(it->first.length()-1)+4, 13); - QGraphicsRectItem * rect = new QGraphicsRectItem(r, NULL); - this->addItem(rect); - rect->setZValue(9); - rect->setPen(QPen(Qt::NoPen)); - rect->setBrush(QColor(255,255,255,160)); - itsStationNameLabels[it->second] = std::pair<QGraphicsSimpleTextItem *, QGraphicsRectItem *>(stationName, rect); - itsStationTimeLines[it->second] = std::pair<int, GraphicStationTaskLine *>(StationLineYPos, stationTimeLine); - } - setSceneRect(0, 0, itsTimeLine->getWidth() + 150.0, itsStationTimeLines.size() * 20 + 60); - itsCurrentTimeLine->updateHeight(itsStationTimeLines.size() * 20 + 15); - itsCurrentTimeLine->redrawTime(); - updateStationNamesXPos(); -} - -const std::vector<GraphicTask *> GraphicResourceScene::findTask(unsigned taskID) const { - tasksMap::const_iterator it = itsTasks.find(taskID); - if (it != itsTasks.end()) { - return it->second; - } - else { - std::vector<GraphicTask *> graphic_tasks; - return graphic_tasks; - } -} - - -void GraphicResourceScene::clearTasks(void) { - this->blockSignals(true); - for (tasksMap::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - removeItem(*git); - delete *git; - *git = 0; - } - it->second.clear(); - } - itsTasks.clear(); - this->blockSignals(false); -} - -GraphicTask *GraphicResourceScene::findGraphicTaskByStation(unsigned task_id, unsigned station_id) const { - tasksMap::const_iterator it = itsTasks.find(task_id); - if (it != itsTasks.end()) { - for (std::vector<GraphicTask *>::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { - if ((*sit)->stationID() == station_id) { - return *sit; - } - } - return 0; - } - else { - return 0; - } -} - -void GraphicResourceScene::addTask(const Task *task) { - const StationTask *pTask = dynamic_cast<const StationTask *>(task); - if (pTask) { - Task::task_status status = pTask->getStatus(); - if ((status >= Task::PRESCHEDULED) && (pTask->getScheduledStart().isSet())) { // only insert in graphic view if task status is above or equal to scheduled state - const std::map<std::string, unsigned> &stations = pTask->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - stationTimeLineMap::iterator ssit = itsStationTimeLines.find(sit->second); - if (ssit != itsStationTimeLines.end()) { - if (status >= Task::FINISHED) { - addGraphicTask(ssit->second.second, pTask->getID(), sit->second, itsTaskColorMode); - } - else { - addGraphicTask(ssit->second.second, pTask->getID(), sit->second, itsTaskColorMode); - } - } - } - } - } - else { - debugWarn("si","GraphicResourceScene::addTask: not a StationTask or task not found, ID:", pTask->getID()); - } -} - -void GraphicResourceScene::addGraphicTask(GraphicStationTaskLine *stationLine, unsigned task_id, unsigned station_id, Task::task_color_mode color_mode/*, bool inactive*/) { - GraphicTask *graphicTask = new GraphicTask(stationLine, this, task_id, station_id, color_mode/*, inactive*/); // implicitly adds the item to the scene - itsTasks[task_id].push_back(graphicTask); -} - -void GraphicResourceScene::removeTaskFromScene(unsigned task_id) { - tasksMap::iterator it = itsTasks.find(task_id); - blockSignals(true); // we have to block signals from the scene otherwise it will send signals (rubberbandselection changed) and cause SIGTRAPS - if (it != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - removeItem(*git); - delete *git; // deletes the graphicTask objects and implicitly removes them from the scene - } - it->second.clear(); - } - itsTasks.erase(task_id); - blockSignals(false); -} - -void GraphicResourceScene::updateTask(const Task *task) { - const StationTask *pTask = dynamic_cast<const StationTask *>(task); - if (pTask) { - unsigned task_id(pTask->getID()); - if (pTask->getStatus() >= Task::PRESCHEDULED && pTask->getScheduledStart().isSet()) { // it the task is still in the schedule (i.e. if it should be displayed) - const std::map<std::string, unsigned> &stations = pTask->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - stationTimeLineMap::iterator ssit = itsStationTimeLines.find(sit->second); - if (ssit != itsStationTimeLines.end()) { - //search for an existing graphictask with this station id - GraphicTask *graphicTask = findGraphicTaskByStation(task_id, sit->second); - this->blockSignals(true); - if (!graphicTask) { // this station was added to the task or this task has just been added - addGraphicTask(ssit->second.second, task_id, sit->second, itsTaskColorMode); - } - else { - graphicTask->updateTask(); - } - this->blockSignals(false); - } - } - //remove graphictasks from removed stations for this task - tasksMap::iterator it = itsTasks.find(task_id); - if (it != itsTasks.end()) { - bool changed(false); - std::vector<GraphicTask *> newVec; - this->blockSignals(true); - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - if (stations.find(Controller::theSchedulerSettings.getStationName((*git)->stationID())) == stations.end()) { - removeItem(*git); - delete *git; // implicitly removes the item from the scene - } - else { - newVec.push_back(*git); - changed = true; - } - } - this->blockSignals(false); - if (changed) it->second = newVec; - } - } - else { // task is not ACTIVE anymore, remove the graphictask objects from the scene - removeTaskFromScene(task_id); - } - this->update(); - } -} - -void GraphicResourceScene::updateTasks(const scheduledTasksMap &scheduledTasks, const reservationsMap &reservations, const inActiveTasksMap & inactiveTasks) { - unsigned taskID; - clearTasks(); - - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - taskID = it->second->getID(); - const std::map<std::string, unsigned> &stations = it->second->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - stationTimeLineMap::iterator ssit = itsStationTimeLines.find(sit->second); - if (ssit != itsStationTimeLines.end()) { - addGraphicTask(ssit->second.second, taskID, sit->second, itsTaskColorMode); - } - } - } - for (reservationsMap::const_iterator it = reservations.begin(); it != reservations.end(); ++it) { - if (it->second->getStatus() == Task::PRESCHEDULED || it->second->getStatus() == Task::SCHEDULED) { - taskID = it->second->getID(); - const std::map<std::string, unsigned> &stations = it->second->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - stationTimeLineMap::iterator ssit = itsStationTimeLines.find(sit->second); - if (ssit != itsStationTimeLines.end()) { - addGraphicTask(ssit->second.second, taskID, sit->second, itsTaskColorMode); - } - } - } - } - for (inActiveTasksMap::const_iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++it) { - taskID = it->second->getID(); - if (it->second->isStationTask()) { - const StationTask *pTask(static_cast<const StationTask *>(it->second)); - if (pTask->getScheduledStart().isSet()) { - const std::map<std::string, unsigned> &stations = pTask->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - stationTimeLineMap::iterator ssit = itsStationTimeLines.find(sit->second); - if (ssit != itsStationTimeLines.end()) { - addGraphicTask(ssit->second.second, taskID, sit->second, itsTaskColorMode); - } - } - } - } - } - - // see if the previously selected task is still displayed (is still scheduled) and select it again - if (!itsController->selectedTasks().empty()) { - tasksMap::iterator it; - const std::vector<unsigned> &selectedTasks = itsController->selectedTasks(); - for (std::vector<unsigned>::const_iterator vit = selectedTasks.begin(); vit != selectedTasks.end(); ++vit) { - if ((it = itsTasks.find(*vit)) != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - (*git)->setSelected(true); - } - } - } - if (Controller::theSchedulerSettings.getFocusTaskAtClick()) { - emit clickedGraphicTask(itsController->lastSelectedTask()); - } - } -} - -void GraphicResourceScene::selectGraphicTask(unsigned taskID, bool centerOnTask) { - tasksMap::iterator tit = itsTasks.find(taskID); - if (tit != itsTasks.end()) { - if (!tit->second.empty()) { - for (std::vector<GraphicTask *>::iterator git = tit->second.begin(); git != tit->second.end(); ++git) { - (*git)->setSelected(true); - (*git)->update(); - } - // set highlight on possible predecessors - /* - const IDvector &predecessors = tit->second.front()->getPredecessors(); - if (!predecessors.emtpy()) { - for (IDvector::const_iterator pit = predecessors.begin(); pit != predecessors.end(); ++pit) { - - if ((tit = itsTasks.find(predecessor)) != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator it = tit->second.begin(); it != tit->second.end(); ++it) { - (*it)->setPredecessorHighLight(true); - (*it)->update(); - } - } - } - } - */ - } - } - if (centerOnTask) { - tit = itsTasks.find(taskID); - if (tit != itsTasks.end()) { - tit->second.front()->ensureVisible(); - } - } -} - -void GraphicResourceScene::handleRubberBandSelection(void) { // called when user drags a rubberband over graphicTasks - if (QApplication::keyboardModifiers() != Qt::ControlModifier) { // control key was held down while changing selection - itsController->deselectAllTasks(); - } - // add the rubberband bounded tasks to the selection - unsigned taskID;//, predecessor; - tasksMap::iterator tit; - QList<QGraphicsItem *> selectedGraphicTasks = selectedItems(); - for (QList<QGraphicsItem *>::iterator it = selectedGraphicTasks.begin(); it != selectedGraphicTasks.end(); ++it) { - taskID = static_cast<GraphicTask *>(*it)->getTaskID(); - itsController->selectTask(taskID,false,true); - } -} - -void GraphicResourceScene::selectTask(unsigned taskID, bool singleSelection) { - itsController->selectTask(taskID, singleSelection, true); -} - -void GraphicResourceScene::deselectTask(unsigned taskID, bool singleSelection) { - itsController->deselectTask(taskID, singleSelection, true); -} - -void GraphicResourceScene::deselectGraphicTask(unsigned taskID) { - this->blockSignals(true); - tasksMap::iterator tit; - if ((tit = itsTasks.find(taskID)) != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator it = tit->second.begin(); it != tit->second.end(); ++it) { - (*it)->setSelected(false); - } - // remove highlight from possible predecessors - /* - predecessor = tit->second.front()->getPredecessor(); - if (predecessor) { - if ((tit = itsTasks.find(predecessor)) != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator it = tit->second.begin(); it != tit->second.end(); ++it) { - (*it)->setPredecessorHighLight(false); -// (*it)->update(); - } - } - } - */ - } - this->blockSignals(false); -} - -void GraphicResourceScene::deselectAllGraphicTasks(void) { - this->blockSignals(true); - for (tasksMap::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - (*git)->setSelected(false); - (*git)->setPredecessorHighLight(false); -// (*git)->update(); - } - } - this->blockSignals(false); -} - -void GraphicResourceScene::clearSelection(void) { - itsController->deselectAllTasks(); -} - -void GraphicResourceScene::moveTask(unsigned task_id, QGraphicsSceneMouseEvent *event) { - tasksMap::iterator tit; - if ((tit = itsTasks.find(task_id)) != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator it = tit->second.begin(); it != tit->second.end(); ++it) { - (*it)->moveBy(event->lastScreenPos().x() - lastXPosition, 0); - } - lastXPosition = event->lastScreenPos().x(); - } -} - -void GraphicResourceScene::moveSelectedTasks(QGraphicsSceneMouseEvent *event) { - int move(event->lastScreenPos().x() - lastXPosition); - tasksMap::iterator tit; - const std::vector<unsigned> &selectedTasks(itsController->selectedTasks()); - for (std::vector<unsigned>::const_iterator it = selectedTasks.begin(); it != selectedTasks.end(); ++it) { - if ((tit = itsTasks.find(*it)) != itsTasks.end()) { - for (std::vector<GraphicTask *>::iterator git = tit->second.begin(); git != tit->second.end(); ++git) { - (*git)->moveBy(move, 0); - } - } - } - lastXPosition = event->lastScreenPos().x(); -} - - -void GraphicResourceScene::setZoomLevel(zoom_level zoom) { - zoom_level prev_zoom = itsZoomLevel; - itsZoomLevel = zoom; - applyNewScheduleTimeSpan(true); - if (zoom != itsZoomLevel) { - if ((prev_zoom == ZM_MIN) & (zoom > ZM_MIN)) - emit setEnableZoomIn(true); - else if ((prev_zoom == ZM_MONTH) & (zoom < ZM_MONTH)) - emit setEnableZoomOut(true); - } -} - -void GraphicResourceScene::zoomIn(void) { - if (itsZoomLevel == ZM_MONTH) { - itsZoomLevel = ZM_WEEK; - applyNewScheduleTimeSpan(true); - emit setEnableZoomOut(true); - } - else if (itsZoomLevel == ZM_WEEK) { - itsZoomLevel = ZM_DAY; - applyNewScheduleTimeSpan(true); - } - else if (itsZoomLevel == ZM_DAY) { - itsZoomLevel = ZM_HOUR; - applyNewScheduleTimeSpan(true); - } - else if (itsZoomLevel == ZM_HOUR) { - itsZoomLevel = ZM_MIN; - applyNewScheduleTimeSpan(true); - emit setEnableZoomIn(false); - } -} - -void GraphicResourceScene::zoomOut(void) { - if (itsZoomLevel == ZM_MIN) { - itsZoomLevel = ZM_HOUR; - applyNewScheduleTimeSpan(true); - emit setEnableZoomIn(true); - } - else if (itsZoomLevel == ZM_HOUR) { - itsZoomLevel = ZM_DAY; - applyNewScheduleTimeSpan(true); - } - else if (itsZoomLevel == ZM_DAY) { - itsZoomLevel = ZM_WEEK; - applyNewScheduleTimeSpan(true); - } - else if (itsZoomLevel == ZM_WEEK) { - itsZoomLevel = ZM_MONTH; - applyNewScheduleTimeSpan(true); - emit setEnableZoomOut(false); - } -} - -void GraphicResourceScene::setTaskColorMode(Task::task_color_mode color_mode) { - if (itsTaskColorMode != color_mode) { - itsTaskColorMode = color_mode; - for (tasksMap::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - for (std::vector<GraphicTask *>::iterator git = it->second.begin(); git != it->second.end(); ++git) { - (*git)->setTaskColorMode(itsTaskColorMode); - } - } - } -} - -void GraphicResourceScene::openMoveTasksDialog(void) { - itsController->openMoveTasksDialog(); -} - -void GraphicResourceScene::requestTaskMove(unsigned task_id, const AstroDateTime &new_start_time) { - itsController->moveSelectedTasksRequest(task_id, new_start_time); -} - - -void GraphicResourceScene::openTaskDialog(const Task *task) { - emit showTaskDialog(task); -} -/* -void GraphicResourceScene::updateTaskDialog(const Task *task) { - emit updateTaskDialogWithTask(task); -} -*/ -/* -void GraphicResourceScene::abortTask(unsigned taskID) { - itsController->abortTask(taskID); -} -*/ -void GraphicResourceScene::unscheduleTask(unsigned taskID) { - itsController->unscheduleTask(taskID); -// update(); -} - -void GraphicResourceScene::unscheduleSelectedTasks(void) { - itsController->unscheduleSelectedTasks(); -} - - -void GraphicResourceScene::scheduleTask(unsigned taskID, Task::task_status status) { - itsController->scheduleTask(taskID, status); -} - -void GraphicResourceScene::preScheduleSelectedTasks(void) { - itsController->scheduleSelectedTasks(Task::PRESCHEDULED); -} - -void GraphicResourceScene::scheduleSelectedTasks(void) { - itsController->scheduleSelectedTasks(Task::SCHEDULED); -} - -void GraphicResourceScene::setTaskOnHold(unsigned taskID) { - itsController->setTaskOnHold(taskID); -} - -void GraphicResourceScene::setSelectedTasksOnHold(void) { - itsController->setSelectedTasksOnHold(); -} - -void GraphicResourceScene::copyTask(unsigned taskID) { - itsController->copyTask(taskID); -} - -void GraphicResourceScene::copySelectedTasks(void) { - itsController->copySelectedTasks(); -} - -void GraphicResourceScene::rescheduleTask(unsigned taskID){ - if (itsCurrentTimeLine->isWithinSchedule()) { - itsController->rescheduleAbortedTask(taskID, itsCurrentTimeLine->currentDateTime() + Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); - } - else { - QMessageBox::warning(0, tr("Cannot reschedule task"), - tr("The current time is outside of the defined scheduling range.\nAn aborted task can only be scheduled in the future.")); - QApplication::beep(); - } -} - -void GraphicResourceScene::deleteTask(unsigned taskID) { - itsController->deleteTask(taskID); -} - -void GraphicResourceScene::deleteSelectedTasks(void) { - itsController->deleteSelectedTasks(); -} - -void GraphicResourceScene::showTaskProperties(unsigned taskID) { - const Task *pTask = itsController->getScheduledTask(taskID); - if (pTask) { emit showTaskDialog(pTask); } - else { - pTask = itsController->getInactiveTask(taskID); - if (pTask) { emit showTaskDialog(pTask); } - } - -} - -void GraphicResourceScene::showSelectedTasksProperties(void) { - itsController->multiEditSelectedTasks(); -} - -void GraphicResourceScene::showTaskStateHistory(unsigned taskID) { - itsController->showTaskStateHistory(taskID); -} - diff --git a/SAS/Scheduler/src/GraphicResourceScene.h b/SAS/Scheduler/src/GraphicResourceScene.h deleted file mode 100644 index 5c153c7854ed3ca4dad972a3fd64957ad867a5a3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicResourceScene.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - * GraphicResourceScene.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 14, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicResourceScene.h $ - * - */ - -#ifndef GRAPHICRESOURCESCENE_H_ -#define GRAPHICRESOURCESCENE_H_ - -enum zoom_level { - ZM_MIN, - ZM_HOUR, - ZM_DAY, - ZM_WEEK, - ZM_MONTH -// ZM_YEAR -}; - -#include "astrodatetime.h" -#include "GraphicTimeLine.h" -#include "GraphicCurrentTimeLine.h" -#include "schedulerdatablock.h" -#include "taskdialog.h" -#include "Controller.h" -#include <map> -#include <vector> -#include <QGraphicsScene> - -class QGraphicsView; -class GraphicStationTaskLine; -class GraphicTask; -class QGraphicsSceneMouseEvent; -class QGraphicsSimpleTextItem; -class Station; -class QTimer; - -// key = stationID, second.first = StationLineYPos, second.second = graphic station time line -typedef std::map<unsigned, std::pair<int, GraphicStationTaskLine * > > stationTimeLineMap; -// key = taskID, vector contains the GraphicTask objects (one for every station time line) -typedef std::map<unsigned, std::vector<GraphicTask *> > tasksMap; - -class GraphicResourceScene : public QGraphicsScene { - - Q_OBJECT - -public: - GraphicResourceScene(Controller *controller); - virtual ~GraphicResourceScene(); - - zoom_level getZoomLevel(void) const {return itsZoomLevel;} - void setZoomLevel(zoom_level zoom);// {itsZoomLevel = zoom; update();} - - void setViewPort(QGraphicsView *view) {itsParentView = view;} - - const stationTimeLineMap &getStationTimeLines(void) const {return itsStationTimeLines;} - qreal getTimeLineWidth(void) {return itsTimeLine->getWidth();} - // convert a AstroDateTime to a position on the station time line - // where 0 corresponds to the position of the start of the station time line - int time2xPos(const AstroDateTime &date) const; - AstroDateTime xPos2Time(int xpos); - void updateTimeLineYPos(void); - void updateCurrentTime(const QDateTime &UTC) {itsCurrentTimeLine->updateTime(UTC);} - void updateStationNamesXPos(void); - int getHorizontalScrollPos(void); - - const AstroDate &getStartDay(void) {return itsStartDay;} - const AstroDate &getEndDay(void) {return itsEndDay;} - qreal getTimeLineZeroPos(void) const {return itsTimeLineZeroPos;} - - const Controller *controller(void) {return itsController;} - - void applyNewScheduleTimeSpan(bool centerOnSelectedTask = false); - void updateStationTimeLines(); - void updateTask(const Task *task); - void updateTasks(const scheduledTasksMap &scheduledTasks, const reservationsMap &reservations, const inActiveTasksMap & inactiveTasks); - void zoomIn(void); - void zoomOut(void); - void setTaskColorMode(Task::task_color_mode color_mode); - Task::task_color_mode getTaskColorMode(void) const {return itsTaskColorMode;} - void setNewTimeSpan(void); - void showCurrentTimeLine(void) { itsCurrentTimeLine->show(); } - void hideCurrentTimeLine(void) { itsCurrentTimeLine->hide(); } - void scrollToNow(void);// {itsParentView->centerOn(itsCurrentTimeLine)/*->ensureVisible(0,0,10,10)*/; } - void ensureTaskIsVisible(unsigned int taskID); - - void clearTasks(void); - const std::vector<GraphicTask *> findTask(unsigned taskID) const; - - void startMoveTask(int x_start_pos) {lastXPosition = x_start_pos;} - void moveTask(unsigned task_id, QGraphicsSceneMouseEvent *event); - void moveSelectedTasks(QGraphicsSceneMouseEvent *event); - void requestTaskMove(unsigned task_id, const AstroDateTime &new_start_time); - void openTaskDialog(const Task *task); - void addTask(const Task *); // add a task to the scene - void removeTaskFromScene(unsigned task_id); // delete a task from the scene - const Task *getTask(unsigned task_id) const {return itsController->getTask(task_id);} - const Task *getScheduledTask(unsigned task_id) const {return itsController->getScheduledTask(task_id);} - const Task *getUnscheduledTask(unsigned task_id) const {return itsController->getUnscheduledTask(task_id);} - const Task *getInactiveTask(unsigned task_id) const {return itsController->getInactiveTask(task_id);} - const tasksMap &getGraphicTasks(void) const { return itsTasks; } - - // used by graphicTask context menu - void unscheduleTask(unsigned taskID); - void unscheduleSelectedTasks(void); - void scheduleTask(unsigned taskID, Task::task_status status); - void preScheduleSelectedTasks(void); - void scheduleSelectedTasks(void); - void setTaskOnHold(unsigned taskID); - void setSelectedTasksOnHold(void); - void copyTask(unsigned taskID); - void copySelectedTasks(void); - void rescheduleTask(unsigned taskID); - void deleteTask(unsigned taskID); - void deleteSelectedTasks(void); - void showTaskProperties(unsigned taskID); - void showSelectedTasksProperties(void); - void showTaskStateHistory(unsigned taskID); - void clearSelection(void); - void selectTask(unsigned taskID, bool singleSelection); - void deselectTask(unsigned taskID, bool singleSelection); - void openMoveTasksDialog(void); - -private: - GraphicTask *findGraphicTaskByStation(unsigned task_id, unsigned station_id) const; - void addGraphicTask(GraphicStationTaskLine *stationLine, unsigned task_id, unsigned station_id, Task::task_color_mode color_mode/*, bool inActive*/); - void selectGraphicTask(unsigned taskID, bool centerOnTask = false); - void deselectGraphicTask(unsigned taskID); - void deselectAllGraphicTasks(void); - - friend class SchedulerGUI; // schedulerGUI may access my private members - -signals: - void showTaskDialog(const Task *task); - void updateTaskDialogWithTask(const Task *task); -// void graphicSceneChanged(void); - void setEnableZoomIn(bool); - void setEnableZoomOut(bool); - void clickedGraphicTask(unsigned taskID); - void taskRescheduleRequest(unsigned, const AstroDateTime &, bool forced_unschedule = false); - -private slots: - void handleRubberBandSelection(void); - - -private: - QGraphicsView *itsParentView; - - // controller - Controller *itsController; - - zoom_level itsZoomLevel; - int itsTimeLineZeroPos; // corresponds to time line zero position - AstroDate itsStartDay, itsEndDay; - - //graphic objects - Task::task_color_mode itsTaskColorMode; - GraphicTimeLine *itsTimeLine; - GraphicCurrentTimeLine *itsCurrentTimeLine; - stationTimeLineMap itsStationTimeLines; - std::map<unsigned, std::pair<QGraphicsSimpleTextItem *, QGraphicsRectItem *> > itsStationNameLabels; - tasksMap itsTasks; - int lastXPosition; -}; - -#endif /* GRAPHICRESOURCESCENE_H_ */ diff --git a/SAS/Scheduler/src/GraphicStationTaskLine.cpp b/SAS/Scheduler/src/GraphicStationTaskLine.cpp deleted file mode 100644 index 4d96c06d968f5728714fbeb4d2744f055a12f374..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicStationTaskLine.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * GraphicStationTaskLine.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 15, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicStationTaskLine.cpp $ - * - */ - -#include "GraphicStationTaskLine.h" -#include "GraphicResourceScene.h" -#include "station.h" -#include "Controller.h" -#include <algorithm> -#include <QPainter> -#include <QRect> -#include <QGraphicsSceneMouseEvent> - -using std::max; -using std::min; - -GraphicStationTaskLine::GraphicStationTaskLine(GraphicResourceScene *parent, const Station &station, int yPos) - : itsScene(parent), itsStationID(station.getStationID()), itsHeight(13) - { - setZValue(0); // stacking level - setPos(parent->getTimeLineZeroPos(), yPos -1); - updateWidth(); -} - -GraphicStationTaskLine::GraphicStationTaskLine(GraphicResourceScene *parent, unsigned int stationID, int yPos) - : itsScene(parent), itsStationID(stationID), itsHeight(13) -{ - setZValue(0); // background level - setPos(parent->getTimeLineZeroPos(), yPos -1); - updateWidth(); -} - - -GraphicStationTaskLine::~GraphicStationTaskLine() { - itsScene = 0; -} - -QRectF GraphicStationTaskLine::boundingRect() const { - return QRectF(-40.5, -0.5, itsWidth + 1, itsHeight + 2); -} - -void GraphicStationTaskLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - // draw day and night times - QRect nightRect; - QPen nightPen(Qt::lightGray, 0.5); - QBrush nightBrush(Qt::lightGray, Qt::Dense4Pattern); - painter->setPen(nightPen); - painter->setBrush(nightBrush); - nightRect.setBottom(itsHeight); - const std::vector<std::pair<double, double> > &stationSunVector = Controller::theSchedulerSettings.getStationSunVector(itsStationID); - if (!stationSunVector.empty()) { - int firstDayInSunVector = Controller::theSchedulerSettings.getEarliestSchedulingDay().toJulian(); - int startDayIdx = itsScene->getStartDay().toJulian() - firstDayInSunVector; - int endDayIdx = itsScene->getEndDay().toJulian() - firstDayInSunVector; - // take care not to go out of sun vector bounds - startDayIdx = max(startDayIdx, 1); - endDayIdx = min(endDayIdx, static_cast<int>(stationSunVector.size())); - for (int dayIdx = startDayIdx; dayIdx < endDayIdx; ++dayIdx) { - nightRect.setLeft(itsScene->time2xPos(stationSunVector.at(dayIdx-1).second) - static_cast<int>(pos().x())); - nightRect.setRight(itsScene->time2xPos(stationSunVector.at(dayIdx).first) - static_cast<int>(pos().x())); - painter->drawRect(nightRect); - } - } - - // draw the station base line - painter->setPen(QPen(Qt::black, 1.0)); - painter->drawLine(0, itsHeight - 2, itsWidth - 41, itsHeight - 2); -} diff --git a/SAS/Scheduler/src/GraphicStationTaskLine.h b/SAS/Scheduler/src/GraphicStationTaskLine.h deleted file mode 100644 index 9199381f0488b7b01001280ef114fa32aabcf130..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicStationTaskLine.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GraphicStationTaskLine.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 15, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicStationTaskLine.h $ - * - */ - -#ifndef GRAPHICSTATIONTASKLINE_H_ -#define GRAPHICSTATIONTASKLINE_H_ - -#include <QGraphicsItem> -#include "GraphicResourceScene.h" - -class Station; - -class GraphicStationTaskLine : public QGraphicsItem { -public: - GraphicStationTaskLine(GraphicResourceScene *parent, const Station &station, int yPos); - GraphicStationTaskLine(GraphicResourceScene *parent, unsigned int stationID, int yPos); - virtual ~GraphicStationTaskLine(); - - QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - - unsigned int stationID(void) const {return itsStationID;} - inline void updateWidth(void) {itsWidth = static_cast<int>(itsScene->getTimeLineWidth()) + 41; update();} - -private: - GraphicResourceScene *itsScene; - unsigned int itsStationID; //, itsCurrentHighlightTask; - int itsWidth, itsHeight; -}; - -#endif /* GRAPHICSTATIONTASKLINE_H_ */ diff --git a/SAS/Scheduler/src/GraphicStorageTimeLine.cpp b/SAS/Scheduler/src/GraphicStorageTimeLine.cpp deleted file mode 100644 index 88c5a1de1e95aac503f2b56c0ad8bf8006470e81..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicStorageTimeLine.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * GraphicStorageTimeLine.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Nov 16, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicStorageTimeLine.cpp $ - * - */ - -#include "GraphicStorageTimeLine.h" -#include "graphicstoragescene.h" -#include "Controller.h" -#include <QPainter> -#include <QRect> -#include <QGraphicsSceneMouseEvent> - -using std::max; -using std::min; - -GraphicStorageTimeLine::GraphicStorageTimeLine(GraphicStorageScene *parent, int yPos) - : itsScene(parent), itsHeight(13) - { - setZValue(0); // background level - setPos(parent->getTimeLineZeroPos(), yPos -1); - updateWidth(); -} - -GraphicStorageTimeLine::~GraphicStorageTimeLine() { - itsScene = 0; -} - -QRectF GraphicStorageTimeLine::boundingRect() const { - return QRectF(-40.5, -0.5, itsWidth + 1, itsHeight + 2); -} - -void GraphicStorageTimeLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - QPen thickPen(Qt::black, 1.5); - QPen thinPen(Qt::black, 0.5); - - // draw the station name -// painter->drawText(-40, itsHeight - 2, itsStationName.c_str()); - - // draw day and night times -// QRect nightRect; -// QPen nightPen(Qt::lightGray, 0.5); -// QBrush nightBrush(Qt::lightGray, Qt::Dense4Pattern); -// painter->setPen(nightPen); -// painter->setBrush(nightBrush); -// nightRect.setBottom(itsHeight); -// const std::vector<std::pair<double, double> > &stationSunVector = Controller::theSchedulerSettings.getStationSunVector(itsStationID); -// if (!stationSunVector.empty()) { -// int firstDayInSunVector = Controller::theSchedulerSettings.getEarliestSchedulingDay().toJulian(); -// int startDayIdx = itsScene->getStartDay().toJulian() - firstDayInSunVector; -// int endDayIdx = itsScene->getEndDay().toJulian() - firstDayInSunVector; -// // take care not to go out of sun vector bounds -// startDayIdx = max(startDayIdx, 1); -// endDayIdx = min(endDayIdx, static_cast<int>(stationSunVector.size())); -// for (int dayIdx = startDayIdx; dayIdx < endDayIdx; ++dayIdx) { -// nightRect.setLeft(itsScene->time2xPos(stationSunVector.at(dayIdx-1).second) - pos().x()); -// nightRect.setRight(itsScene->time2xPos(stationSunVector.at(dayIdx).first) - pos().x()); -// painter->drawRect(nightRect); -// } -// } - - // draw the station base line - painter->setPen(QPen(Qt::black, 1.0)); - painter->drawLine(0, itsHeight - 2, itsWidth - 41, itsHeight - 2); - // for test purpose: draw boundings -// painter->setPen(QPen(Qt::blue, 1)); -// painter->setBrush(Qt::NoBrush); -// painter->drawRect(boundingRect()); -} diff --git a/SAS/Scheduler/src/GraphicStorageTimeLine.h b/SAS/Scheduler/src/GraphicStorageTimeLine.h deleted file mode 100644 index e7b4470c4a373a28fd38cd508aae0945fd732a10..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicStorageTimeLine.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * GraphicStorageTimeLine.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Nov 16, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicStorageTimeLine.h $ - * - */ - -#ifndef GRAPHICSTORAGETIMELINE_H_ -#define GRAPHICSTORAGETIMELINE_H_ - -#include <QGraphicsItem> -#include "graphicstoragescene.h" - -class GraphicStorageTimeLine : public QGraphicsItem { -public: - GraphicStorageTimeLine(GraphicStorageScene *parent, int yPos); - virtual ~GraphicStorageTimeLine(); - - QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - -// void mousePressEvent(QGraphicsSceneMouseEvent * event); - - inline void updateWidth(void) {itsWidth = itsScene->getTimeLineWidth() + 41; update();} - -private: - GraphicStorageScene *itsScene; - int itsWidth, itsHeight; -}; - -#endif /* GRAPHICSTORAGETIMELINE_H_ */ diff --git a/SAS/Scheduler/src/GraphicTask.cpp b/SAS/Scheduler/src/GraphicTask.cpp deleted file mode 100644 index 00b0ac11e7240482e09dc62ab779e3fdb7fa71b8..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicTask.cpp +++ /dev/null @@ -1,526 +0,0 @@ -/* - * GraphicTask.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 20, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicTask.cpp $ - * - */ - -#include "GraphicTask.h" -#include "GraphicResourceScene.h" -#include "task.h" -#include "GraphicStationTaskLine.h" -#include <QPainter> -#include <QGraphicsSceneMouseEvent> -#include <QWhatsThis> -#include <QDrag> -#include <QMimeData> -#include <QBitmap> -#include <QToolTip> -#include <algorithm> -using std::max; -using std::min; -using std::string; - -GraphicTask::GraphicTask(GraphicStationTaskLine *stationLine, GraphicResourceScene *scene, unsigned int task_id, - unsigned station_id, Task::task_color_mode color_mode) - : itsScene(scene), itsTaskID(task_id), itsStationID(station_id), - itsHeight(TASK_RECT_HEIGHT), EndBeforeStart(false), itsColorMode(color_mode), itsSelectedHighLightOn(false), - itsPredecessorHighLightOn(false), dontMove(false), hasBeenMoved(false) -{ - scene->addItem(this); // adds the item to the scene - yZeroPosTimeLine = static_cast<int>(stationLine->pos().y()); - setZValue(3); // item is at z level 3 (background is 0) - const Task *pTask = itsScene->getTask(itsTaskID); - setPos(itsScene->time2xPos(pTask->getScheduledStart()), yZeroPosTimeLine); - - AstroDateTime endTime(pTask->getScheduledEnd()); - const AstroDateTime &realEnd(pTask->SASTree().stopTime()); - if (pTask->isObservation() && pTask->getStatus() >= Task::FINISHED && realEnd.isSet()) { - if (realEnd <= pTask->getScheduledEnd().subtractMinutes(1)) { - endTime = realEnd; - } - } - itsWidth = itsScene->time2xPos(endTime) - static_cast<int>(pos().x()); - if (itsWidth < 0) { - itsWidth = 5; - EndBeforeStart = true; - } - else EndBeforeStart = false; - itsBoundings = QRectF(-0.5, -0.5, itsWidth + 3, itsHeight + 3); - updateTask(/*inactive*/); // updates the tooltip - setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); - setFlags(QGraphicsItem::ItemIsSelectable); -} - -GraphicTask::~GraphicTask() { -} - -void GraphicTask::updatePosition(void) { - const Task *pTask = itsScene->getTask(itsTaskID); - setPos(itsScene->time2xPos(pTask->getScheduledStart()), yZeroPosTimeLine); - AstroDateTime endTime(pTask->getScheduledEnd()); - const AstroDateTime &realEnd(pTask->SASTree().stopTime()); - if (pTask->isObservation() && pTask->getStatus() >= Task::FINISHED && realEnd.isSet()) { - if (realEnd <= pTask->getScheduledEnd().subtractMinutes(1)) { - endTime = realEnd; - } - } - itsWidth = itsScene->time2xPos(endTime) - static_cast<int>(pos().x()); - if (itsWidth < 0) { - itsWidth = 5; - EndBeforeStart = true; - } - else EndBeforeStart = false; - itsBoundings = QRectF(-0.5, -0.5, itsWidth + 3, itsHeight + 3); - update(); -} - -void GraphicTask::updateTask() { - const Task *pTask = itsScene->getTask(itsTaskID); - Task::task_status status(pTask->getStatus()); - Task::task_type type(pTask->getType()); - if (status >= Task::SCHEDULED) dontMove = true; - else dontMove = false; - if (type == Task::RESERVATION) { - setZValue(2); // reservation is at stacking level 2, regular task at 3 - } - else { - setZValue(3); // draw regular task always on top of reservations - } - setPos(itsScene->time2xPos(pTask->getScheduledStart()), yZeroPosTimeLine); - AstroDateTime endTime(pTask->getScheduledEnd()); - string earlyStr; - const AstroDateTime &realEnd(pTask->SASTree().stopTime()); - if (pTask->isObservation() && pTask->getStatus() >= Task::FINISHED && realEnd.isSet()) { - if (realEnd <= pTask->getScheduledEnd().subtractMinutes(1)) { - endTime = realEnd; - earlyStr = " (EARLY)"; - } - } - itsWidth = itsScene->time2xPos(endTime) - static_cast<int>(pos().x()); if (itsWidth < 0) { - itsWidth = 5; - EndBeforeStart = true; - } - else EndBeforeStart = false; - itsBoundings = QRectF(-0.5, -0.5, itsWidth + 3, itsHeight + 3); - itsTooltip = "Task:" + int2String(pTask->getID()) + " " + pTask->getTypeStr() + " (" + - int2String(pTask->getSASTreeID()) + - ")\nSubtype:" + pTask->getProcessSubtypeStr() + - std::string("\nProject:") + - pTask->getProjectName() + "\nTask:" + - pTask->getTaskName() + "\nStatus:" + - pTask->getStatusStr() + earlyStr + "\n" + - pTask->getScheduledStart().getDate().toString() + " - " + - pTask->getScheduledEnd().getDate().toString(); - if (EndBeforeStart) { - itsTooltip += string("(!)"); - } - if (pTask->getFixedDay()) { - itsTooltip += " (Fixed)"; - } - itsTooltip += "\n" + pTask->getScheduledStart().getTime().toString() + " - " + - pTask->getScheduledEnd().getTime().toString(); - if (pTask->getFixedTime()) { - itsTooltip += " (Fixed)"; - } - itsTooltip += "\nDuration:" + pTask->getDuration().toString(); - if (pTask->hasStorage()) { - itsTooltip += string("\nData size:") + humanReadableUnits((long double)pTask->storage()->getTotalStoragekBytes(), SIZE_UNITS).c_str(); - } - if (pTask->isStationTask()) { - itsTooltip += "\nStations:\n" + static_cast<const StationTask *>(pTask)->getStationNamesStr(',', 6); - } - - setToolTip(QString(itsTooltip.c_str())); - update(); // also do a redraw because task times changed -} - -std::string GraphicTask::toolTipHTML(void) const { - const Task *pTask = itsScene->getTask(itsTaskID); - string br("<br>"); - string tooltip(string(pTask->getTypeStr()) + " (" + int2String(pTask->getSASTreeID()) + ")"); - - if (pTask->hasLinkedTask()) { - tooltip += " (linked task)"; - } - tooltip += br + pTask->getProcessSubtypeStr() + br - + string("Project: ") + pTask->getProjectName() + br - + string("Task: ") + pTask->getTaskName() + br - + string("Start: ") + pTask->getScheduledStart().toString() + br - + string("Stop: ") + pTask->getScheduledEnd().toString() + br - + string("Duration: ") + pTask->getDuration().toString(); - if (pTask->isObservation()) { - const Observation *pObs = static_cast<const Observation *>(pTask); - tooltip += br + "Settings: " + pObs->getStationClockStr() + br + pObs->getAntennaModeStr() + " / " + pObs->getFilterTypeStr() + br; - } - return tooltip; -} - -void GraphicTask::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - QBrush brush; - QPen pen; - QColor color; - bool penSet(false); - const Task *pTask(0); - pTask = itsScene->getTask(itsTaskID); - if (pTask) { - Task::task_type type(pTask->getType()); - - if (itsSelectedHighLightOn) { - pen.setColor(Qt::red); - pen.setWidth(3); - penSet = true; - } - else if (itsPredecessorHighLightOn) { - pen.setColor(QColor(0,255,255)); - pen.setWidth(3); - penSet = true; - } - - if (itsColorMode == Task::TASK_TYPE_COLOR_MODE) { - if (type == Task::RESERVATION) { - color = pTask->getTypeColor(); - if (!penSet) { - pen.setColor(color); - pen.setWidth(1); - } - brush.setColor(color); - brush.setStyle(Qt::BDiagPattern); - } - else if (type == Task::MAINTENANCE) { - color = pTask->getTypeColor(); - if (!penSet) { - pen.setColor(color); - pen.setWidth(1); - } - brush.setColor(color); - brush.setStyle(Qt::DiagCrossPattern); - } - else { - color = pTask->getTypeColor(); - if (!penSet) { - pen.setColor(color); - pen.setWidth(1); - } - brush.setColor(color); - brush.setStyle(Qt::SolidPattern); - } - } - else { // task status color mode - if (type == Task::RESERVATION) { - color = pTask->getTypeColor(); - brush.setStyle(Qt::BDiagPattern); - if (!penSet) { - pen.setWidth(1); - } - } - else if (type == Task::MAINTENANCE) { - color = pTask->getTypeColor(); - brush.setStyle(Qt::DiagCrossPattern); - if (!penSet) { - pen.setWidth(1); - } - } - else { - color = pTask->getStatusColor(); - brush.setStyle(Qt::SolidPattern); - if (!penSet) { - pen.setWidth(1); - } - } - if (!penSet) { - pen.setColor(color); - } - brush.setColor(color); - } - - painter->setPen(pen); - painter->setBrush(brush); - - int xpos = static_cast<int>(pos().x()); - if (xpos + itsWidth > 70) { - if (xpos <= 70) { - int h2 = itsHeight/2; - itsBoundings.setX(- xpos - h2); - QPointF points[3] = { - QPointF(70 - xpos, 0), - QPointF(70 - xpos - h2, h2), - QPointF(70 - xpos, itsHeight), - }; - - painter->drawRect(QRectF(70 - xpos, 0, itsWidth - (70 - xpos), itsHeight)); - painter->drawPolygon(points, 3); - } - else { - if (EndBeforeStart) { - QPolygon polygon; - polygon << QPoint(0, 0) << QPoint(5, 0) << QPoint(3, itsHeight/2) << QPoint(5,itsHeight/2) << QPoint(3,itsHeight) << QPoint(0,itsHeight); - painter->drawPolygon(polygon); - } - else { - painter->drawRect(QRectF(0, 0, itsWidth, itsHeight)); - } - } - } - if (EndBeforeStart) { - QPolygon polygon; - polygon << QPoint(0, 0) << QPoint(5, 0) << QPoint(3, itsHeight/2) << QPoint(5,itsHeight/2) << QPoint(3,itsHeight) << QPoint(0,itsHeight); - painter->drawPolygon(polygon); - } -// for test purpose: draw boundings -// QPen pen(Qt::black, 1); -// painter->setBrush(Qt::NoBrush); -// painter->setPen(pen); -// painter->drawRect(itsBoundings); - -} -} - -void GraphicTask::mousePressEvent(QGraphicsSceneMouseEvent * event) { - if (event->button() == Qt::LeftButton) { - dragStartPosition = event->lastScreenPos(); - itsScene->startMoveTask(dragStartPosition.x()); - if (event->modifiers() == Qt::ControlModifier) { // control key was pressed - if (itsSelectedHighLightOn) { - itsSelectedHighLightOn = false; - itsScene->deselectTask(itsTaskID, false); - } - else { - itsSelectedHighLightOn = true; - itsScene->selectTask(itsTaskID, false); - } - } - else { // without control key - if (!itsSelectedHighLightOn) { // if not already selected - itsSelectedHighLightOn = true; - itsScene->selectTask(itsTaskID, true); - } - } - update(); - } - else if (event->button() == Qt::RightButton) { - if (!itsSelectedHighLightOn) { - itsScene->selectTask(itsTaskID, true); - } - } - event->accept(); -} - -void GraphicTask::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event ) { - itsSelectedHighLightOn = true; - itsScene->selectTask(itsTaskID, true); - itsScene->showTaskProperties(itsTaskID); - event->accept(); -} - -void GraphicTask::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { - if (!hasBeenMoved) { - if (!(event->modifiers() == Qt::ControlModifier)) { // no control key - itsSelectedHighLightOn = true; - } - } - setCursor(Qt::ArrowCursor); - if ((event->button() == Qt::LeftButton) && (!dontMove)) { - if (hasBeenMoved) { - // get the new position and calculate the new time - itsScene->requestTaskMove(itsTaskID, itsScene->xPos2Time(static_cast<int>(scenePos().x()))); - hasBeenMoved = false; - } - } -} - -void GraphicTask::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if (!dontMove) { - if (!(event->buttons() & Qt::LeftButton)) - return; - if ((event->lastScreenPos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()) - return; - else setCursor(Qt::SizeHorCursor); - } - else { // cannot move an inactive task - setCursor(Qt::ForbiddenCursor); - event->ignore(); - return; - } - - itsScene->moveSelectedTasks(event); - hasBeenMoved = true; -} - -void GraphicTask::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) -{ - // first check if this should apply to multiple tasks - if (itsScene->controller()->multipleSelected()) { - QMenu menu; - QAction *action = menu.addAction("Unschedule multiple tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(unscheduleSelectedTasks())); - action = menu.addAction("set PRESCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(preScheduleSelectedTasks())); - action = menu.addAction("set SCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(scheduleSelectedTasks())); - action = menu.addAction("Move/Redistribute tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(showMoveTaskDialog())); - action = menu.addAction("Copy tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(copySelectedTasks())); - action = menu.addAction("Delete tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(deleteSelectedTasks())); - action = menu.addAction("Put on hold now!"); - connect(action, SIGNAL(triggered()), this, SLOT(setSelectedTasksOnHold())); - action = menu.addAction("Multi-edit"); - connect(action, SIGNAL(triggered()), this, SLOT(showSelectedTasksProperties())); - menu.exec(event->screenPos()); - } - else { - const Task *pTask(itsScene->getTask(itsTaskID)); - if (pTask) { - Task::task_status status = pTask->getStatus(); - QMenu menu; - QAction *action; - if ((pTask->isObservation()) && ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED))) { - action = menu.addAction("Unschedule task"); - connect(action, SIGNAL(triggered()), this, SLOT(unscheduleTask())); - } - if ((pTask->isObservation()) && ((status < Task::PRESCHEDULED) || (status == Task::SCHEDULED))) { - action = menu.addAction("set PRESCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(preScheduleTask())); - } - if ((pTask->isObservation()) && (status == Task::PRESCHEDULED)) { - action = menu.addAction("set SCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(scheduleTask())); - } - action = menu.addAction("Move task"); - connect(action, SIGNAL(triggered()), this, SLOT(showMoveTaskDialog())); - action = menu.addAction("Copy task"); - connect(action, SIGNAL(triggered()), this, SLOT(copyTask())); - if (status == Task::ABORTED) { - action = menu.addAction("Reschedule aborted task"); - connect(action, SIGNAL(triggered()), this, SLOT(rescheduleTask())); - } - action = menu.addAction("Delete task"); - connect(action, SIGNAL(triggered()), this, SLOT(deleteTask())); - - if ((status <= Task::SCHEDULED) & (status != Task::ON_HOLD)) { - action = menu.addAction("Put on hold now!"); - connect(action, SIGNAL(triggered()), this, SLOT(setTaskOnHold())); - } - action = menu.addAction("Properties"); - connect(action, SIGNAL(triggered()), this, SLOT(showTaskProperties())); - - action = menu.addAction("SAS State history"); - connect(action, SIGNAL(triggered()), this, SLOT(showStateHistory())); - - int sasTreeID(pTask->getSASTreeID()); - if (sasTreeID) { - action = menu.addAction("SAS tree viewer"); - connect(action, SIGNAL(triggered()), this, SLOT(openSASTreeViewer(void))); - action = menu.addAction("View meta-data"); - connect(action, SIGNAL(triggered()), this, SLOT(openMetaDataViewer(void))); - } - - menu.exec(event->screenPos()); - } - } -} - -void GraphicTask::unscheduleTask(void) { - itsScene->unscheduleTask(itsTaskID); -} - -void GraphicTask::unscheduleSelectedTasks(void) { - itsScene->unscheduleSelectedTasks(); -} - -void GraphicTask::preScheduleTask(void) { - itsScene->scheduleTask(itsTaskID, Task::PRESCHEDULED); -} - -void GraphicTask::scheduleTask(void) { - itsScene->scheduleTask(itsTaskID, Task::SCHEDULED); -} - -void GraphicTask::preScheduleSelectedTasks(void) { - itsScene->preScheduleSelectedTasks(); -} - -void GraphicTask::scheduleSelectedTasks(void) { - itsScene->scheduleSelectedTasks(); -} - -void GraphicTask::setTaskOnHold(void) { - itsScene->setTaskOnHold(itsTaskID); -} - -void GraphicTask::setSelectedTasksOnHold(void) { - itsScene->setSelectedTasksOnHold(); -} - -void GraphicTask::copyTask(void) { - itsScene->copyTask(itsTaskID); -} - -void GraphicTask::copySelectedTasks(void) { - itsScene->copySelectedTasks(); -} - -void GraphicTask::rescheduleTask(void) { - itsScene->rescheduleTask(itsTaskID); -} - -void GraphicTask::deleteTask(void) { - itsScene->deleteTask(itsTaskID); -} - -void GraphicTask::deleteSelectedTasks(void) { - itsScene->deleteSelectedTasks(); -} - -void GraphicTask::showTaskProperties(void) { - itsScene->showTaskProperties(itsTaskID); -} - -void GraphicTask::showMoveTaskDialog(void) { - itsScene->openMoveTasksDialog(); -} - -void GraphicTask::showSelectedTasksProperties(void) { - itsScene->showSelectedTasksProperties(); -} - -void GraphicTask::showStateHistory(void) { - itsScene->showTaskStateHistory(itsTaskID); -} - -void GraphicTask::openSASTreeViewer(void) const { - const Task *pTask(itsScene->controller()->getTask(itsTaskID)); - if (pTask) { - itsScene->controller()->openSASTreeViewer(pTask->getSASTreeID()); - } -} - -void GraphicTask::openMetaDataViewer(void) const { - const Task *pTask(itsScene->controller()->getTask(itsTaskID)); - if (pTask) { - itsScene->controller()->openMetaDataViewer(pTask->getSASTreeID()); - } -} - - -void GraphicTask::setSelected(bool is_selected) { - if (is_selected) { - if (!itsSelectedHighLightOn) { - itsSelectedHighLightOn = true; - update(itsBoundings); - } - } - else if (itsSelectedHighLightOn) { - itsSelectedHighLightOn = false; - update(itsBoundings); - } -} diff --git a/SAS/Scheduler/src/GraphicTask.h b/SAS/Scheduler/src/GraphicTask.h deleted file mode 100644 index 42362e99659ed2fd6a2b914e491ae548095a1934..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicTask.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * GraphicTask.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 20, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicTask.h $ - * - */ - -#ifndef GRAPHICTASK_H_ -#define GRAPHICTASK_H_ - -#define TASK_RECT_HEIGHT 10 - -#include <QGraphicsItem> -#include <QRectF> -#include <QPoint> -#include <QObject> -#include "astrodatetime.h" -#include "task.h" -#include <string> - -class GraphicResourceScene; -class QDragMoveEvent; -class Task; -class GraphicStationTaskLine; - -class GraphicTask : /*public QObject,*/ public QGraphicsObject { - - Q_OBJECT - -public: - GraphicTask(GraphicStationTaskLine *stationLine, GraphicResourceScene *scene, unsigned int task_id, - unsigned station_id, Task::task_color_mode color_mode/*, bool inactive*/); - virtual ~GraphicTask(); - - QRectF boundingRect() const {return itsBoundings;} - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - - unsigned getTaskID(void) const {return itsTaskID;} - - const std::string &toolTip(void) const { return itsTooltip; } - std::string toolTipHTML(void) const; // the tooltip but with all the '\n' replaced by <br> - - void setTaskColorMode(Task::task_color_mode color_mode) { if (itsColorMode != color_mode) {itsColorMode = color_mode; update(itsBoundings);} } -// void setNormalColorMode(void) {itsTaskTypeColorOn = false;} -// void hoverEnterEvent(QGraphicsSceneMouseEvent * event); -// void hoverLeaveEvent(QGraphicsSceneMouseEvent * event); - - void setSelected(bool is_selected); - void setPredecessorHighLight(bool onoff) {itsPredecessorHighLightOn = onoff; update(itsBoundings);} -// void fixSchedule(bool fix_schedule) {fixedSchedule = fix_schedule;} -// void setStatus(task_status) { itsStatus = task_status;} -// void setInactive(bool inactive) {isInactive = inactive;} -// void setHovered(bool is_hovered); - - unsigned stationID(void) const {return itsStationID;} -// const IDvector &getPredecessors(void) const; - - void updateTask(/*bool inActive*/); - void updatePosition(void); - - int xPos(void) const {return static_cast<int>(pos().x());} - int yPos(void) const {return yZeroPosTimeLine;} - int left(void) const {return static_cast<int>(pos().x());} - int right(void) const {return static_cast<int>(pos().x()) + itsWidth;} - int top(void) const {return yZeroPosTimeLine;} - int bottom(void) const {return yZeroPosTimeLine + itsHeight;} - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent * event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event ); - -private slots: -// void abortTask(void); - void unscheduleTask(void); - void unscheduleSelectedTasks(void); - void preScheduleTask(void); - void scheduleTask(void); - void preScheduleSelectedTasks(void); - void scheduleSelectedTasks(void); - void setTaskOnHold(void); - void setSelectedTasksOnHold(void); - void copyTask(void); - void copySelectedTasks(void); - void rescheduleTask(void); - void deleteTask(void); - void deleteSelectedTasks(void); - void showTaskProperties(void); - void showSelectedTasksProperties(void); - void showStateHistory(void); - void openSASTreeViewer(void) const; - void openMetaDataViewer(void) const; - void showMoveTaskDialog(void); - - -protected: - void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); - -private: - GraphicResourceScene *itsScene; - unsigned itsTaskID; - unsigned itsStationID; - int yZeroPosTimeLine; - int itsWidth, itsHeight; - QRectF itsBoundings; - bool EndBeforeStart; - std::string itsTooltip; - Task::task_color_mode itsColorMode; - bool itsSelectedHighLightOn, itsPredecessorHighLightOn; //itsHoverHighLightOn - QPoint dragStartPosition; - bool dontMove, hasBeenMoved; -}; - -#endif /* GRAPHICTASK_H_ */ diff --git a/SAS/Scheduler/src/GraphicTimeLine.cpp b/SAS/Scheduler/src/GraphicTimeLine.cpp deleted file mode 100644 index 858adbc571414193c2a476ae3fcf74abb749b362..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicTimeLine.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * GraphicTimeLine.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 14, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicTimeLine.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "lofar_utils.h" -#include "GraphicTimeLine.h" -#include "GraphicResourceScene.h" -#include "astrodate.h" -#include <QPainter> - -GraphicTimeLine::GraphicTimeLine(GraphicResourceScene *parent) - : itsHeight(27), itsScene(parent), itsScenePos(70) -{ - setPos(70,0); - setZValue(4); // set stacking level - updateWidth(); - itsTimeLineDayImage1 = new QImage(":/images/timeline_day.png"); - itsTimeLineDayImage2 = new QImage(":/images/timeline_day_long.png"); - -} - -GraphicTimeLine::~GraphicTimeLine() { - delete itsTimeLineDayImage1; - delete itsTimeLineDayImage2; -} - -void GraphicTimeLine::updateWidth(void) { - AstroDate lastDay = itsScene->getEndDay(); - lastDay = lastDay.addDays(1); - itsWidth = itsScene->time2xPos(lastDay) - itsScenePos; - update(); -} - -QRectF GraphicTimeLine::boundingRect() const { - return QRectF(-65.5, 0, itsWidth + 36, itsHeight + 10); -} - -void GraphicTimeLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - - // draw a non-opaque white rectangle for the background - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(255, 255, 255, 200)); - painter->drawRect(boundingRect()); - - QFont normalFont("Liberation Sans",9,QFont::Normal); - QPen thickPen(Qt::black, 2); - QPen thinPen(Qt::black, 1); - AstroDate currentDate = itsScene->getStartDay(); - AstroDate endDate = itsScene->getEndDay(); - - painter->setPen(thickPen); - painter->setFont(normalFont); - - zoom_level zl = itsScene->getZoomLevel(); - - if (zl == ZM_MONTH) { - unsigned int month; - int xMonthPos, xWeekPos; - //draw the first week tick - QString weekStr = QString::number(currentDate.getWeek()); - painter->drawLine(0, 15, 0, 17); - painter->drawText(-35, 27, "Week: "); - painter->drawText(16 - (weekStr.length()-1)*5, 27, weekStr); - - // draw the base time line - painter->setPen(thinPen); - painter->drawLine(0, 15, itsWidth, 15); - - unsigned int lastMonth(currentDate.getMonth()); - currentDate = currentDate.addDays(7); - QString monthStr; - while (currentDate <= endDate) { - month = currentDate.getMonth(); - if (month != lastMonth) { // draw month inset - xMonthPos = itsScene->time2xPos(AstroDate(1,month,currentDate.getYear())) - itsScenePos; - painter->setPen(thickPen); - painter->drawLine(xMonthPos, 5, xMonthPos, 17); - painter->setPen(thinPen); - monthStr = QString(MONTH_NAMES_ENG[month-1]) + " (" + QString::number(currentDate.getYear()) + ")"; - painter->drawText(QPoint(xMonthPos + 50 - monthStr.length()/2, 11), monthStr); - lastMonth = month; - } - xWeekPos = itsScene->time2xPos(currentDate) - itsScenePos; - painter->drawLine(xWeekPos, 15, xWeekPos, 17); // week ticks - weekStr = QString::number(currentDate.getWeek()); - painter->drawText(QPoint(xWeekPos + 16 - (weekStr.length()-1)*5, 27), weekStr); - currentDate = currentDate.addDays(7); - } - xWeekPos = itsScene->time2xPos(currentDate) - itsScenePos; - painter->drawLine(xWeekPos, 15, xWeekPos, 17); // last week thick - } - else if (zl == ZM_WEEK) { - unsigned int week; - int xDayPos, xWeekPos; - //draw the first day tick - QString dayStr = QString::number(currentDate.getDay()); - QString weekStr; - painter->drawLine(0, 15, 0, 17); - painter->drawText(-35, 27, "Day:"); - painter->drawText(20 - (dayStr.length()-1)*5, 27, dayStr); - - // draw the base time line - painter->setPen(thinPen); - painter->drawLine(0, 15, itsWidth, 15); - - unsigned int lastWeek(currentDate.getWeek()); - currentDate = currentDate.addDays(1); - while (currentDate <= endDate) { - week = currentDate.getWeek(); - if (week != lastWeek) { // draw week inset - xWeekPos = itsScene->time2xPos(currentDate) - itsScenePos; - painter->setPen(thickPen); - painter->drawLine(xWeekPos, 5, xWeekPos, 17); - painter->setPen(thinPen); - weekStr = "week " + QString::number(currentDate.getWeek()) + " (" - + MONTH_SHORT_NAMES_ENG[currentDate.getMonth()-1] + " " + QString::number(currentDate.getYear()) + ")"; - painter->drawText(QPoint(xWeekPos + 120 /*- weekStr.length()*4*/, 11), weekStr); - lastWeek = week; - } - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - painter->drawLine(xDayPos, 15, xDayPos, 17); // day ticks - dayStr = QString::number(currentDate.getDay()); - painter->drawText(QPoint(xDayPos + 20 - (dayStr.length()-1)*5, 27), dayStr); - currentDate = currentDate.addDays(1); - } - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - painter->drawLine(xDayPos, 15, xDayPos, 17); // last day thick - } - else if (zl == ZM_DAY) { - painter->drawText(-65, 27, "Hour (UTC)"); - // draw the base time line - painter->setPen(thinPen); - painter->drawLine(0, 15, itsWidth, 15); - QString dayStr; - int xDayPos; - while (currentDate <= endDate) { - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - dayStr = QString(DAY_SHORT_NAMES_ENG[currentDate.getDayOfTheWeek()]) + " " - + QString::number(currentDate.getDay()) + " " - + MONTH_SHORT_NAMES_ENG[currentDate.getMonth()-1] + ", " - + QString::number(currentDate.getYear()); - painter->drawText(xDayPos + 15, 13, dayStr); - painter->drawLine(xDayPos, 5, xDayPos, 19); - for (unsigned int hour = 0; hour < 24; ++hour) { - painter->drawLine(xDayPos + hour * 5, 15, xDayPos + hour * 5, 17); - } - painter->drawLine(xDayPos + 60, 15, xDayPos + 60, 19); // 12:00 hour longer tick - currentDate = currentDate.addDays(1); - } - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - painter->drawLine(xDayPos, 5, xDayPos, 19); // last day thick - } - else if (zl == ZM_HOUR) { - painter->drawText(-65, 27, "Hour (UTC)"); - // draw the base time line - painter->setPen(thinPen); - QString dayStr; - int xDayPos; - while (currentDate <= endDate) { - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - dayStr = QString(DAY_NAMES_ENG[currentDate.getDayOfTheWeek()]) + " " - + QString::number(currentDate.getDay()) + " " - + MONTH_NAMES_ENG[currentDate.getMonth()-1] + ", " - + QString::number(currentDate.getYear()); - painter->drawText(xDayPos + 180, 13, dayStr); - painter->drawImage(xDayPos -1, 3, *itsTimeLineDayImage1); - currentDate = currentDate.addDays(1); - } - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - } - else if (zl == ZM_MIN) { - painter->drawText(-65, 27, "Hour (UTC)"); - // draw the base time line - QString dayStr; - int xDayPos; - painter->setPen(thinPen); - while (currentDate <= endDate) { - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - dayStr = QString(DAY_NAMES_ENG[currentDate.getDayOfTheWeek()]) + " " - + QString::number(currentDate.getDay()) + " " - + MONTH_NAMES_ENG[currentDate.getMonth()-1] + ", " - + QString::number(currentDate.getYear()); - painter->drawText(xDayPos + 180, 13, dayStr); - painter->drawImage(xDayPos -7, 0, *itsTimeLineDayImage2); - currentDate = currentDate.addDays(1); - } - xDayPos = itsScene->time2xPos(currentDate) - itsScenePos; - } - -// painter->setPen(QPen(Qt::magenta, 0.5)); -// painter->drawRect(boundingRect()); - // for test purpose: draw boundings -// painter->setPen(QPen(Qt::magenta, 1.0)); -// painter->setBrush(Qt::NoBrush); -// painter->drawRect(boundingRect()); - -} diff --git a/SAS/Scheduler/src/GraphicTimeLine.h b/SAS/Scheduler/src/GraphicTimeLine.h deleted file mode 100644 index 16edd957a19c00052413d8217438b78aeea575c7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/GraphicTimeLine.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * GraphicTimeLine.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Oct 14, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/GraphicTimeLine.h $ - * - */ - -#ifndef GRAPHICTIMELINE_H_ -#define GRAPHICTIMELINE_H_ - -#include <QGraphicsItem> -#include "astrodatetime.h" -class GraphicResourceScene; - -class GraphicTimeLine : public QGraphicsItem { -public: - GraphicTimeLine(GraphicResourceScene *parent); - virtual ~GraphicTimeLine(); - - QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - - int getWidth(void) {return itsWidth;} - int time2xPos(const AstroDate &date) const; - - void updateWidth(void); - -private: - int itsWidth, itsHeight; - GraphicResourceScene *itsScene; - int itsScenePos; - QImage *itsTimeLineDayImage1, *itsTimeLineDayImage2; -}; - -#endif /* GRAPHICTIMELINE_H_ */ diff --git a/SAS/Scheduler/src/LOFAR_libScheduler.pro b/SAS/Scheduler/src/LOFAR_libScheduler.pro deleted file mode 100644 index f2852070cb875615efc44b2d60879f8524524e03..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/LOFAR_libScheduler.pro +++ /dev/null @@ -1,224 +0,0 @@ -# ##################################################################### -# Automatically generated by qmake (2.01a) Tue Mar 15 12:58:58 2011 -# ##################################################################### -TEMPLATE = lib -TEMPLATE = app -TARGET = libScheduler -QT += core \ - gui \ - sql -CONFIG += debug_and_release -CONFIG += staticlib # dynamic link: Problem with linking into app. -# This needs to be fixed with help of Marcel / JD - -CONFIG(debug, debug|release) { - message(Building Makefile.Debug) - DEFINES += _DEBUG_ - DESTDIR = debug - OBJECTS_DIR = debug - MOC_DIR = debug - UI_DIR = debug - RCC_DIR = debug - INCLUDEPATH += . \ - debug - DEPENDPATH += . \ - debug -} -else { - message(Building Makefile.Release) - DEFINES += _RELEASE_ - DESTDIR = release - OBJECTS_DIR = release - MOC_DIR = release - UI_DIR = release - RCC_DIR = release - INCLUDEPATH += . \ - release - DEPENDPATH += . \ - release -} - -# Input -HEADERS += blocksize.h \ - ListWidget.h \ - redistributetasksdialog.h \ - sasconnectdialog.h \ - DataTreeWidgetItem.h \ - shifttasksdialog.h \ - tiedarraybeamdialog.h \ - DigitalBeam.h \ - TiedArrayBeam.h \ - SpinBox.h \ - parsettreeviewer.h \ - FileUtils.h \ - Angle.h \ - astrodate.h \ - astrodatetime.h \ - astrotime.h \ - ComboBox.h \ - conflictdialog.h \ - Controller.h \ - DataHandler.h \ - DataMonitorConnection.h \ - dataslotdialog.h \ - DateEdit.h \ - DateTimeEdit.h \ - digitalbeamdialog.h \ - GraphicCurrentTimeLine.h \ - GraphicResourceScene.h \ - GraphicStationTaskLine.h \ - graphicstoragescene.h \ - GraphicStorageTimeLine.h \ - GraphicTask.h \ - GraphicTimeLine.h \ - LineEdit.h \ - longbaselinepipeline.h \ - lofar_scheduler.h \ - lofar_utils.h \ - neighboursolution.h \ - OTDBnode.h \ - OTDBtree.h \ - publishdialog.h \ - qlofardatamodel.h \ - SASConnection.h \ - sasprogressdialog.h \ - sasstatusdialog.h \ - sasuploaddialog.h \ - Scheduler.h \ - schedulerdata.h \ - schedulerdatablock.h \ - schedulergui.h \ - schedulersettings.h \ - schedulesettingsdialog.h \ - scheduletabledelegate.h \ - statehistorydialog.h \ - station.h \ - stationlistwidget.h \ - stationtreewidget.h \ - Storage.h \ - StorageNode.h \ - tablecolumnselectdialog.h \ - tableview.h \ - task.h \ - taskcopydialog.h \ - taskdialog.h \ - thrashbin.h \ - TimeEdit.h \ - doublespinbox.h \ - pipeline.h \ - pulsarpipeline.h \ - imagingpipeline.h \ - calibrationpipeline.h \ - observation.h \ - taskstorage.h \ - stationtask.h \ - storage_definitions.h \ - demixingsettings.h \ - CheckBox.h \ - schedulerLib.h \ - signalhandler.h -FORMS += \ - redistributetasksdialog.ui \ - sasconnectdialog.ui \ - shifttasksdialog.ui \ - tiedarraybeamdialog.ui \ - parsettreeviewer.ui \ - conflictdialog.ui \ - dataslotdialog.ui \ - digitalbeamdialog.ui \ - graphicstoragescene.ui \ - publishdialog.ui \ - sasprogressdialog.ui \ - sasstatusdialog.ui \ - sasuploaddialog.ui \ - schedulergui.ui \ - schedulesettingsdialog.ui \ - statehistorydialog.ui \ - stationlistwidget.ui \ - stationtreewidget.ui \ - tablecolumnselectdialog.ui \ - taskcopydialog.ui \ - taskdialog.ui \ - thrashbin.ui -SOURCES += \ - ListWidget.cpp \ - redistributetasksdialog.cpp \ - sasconnectdialog.cpp \ - DataTreeWidgetItem.cpp \ - shifttasksdialog.cpp \ - tiedarraybeamdialog.cpp \ - DigitalBeam.cpp \ - TiedArrayBeam.cpp \ - SpinBox.cpp \ - parsettreeviewer.cpp \ - FileUtils.cpp \ - Angle.cpp \ - astrodate.cpp \ - astrodatetime.cpp \ - astrotime.cpp \ - ComboBox.cpp \ - conflictdialog.cpp \ - Controller.cpp \ - DataHandler.cpp \ - DataMonitorConnection.cpp \ - dataslotdialog.cpp \ - DateEdit.cpp \ - DateTimeEdit.cpp \ - debug_lofar.cpp \ - digitalbeamdialog.cpp \ - GraphicCurrentTimeLine.cpp \ - GraphicResourceScene.cpp \ - GraphicStationTaskLine.cpp \ - graphicstoragescene.cpp \ - GraphicStorageTimeLine.cpp \ - GraphicTask.cpp \ - GraphicTimeLine.cpp \ - LineEdit.cpp \ - longbaselinepipeline.cpp \ - lofar_utils.cpp \ - main.cpp \ - neighboursolution.cpp \ - OTDBnode.cpp \ - OTDBtree.cpp \ - publishdialog.cpp \ - qlofardatamodel.cpp \ - SASConnection.cpp \ - sasprogressdialog.cpp \ - sasstatusdialog.cpp \ - sasuploaddialog.cpp \ - Scheduler.cpp \ - schedulerdata.cpp \ - schedulerdatablock.cpp \ - schedulergui.cpp \ - schedulersettings.cpp \ - schedulesettingsdialog.cpp \ - scheduletabledelegate.cpp \ - statehistorydialog.cpp \ - station.cpp \ - stationlistwidget.cpp \ - stationtreewidget.cpp \ - Storage.cpp \ - StorageNode.cpp \ - tablecolumnselectdialog.cpp \ - tableview.cpp \ - task.cpp \ - taskcopydialog.cpp \ - taskdialog.cpp \ - thrashbin.cpp \ - TimeEdit.cpp \ - doublespinbox.cpp \ - pipeline.cpp \ - pulsarpipeline.cpp \ - imagingpipeline.cpp \ - calibrationpipeline.cpp \ - observation.cpp \ - taskstorage.cpp \ - stationtask.cpp \ - demixingsettings.cpp \ - blocksize.cpp \ - CheckBox.cpp \ - schedulerLib.cpp \ - signalhandler.cpp -RESOURCES += scheduler_resources.qrc - - diff --git a/SAS/Scheduler/src/LineEdit.cpp b/SAS/Scheduler/src/LineEdit.cpp deleted file mode 100644 index 88beff2b76de0abcd2f69e68f1bf592412efffb4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/LineEdit.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * LineEdit.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/LineEdit.cpp $ - * - */ - -#include "LineEdit.h" -#include "lofar_scheduler.h" -#include <QFocusEvent> -#include <iostream> - -LineEdit::LineEdit(QWidget *parent) - : QLineEdit(parent), itsUndefined(false), itsPreviousUndefined(false) -{ - connect(this, SIGNAL(textEdited(QString)), this, SLOT(checkTextChange())); -} - -LineEdit::~LineEdit() { -} - - -void LineEdit::setText(const QString &text) { - this->blockSignals(true); - QLineEdit::setInputMask(itsInputMask); - QLineEdit::setText(text); - itsPreviousText = this->text(); - itsPreviousUndefined = false; - itsUndefined = false; - this->blockSignals(false); -} - -void LineEdit::setUndefined(bool enabled = true) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - blockSignals(true); - QLineEdit::setInputMask(""); - QLineEdit::setText(MULTIPLE_VALUE_TEXT); - itsPreviousText = text(); - } - else { - setInputMask(itsInputMask); - setText(itsPreviousText); - } - this->blockSignals(false); -} - -void LineEdit::focusInEvent(QFocusEvent* event) -{ - if (itsUndefined) { - blockSignals(true); - QLineEdit::setInputMask(itsInputMask); - QLineEdit::setText(itsDefaultText); - itsPreviousText = text(); - itsPreviousUndefined = true; - blockSignals(false); - } - - QLineEdit::focusInEvent(event); -} - -void LineEdit::focusOutEvent(QFocusEvent* event) -{ - if (itsUndefined) - checkTextChange(); - - QLineEdit::focusOutEvent(event); -} - -void LineEdit::checkTextChange(void) { - if (itsUndefined) { - if (itsPreviousText == text()) { // did not change? - blockSignals(true); - QLineEdit::setInputMask(""); - QLineEdit::setText(MULTIPLE_VALUE_TEXT); - blockSignals(false); - } - else { - itsUndefined = false; - } - } -} diff --git a/SAS/Scheduler/src/LineEdit.h b/SAS/Scheduler/src/LineEdit.h deleted file mode 100644 index c9953ba4e99513c57ef5b2be2dabe56470ea5f82..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/LineEdit.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * LineEdit.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/LineEdit.h $ - * - */ - -#include <QLineEdit> -#include <string> - -#ifndef LINEEDIT_H_ -#define LINEEDIT_H_ - -class LineEdit : public QLineEdit { - - Q_OBJECT - -public: - LineEdit(QWidget *parent); - virtual ~LineEdit(); - - void setText(const QString &text); - inline void setText(const std::string &text) {setText(QString(text.c_str()));} - inline void setText(const char *text) {setText(QString(text));} - bool hasBeenChanged(void) const { - if (itsUndefined) return false; - else if (itsPreviousUndefined) return true; - else if (itsPreviousText != text()) return true; - else return false; - } - void setUndefined(bool enabled); - void setDefaultText(const QString &text) {itsDefaultText = text;} - bool isUndefined(void) {return itsUndefined;} - void setInputMask(const QString &mask) {QLineEdit::setInputMask(mask); itsInputMask = mask;} - void resetChangeDetect(void) {itsPreviousText = text();} - -protected: - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkTextChange(void); - -private: - bool itsUndefined, itsPreviousUndefined; - QString itsPreviousText, itsDefaultText, itsInputMask; -}; - -#endif /* LINEEDIT_H_ */ diff --git a/SAS/Scheduler/src/ListWidget.cpp b/SAS/Scheduler/src/ListWidget.cpp deleted file mode 100644 index 155aa64cd5575ed8aa157608cb4bbfeac3991209..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/ListWidget.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ListWidget.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 13-feb-2013 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/ListWidget.cpp $ - * - */ - -#include "ListWidget.h" -#include "lofar_scheduler.h" -#include <QFocusEvent> - -ListWidget::ListWidget(QWidget *parent) - : QListWidget(parent), itsUndefined(false) -{ -} - -ListWidget::~ListWidget() { -} - - -void ListWidget::addItems(const QStringList &names, const QStringList &checkedNames) { - clear(); - for (QStringList::const_iterator it = names.begin(); it != names.end(); ++it) { - QListWidgetItem *item = new QListWidgetItem(*it, this); - if (checkedNames.contains(*it)) { - item->setCheckState(Qt::Checked); - } - else { - item->setCheckState(Qt::Unchecked); - } - } - itsPreviousCheckedNames = checkedNames; - itsUndefined = false; -} - -void ListWidget::checkItems(const QStringList &items_to_select) { - this->blockSignals(true); - for (int i = 0; i < count(); ++i) { - if (items_to_select.contains(item(i)->text())) { - item(i)->setCheckState(Qt::Checked); - } - else { - item(i)->setCheckState(Qt::Unchecked); - } - } - itsUndefined =false; - resetChangeDetect(); - - this->blockSignals(false); -} - -QStringList ListWidget::checkedItemsList(void) const { - QStringList list; - int cnt(count()); - for (int i = 0; i < cnt; ++i) { - if (item(i)->checkState() == Qt::Checked) { - list.append(item(i)->text()); - } - } - return list; -} - -QString ListWidget::checkedItemsAsString(void) const { - return checkedItemsList().join(","); -} - -QStringList ListWidget::items(void) const { - QStringList items; - for (int i = 0; i < count(); ++i) { - items.append(item(i)->text()); - } - return items; -} - -void ListWidget::setUndefined(bool enabled) { - this->blockSignals(true); - itsUndefined = enabled; - itsPreviousCheckedNames.clear(); - itsPreviousNames = items(); - clear(); - if (enabled) { - addItem(MULTIPLE_VALUE_TEXT); - } - else { - addItems(itsPreviousNames); - } - this->blockSignals(false); -} - -bool ListWidget::hasBeenChanged(void) const { - return (!isUndefined() && (itsPreviousCheckedNames != checkedItemsList())); -} diff --git a/SAS/Scheduler/src/ListWidget.h b/SAS/Scheduler/src/ListWidget.h deleted file mode 100644 index ff796b0542cb95cb7f4789846e43bb1ee12b81a4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/ListWidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ListWidget.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 13-feb-2013 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/ListWidget.h $ - * - */ - -#include <QListWidget> -#include <QString> -#include <QStringList> - -#ifndef LISTWIDGET_H_ -#define LISTWIDGET_H_ - -class ListWidget : public QListWidget { - - Q_OBJECT - -public: - ListWidget(QWidget *parent); - virtual ~ListWidget(); - -// void setCurrentIndex(int index, bool removeUndefined = true) { -// itsPreviousSelection = selectedIndexes(); setUndefined(false, removeUndefined); -// } -// void setFromString(const QString &t); - void addItems(const QStringList &names, const QStringList &checkedNames = QStringList()); - QString checkedItemsAsString(void) const; - void checkItems(const QStringList &items_to_select); - void setUndefined(bool enabled = true); - bool isUndefined(void) const {return itsUndefined;} - bool hasBeenChanged(void) const; - void resetChangeDetect(void) { - itsPreviousCheckedNames = checkedItemsList(); - } - -private: - QStringList checkedItemsList(void) const; - QStringList items(void) const; - -private: - bool itsUndefined; - QStringList itsPreviousNames, itsPreviousCheckedNames; -}; - -#endif /* LISTWIDGET_H_ */ diff --git a/SAS/Scheduler/src/OTDBnode.cpp b/SAS/Scheduler/src/OTDBnode.cpp deleted file mode 100644 index bf1aa394843c8c457e5aa0486d37010a81cf662a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/OTDBnode.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * OTDBnode.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 12-feb-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/OTDBnode.cpp $ - * - */ - -#include "OTDBnode.h" -#include "lofar_utils.h" -#include <QSqlRecord> -#include <QVariant> -#include <iostream> -using std::endl; - -OTDBnode::OTDBnode(int treeID, const QSqlQuery &query) : - itsTreeID(treeID) -{ - // nodeid - itsNodeID = query.value(query.record().indexOf("nodeid")).toInt(); - // parentid - itsParentID = query.value(query.record().indexOf("parentid")).toInt(); - // paramdefid - itsParamDefID = query.value(query.record().indexOf("paramdefid")).toInt(); - // name - itsName = query.value(query.record().indexOf("name")).toString().toStdString(); - // index - itsIndex = query.value(query.record().indexOf("index")).toInt(); - // leaf - itsIsLeaf = query.value(query.record().indexOf("leaf")).toBool(); - // instances - itsInstances = query.value(query.record().indexOf("instances")).toInt(); - // limits - itsLimits = query.value(query.record().indexOf("limits")).toString().toStdString(); - // description - itsDescription = query.value(query.record().indexOf("description")).toString().toStdString(); -} - -// -// print(ostream&): os& -// -// print Tree charateristics. -std::ostream& OTDBnode::print (std::ostream& os) const -{ - os << "treeID : " << itsTreeID << endl - << "nodeID : " << itsNodeID << endl - << "parentID : " << itsParentID << endl - << "paramdefID: " << itsParamDefID << endl - << "name : " << itsName << endl - << "index : " << itsIndex << endl - << "leaf : " << ((itsIsLeaf) ? "T" : "F") << endl - << "instances : " << itsInstances << endl - << "limits : " << itsLimits << endl - << "descr. : " << itsDescription << endl; - - return (os); -} - -std::ostream& operator<< (std::ostream &out, const OTDBnode &node) { - write_primitive<int>(out, node.itsTreeID); - write_primitive<int>(out, node.itsNodeID); - write_primitive<int>(out, node.itsParentID); - write_primitive<int>(out, node.itsParamDefID); - write_string(out, node.itsName); - write_primitive<int>(out, node.itsIndex); - write_primitive<bool>(out, node.itsIsLeaf); - write_primitive<int>(out, node.itsInstances); - write_string(out, node.itsLimits); - write_string(out, node.itsDescription); - return out; -} - -std::istream& operator>> (std::istream &in, OTDBnode &node) { - read_primitive<int>(in, node.itsTreeID); - read_primitive<int>(in, node.itsNodeID); - read_primitive<int>(in, node.itsParentID); - read_primitive<int>(in, node.itsParamDefID); - read_string(in, node.itsName); - read_primitive<int>(in, node.itsIndex); - read_primitive<bool>(in, node.itsIsLeaf); - read_primitive<int>(in, node.itsInstances); - read_string(in, node.itsLimits); - read_string(in, node.itsDescription); - return in; -} diff --git a/SAS/Scheduler/src/OTDBnode.h b/SAS/Scheduler/src/OTDBnode.h deleted file mode 100644 index 127bec4539b121bf34e00703f4bcbe5900eb5aca..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/OTDBnode.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * OTDBnode.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 12-feb-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/OTDBnode.h $ - * - * An OTDBnode describes a single item/element of the OTDB. An item can be a node or a parameter. - * Note: it does NOT contain the value of the item. - * - */ - -#ifndef OTDBnode_H_ -#define OTDBnode_H_ - -#include <ostream> -#include <istream> -#include <QSqlQuery> - -//const char * SAS_node_names [9] = {"nodeid", "parentid", "paramdefid", "name", "index", "leaf", "instances", "limits", "description"}; - -class OTDBnode { -public: - OTDBnode() : itsTreeID(0), itsNodeID(0), itsParentID(0), itsParamDefID(0), - itsIndex(0), itsIsLeaf(false), itsInstances(0) {}; - OTDBnode(int treeID, const QSqlQuery &query); - ~OTDBnode() {}; - - int treeID(void) const { return itsTreeID; } - int nodeID(void) const { return itsNodeID; } - int parentID(void) const { return itsParentID; } - int paramDefID(void) const { return itsParamDefID; } - int instances(void) const { return itsInstances; } - const std::string &name(void) const {return itsName;} - const std::string &limits(void) const { return itsLimits; } - const std::string &description(void) { return itsDescription; } - - friend std::ostream& operator<< (std::ostream &out, const OTDBnode &OTDBnode); // used for writing data to binary file - friend std::istream& operator>> (std::istream &in, OTDBnode &OTDBnode); // used for reading data from binary file - - std::ostream& print (std::ostream& os) const; - - friend class SASConnection; // SASConnection may change or init a OTDBnode - -private: - OTDBnode(int aTreeID, int aNodeID, int aParentID, int aParamDefID) : - itsTreeID(aTreeID), itsNodeID(aNodeID), itsParentID(aParentID), itsParamDefID(aParamDefID) {}; - -private: - int itsTreeID; - int itsNodeID; - int itsParentID; - int itsParamDefID; - std::string itsName; - int itsIndex; - bool itsIsLeaf; - int itsInstances; - std::string itsLimits; - std::string itsDescription; -}; - -#endif /* OTDBnode_H_ */ diff --git a/SAS/Scheduler/src/OTDBtree.cpp b/SAS/Scheduler/src/OTDBtree.cpp deleted file mode 100644 index 5602ab875ee8994cce10f82f6f9c8505da462e34..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/OTDBtree.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* - * OTDBtree.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 9-feb-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/OTDBtree.cpp $ - * Description : This 'value' class holds the SAS metadata of a single SAS VIC-tree - * - */ - -#include "OTDBtree.h" -#include "lofar_utils.h" -#include <QSqlRecord> -#include <QVariant> -#include <QDateTime> -#include <iostream> -using std::endl; - -const char *SAS_states_strings[15] = {"IDLE", "DESCRIBED", "PREPARED", "APPROVED", "ON_HOLD", "CONFLICT", - "PRESCHEDULED", "SCHEDULED", "QUEUED", "ACTIVE", "COMPLETING", "FINISHED", "ABORTED", "ERROR", "OBSOLETE"}; - -// TODO: Upgrade SAS_states_strings to sas_state to string map create a config header which is -// included in all the sources -std::string sasStateString(int sas_state) { - switch (sas_state) { - case SAS_STATE_IDLE: - return SAS_states_strings[0]; - break; - case SAS_STATE_DESCRIBED: - return SAS_states_strings[1]; - break; - case SAS_STATE_PREPARED: - return SAS_states_strings[2]; - break; - case SAS_STATE_APPROVED: - return SAS_states_strings[3]; - break; - case SAS_STATE_ON_HOLD: - return SAS_states_strings[4]; - break; - case SAS_STATE_CONFLICT: - return SAS_states_strings[5]; - break; - case SAS_STATE_PRESCHEDULED: - return SAS_states_strings[6]; - break; - case SAS_STATE_SCHEDULED: - return SAS_states_strings[7]; - break; - case SAS_STATE_QUEUED: - return SAS_states_strings[8]; - break; - case SAS_STATE_ACTIVE: - return SAS_states_strings[9]; - break; - case SAS_STATE_COMPLETING: - return SAS_states_strings[10]; - break; - case SAS_STATE_FINISHED: - return SAS_states_strings[11]; - break; - case SAS_STATE_ABORTED: - return SAS_states_strings[12]; - break; - case SAS_STATE_ERROR: - return SAS_states_strings[13]; - break; - case SAS_STATE_OBSOLETE: - return SAS_states_strings[14]; - break; - } - return "Unknown"; -} - -const char * PROCESS_SUBTYPES[NR_PROCESS_SUBTYPES] = {"Averaging Pipeline", "Beam Observation", "Calibration Pipeline", - "Imaging Pipeline", "Imaging Pipeline MSSS", "Long Baseline Pipeline", "Pulsar Pipeline", - "Interferometer", "STAND_ALONE", "TBB (piggyback)", "TBB (standalone)", "", "Unknown Process Subtype"}; - -processSubTypes stringToProcessSubType(const QString &str) { - for (short i = 0; i < _END_PROCESS_SUBTYPE_ENUM_; ++i) { - if (str.toUpper().compare(QString(PROCESS_SUBTYPES[i]).toUpper()) == 0) { - return static_cast<processSubTypes>(i); - } - } - return static_cast<processSubTypes>(PST_UNKNOWN); -} - -OTDBtree::OTDBtree() -: itsTreeID(0), itsMomID(0), itsGroupID(0), itsClassification(0), itsCreator("scheduler"), itsProcessSubtype(PST_UNKNOWN), itsTreeType(0), - itsTreeState(SAS_STATE_IDLE), itsOriginalTree(0) -{ - // default constructor is ok -} - -OTDBtree::OTDBtree(const QSqlQuery &query) { - // treeid - itsTreeID = query.value(query.record().indexOf("treeid")).toInt(); - // momid - itsMomID = query.value(query.record().indexOf("momid")).toInt(); - // groupid - itsGroupID = query.value(query.record().indexOf("groupid")).toInt(); - // classification - itsClassification = query.value(query.record().indexOf("classification")).toInt(); - // creator - itsCreator = query.value(query.record().indexOf("creator")).toString().toStdString(); - // creationDate - itsCreationDate = AstroDateTime(query.value(query.record().indexOf("creationdate")).toDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString()); - // creationDate - itsModificationDate = AstroDateTime(query.value(query.record().indexOf("modificationdate")).toDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString()); - // type - itsTreeType = query.value(query.record().indexOf("type")).toInt(); - // state - itsTreeState = static_cast<SAS_task_status>(query.value(query.record().indexOf("state")).toInt()); - // processType - itsProcessType = query.value(query.record().indexOf("processtype")).toString().toUpper(); - // processSubtype - itsProcessSubtype = stringToProcessSubType(query.value(query.record().indexOf("processsubtype")).toString()); - // strategy - itsStrategy = query.value(query.record().indexOf("strategy")).toString(); - // originalTree - itsOriginalTree = query.value(query.record().indexOf("originaltree")).toInt(); - // campaign - itsCampaign = query.value(query.record().indexOf("campaign")).toString().toStdString(); - // starttime - if (!query.value(query.record().indexOf("starttime")).isNull()) - itsStarttime = AstroDateTime(query.value(query.record().indexOf("starttime")).toDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString()); - // stoptime - if (!query.value(query.record().indexOf("stoptime")).isNull()) - itsStoptime = AstroDateTime(query.value(query.record().indexOf("stoptime")).toDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString()); - // description - itsDescription = query.value(query.record().indexOf("description")).toString().toStdString(); -} - -OTDBtree::~OTDBtree() { - // default destructor is ok -} - -// -// print(ostream&): os& -// -// Show Tree charateristics. -std::ostream& OTDBtree::print (std::ostream& os) const -{ - os - << "treeID : " << itsTreeID << endl - << "momID : " << itsMomID << endl - << "groupID : " << itsGroupID << endl - << "classification : " << itsClassification << endl - << "creator : " << itsCreator << endl - << "creationDate : " << itsCreationDate.toString() << endl - << "modificationDate: " << itsModificationDate.toString() << endl - << "type : " << itsTreeType << endl - << "state : " << itsTreeState << endl - << "processType : " << itsProcessType.toStdString() << endl - << "processSubType : " << std::string(getProcessSubtypeStr()) << endl - << "strategy : " << itsStrategy.toStdString() << endl - << "originalTree : " << itsOriginalTree << endl - << "campaign : " << itsCampaign << endl - << "starttime : " << itsStarttime.toString() << endl - << "stoptime : " << itsStoptime.toString() << endl - << "description : " << itsDescription << endl; - - return (os); -} - -std::ostream& operator<< (std::ostream &out, const OTDBtree &meta_data) { - out << meta_data.itsTreeID - << meta_data.itsMomID - << meta_data.itsGroupID - << meta_data.itsOriginalTree - << meta_data.itsClassification - << meta_data.itsTreeType - << (quint16) meta_data.itsTreeState - << meta_data.itsProcessType.toStdString() << std::string(PROCESS_SUBTYPES[meta_data.itsProcessSubtype]) << meta_data.itsStrategy.toStdString() - << meta_data.itsCreator - << meta_data.itsCampaign - << meta_data.itsDescription - << meta_data.itsCreationDate.toString() - << meta_data.itsModificationDate.toString() - << meta_data.itsStarttime.toString() - << meta_data.itsStoptime.toString(); - - return out; -} - -QDataStream& operator<< (QDataStream &out, const OTDBtree &meta_data) { - out << meta_data.itsTreeID - << meta_data.itsMomID - << meta_data.itsGroupID - << meta_data.itsOriginalTree - << meta_data.itsClassification - << meta_data.itsTreeType - << (quint16) meta_data.itsTreeState - << meta_data.itsProcessType.toStdString() << std::string(PROCESS_SUBTYPES[meta_data.itsProcessSubtype]) << meta_data.itsStrategy.toStdString() - << meta_data.itsCreator - << meta_data.itsCampaign - << meta_data.itsDescription - << meta_data.itsCreationDate - << meta_data.itsModificationDate - << meta_data.itsStarttime - << meta_data.itsStoptime; - - return out; -} - -QDataStream& operator>> (QDataStream &in, OTDBtree &meta_data) { - in >> meta_data.itsTreeID - >> meta_data.itsMomID - >> meta_data.itsGroupID - >> meta_data.itsOriginalTree - >> meta_data.itsClassification - >> meta_data.itsTreeType; - quint16 treestate; - QString strVal; - in >> treestate; - meta_data.itsTreeState = (SAS_task_status) treestate; - in >> meta_data.itsProcessType; - in >> strVal; - meta_data.itsProcessSubtype = stringToProcessSubType(strVal); - in >> meta_data.itsStrategy - >> meta_data.itsCreator - >> meta_data.itsCampaign - >> meta_data.itsDescription - >> meta_data.itsCreationDate - >> meta_data.itsModificationDate - >> meta_data.itsStarttime - >> meta_data.itsStoptime; - - return in; -} diff --git a/SAS/Scheduler/src/OTDBtree.h b/SAS/Scheduler/src/OTDBtree.h deleted file mode 100644 index 7d720f169ec2270fa3cf6e71d38672b8a8623eca..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/OTDBtree.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * OTDBtree.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 9-feb-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/OTDBtree.h $ - * Description : This 'value' class holds the SAS metadata of a single SAS VIC-tree - * - */ - -#ifndef OTDBtree_H_ -#define OTDBtree_H_ - -enum SAS_task_status { - SAS_STATE_IDLE = 0, - SAS_STATE_DESCRIBED = 100, - SAS_STATE_PREPARED = 200, - SAS_STATE_APPROVED = 300, // the state where the observation has been approved by all parties - SAS_STATE_ON_HOLD = 320, - SAS_STATE_CONFLICT = 335, - SAS_STATE_PRESCHEDULED = 350, - SAS_STATE_SCHEDULED = 400, // the state scheduled if the observation has a start and stop time and can be started - SAS_STATE_QUEUED = 500, // the state the SAS observation is being started - SAS_STATE_ACTIVE = 600, // when the SAS observation is running - SAS_STATE_COMPLETING = 900, - SAS_STATE_FINISHED = 1000, - SAS_STATE_ABORTED = 1100, - SAS_STATE_ERROR = 1150, - SAS_STATE_OBSOLETE = 1200 -}; - -extern const char *SAS_states_strings[15]; - -enum processSubTypes { - PST_AVERAGING_PIPELINE, - PST_BEAM_OBSERVATION, - PST_CALIBRATION_PIPELINE, - PST_IMAGING_PIPELINE, - PST_MSSS_IMAGING_PIPELINE, - PST_LONG_BASELINE_PIPELINE, - PST_PULSAR_PIPELINE, - PST_INTERFEROMETER, - PST_STAND_ALONE, - PST_TBB_PIGGYBACK, - PST_TBB_STANDALONE, - PST_EMPTY, - PST_UNKNOWN, - _END_PROCESS_SUBTYPE_ENUM_ -}; - -#define NR_PROCESS_SUBTYPES _END_PROCESS_SUBTYPE_ENUM_ -extern const char * PROCESS_SUBTYPES[NR_PROCESS_SUBTYPES]; - -#include <string> -#include <QString> -#include <QSqlQuery> -#include "astrodatetime.h" - -extern processSubTypes stringToProcessSubType(const QString &str); -std::string sasStateString(int sas_state); - -class OTDBtree { -public: - OTDBtree(); - OTDBtree(const QSqlQuery &query); - ~OTDBtree(); - - inline quint32 treeID(void) const {return itsTreeID;} - inline quint32 momID(void) const {return itsMomID;} - inline quint32 groupID(void) const {return itsGroupID;} - inline quint16 classification(void) const {return itsClassification;} - inline const std::string &creator(void) const {return itsCreator;} - inline const AstroDateTime &creationDate(void) const {return itsCreationDate;} - inline const AstroDateTime &modificationDate(void) const {return itsModificationDate;} - inline const QString &processType(void) const {return itsProcessType;} - inline processSubTypes processSubType(void) const {return itsProcessSubtype;} - inline const char *getProcessSubtypeStr(void) const {return PROCESS_SUBTYPES[itsProcessSubtype];} - inline const QString &strategy(void) const {return itsStrategy;} - quint16 type(void) const {return itsTreeType;} - SAS_task_status state(void) const {return itsTreeState;} - inline const std::string &description(void) const {return itsDescription;} - inline int originalTree(void) const {return itsOriginalTree;} - inline const std::string &campaign(void) const {return itsCampaign;} - inline const AstroDateTime &startTime(void) const {return itsStarttime;} - inline const AstroDateTime &stopTime(void) const {return itsStoptime;} - - void setProcessType(const QString &ptype) {itsProcessType = ptype;} - void setProcessSubtype(processSubTypes pstype) {itsProcessSubtype = pstype;} - void setStrategy(const QString &strategy) {itsStrategy = strategy;} - void setOriginalTreeID(int parentID) {itsOriginalTree = parentID;} - void setState(SAS_task_status state) {itsTreeState = state;} - void resetTimes(void) {itsStarttime.clear(); itsStoptime.clear();} - void setStartTime(const AstroDateTime &start) {itsStarttime = start;} - void setStopTime(const AstroDateTime &stop) {itsStoptime = stop;} - - // Show treeinfo - std::ostream& print (std::ostream& os) const; - - // let SASConnection have access to my data members -// friend class SASConnection; - friend class Task; - - friend std::ostream& operator<< (std::ostream &out, const OTDBtree &meta_data); - friend QDataStream& operator<< (QDataStream &out, const OTDBtree &meta_data); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, OTDBtree &meta_data); // used for reading data from binary file - -private: - quint32 itsTreeID, itsMomID, itsGroupID; - quint16 itsClassification; // development / test / operational - std::string itsCreator; - AstroDateTime itsCreationDate, itsModificationDate; // in SAS software this is a boost ptime object - QString itsProcessType, /*itsProcessSubtype, */itsStrategy; - processSubTypes itsProcessSubtype; - quint16 itsTreeType; // hardware / VItemplate / VHtree - SAS_task_status itsTreeState; // idle / configure / ... / active / ... - std::string itsDescription; // free text - quint32 itsOriginalTree; - std::string itsCampaign; - AstroDateTime itsStarttime; // in SAS software this is a boost ptime object - AstroDateTime itsStoptime; // in SAS software this is a boost ptime object -}; - -#endif /* OTDBtree_H_ */ diff --git a/SAS/Scheduler/src/SASConnection.cpp b/SAS/Scheduler/src/SASConnection.cpp deleted file mode 100644 index 395f032285d9bce5a3ccdb90982fb15f1c8b50b4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/SASConnection.cpp +++ /dev/null @@ -1,5056 +0,0 @@ -/* - * SASConnection.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 8-febr-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/SASConnection.cpp $ - * - */ - -#include <QDateTime> -#include <QSqlError> -#include <QSqlRecord> -#include <QMessageBox> -#include <QString> -#include <QProgressDialog> -#include "lofar_utils.h" -#include "SASConnection.h" -#include "Controller.h" -#include "sasstatusdialog.h" -using std::string; -using std::vector; -using std::map; - -SASConnection::SASConnection(void) - : itsController(0), itsUploadDialog(0) -{ - QSqlDatabase::addDatabase( "QPSQL", "SASDB" ); -} - -SASConnection::SASConnection(Controller *controller) - : itsController(controller) -{ - QSqlDatabase::addDatabase( "QPSQL", "SASDB" ); - itsUploadDialog = new SASUploadDialog(0, itsController); -} - -SASConnection::~SASConnection() { - QSqlDatabase::database( "SASDB" ).close(); - QSqlDatabase::removeDatabase( "SASDB" ); - - if (itsUploadDialog) { - delete itsUploadDialog; - } -} - -void SASConnection::init(const QString &username, const QString &password, const QString &DBName, const QString &hostname) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlDatabase::database( "SASDB" ).close(); - QSqlDatabase::removeDatabase( "SASDB" ); - sasDB = QSqlDatabase::addDatabase("QPSQL","SASDB"); - - itsSASUserName = username; - itsSASPassword = password; - sasDB.setHostName(hostname); - sasDB.setDatabaseName(DBName); - sasDB.setUserName("postgres"); - sasDB.setPassword(""); -} - -void SASConnection::cleanup(void) { - clearItsSASTasks(); - itsMomToSasIDmap.clear(); - itsSASVicTrees.clear(); - itsChangedTasks.clear(); - itsNewSchedulerTasks.clear(); - itsTreesToDelete.clear(); - itsSASdeletedTrees.clear(); -} - -int SASConnection::testConnect(const QString &username, const QString &password, const QString &DBname, const QString &hostname) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - sasDB.close(); - QSqlDatabase::removeDatabase( "SASDB" ); - sasDB = QSqlDatabase::addDatabase("QPSQL","SASDB"); - sasDB.setUserName("postgres"); - sasDB.setPassword(""); - sasDB.setHostName(hostname); - sasDB.setDatabaseName(DBname); - - if (!sasDB.open()) { - return -1; // could not connect to SAS database - } - else { - QSqlQuery query(sasDB); - query.exec("SELECT OTDBlogin('" + username + "','" + password + "')"); - if (query.next()) { - if (query.value(0).toUInt() == 0) { // check authentication token (should not be zero) - return -2; // no write permissions to SAS DB - } - } - else return -3; // could not execute query on database - query.finish(); - } - //cleanup test connection to database - return 0; // test OK. -} - - -QString SASConnection::lastConnectionError(void) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - return sasDB.lastError().text(); -} - -int SASConnection::connect(void) { - return connect(Controller::theSchedulerSettings.getSASUserName(), - Controller::theSchedulerSettings.getSASPassword(), - Controller::theSchedulerSettings.getSASDatabase(), - Controller::theSchedulerSettings.getSASHostName()); -} - -int SASConnection::connect(const QString &user, const QString &password, const QString &DBName, const QString &hostName) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QVariant value; - if (!sasDB.open()) { // sasDB could not be opened, re-init connection - init(user, password, DBName, hostName); - if (!sasDB.open()) { - debugErr("sssssss","Could not establish SAS connection! Settings used:\n", - "Username: ", sasDB.userName().toStdString().c_str(), - ", database: ", sasDB.databaseName().toStdString().c_str(), - ", hostname: ", sasDB.hostName().toStdString().c_str() - ); - return -1; // could not connect to SAS database - } - } - if (sasDB.isOpen()) { - QSqlQuery query(sasDB); - if (itsAuthToken.isEmpty()) { - query.exec("SELECT OTDBlogin('" + itsSASUserName + "','" + itsSASPassword + "')"); - if (query.next()) { - itsAuthToken = query.value(0).toString(); - if (itsAuthToken.isEmpty()) { - return -2; // no write permissions to SAS DB - } - } - query.finish(); - } - -/* - if (itsDataslotTemplateIDstr.isEmpty()) { - // get the node ID of the dataslotsinfo node in the default template tree (needed to be able to create and save dataslot info for new trees) - query.exec("SELECT nodeid from getVTitemList(" + QString::number(Controller::theSchedulerSettings.getSchedulerDefaultTemplate()) + ",'DataslotInfo')"); - if (query.next()) { - itsDataslotTemplateIDstr = query.value(0).toString(); - } - query.finish(); - } -*/ - - // get the list of campaigns from SAS - getCampaignsFromSAS(); - } - return 0; -} - - -int SASConnection::getModifiedVICTrees(const QDateTime &afterdate) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - - // check which trees still exist in sas database and remove them from itsSASVicTrees if they don't exist anymore - std::vector<unsigned> existingVICs; - QSqlQuery query("SELECT treeid FROM gettreelist('" + QString::number(VIC_TREE) + "','0',0,'','','')", sasDB); - if (query.isActive()) { - while (query.next()) { - existingVICs.push_back(query.value(0).toUInt()); - } - } - query.finish(); - itsSASdeletedTrees.clear(); - for (std::map<unsigned, OTDBtree>::const_iterator oit = itsSASVicTrees.begin(); oit != itsSASVicTrees.end(); ++oit) { - if (std::find(existingVICs.begin(), existingVICs.end(), oit->first) == existingVICs.end()) { - itsSASdeletedTrees.push_back(oit->first); - } - } - for (std::vector<unsigned>::const_iterator vit = itsSASdeletedTrees.begin(); vit != itsSASdeletedTrees.end(); ++vit) { - itsSASVicTrees.erase(*vit); - } - - // clear out itsSASmodifiedTasks - for (std::map<unsigned, Task *>::const_iterator mit = itsSASmodifiedTasks.begin(); mit != itsSASmodifiedTasks.end(); ++mit) { - delete mit->second; - } - itsSASmodifiedTasks.clear(); - - AstroDateTime start_date(Controller::theSchedulerSettings.getEarliestSchedulingDay()); - AstroDateTime end_date = Controller::theSchedulerSettings.getLatestSchedulingDay().addDays(1); - // add 1 second to prevent false positives of external changed tasks being caused by slow updates in OTDB of changes made by me - QString fromDate(afterdate.addSecs(1).toString("yyyy-MM-dd hh:mm:ss")); - - // update the last download date before actually getting the changes. - // This should make sure that changes made during this download will still be fetched next time a synchronize is run - QDateTime prevDate(itsLastDownloadDate); - updateLastDownloadDate(); - - query.exec("SELECT * from getmodifiedtrees('" + - fromDate + "','" + - QString::number(VIC_TREE) + "')"); - - if (query.isActive()) { - std::pair<bool ,Task *> retVal; - while (query.next()) { - OTDBtree otdb_tree(query); - const unsigned &otdbTreeID(otdb_tree.treeID()); - // update the task in itsSASVicTrees when it was already in there - std::map<unsigned, OTDBtree>::iterator sit = itsSASVicTrees.find(otdbTreeID); - if (sit != itsSASVicTrees.end()) { - // task was already downloaded before, thus it needs updating again (download it again) - retVal = getTaskFromSAS(otdbTreeID, otdb_tree); - if (retVal.second) { - sit->second = retVal.second->SASTree(); // replace the tree in itsSASVicTrees with the updated tree - itsSASmodifiedTasks.insert(std::map<unsigned, Task *>::value_type(otdbTreeID, retVal.second)); // also put in itsSASmodifiedTasks - } - } - else { // new tree that was not downloaded before - // only download the tree if the start date is within the scheduling period or if the start time is not set - if (!otdb_tree.startTime().isSet() || (otdb_tree.startTime() >= start_date && otdb_tree.stopTime() <= end_date)) { - retVal = getTaskFromSAS(otdbTreeID, otdb_tree); - if (retVal.second) { - itsSASmodifiedTasks.insert(std::map<unsigned, Task *>::value_type(otdbTreeID, retVal.second)); - itsSASVicTrees.insert(std::map<unsigned, OTDBtree>::value_type(otdbTreeID, retVal.second->SASTree())); - } - } - } - } - } - else { - itsLastDownloadDate = prevDate; - return -1;// could not fetch any task from SAS, query not valid - } - - query.finish(); - - // also update all OTDBtrees in itsSASVicTrees that had a status change after itsLastDownloadDate and were already in itsSASVicTrees - // use the SAS sql procedure getstatelist without a tree ID to get all state changes after a certain datetime - query.exec("SELECT * FROM getstatelist(0,false,'" + fromDate + "',NULL) ORDER BY modtime DESC"); - SAStasks::const_iterator sasit; - if (query.isActive()) { - unsigned treeID; - SAS_task_status SASstate; - std::pair<bool, Task *> retVal; - while (query.next()) { - treeID = query.value(query.record().indexOf("treeid")).toUInt(); - if (itsSASVicTrees.find(treeID) != itsSASVicTrees.end()) { // only consider the state change if the task is already downloaded in the scheduler - if (itsSASmodifiedTasks.find(treeID) == itsSASmodifiedTasks.end()) { // don't check state change if the task is already marked as changed and thus already in itsSASmodifiedTasks - sasit = itsSASTasks.find(treeID); - if (sasit != itsSASTasks.end()) { - SASstate = static_cast<SAS_task_status>(query.value(query.record().indexOf("state")).toInt()); - if (SASstate != sasit->second->getSAStreeState()) { // if current state in SAS is different from previously downloaded task state - retVal = getTaskFromSAS(treeID); - if (retVal.second) { - itsSASmodifiedTasks.insert(std::map<unsigned, Task *>::value_type(treeID, retVal.second)); - itsSASVicTrees[treeID] = retVal.second->SASTree(); - } - } - } - } - } - } - } - query.finish(); - - return 0; -} - -void SASConnection::updateLastDownloadDate(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT now()", sasDB); - if (query.isActive()) { - if (query.next()) { - itsLastDownloadDate = QDateTime::fromString(query.value(0).toString(),"yyyy-MM-ddThh:mm:ss"); // one second added because some sas stored procedures will return changes *equal to* and greater this modification date, not - } - } - query.finish(); -} - -// function getAllSASTasksWithinPeriod gets all OTDB trees (not complete vic trees but only their metadata) within the specified period -// This function will also check if the tree depends (has predecessors) on other trees and will the also download those predecessor trees -int SASConnection::getAllSASTasksWithinPeriod(int treeType, const AstroDateTime &begindate, const AstroDateTime &enddate) { - int retVal(0); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - itsSASVicTrees.clear(); - QDateTime start_date = begindate.toQDateTime(), end_date = enddate.toQDateTime(); - - QSqlQuery query("SELECT * from getTreesInPeriod('" + - QString::number(treeType) + "','" + - start_date.toString("yyyy-MM-dd hh:mm:ss") + "','" + - end_date.toString("yyyy-MM-dd hh:mm:ss") + "')", sasDB); - - if (query.isActive()) { - while (query.next()) { - OTDBtree tree(query); - itsSASVicTrees.insert(std::map<unsigned, OTDBtree>::value_type(tree.treeID(), tree)); - } - query.finish(); - } - else { - query.finish(); - return -1;// could not fetch any task from SAS query not valid - } - - if (!fetchAllPredecessorTasks()) { - retVal = -2; // not all predecessors could be fetched from SAS - } - - // store IDs in MomId to SasId table - updateMoMToSasIDmapping(); - - return retVal; -} - -void SASConnection::updateMoMToSasIDmapping(void) { - for (std::map<unsigned, OTDBtree>::const_iterator it = itsSASVicTrees.begin(); it != itsSASVicTrees.end(); ++it) { - itsMomToSasIDmap[it->second.momID()] = it->second.treeID(); - } -} - -bool SASConnection::alreadyDownloaded(unsigned id, id_type IDtype) const { - if (IDtype == ID_MOM) { - for (std::map<unsigned, OTDBtree>::const_iterator sit = itsSASVicTrees.begin(); sit != itsSASVicTrees.end(); ++sit) { - if (sit->second.momID() == id) return true; - } - } - else if (IDtype == ID_SAS) { - for (std::map<unsigned, OTDBtree>::const_iterator sit = itsSASVicTrees.begin(); sit != itsSASVicTrees.end(); ++sit) { - if (sit->first == id) return true; - } - } - return false; -} - -void SASConnection::translateMomPredecessors(IDvector &predecessors) { - unsigned pred; - for (IDvector::iterator it = predecessors.begin(); it != predecessors.end(); ++it) { - if (it->first == ID_MOM) { - pred = itsMomToSasIDmap.value(it->second); - if (pred) { - it->first = ID_SAS; - it->second = pred; - } - } - } -} - -bool SASConnection::fetchAllPredecessorTasks(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - bool bResult(true); - QString IDonly; - QSqlQuery query(sasDB); - std::map<unsigned, OTDBtree> itsTmpSASVicTrees1(itsSASVicTrees), itsTmpSASVicTrees2; - - const QString & ObsIDPrefix(Controller::theSchedulerSettings.getObservationIDprefix()); - - bool fetchPredecessor(false); - if (!itsTmpSASVicTrees1.empty()) { - itsProgressDialog.addText("Now fetching required predecessor tasks..."); - } - while (!itsTmpSASVicTrees1.empty()) { - for (std::map<unsigned, OTDBtree>::const_iterator it_1 = itsTmpSASVicTrees1.begin(); it_1 != itsTmpSASVicTrees1.end(); ++it_1) { - // fetch all predecessor trees from the current tree and put them in itsTmpSASVicTrees2 and in itsSASVicTrees - // first get the predecessor list from the current task - const SAS_task_status &state(it_1->second.state()); - query.exec("SELECT limits from getVHitemList(" + QString::number(it_1->first) + ",'LOFAR.ObsSW.Observation.Scheduler.predecessors')"); - if (query.next()) { - std::vector<QString> predecessors(string2VectorOfStrings(query.value(0).toString())); - query.finish(); - QString isMomID, nonExistingPredecessors; - for (std::vector<QString>::const_iterator it = predecessors.begin(); it != predecessors.end(); ++it) { - // TODO: predecessor specified with scheduler task IDs should be translated to sas id during upload of the task - fetchPredecessor = false; - IDonly = it->right(it->size()-1); - if (it->startsWith('M')) { - if (!alreadyDownloaded(IDonly.toUInt(), ID_MOM)) { - isMomID = "true"; - fetchPredecessor = true; - } - } - else if (it->startsWith(ObsIDPrefix)) { // SAS ID used for predecessor, fetch the predecessor directly - if (!alreadyDownloaded(IDonly.toUInt(), ID_SAS)) { - isMomID = "false"; - fetchPredecessor = true; - } - } - else { - itsProgressDialog.addError(QString("Warning: incorrect predecessor:") + *it + " specified in SAS tree: " + QString::number(it_1->first) + ". Predecessor ID should start with M or " + ObsIDPrefix); - bResult = false; - } - - // fetch the predecessor task and push it in itsTmpSASVicTrees2 - if (fetchPredecessor) { - query.exec("SELECT * from gettreeinfo(" + IDonly + ",'" + isMomID + "')"); - if (query.next()) { - OTDBtree tree(query); - query.finish(); - // check if predecessor is indeed a VIC tree - if (tree.type() == VIC_TREE) { - itsTmpSASVicTrees2.insert(std::map<unsigned, OTDBtree>::value_type(tree.treeID(), tree)); - } - else if (!nonExistingPredecessors.isEmpty()) { - nonExistingPredecessors += ","; - } - else { - nonExistingPredecessors += *it; - } - } - else if (state < SAS_STATE_FINISHED) { // only complain about non-existing predecessors if task still has to be performed - if (!nonExistingPredecessors.isEmpty()) { - nonExistingPredecessors += ","; - } - nonExistingPredecessors += *it; - } - } - } - if (!nonExistingPredecessors.isEmpty()) { - itsProgressDialog.addError(QString("Warning: SAS tree: ") + QString::number(it_1->first) + " contains non-existing predecessor task(s):" + nonExistingPredecessors); - } - } - else { - query.finish(); - itsProgressDialog.addError(QString("Warning: Scheduler.predecessors info of SAS tree: ") + QString::number(it_1->first) + " could not be fetched"); - bResult = false; - } - } - - itsTmpSASVicTrees1 = itsTmpSASVicTrees2; // continue fetching predecessors of predecessors if any, until no more predecessors need fetching - - // add the predecessor trees to itsSASVictrees if they aren't already inserted there (which could happen if a task is also a predecessor - // of another task and therefore was already fetched. - for (std::map<unsigned, OTDBtree>::const_iterator tit = itsTmpSASVicTrees2.begin(); tit != itsTmpSASVicTrees2.end(); ++tit) { - if (itsSASVicTrees.find(tit->first) == itsSASVicTrees.end()) { - itsSASVicTrees.insert(std::map<unsigned, OTDBtree>::value_type(*tit)); - } - } - itsTmpSASVicTrees2.clear(); - } - - return bResult; -} - -int SASConnection::createNewTree(Task &task) { - // step 1: create a new template tree from a default template tree - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - QString authToken(itsAuthToken); -// Task::task_type type(task.getType()); - if (sasDB.isOpen()) { - bool scheduler_template_used(false); - // step 1a: check for the existence of the requested default template, - // if the default template id mentioned in the task is 0 then use the Scheduler default template - // if it doesn't exist then return error - int parentTemplateID = task.getOriginalTreeID(); - if (parentTemplateID == 0) { // unknown default template id, use the Scheduler default template to create this tree - int schedulerDefaultTemplateID = Controller::theSchedulerSettings.getSchedulerDefaultTemplate(); - if (schedulerDefaultTemplateID) { - parentTemplateID = schedulerDefaultTemplateID; - itsProgressDialog.addError(QString("Warning: Task ") + QString::number(task.getID()) + " has unknown parent template ID, using 'Scheduler default template' to create the task in SAS"); - scheduler_template_used = true; - } - else { - itsProgressDialog.addError("'Scheduler default template' does not exist in the database. Could not create the task in SAS"); - return 0; - } - } - - int newTemplateTreeID(0), newVICTreeID(0); - QString newTemplateTreeIDstr; - query.exec("SELECT * from copyTree(" + - authToken + "," + - QString::number(parentTemplateID) + ")"); // constructs a new template tree - if (query.next()) { - newTemplateTreeID = query.value(0).toInt(); - newTemplateTreeIDstr = QString::number(newTemplateTreeID); - query.finish(); - - // set the processType, processSubtype and strategy of the new template if the scheduler default template was used to create it - if (scheduler_template_used) { - query.exec("SELECT assignprocesstype(" + - authToken + "," + - newTemplateTreeIDstr + ",'" + - task.getProcessType() + "','" + - task.getProcessSubtypeStr() + "','" + - task.getStrategy() + "')"); - - if (!query.isActive()) { // query successfully executed? - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - } - query.finish(); - } - - if (task.isObservation()) { - Observation &observation(static_cast<Observation &>(task)); - QString templateBeamNodeID,templateTABNodeID, ObservationNodeID; - // step 2a: (OBSERVATIONs only) create if needed the digital beams, analog beams and pencils (they cannot in principle be created in a VIC tree) - // digital beams - // get the node id of the Beam leaf in the template tree - const std::map<unsigned, DigitalBeam> & digitalBeams = observation.getDigitalBeams(); - query.exec("SELECT nodeid from getVTitem(" + newTemplateTreeIDstr + ",'Observation')"); - if (query.next()) { - ObservationNodeID = query.value(0).toString(); - } - query.finish(); - if (digitalBeams.size() > 0) { - query.exec("SELECT nodeid from getVTitemRecursive(" + newTemplateTreeIDstr + ",'Beam'," + ObservationNodeID + ")"); - if (query.next()) { - templateBeamNodeID = query.value(0).toString(); // the nodeid (as a string) of the digital beam default beam used as 'template' to create new digital beams - query.finish(); - - QString newBeamNodeID; - QString newTABNodeID; - for (std::map<unsigned, DigitalBeam>::const_iterator dit = digitalBeams.begin(); dit != digitalBeams.end(); ++dit) { - query.exec("SELECT dupVTnode(" + authToken + "," + - newTemplateTreeIDstr + "," + - templateBeamNodeID + ",'" + QString::number(dit->first) + "')" - ); - if (query.next()) { - newBeamNodeID = query.value(0).toString(); - saveDigitalBeamToSAStemplate(newTemplateTreeID, newBeamNodeID, dit->second); - } - query.finish(); - - // add the Tied Array Beams for this digital beam - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams = dit->second.tiedArrayBeams(); - if (tiedArrayBeams.size() != 0) { - - // now get the node ID of the Tied Array Beam template component (for this digital beam) - query.exec("SELECT nodeid from getVTitemRecursive(" + newTemplateTreeIDstr + ",'TiedArrayBeam'," + newBeamNodeID + ")"); - if (query.next()) { - templateTABNodeID = query.value(0).toString(); - } - query.finish(); - - for (std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.begin(); tit != tiedArrayBeams.end(); ++tit) { - query.exec("SELECT dupVTnode(" + authToken + "," + - newTemplateTreeIDstr + "," + - templateTABNodeID + ",'" + QString::number(tit->first) + "')" - ); - - if (query.next()) { - newTABNodeID = query.value(0).toString(); // the node id of the newly created tied array beam - saveTiedArrayBeamToSAStemplate(newTemplateTreeID, newTABNodeID, tit->second); - } - query.finish(); - } - - // save the number of Tied Array Beams in the default Tied Array Beam instance property - OTDBnode node = getNode(newTemplateTreeID, templateTABNodeID); - node.itsInstances = tiedArrayBeams.size(); - saveNode(node); - // also set the Beam[x].nrTiedArrayBeams correctly - setTemplateNodeByID(newTemplateTreeID, newBeamNodeID, "nrTiedArrayBeams", QString::number(node.itsInstances)); - } - } - // save the number of beams in the default beam instances property - OTDBnode node = getNode(newTemplateTreeID, templateBeamNodeID); - node.itsInstances = digitalBeams.size(); - saveNode(node); - // also set Observation.nrBeams correctly - setTemplateNodeByID(newTemplateTreeID, ObservationNodeID, "nrBeams", QString::number(digitalBeams.size())); - } - } - - // step2c: also create the single ANALOG BEAM (always, even if not HBA observation to enable later changing to HBA) - query.exec("SELECT nodeid from getVTitemList(" + QString::number(newTemplateTreeID) + ",'AnaBeam')"); - if (query.next()) { - QString analogBeamNodeID = query.value(0).toString(); // the nodeid of the analog template beam, used as template to create an analog beam - query.finish(); - query.exec("SELECT dupVTnode(" + authToken + "," + - QString::number(newTemplateTreeID) + "," + - analogBeamNodeID + ",'0')" - ); - const Observation::analogBeamSettings & analogBeam = observation.getAnalogBeam(); - if (query.next()) { - int nodeID = query.value(0).toInt(); - saveAnalogBeamToSAStemplate(newTemplateTreeID, nodeID, analogBeam); - } - query.finish(); - // save the number of beams in the default beam instances property -// OTDBnode node = getNode(newTemplateTreeID, analogBeamNodeID); -// node.itsInstances = 1; // there can be only one analog beam -// saveNode(node); - setTemplateNodeByID(newTemplateTreeID, ObservationNodeID, "nrAnaBeams", "1"); - } - - - } - - // step : instantiate the VIC tree after which no beams can be added or deleted (but their properties can still be changed) - newVICTreeID = instantiateVICTree(newTemplateTreeID); - if (newVICTreeID != 0) { - task.setSASTreeID(newVICTreeID); - // this is a new task. Check if it has been set (PRE)SCHEDULED. If so generate the file list again so that it includes the SAS ID - Task::task_status status(task.getStatus()); - if (task.hasStorage() && ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED))) { - task.storage()->generateFileList(); - } - // step 4: apply task properties to the new VICtree - saveTaskToSAS(newVICTreeID, task); - } - else { - std::cerr << "ERROR:instantiateVICTree did not succeed" << std::endl << sasDB.lastError().text().toStdString() << std::endl; - } - // step 5: delete the intermediate template tree - query.exec("SELECT deleteTree(" + authToken + "," + QString::number(newTemplateTreeID) + ")"); - return newVICTreeID; - } - else { - std::cerr << "ERROR: could not create new tree. Is the default tree set correctly in the scheduler settings (tab SAS)?" - << query.lastError().text().toStdString() << std::endl; - return 0; - } - } - else { - std::cerr << "createNewTree: SAS db is closed!" << std::endl; - return 0; - } -} - -int SASConnection::instantiateVICTree(int baseTreeID) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - int newTreeID(0); - QSqlQuery query("SELECT * from instanciateVHtree(" + - itsAuthToken + "," + - QString::number(baseTreeID) + ")", sasDB); // constructs AND executes the query - if (query.next()) { - newTreeID = query.value(0).toInt(); - if (newTreeID == 0) { // unable to create new VIC tree - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - } - } - return newTreeID; -} - -// gets the history of state changes for the SAS tree -// the query fields are: 'treeid', 'momid', 'state', 'username' and 'modtime' -void SASConnection::showTaskStateHistory(int treeID) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if (connect() == 0) { - itsStateHistoryDialog.clear(); - if (treeID != 0) { - QSqlQuery query(QString("SELECT * FROM getstatelist(") + QString::number(treeID) + ",false,NULL,NULL)",sasDB); - if (query.isActive()) { - while (query.next()) { - QString treeID = query.value(query.record().indexOf("treeid")).toString(); - QString momID = query.value(query.record().indexOf("momid")).toString(); - QString state = getSasTextState(query.value(query.record().indexOf("state")).toInt()).c_str(); - QString userName = query.value(query.record().indexOf("username")).toString(); - QDateTime datetime = QDateTime::fromString(query.value(query.record().indexOf("modtime")).toString(), "yyyy-MM-ddThh:mm:ss"); - itsStateHistoryDialog.addStateInfo(treeID, momID, state, userName, datetime); - } - itsStateHistoryDialog.show(); - } - else { - QMessageBox::critical(0,QObject::tr("State list retrieve error"), QObject::tr("Could not retrieve the state change history from the SAS database")); - std::cerr << query.lastError().text().toStdString() << std::endl; - } - } - else { - QMessageBox::warning(0,QObject::tr("No history for new task"), QObject::tr("This seems to be a new task which is not in the SAS database yet")); - } - } - else { - QMessageBox::critical(0, QObject::tr("No connection to SAS"), - QObject::tr("Could not connect to SAS database.\n Please check SAS connection settings.")); - } -} - -std::vector<int> SASConnection::getAllVICTreeIDs(void) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - std::vector<int> vicTreeIDs; - QSqlQuery query(QString("SELECT * from gettreelist('") + QString::number(VIC_TREE) +"','0','0','','','')", sasDB); - while (query.next()) { - vicTreeIDs.push_back(query.value(query.record().indexOf("treeID")).toInt()); - } - return vicTreeIDs; -} - -std::vector<unsigned> SASConnection::getUsedSASTaskIDs(void) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - std::vector<unsigned> taskIDs; - QSqlQuery query(QString("SELECT * from getalltaskid()"), sasDB); - while (query.next()) { - taskIDs.push_back(query.value(0).toUInt()); - } - return taskIDs; -} - -// gets the current status of a task from SAS -Task::task_status SASConnection::getTaskStatus(int treeID) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if (sasDB.isOpen()) { - QSqlQuery query("select state from gettreeinfo(" + QString::number(treeID) + ", false)", sasDB); - if (query.next()) { - return convertSASstatus(static_cast<SAS_task_status>(query.value(0).toInt())); - } - } - return Task::TASK_STATUS_END; -} - -AstroDateTime SASConnection::getScheduledStartTime(int treeID) const { - AstroDateTime start; - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if (sasDB.isOpen()) { - QSqlQuery query("SELECT limits from getVHitemList(" + QString::number(treeID) + ",'LOFAR.ObsSW.Observation.startTime')", sasDB); - if (query.next()) { - QString startTimeStr(query.value(0).toString()); - if (!startTimeStr.isEmpty()) { - start = startTimeStr; - } - } - } - return start; -} - - - -Task *SASConnection::createNewTaskFromTree(const OTDBtree &otdb_tree, const QSqlQuery *query) { - Task *pTask(0); - Task::task_type type(taskTypeFromString(otdb_tree.processType().toStdString())); - switch(type) { - case Task::OBSERVATION: - if (query) pTask = new Observation(*query, otdb_tree); - else pTask = new Observation(0, otdb_tree); - break; - case Task::PIPELINE: - switch (otdb_tree.processSubType()) { - case PST_AVERAGING_PIPELINE: - case PST_CALIBRATION_PIPELINE: - if (query) pTask = new CalibrationPipeline(*query, otdb_tree); - else pTask = new CalibrationPipeline(0, otdb_tree); - break; - case PST_IMAGING_PIPELINE: - case PST_MSSS_IMAGING_PIPELINE: - if (query) pTask = new ImagingPipeline(*query, otdb_tree); - else pTask = new ImagingPipeline(0, otdb_tree); - break; - case PST_PULSAR_PIPELINE: - if (query) pTask = new PulsarPipeline(*query, otdb_tree); - else pTask = new PulsarPipeline(0, otdb_tree); - break; - case PST_LONG_BASELINE_PIPELINE: - if (query) pTask = new LongBaselinePipeline(*query, otdb_tree); - else pTask = new LongBaselinePipeline(0, otdb_tree); - break; - default: - if (query) pTask = new Pipeline(*query, otdb_tree); - else pTask = new Pipeline(0, otdb_tree); - break; - } - break; - case Task::RESERVATION: - case Task::MAINTENANCE: - if (query) pTask = new StationTask(*query, otdb_tree, type); - else pTask = new StationTask(0, otdb_tree, type); - break; - case Task::SYSTEM: - default: // unknown task processType - QString err("Unknown processType: " + otdb_tree.processType() + " in tree ID:" + QString::number(otdb_tree.treeID()) + ". Tree not downloaded."); - itsProgressDialog.addError(err); - qDebug() << err; - - break; - } - return pTask; -} - -std::pair<bool, Task *> SASConnection::getTaskFromSAS(int treeID, OTDBtree otdb_tree) { - std::pair<bool, Task *> retVal; - retVal.first = false; - retVal.second = 0; - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - QString treeIDstr(QString::number(treeID)); - if (otdb_tree.treeID() == 0) { // no OTDB_tree supplied fetch it - query.exec("select * from gettreeinfo(" + treeIDstr + ", false)"); - if (query.next()) { - OTDBtree tree(query); - otdb_tree = tree; - query.finish(); - } - } - - //check if this is indeed a VIC tree not a template - if (otdb_tree.type() == VIC_TREE) { - if (query.exec("SELECT * from getSchedulerInfo(" + QString::number(treeID) + ")")) { // first try to fetch all scheduler nodes in one go - if (query.next()) { - retVal.second = createNewTaskFromTree(otdb_tree, &query); - if (retVal.second) { - // now fetch the other non-scheduler-branch settings from the SAS vic tree - if (getSASTaskProperties(treeID, *retVal.second)) { - retVal.first = true; - } - else { - retVal.second->setReason("Warning:not all SAS tree properties could be read"); - retVal.first = false; - } - } - query.finish(); - return retVal; - } - } - else { - query.finish(); - retVal.second = createNewTaskFromTree(otdb_tree); - if (retVal.second) { - if (!getSchedulerInfo(treeID, *retVal.second)) { // fetching all scheduler nodes in one go didn't succeed, try fetching one-by-one - // one of the scheduler settings could not be fetched from SAS - getSASTaskProperties(treeID, *retVal.second); // get other SAS task properties from the SAS VIC tree - retVal.second->setReason("Warning:not all SAS tree properties could be read"); - retVal.first = false; - } - else { - if (getSASTaskProperties(treeID, *retVal.second)) { - retVal.first = true; - } - else { - retVal.second->setReason("Warning:not all SAS tree properties could be read"); - retVal.first = false; - } - } - } - return retVal; - } - } - else { - std::cout << "requested task is not a VIC tree!" << std::endl; - } - - return retVal; -} - -void SASConnection::updateDefaultTemplates(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - Controller::theSchedulerSettings.updateDefaultTemplates(); - // also update the default dataslot node id, used for creating data slots in VIC trees. -/* - QSqlQuery query(sasDB); - query.exec("SELECT nodeid from getVTitemList(" + QString::number(Controller::theSchedulerSettings.getSchedulerDefaultTemplate()) + ",'DataslotInfo')"); - if (query.next()) { - itsDataslotTemplateIDstr = query.value(0).toString(); - } - query.finish(); -*/ -} - - -void SASConnection::clearItsSASTasks(void) { - for (SAStasks::iterator it = itsSASTasks.begin(); it != itsSASTasks.end(); ++it) { - delete it->second; - } - itsSASTasks.clear(); -} - -bool SASConnection::downloadAllSASTasks(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - itsSASVicTrees.clear(); - clearItsSASTasks(); - - if (sasDB.isOpen()) { - updateDefaultTemplates(); - // show the progress dialog - itsProgressDialog.clear(); - itsProgressDialog.show(); - itsProgressDialog.setWindowTitle("Download running schedule from SAS database"); - itsProgressDialog.addText(QObject::tr("Start Download SAS schedule procedure")); - itsProgressDialog.addText(QObject::tr("Starting inventory of tasks to download from SAS database...")); - AstroDateTime endDate = Controller::theSchedulerSettings.getLatestSchedulingDay() + AstroTime("23:59:59"); - - QDateTime prevLastDownloadDate(itsLastDownloadDate); - updateLastDownloadDate(); - - int retVal(getAllSASTasksWithinPeriod(VIC_TREE, Controller::theSchedulerSettings.getEarliestSchedulingDay(), endDate)); - if (retVal == -1) { - itsProgressDialog.addError(QObject::tr("ERROR: could not fetch tasks from SAS. Aborting download!")); - itsProgressDialog.enableClose(); - itsLastDownloadDate = prevLastDownloadDate; - return false; - } - else if (retVal == -2) { - itsProgressDialog.addText(QObject::tr("Warning: Not all predecessor tasks were found in the SAS database.")); - } - size_t nrOfSASTrees = itsSASVicTrees.size(); - if (nrOfSASTrees) { - itsProgressDialog.addText(QObject::tr("Check complete. Number of tasks to download (within scheduling period): ") + - QString::number(nrOfSASTrees)); - itsProgressDialog.addText(QObject::tr("Downloading tasks...")); - } - else { - itsProgressDialog.addText(QObject::tr("Inventory complete. There are no tasks to download from SAS within the schedule period.")); - } - - if (nrOfSASTrees) { - // copy SAS tree's to regular task objects in itsSASTasks map - size_t count(0); - std::pair<bool, Task *> retVal; - for (std::map<unsigned, OTDBtree>::const_iterator it = itsSASVicTrees.begin(); it != itsSASVicTrees.end(); ++it) { - retVal = getTaskFromSAS(it->first, it->second); - if (retVal.second) { - itsSASTasks.insert(SAStasks::value_type(it->first, retVal.second)); - } - itsProgressDialog.setProgressPercentage((++count * 100) / nrOfSASTrees); - } - - itsProgressDialog.addText(QObject::tr("Task download complete.")); - itsProgressDialog.addText(QObject::tr("Number of downloaded valid tasks: ") + QString::number(itsSASTasks.size())); - } - // now insert the downloaded tasks into the schedule if required - if (!itsSASTasks.empty()) { - itsProgressDialog.addText(QObject::tr("Inserting tasks in scheduler...")); - itsController->mergeDownloadedSASTasks(); - itsProgressDialog.addText(QObject::tr("Tasks inserted.")); - itsProgressDialog.addText(QObject::tr("Download schedule from SAS completed successfully.")); - } - itsProgressDialog.enableClose(); - return true; - } - else return false; // no connection to SAS database -} - - -void SASConnection::showProgressUploadDialog(void) { - itsProgressDialog.clear(); - itsProgressDialog.setWindowTitle("Upload new schedule to SAS database"); - itsProgressDialog.show(); -} - - -bool SASConnection::checkSynchronizeNeeded(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if (sasDB.isOpen()) { - updateDefaultTemplates(); - itsProgressDialog.addText(QObject::tr("Start synchronize SAS schedule procedure")); - itsProgressDialog.addText(QObject::tr("Checking for changes in SAS database...")); - - int retVal(getModifiedVICTrees(itsLastDownloadDate)); - - if (retVal == -1) { - itsProgressDialog.addError(QObject::tr("ERROR: could not fetch tasks from SAS. Aborting synchronize!")); - return false; - } - - size_t nrOfModifiedSASTrees = itsSASmodifiedTasks.size(); - if (nrOfModifiedSASTrees != 0) { - itsProgressDialog.addText(QObject::tr("Check complete. Number of modified tasks in SAS database: ") + - QString::number(nrOfModifiedSASTrees)); - return true; - } - else { - itsProgressDialog.addText(QObject::tr("Check complete. No modified tasks needed to be downloaded.")); - return true; - } - } - else { - itsProgressDialog.addError(QObject::tr("ERROR: Not connected to SAS database. Aborting synchronize!")); - return false; - } -} - -bool SASConnection::startSynchronizeProcedure(const SchedulerData &scheduler_data) { - // ------------------------------- STEP 1 ------------------------------- - // Do a new download from SAS database so that any intermediate changes are also taken into account - bool issueChangeConflict(false); - - if (checkSynchronizeNeeded()) { - itsProgressDialog.addText(QObject::tr("Start compare with SAS database schedule...")); - itsNewSchedulerTasks.clear(); - itsChangedTasks.clear(); - itsUploadDialog->clear(); // resets the upload dialog - - // itsSASVicTrees contains all previously downloaded trees including modifications that have just been detected - // vic trees that don't exist anymore in SAS have been deleted already from itsSASVicTrees and - // their tree ID have been inserted in itsSASdeletedTrees - // itsSASmodifiedTrees contain all tasks with modifications since last download - - // ------------------------------- STEP 1 ------------------------------- - const scheduledTasksMap &scheduled_tasks = scheduler_data.getScheduledTasks(); - unsigned treeID; - for (scheduledTasksMap::const_iterator it = scheduled_tasks.begin(); it != scheduled_tasks.end(); ++it) { - treeID = it->second->getSASTreeID(); - if (treeID == 0) { // new task added by scheduler - // add to new scheduler tasks - itsNewSchedulerTasks.push_back(it->second->getID()); - itsUploadDialog->addNewSchedulerTask(*(it->second)); - } - } - const reservationsMap &reservations = scheduler_data.getReservations(); - for (reservationsMap::const_iterator it = reservations.begin(); it != reservations.end(); ++it) { - treeID = it->second->getSASTreeID(); - if (treeID == 0) { // new task added by scheduler - // add to new scheduler tasks - itsNewSchedulerTasks.push_back(it->second->getID()); - itsUploadDialog->addNewSchedulerTask(*(it->second)); - } - } - const unscheduledTasksDeque &unscheduled_tasks = scheduler_data.getUnscheduledTasks(); - for (unscheduledTasksDeque::const_iterator it = unscheduled_tasks.begin(); it != unscheduled_tasks.end(); ++it) { - treeID = (*it)->getSASTreeID(); - if (treeID == 0) { // new task added by scheduler - // add to new scheduler tasks - itsNewSchedulerTasks.push_back((*it)->getID()); - itsUploadDialog->addNewSchedulerTask(**it); - // For these tasks a new tree has to be build using the SAS DB API - } - } - const pipelinesMap &pipeline_tasks = scheduler_data.getPipelineTasks(); - for (pipelinesMap::const_iterator it = pipeline_tasks.begin(); it != pipeline_tasks.end(); ++it) { - treeID = it->second->getSASTreeID(); - if (treeID == 0) { // new task added by scheduler - // add to new scheduler tasks - itsNewSchedulerTasks.push_back(it->second->getID()); - itsUploadDialog->addNewSchedulerTask(*(it->second)); - } - } - - - // ------------------------------- STEP 2 ------------------------------- - // check for differences that need to be uploaded to SAS - - bool difDetected; - SAStasks::const_iterator sit; - std::vector<unsigned> new_tasks; - for (std::map<unsigned, OTDBtree>::const_iterator it = itsSASVicTrees.begin(); it != itsSASVicTrees.end(); ++it) { - task_diff diff; - const unsigned &treeID(it->first); - if (find(itsTreesToDelete.begin(), itsTreesToDelete.end(), it->first) == itsTreesToDelete.end()) { // don't consider trees that have to be deleted here - sit = itsSASTasks.find(treeID); - if (sit != itsSASTasks.end()) { - // diff between current! SAS task state (at upload time) and previous SAS task state at download time - // to prevent changing a task that in the meantime had a status change in SAS - if (it->second.state() == sit->second->SASTree().state()) { - // only allow changes to tasks with state < FINISHED - const Task *pTask = scheduler_data.getTask(treeID, ID_SAS); - if (pTask) { - difDetected = pTask->diff(sit->second, diff); // diff between task currently in scheduler memory and the previously! downloaded SAS task - if (difDetected) { - QString difstr = pTask->diffString(diff); - if (itsSASmodifiedTasks.find(treeID) == itsSASmodifiedTasks.end()) { - itsUploadDialog->addChangedTask(*pTask, difstr); - itsChangedTasks.insert(changedTasks::value_type(treeID, diff)); - } - else { // the task was also externally modified, issue change conflict - itsUploadDialog->addChangedTask(*pTask, difstr, true); - issueChangeConflict = true; - } - } - else { - itsUploadDialog->addUnchangedTask(*pTask); - } - } - } - else { - // special case the tree state was changed externally in sas database - // check if this task was also changed by the user, if not just download without warning - // if it was changed also by the user then warning that the changes will be lost and the task will be downloaded again -// externallyChangedTasks.push_back(it->treeID()); - const Task *pTask = scheduler_data.getTask(treeID, ID_SAS); - if (pTask) { - difDetected = pTask->diff(sit->second, diff); - if (difDetected) { - QString difstr = pTask->diffString(diff); - itsUploadDialog->addChangedTask(*pTask, difstr, true); - issueChangeConflict = true; - } - } - } - } - else { - // new tree in the SAS database detected, download it in the scheduler - new_tasks.push_back(treeID); - } - } - } - - - SAStasks::iterator sasit; - Task *pCloneTask; - // update externally modified tasks in scheduler now - for (std::map<unsigned, Task *>::const_iterator sit = itsSASmodifiedTasks.begin(); sit != itsSASmodifiedTasks.end(); ++sit) { - // replace the task in itsSAStasks with the updated task from SAS - sasit = itsSASTasks.find(sit->first); - if (sasit != itsSASTasks.end()) { - pCloneTask = cloneTask(sit->second); - if (pCloneTask) { - delete sasit->second; - sasit->second = pCloneTask; - } - } - itsController->synchronizeTask(sit->second); - if (find(new_tasks.begin(), new_tasks.end(), sit->first) != new_tasks.end()) { - itsUploadDialog->addNewSASTask(sit->second); - } - } - - // ------------------------------- STEP 4 ------------------------------- - // Add the trees that have to be deleted from SAS - for (std::vector<unsigned>::const_iterator it = itsTreesToDelete.begin(); it != itsTreesToDelete.end(); ++it) { - sasit = itsSASTasks.find(*it); - if (sasit != itsSASTasks.end()) { - itsUploadDialog->addDeletedSchedulerTask(sasit->second); - } - } - - // add the tasks that have been deleted from sas in the upload dialog - for (std::vector<unsigned>::const_iterator dsit = itsSASdeletedTrees.begin(); dsit != itsSASdeletedTrees.end(); ++dsit) { - const Task *pTask = scheduler_data.getTask(*dsit, ID_SAS); - itsUploadDialog->addDeletedSASTask(pTask); - // directly delete the task from the scheduler because the tree does not exist anymore and nothing can be done abuot that (no cancel option) - sasit = itsSASTasks.find(*dsit); - if (sasit != itsSASTasks.end()) { - delete sasit->second; - itsSASTasks.erase(sasit); - } - itsController->expungeTask(*dsit); - } - itsSASdeletedTrees.clear(); - - // ALL DONE - itsProgressDialog.addText(QObject::tr("Compare finished.")); - itsProgressDialog.hide(); - itsUploadDialog->show(); - - if (issueChangeConflict) { - QMessageBox::warning(0, QObject::tr("External changes detected"), - QObject::tr("Some task changes cannot be applied because their status has been changed in SAS. These tasks are marked red in the changed tasks table.\nThey have been updated to their current state in SAS.\nYou will have to redo the changes you made to these tasks")); - } - - return true; - } - else { - itsProgressDialog.enableClose(); - return false; - } -} - -void SASConnection::addToTreesToDelete(unsigned treeID, unsigned task_id) { - if (find(itsTreesToDelete.begin(), itsTreesToDelete.end(), treeID) == itsTreesToDelete.end()) { - itsTreesToDelete.push_back(treeID); - } - else { - debugWarn("sis", "task ", task_id, "was already added to the list of SAS trees to delete"); - } -} - -void SASConnection::removeFromSASTaskToDelete(unsigned treeID) { - if (treeID) { - std::vector<unsigned>::iterator it = find(itsTreesToDelete.begin(), itsTreesToDelete.end(), treeID); - if (it != itsTreesToDelete.end()) { - itsTreesToDelete.erase(it); - } - else { - debugWarn("sis", "tree ", treeID, "was not found in the list of SAS trees to delete"); - } - } -} - -/* -void SASConnection::addChangedIDTasks(const changedIDTasks &changedIDTasks) { - for (changedIDTasks::const_iterator it = changedIDTasks.begin(); it != changedIDTasks.end(); ++it) { - itsChangedIDTasks.push_back(*it); - const Task *pTask(itsController->getTask(it->newTaskID)); - if (pTask) { - itsProgressDialog.addText(QString("Tree ") + QString::number(pTask->getSASTreeID()) + - " has non unique task ID " + QString::number(it->oldTaskID) + ". Task ID is changed to " + QString::number(it->newTaskID)); - } - } -} -*/ - -bool SASConnection::deleteTrees(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - bool bResult(true); - QSqlQuery query(sasDB); - QString delquery("SELECT deleteTree(" + itsAuthToken + ","); - for (std::vector<unsigned>::const_iterator it = itsTreesToDelete.begin(); it != itsTreesToDelete.end(); ++it) { - if (!query.exec(delquery + QString::number(*it) + ")")) { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - bResult = false; - } - query.finish(); - } - itsTreesToDelete.clear(); - return bResult; -} - -bool SASConnection::deleteTreesCleanup(const deleteVICmap &treeIDs, const QString &hostname, const QString &user, const QString &password) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - for (deleteVICmap::const_iterator DBit = treeIDs.begin(); DBit != treeIDs.end(); ++DBit) { - if (sasDB.isOpen()) { - sasDB.close(); - } - QSqlDatabase::removeDatabase( "SASDB" ); - sasDB = QSqlDatabase::addDatabase("QPSQL","SASDB"); - sasDB.setDatabaseName(DBit->first); - sasDB.setHostName(hostname); - sasDB.setUserName("postgres"); - sasDB.setPassword(""); - - if (sasDB.open()) { - QSqlQuery query(sasDB); - - QString authToken; - query.exec("SELECT OTDBlogin('" + user + "','" + password + "')"); - if (query.next()) { - authToken = query.value(0).toString(); - if (authToken.isEmpty()) { - QMessageBox::critical(0, "no SAS write permissions", "No write permissions in sas database. Could not delete trees.\nDid you specify the correct user name and password?"); - return false; // no write permissions to SAS DB - } - } - query.finish(); - - QString delquery("SELECT deleteTree(" + authToken + ","); - for (QStringList::const_iterator it = DBit->second.begin(); it != DBit->second.end(); ++it) { - if (!query.exec(delquery + *it + ")")) { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); -// bResult = false; - } - query.finish(); - } - } - else return false; - } - return true; -} - -bool SASConnection::markDataProductsDeleted(const deletedDataMap &data, const QString &hostname/*, const QString &user, const QString &password*/) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - for (deletedDataMap::const_iterator DBit = data.begin(); DBit != data.end(); ++DBit) { - if (sasDB.isOpen()) { - sasDB.close(); - } - QSqlDatabase::removeDatabase( "SASDB" ); - sasDB = QSqlDatabase::addDatabase("QPSQL","SASDB"); - sasDB.setDatabaseName(DBit->first); - sasDB.setHostName(hostname); - sasDB.setUserName("postgres"); - sasDB.setPassword(""); - - if (sasDB.open()) { - - QString dpNodeName("LOFAR.ObsSW.Observation.DataProducts."); - for (std::vector<std::pair<int, dataProductTypes> >::const_iterator treeit = DBit->second.begin(); treeit != DBit->second.end(); ++treeit) { - switch (treeit->second) { - case DP_CORRELATED_UV: - dpNodeName += "Output_Correlated.deleted"; - break; - case DP_COHERENT_STOKES: - dpNodeName += "Output_CoherentStokes.deleted"; - break; - case DP_INCOHERENT_STOKES: - dpNodeName += "Output_IncoherentStokes.deleted"; - break; - case DP_INSTRUMENT_MODEL: - dpNodeName += "Output_InstrumentModel.deleted"; - break; - case DP_PULSAR: - dpNodeName += "Output_Pulsar.deleted"; - break; - case DP_SKY_IMAGE: - dpNodeName += "Output_SkyImage.deleted"; - break; - default: - continue; - } - setNodeValue(treeit->first, dpNodeName, "true"); - } - } - else { - debugErr("sssssss","Could not establish SAS connection! Settings used:\n", - "Username: ", sasDB.userName().toStdString().c_str(), - ", database: ", sasDB.databaseName().toStdString().c_str(), - ", hostname: ", sasDB.hostName().toStdString().c_str() - ); - return false; - } - } - return true; -} - - - -// getItemList(int aTreeID, const string& aNameFragment): get children of a tree by means of a name fragment -// this function was ported from LOFAR software 'TreeMaintenance::getItemList (treeIDType aTreeID, const string& aNameFragment)' -vector<OTDBnode> SASConnection::getItemList(int aTreeID, const QString &nameFragment) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - vector<OTDBnode> resultVec; - QSqlQuery query("SELECT * from getVHitemList(" + QString::number(aTreeID) + ",'" + nameFragment + "')", sasDB); - while (query.next()) { - resultVec.push_back(OTDBnode(aTreeID, query)); - } - return resultVec; -} - -QVariant SASConnection::getNodeValue(int treeID, const QString &nameFragment, bool noWarnings) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT limits from getVHitemList(" + QString::number(treeID) + ",'" + nameFragment + "')", sasDB); - if (query.next()) { - return query.value(0); - } - else { - if (!noWarnings) { - itsProgressDialog.addError(QString("Warning: property:") + nameFragment + " of SAS tree:" + QString::number(treeID) + " could not be read from SAS."); - } - return QVariant(QVariant::Invalid); - } -} - -bool SASConnection::getDigitalBeams(int treeID, Observation &observation) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - bool bResult(true); - int idx(0); - QString beamName; - QString propertyName; - while(true) { - beamName = "LOFAR.ObsSW.Observation.Beam[" + QString::number(idx) + "]"; - if (query.exec("SELECT name,limits from getVHitemList(" + QString::number(treeID) + ",'" + beamName + ".%')")) { - if (query.size()) { - DigitalBeam digitalBeam; - std::map<unsigned, TiedArrayBeam> &TAB(digitalBeam.getTiedArrayBeamsForChange()); - while (query.next()) { - propertyName = query.value(0).toString().remove(beamName + "."); - if (propertyName.startsWith("Tie")) { // TiedArrayBeam - // get tied array beam number - int p1(propertyName.indexOf('[')+1), p2(propertyName.indexOf("].")); - if (p1 != 0 && p2 != -1) { - int TABnr(propertyName.mid(p1,p2-p1).toInt()); - propertyName = propertyName.mid(p2+2); - if (propertyName.startsWith("angle1")) { - TAB[TABnr].setAngle1(query.value(1).toDouble()); - } - else if (propertyName.startsWith("angle2")) { - TAB[TABnr].setAngle2(query.value(1).toDouble()); - } - else if (propertyName.startsWith("co")) { // coherent - TAB[TABnr].setCoherent(query.value(1).toBool()); - } - else if (propertyName.startsWith("dis")) { // dispersionMeasure - TAB[TABnr].setDispersionMeasure(query.value(1).toDouble()); - } - } - } - else if (propertyName.startsWith("angle1")) { - digitalBeam.setAngle1Radian(query.value(1).toDouble()); - } - else if (propertyName.startsWith("angle2")) { - digitalBeam.setAngle2Radian(query.value(1).toDouble()); - } - else if (propertyName.startsWith("dir")) { // directionType - digitalBeam.setDirectionType(stringToBeamDirectionType(query.value(1).toString().toStdString())); - switch (digitalBeam.directionType()) { - default: - case DIR_TYPE_J2000: // Right ascension & declination - case DIR_TYPE_B1950: - case DIR_TYPE_ICRS: - case DIR_TYPE_ITRF: - case DIR_TYPE_TOPO: - case DIR_TYPE_APP: - case DIR_TYPE_HADEC: - digitalBeam.setUnits(ANGLE_PAIRS_HMS_DMS); - break; - case DIR_TYPE_AZELGEO: - case DIR_TYPE_SUN: - case DIR_TYPE_MOON: - case DIR_TYPE_PLUTO: - case DIR_TYPE_NEPTUNE: - case DIR_TYPE_URANUS: - case DIR_TYPE_SATURN: - case DIR_TYPE_JUPITER: - case DIR_TYPE_MARS: - case DIR_TYPE_VENUS: - case DIR_TYPE_MERCURY: - case DIR_TYPE_GALACTIC: - case DIR_TYPE_ECLIPTIC: - case DIR_TYPE_COMET: - digitalBeam.setUnits(ANGLE_PAIRS_DMS_DMS); - break; - } - } - else if (propertyName.startsWith("dur")) { // duration - digitalBeam.setDuration(query.value(1).toUInt()); - } - else if (propertyName.startsWith("nrTa")) { // nrTabRings - digitalBeam.setNrTabRings(query.value(1).toInt()); - } - else if (propertyName.startsWith("sta")) { // startTime - digitalBeam.setStartTime(query.value(1).toUInt()); - } - else if (propertyName.startsWith("sub")) { // subbandList - QString subliststr(query.value(1).toString()); - if (!digitalBeam.setSubbandList(subliststr)) { - itsProgressDialog.addError(QString("Warning: The subband list of tree: ") + QString::number(treeID) + " for beam: " + QString::number(idx) + " contains an error."); - bResult = false; - } - if (Vector2StringList(digitalBeam.subbandList()) != subliststr) digitalBeam.setSubbandNotationChange(true); // mark for saving to SAS - } - else if (propertyName.startsWith("tab")) { // tabRingSize - digitalBeam.setTabRingSize(query.value(1).toDouble()); - } - else if (propertyName.startsWith("tar")) { // target - digitalBeam.setTarget(query.value(1).toString().toStdString()); - } - } - observation.setDigitalBeam(idx++, digitalBeam); - } - else return bResult; - query.finish(); - } - } - return bResult; -} - -bool SASConnection::saveTiedArrayBeamSettings(int treeID, const Observation &task, const task_diff *diff) { - bool bResult(true); - if (diff) { - if (diff->tiedarray_beam_settings) { - const std::map<unsigned, DigitalBeam> &digiBeams = task.getDigitalBeams(); - for (std::map<unsigned, DigitalBeam>::const_iterator it = digiBeams.begin(); it != digiBeams.end(); ++it) { - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(it->second.tiedArrayBeams()); - for (std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.begin(); tit != tiedArrayBeams.end(); ++tit) { - if (!saveTiedArrayBeamToSasVicTree(treeID, it->first, tit->first, tit->second)) bResult = false; - } - } - } - } - return bResult; -} - -bool SASConnection::saveTiedArrayBeamToSasVicTree(int treeID, int beamNr, int TABnr, const TiedArrayBeam &TAB) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - int nodeID; - QString compNameShort, isCoherent; - QString compName("LOFAR.ObsSW.Observation.Beam[" + QString::number(beamNr) + "].TiedArrayBeam[" + QString::number(TABnr) + "]."); - QString fetchTABidStr("SELECT nodeid,name from getVHitemList(" + QString::number(treeID) + ",'" + compName + "%')"); - if (query.exec(fetchTABidStr)) { - while (query.next()) { - nodeID = query.value(0).toInt(); - compNameShort = query.value(1).toString().remove(compName); - if (compNameShort.startsWith("angle1")) { - if (!setNodeValue(treeID, nodeID, QString::number(TAB.angle1(),'g',16))) bResult = false; - } - else if (compNameShort.startsWith("angle2")) { - if (!setNodeValue(treeID, nodeID, QString::number(TAB.angle2(),'g',16))) bResult = false; - } - else if (compNameShort.startsWith("dis")) { // dispersionMeasure - if (!setNodeValue(treeID, nodeID, QString::number(TAB.dispersionMeasure(),'g',16))) bResult = false; - } - else if (compNameShort.startsWith("coh")) { // coherent - TAB.isCoherent() ? isCoherent = "true" : isCoherent = "false"; - if (!setNodeValue(treeID, nodeID, isCoherent)) bResult = false; - } - } - query.finish(); - } - else { - std::cerr << query.lastError().text().toStdString() << std::endl; - return false; - } - - return bResult; -} - - -bool SASConnection::saveDigitalBeamSettings(int treeID, Observation &task, const task_diff *diff) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - const std::map<unsigned, DigitalBeam> &digiBeams = task.getDigitalBeams(); - bool bResult(true), doSubbandChangeCheck(false); - if (diff) { - if (diff->digital_beam_settings) { - for (std::map<unsigned, DigitalBeam>::const_iterator it = digiBeams.begin(); it != digiBeams.end(); ++it) { - if (!saveDigitalBeamToSasVicTree(treeID, it->first, it->second)) bResult = false; - } - } - else doSubbandChangeCheck = true; - } - else doSubbandChangeCheck = true; - - if (doSubbandChangeCheck) { // check each beam if the notation of the subbands was changed, if it was then write the new notation to SAS - QString queryFirstPart("SELECT nodeid from getVHitemList(" + QString::number(treeID) + ",'LOFAR.ObsSW.Observation.Beam["); - for (std::map<unsigned, DigitalBeam>::const_iterator it = digiBeams.begin(); it != digiBeams.end(); ++it) { - if (it->second.subbandNotationChange()) { - // set subbandList - query.exec(queryFirstPart + QString::number(it->first) + "].subbandList')"); - if (query.next()) { - if (setNodeValue(treeID, query.value(0).toInt(), Vector2StringList(it->second.subbandList()))) { - task.setSubbandNotationChange(it->first, false); // reset the subband notation change flag of this beam once it has been written back to SAS - } - else bResult = false; - } - else bResult = false; - query.finish(); - } - } - } - - return bResult; -} - - -bool SASConnection::saveDigitalBeamToSasVicTree(int treeID, int beamNr, const DigitalBeam &digiBeam) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - QString beamstr = "SELECT nodeid from getVHitemList(" + QString::number(treeID) + ",'LOFAR.ObsSW.Observation.Beam[" + QString::number(beamNr) + "]."; - // set angle 1 value - query.exec(beamstr + "angle1')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.angle1().radian(),'g',16))) bResult = false; - } - else bResult = false; - query.finish(); - // set angle 2 - query.exec(beamstr + "angle2')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.angle2().radian(),'g',16))) bResult = false; - } - else bResult = false; - query.finish(); - // set directionType - query.exec(beamstr + "directionType')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), BEAM_DIRECTION_TYPES[digiBeam.directionType()])) bResult = false; - } - else bResult = false; - query.finish(); - // set duration - query.exec(beamstr + "duration')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.duration().totalSeconds()))) bResult = false; - } - else bResult = false; - query.finish(); - // set nrTabRings - query.exec(beamstr + "nrTabRings')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.nrTabRings()))) bResult = false; - } - else bResult = false; - query.finish(); - // set startTime - query.exec(beamstr + "startTime')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.startTime().totalSeconds()))) bResult = false; - } - else bResult = false; - query.finish(); - // set subbandList - query.exec(beamstr + "subbandList')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), Vector2StringList(digiBeam.subbandList()))) bResult = false; - } - else bResult = false; - query.finish(); - // set tabRingSize - query.exec(beamstr + "tabRingSize')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.tabRingSize(),'g',16))) bResult = false; - } - else bResult = false; - // set subbandList - query.exec(beamstr + "target')"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), digiBeam.target().c_str())) return false; - } - else bResult = false; - query.finish(); - - return bResult; -} - -bool SASConnection::saveAnalogBeamToSAStemplate(int treeID, int beamNodeId, const Observation::analogBeamSettings &analogBeam) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - QString beamStr = "SELECT nodeid from victemplate WHERE parentid=" + QString::number(beamNodeId) + " AND name='"; - // set angle 1 value - query.exec(beamStr + "angle1'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(analogBeam.angle1.radian(),'g',16))) bResult = false; - } - else bResult = false; - query.finish(); - // set angle 2 - query.exec(beamStr + "angle2'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(analogBeam.angle2.radian(),'g',16))) bResult = false; - } - else bResult = false; - query.finish(); - // set directionType - query.exec(beamStr + "directionType'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), BEAM_DIRECTION_TYPES[analogBeam.directionType])) bResult = false; - } - else bResult = false; - query.finish(); - // set duration - query.exec(beamStr + "duration'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(analogBeam.duration.totalSeconds()))) bResult = false; - } - else bResult = false; - query.finish(); - // set startTime - query.exec(beamStr + "startTime'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(analogBeam.startTime.totalSeconds()))) bResult = false; - } - else bResult = false; - query.finish(); - - return bResult; -} - - -bool SASConnection::saveTiedArrayBeamToSAStemplate(int treeID, const QString &TABNodeID, const TiedArrayBeam &TAB) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); -// QString TABNode(QString::number(TABNodeId)); - // save angle 1 value - query.exec("SELECT nodeid from victemplate WHERE parentid=" + TABNodeID + " AND name='angle1'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(TAB.angle1()))) bResult = false; - } - else bResult = false; - query.finish(); - // save angle 2 - query.exec("SELECT nodeid from victemplate WHERE parentid=" + TABNodeID + " AND name='angle2'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(TAB.angle2()))) bResult = false; - } - else bResult = false; - query.finish(); - // save coherent flag - query.exec("SELECT nodeid from victemplate WHERE parentid=" + TABNodeID + " AND name='coherent'"); - if (query.next()) { - QString isCoherent; - TAB.isCoherent() ? isCoherent = "true" : isCoherent = "false"; - if (!setNodeValue(treeID, query.value(0).toInt(), isCoherent)) bResult = false; - } - else bResult = false; - query.finish(); - // save dispersion measure - query.exec("SELECT nodeid from victemplate WHERE parentid=" + TABNodeID + " AND name='dispersionMeasure'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(TAB.dispersionMeasure()))) bResult = false; - } - else bResult = false; - query.finish(); - - return bResult; -} - - - -bool SASConnection::saveDigitalBeamToSAStemplate(int treeID, const QString &beamNodeId, const DigitalBeam &digiBeam) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); -// QString beamNode(QString::number(beamNodeId)); - // set angle 1 value - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='angle1'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.angle1().radian()))) bResult = false; - } - else bResult = false; - query.finish(); - // set angle 2 - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='angle2'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.angle2().radian()))) bResult = false; - } - else bResult = false; - query.finish(); - // set directionType - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='directionType'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), BEAM_DIRECTION_TYPES[digiBeam.directionType()])) bResult = false; - } - else bResult = false; - query.finish(); - // set duration - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='duration'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.duration().totalSeconds()))) bResult = false; - } - else bResult = false; - query.finish(); - // set startTime - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='startTime'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.startTime().totalSeconds()))) bResult = false; - } - else bResult = false; - query.finish(); - // nrTABrings - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='nrTabRings'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.nrTabRings()))) bResult = false; - } - else bResult = false; - query.finish(); - // set subbandList - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='subbandList'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), Vector2StringList(digiBeam.subbandList()))) bResult = false; - } - else bResult = false; - query.finish(); - // set subbandList - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='target'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), digiBeam.target().c_str())) bResult = false; - } - else bResult = false; - query.finish(); - // tabRingSize - query.exec("SELECT nodeid from victemplate WHERE parentid=" + beamNodeId + " AND name='tabRingSize'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), QString::number(digiBeam.tabRingSize(),'g',16))) bResult = false; - } - else bResult = false; - query.finish(); - - - return bResult; -} - -/* -std::vector<unsigned> SASConnection::subbandStringToVector(const QString &subbandStr) const { - std::vector<unsigned> subbandList; - QStringList strList; - QString tmp; - if (!subbandStr.isEmpty()) { - tmp = subbandStr.trimmed(); - if (tmp.size() > 2) { - if ((tmp[0] == '[') & (tmp[tmp.size()-1] == ']')) { - tmp = tmp.mid(1,tmp.size()-2); - strList = tmp.split(',',QString::SkipEmptyParts); - // we should now have a stringlist containing either individual subband numbers or a single ranges of subbands expressed as n..m - int pos; - unsigned sbstart, sbend; - for (QStringList::const_iterator it = strList.begin(); it != strList.end(); ++it) { - if ((pos = it->indexOf("..")) != -1) { // this is a range - sbstart = it->left(pos).toUInt(); - sbend = it->mid(pos+2).toUInt(); - for (unsigned sb = sbstart; sb <= sbend; ++sb) { - subbandList.push_back(sb); - } - } - else subbandList.push_back(it->toUInt()); - } - } - } - } - return subbandList; -} -*/ - - -// getSchedulerInfo returns false only for serious errors -bool SASConnection::getSchedulerInfo(int tree_id, Task &task) { - bool bResult = true; - QString treeID(QString::number(tree_id)); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - - // task description -// task.setTaskDescription(SAS_tree.description()); -// task.setSASTreeID(SAS_tree.treeID()); -// task.setSASTree(SAS_tree); -// task.setType(SAS_tree.processType(), SAS_tree.processSubType(), SAS_tree.strategy()); - - // duration, start and stop time - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskDuration')"); - if (query.next()) { - unsigned secondsDuration = query.value(0).toUInt(); - if (secondsDuration) { - AstroTime duration; - duration = duration.addSeconds(secondsDuration); - task.setDuration(duration); - } - } - else { - itsProgressDialog.addError(QString("Error: Scheduler.taskDuration node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - -/* - bool startSet(SAS_tree.startTime().isSet()), endSet(SAS_tree.stopTime().isSet()); - if (startSet && endSet) { - task.setScheduledPeriod(SAS_tree.startTime(), SAS_tree.stopTime()); - } - else if (!startSet & !endSet) { // this is true when the task has just been approved from MoM and no start and end times are defined - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskDuration')"); - if (query.next()) { - unsigned secondsDuration = query.value(0).toUInt(); - if (secondsDuration) { - AstroTime duration; - duration = duration.addSeconds(secondsDuration); - task.setDuration(duration); - } - } - else { - itsProgressDialog.addError(QString("Error: Scheduler.taskDuration node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - } - else if (startSet & !endSet) { - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskDuration')"); - if (query.next()) { - unsigned secondsDuration = query.value(0).toUInt(); - if (secondsDuration) { - AstroTime duration; - duration = duration.addSeconds(secondsDuration); - task.setDuration(duration); - } - } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.taskDuration node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - } - else if (!startSet & endSet) { - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskDuration')"); - if (query.next()) { - unsigned secondsDuration = query.value(0).toUInt(); - if (secondsDuration) { - AstroTime duration; - task.setDuration(duration.addSeconds(secondsDuration)); - task.setScheduledStart(SAS_tree.stopTime() - duration); - } - else { - task.setScheduledStart(SAS_tree.stopTime()); - task.setDuration(AstroTime(0)); - } - } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.taskDuration node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - } -*/ - - // status is set according to the SAS status from SAS_tree -// task.setStatusSAS(SAS_tree.state()); - - // TODO: remove backwards compatible task type, this is replaced by processType meta-data - // taskType - if (task.getType() == Task::UNKNOWN) { - debugWarn("sis", "task type for tree ", tree_id, " is UNKNOWN. Probably caused by processType meta-data not set in SAS VIC-tree. Now fetching Scheduler.taskType node"); - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskType')"); - if (query.next()) { task.setType(static_cast<Task::task_type>(query.value(0).toUInt())); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.taskName node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - } - - // contactEmail - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.contactEmail')"); - if (query.next()) { task.setContactEmail(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.contactEmail node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - // contactName - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.contactName')"); - if (query.next()) { task.setContactName(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.contactName node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // contactPhone - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.contactPhone')"); - if (query.next()) { task.setContactPhone(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.contactPhone node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // firstPossibleDay - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.firstPossibleDay')"); - if (query.next()) { - int day = query.value(0).toInt(); - if (day) task.setWindowFirstDay(day); - else task.setWindowFirstDay(std::max(QDate::currentDate().toJulianDay() - J2000_EPOCH, (qint64)Controller::theSchedulerSettings.getEarliestSchedulingDay().toJulian())); - } - else { // serious error - itsProgressDialog.addError(QString("Error: Scheduler.firstPossibleDay node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - - // fixedDay - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.fixedDay')"); - if (query.next()) { task.setFixDay(query.value(0).toBool()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.fixedDay node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // fixedTime - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.fixedTime')"); - if (query.next()) { task.setFixTime(query.value(0).toBool()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.fixedTime node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // lastPossibleDay - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.lastPossibleDay')"); - if (query.next()) { - int day = query.value(0).toInt(); - if (day) task.setWindowLastDay(day); - else task.setWindowLastDay(Controller::theSchedulerSettings.getLatestSchedulingDay().toJulian()); - } else { - itsProgressDialog.addError(QString("Error: Scheduler.lastPossibleDay node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - - // predecessor - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.predecessors')"); - if (query.next()) { task.setPredecessors(query.value(0).toString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.predecessors node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // predMaxTimeDif - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.predMaxTimeDif')"); - if (query.next()) { task.setPredecessorMaxTimeDif(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.predMaxTimeDif node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // predMinTimeDif - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.predMinTimeDif')"); - if (query.next()) { task.setPredecessorMinTimeDif(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.predMinTimeDif node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // priority - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.priority')"); - if (query.next()) { task.setPriority(query.value(0).toDouble()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.priority node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // projectName -// query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.projectName')"); -// if (query.next()) { task.setProjectName(query.value(0).toString().toStdString()); } -// else { -// itsProgressDialog.addError(QString("Warning: Scheduler.projectName node of SAS tree: ") + treeID + " could not be fetched"); -// } -// query.finish(); - - if (task.isObservation()) { - Observation &obsTask(static_cast<Observation &>(task)); - // nightTimeWeightFactor - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.nightTimeWeightFactor')"); - if (query.next()) { obsTask.setNightTimeWeightFactor(query.value(0).toInt()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.nightTimeWeightFactor node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // reservation - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.reservation')"); - if (query.next()) { obsTask.setReservation(query.value(0).toUInt()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.reservation node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - } - - TaskStorage *tStorage(task.storage()); - if (tStorage) { - // storageSelectionMode - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.storageSelectionMode')"); - if (query.next()) { tStorage->setStorageSelectionMode(static_cast<storage_selection_mode>(query.value(0).toInt())); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.storageSelectionMode node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - } - - // taskID - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskID')"); - if (query.next()) { - unsigned taskID(query.value(0).toUInt()); - if (taskID) { - task.setID(taskID); - } -// else { -// itsProgressDialog.addError(QString("Warning: Scheduler.taskID node of SAS tree: ") + treeID + " is zero (0)"); -// } - } - else { - itsProgressDialog.addError(QString("Error: Scheduler.taskID node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - - // taskName - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.taskName')"); - if (query.next()) { task.setTaskName(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.taskName node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - - // error reason (fetched only when task status == ERROR) - if (task.getStatus() == Task::ERROR) { - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.reason')"); - if (query.next()) { task.setReason(query.value(0).toString().toStdString()); } - else { - itsProgressDialog.addError(QString("Warning: Scheduler.reason node of SAS tree: ") + treeID + " could not be fetched"); - } - query.finish(); - } - - // windowMaximumTime - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.windowMaximumTime')"); - if (query.next()) { - task.setWindowMaxTime(query.value(0).toString()); - } - else { - task.setWindowMaxTime(AstroTime("23:59:59")); - itsProgressDialog.addError(QString("Error: Scheduler.windowMaximumTime node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - query.finish(); - - // windowMinimumTime - query.exec("SELECT limits from getVHitemList(" + treeID + ",'LOFAR.ObsSW.Observation.Scheduler.windowMinimumTime')"); - if (query.next()) { - task.setWindowMinTime(query.value(0).toString()); - } - else { - task.setWindowMinTime(AstroTime()); - itsProgressDialog.addError(QString("Error: Scheduler.windowMinimumTime node of SAS tree: ") + treeID + " could not be fetched"); - bResult = false; - } - - return bResult; -} - -bool SASConnection::saveSchedulerProperties(int treeID, const Task &task, const task_diff *diff) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QString strValue; - if (diff) { - if (diff->task_id) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskID", QString::number(task.getID())); - if (diff->contact_email) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.contactEmail", task.getContactEmail()); - if (diff->contact_name) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.contactName", task.getContactName()); - if (diff->contact_phone) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.contactPhone", task.getContactPhone()); - if (diff->first_possible_day) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.firstPossibleDay", QString::number(task.getWindowFirstDay().toJulian())); - if (diff->fixed_day) { - task.getFixedDay() ? strValue = "true" : strValue = "false"; - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.fixedDay", strValue); - } - if (diff->fixed_time) { - task.getFixedTime() ? strValue = "true" : strValue = "false"; - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.fixedTime", strValue); - } - if (diff->last_possible_day) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.lastPossibleDay", QString::number(task.getWindowLastDay().toJulian())); - if (diff->predecessors) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.predecessors", task.getPredecessorsString()); - if (diff->pred_max_time_dif) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.predMaxTimeDif", task.getPredecessorMaxTimeDif().toString().c_str()); - if (diff->pred_min_time_dif) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.predMinTimeDif", task.getPredecessorMinTimeDif().toString().c_str()); - if (diff->priority) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.priority", QString::number(task.getPriority())); - if (task.getStatus() == Task::ERROR) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.reason", task.getReason().c_str()); - } - if (diff->task_duration) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskDuration", QString::number(task.getDuration().totalSeconds())); - if (diff->task_name) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskName", task.getTaskName()); - if (diff->task_type) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskType", QString::number(static_cast<int>(task.getType()))); - } - if (diff->window_maximum_time) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.windowMaximumTime", task.getWindowMaxTime().toString(1).c_str()); - if (diff->window_minimum_time) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.windowMinimumTime", task.getWindowMinTime().toString(1).c_str()); - if (task.isObservation()) { - const Observation &obs(static_cast<const Observation &>(task)); - if (diff->reservation) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.reservation", QString::number(obs.getReservation())); - if (diff->night_time_weight_factor) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.nightTimeWeightFactor", QString::number(obs.getNightTimeWeightFactor())); - } - const TaskStorage *tStor(task.storage()); - if (tStor) { - if (diff->output_storage_settings) bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.storageSelectionMode", QString::number(static_cast<int>(tStor->getStorageSelectionMode()))); - } - } - else { - QString fixedDay, fixedTime, late; - task.getFixedDay() ? fixedDay = "true" : fixedDay = "false"; - task.getFixedTime() ? fixedTime = "true" : fixedTime = "false"; - QString reservationNr, ntimefac, storMode; - if (task.isObservation()) { - const Observation &obs(static_cast<const Observation &>(task)); - reservationNr = QString::number(obs.getReservation()); - ntimefac = QString::number(obs.getNightTimeWeightFactor()); - } - const TaskStorage *task_storage(task.storage()); - if (task_storage) { - storMode = QString::number(static_cast<int>(task_storage->getStorageSelectionMode())); - } - - QSqlQuery query("SELECT saveSchedulerInfo(" + - itsAuthToken + "," + - QString::number(treeID) + ",'" + - task.getContactEmail() + "','" + - task.getContactName() + "','" + - task.getContactPhone() + "','" + - QString::number(task.getWindowFirstDay().toJulian()) + "','" + - fixedDay + "','" + - fixedTime + "','" + - QString::number(task.getWindowLastDay().toJulian()) + "','" + - late + "','" + - ntimefac + "','" + - task.getPredecessorsString() + "','" + - task.getPredecessorMaxTimeDif().toString().c_str() + "','" + - task.getPredecessorMinTimeDif().toString().c_str() + "','" + - QString::number(task.getPriority()) + "','" + - task.getReason().c_str() + "','J2000','" + - reservationNr + "','" + - storMode + "','" + - QString::number(task.getDuration().totalSeconds()) + "','" + - QString::number(task.getID()) + "','" + - task.getTaskName() + "','" + - QString::number(static_cast<int>(task.getType())) + "','" + // TODO: Task type is not being update to the database (is this a saveSchedulerInfo.sql function error?) - task.getWindowMaxTime().toString(1).c_str() + "','" + - task.getWindowMinTime().toString(1).c_str() + "')" - , sasDB); - - if (query.next()) { - if (!query.value(query.record().indexOf("saveSchedulerInfo")).toBool()) { - debugWarn("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } - } - else { - // save all properties manually - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.contactEmail", task.getContactEmail()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.contactName", task.getContactName()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.contactPhone", task.getContactPhone()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.firstPossibleDay", QString::number(task.getWindowFirstDay().toJulian())); - task.getFixedDay() ? strValue = "true" : strValue = "false"; - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.fixedDay", strValue); - task.getFixedTime() ? strValue = "true" : strValue = "false"; - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.fixedTime", strValue); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.lastPossibleDay", QString::number(task.getWindowLastDay().toJulian())); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.late", strValue); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.predecessors", task.getPredecessorsString()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.predMaxTimeDif", task.getPredecessorMaxTimeDif().toString().c_str()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.predMinTimeDif", task.getPredecessorMinTimeDif().toString().c_str()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.priority", QString::number(task.getPriority())); - if (task.getStatus() == Task::ERROR) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.reason", task.getReason().c_str()); - } - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskDuration", QString::number(task.getDuration().totalSeconds())); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskName", task.getTaskName()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.taskType", QString::number(static_cast<int>(task.getType()))); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.windowMaximumTime", task.getWindowMaxTime().toString(1).c_str()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.windowMinimumTime", task.getWindowMinTime().toString(1).c_str()); - if (task.isObservation()) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.reservation", reservationNr); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.nightTimeWeightFactor", ntimefac); - } - if (task_storage) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.Scheduler.storageSelectionMode", storMode); - } - - - return bResult; - } - } - return true; -} - -QString SASConnection::getTreeParset(int treeID) { - if (connect() == 0) { - QString parset; - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - if (query.exec("SELECT nodeid from getVHitemList(" + QString::number(treeID) + ",'LOFAR')")) { - if (query.next()) { - QString topNodeID = query.value(0).toString(); - query.finish(); - if (query.exec("SELECT * from exportTree(" + itsAuthToken + "," + - QString::number(treeID) + "," + topNodeID + ")")) { - if (query.next()) { - parset = query.value(0).toString(); - if (parset.isEmpty()) { - debugWarn("si","SAS returned empty tree (exportTree function) for tree:", treeID); - } - } - query.finish(); - } - } - } - return parset; - } - else { - QMessageBox::critical(0, QObject::tr("No connection to SAS"), - QObject::tr("Could not connect to SAS database.\n Please check SAS connection settings.")); - return ""; - } -} - -QString SASConnection::getMetaData(int treeID) { - QString parset; - if (connect() == 0) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - if (query.exec("SELECT * from exportmetadata(" + QString::number(treeID) + ")")) { - if (query.next()) { - parset = query.value(0).toString(); - if (parset.isEmpty()) { - debugWarn("si","SAS empty meta data (exportMetaData function) for tree:", treeID); - } - } - query.finish(); - } - } - else { - QMessageBox::critical(0, QObject::tr("No connection to SAS"), - QObject::tr("Could not connect to SAS database.\n Please check SAS connection settings.")); - } - - return parset; -} - -bool SASConnection::abortTask(int treeID) { - // get the current status of the tree from SAS - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("select state from gettreeinfo(" + QString::number(treeID) + ", false)", sasDB); - if (query.next()) { - int state = query.value(0).toInt(); - if ((state == SAS_STATE_ACTIVE) | (state == SAS_STATE_QUEUED)) { - //if the status is SAS_STATE_QUEUED or SAS_STATE_ACTIVE then allow the abort - return setTreeState(treeID, SAS_STATE_ABORTED); - } - else { - debugWarn("sis","SASConnection:abortTask, tree:", treeID, " is not queued nor active, it could not be aborted"); - return false; - } - } - else { - std::cerr << "SASConnection::abortTask: Error, could not get the tree state of tree: " << treeID << std::endl << query.lastError().text().toStdString() << std::endl; - return false; - } -} - -bool SASConnection::setTaskOnHold(int treeID) { - if (setTreeState(treeID, SAS_STATE_ON_HOLD)) { - SAStasks::iterator it = itsSASTasks.find(treeID); - if (it != itsSASTasks.end()) { - it->second->setStatus(Task::ON_HOLD); - } - std::map<unsigned, OTDBtree>::iterator sit = itsSASVicTrees.find(treeID); - if (sit != itsSASVicTrees.end()) { - sit->second.setState(SAS_STATE_ON_HOLD); - } - return true; - } - else return false; -} - -bool SASConnection::setTasksOnHold(const std::vector<int> trees) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if (sasDB.open()) { - for (std::vector<int>::const_iterator it = trees.begin(); it != trees.end(); ++it) { - bResult &= setTaskOnHold(*it); - } - } - else return false; - - return bResult; -} - -OTDBnode SASConnection::getNode(int treeID, const QString &nodeID) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT * from getNode(" + - QString::number(treeID) + "," + - nodeID + ")", sasDB); - if (query.next()) { - return OTDBnode(treeID, query); - } - else return OTDBnode(); -} - -bool SASConnection::saveNode(const OTDBnode &node) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT updateVTnode(" + - itsAuthToken + "," + - QString::number(node.treeID()) + "," + - QString::number(node.nodeID()) + ",'" + - QString::number(node.instances()) + "','" + - node.limits().c_str() + "')", sasDB); -// std::cout << query.lastQuery().toStdString() << std::endl; - if (!query.isActive()) { // query successfully executed? - debugWarn("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } - return true; -} - -bool SASConnection::setTemplateNodeByID(int treeID, const QString &parentNodeID, const QString &nodeName, const QString &valueStr) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - query.exec(QString("SELECT nodeid from victemplate WHERE parentid=") + parentNodeID + " AND name='" + nodeName + "'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), valueStr)) return false; - } - else { - std::cerr << "SASConnection::setTemplateNodeValue: Error" << std::endl << query.lastError().text().toStdString() << std::endl; - return false; - } - return true; -} - -bool SASConnection::setTemplateNodeByName(int treeID, const QString &parentNodeName, const QString &nodeName, const QString &valueStr) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - query.exec("SELECT nodeid from getVTitemList(" + QString::number(treeID) + ",'" + parentNodeName + "')"); - if (query.next()) { - int nodeID = query.value(0).toInt(); - query.finish(); - query.exec(QString("SELECT nodeid from victemplate WHERE parentid=") + QString::number(nodeID) + " AND name='" + nodeName + "'"); - if (query.next()) { - if (!setNodeValue(treeID, query.value(0).toInt(), valueStr)) return false; - } - else { - std::cerr << "SASConnection::setTemplateNodeValue: Error" << std::endl << query.lastError().text().toStdString() << std::endl; - return false; - } - } - else { - debugErr("sssi", "SASConnection::setTemplateNodeValue: parent node '", parentNodeName.toStdString().c_str(), "' not found for template tree: ", treeID); - std::cerr << "SASConnection::setTemplateNodeValue: Error" << std::endl << query.lastError().text().toStdString() << std::endl; - return false; - } - return true; -} - - -bool SASConnection::setNodeValue(int treeID, const QString &nameFragment, const QString &valueStr, bool warnings) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - vector<OTDBnode> fieldList = getItemList(treeID, nameFragment); - if (fieldList.size() == 1) { // should be unique property - QSqlQuery query("SELECT updateVTnode(" + - itsAuthToken + "," + - QString::number(treeID) + "," + - QString::number(fieldList.front().nodeID()) + ",'1','" + - valueStr - + "')", sasDB); - if (!query.isActive()) { // query successfully executed? - debugWarn("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } - } - else if (warnings) { - itsLastErrorString += QString("Non unique node '") + nameFragment + "' for tree:" + QString::number(treeID) + "\n"; - return false; - } - else return false; - - return true; -} - -bool SASConnection::setNodeValue(int treeID, int nodeID, const QString &valueStr) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT updateVTnode(" + - itsAuthToken + "," + - QString::number(treeID) + "," + - QString::number(nodeID) + ",'1','" + - valueStr - + "')", sasDB); - if (!query.isActive()) { // query successfully executed? - debugWarn("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } - - return true; -} - -bool SASConnection::getStationSettings(int treeID, StationTask &task) { - bool bResult(true); - QVariant value; - // station list - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.VirtualInstrument.stationList"); - if (value.isValid()) { - task.setStations(value.toString(),','); - } - else bResult = false; - // TODO: get station beamformers (super stations) - - // get the station antennamode - if (task.getType() != Task::MAINTENANCE) { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaSet"); - if (value.isValid()) { - task.setSASAntennaMode(value.toString().toStdString()); - } - else bResult = false; - - // get station RCU filter type - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.bandFilter"); - if (value.isValid()) { - task.setSASFilterType(value.toString().toStdString()); - } - else bResult = false; - - // get station clock frequency - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.clockMode"); - if (value.isValid()) { - if (value.toString().toStdString().compare("<<Clock160") == 0) { - task.setStationClock(clock_160Mhz); - } - else { - task.setStationClock(clock_200Mhz); - } - } - else bResult = false; - - // TBB piggybacking allowed - if (task.isObservation()) { - Observation &obs = static_cast<Observation &>(task); - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl.tbbPiggybackAllowed"); - if (value.isValid()) { - obs.setTBBPiggybackAllowed(value.toBool()); - } - else { // tbbPiggybackAllowed flag could not be read, this is not a severe error - std::cerr << "could not read TBB piggyback flag for tree:" << treeID << std::endl; - } - // Aartfaac piggybacking allowed - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl.aartfaacPiggybackAllowed"); - if (value.isValid()) { - obs.setAartfaacPiggybackAllowed(value.toBool()); - } - else { // aartfaacPiggybackAllowed flag could not be read, this is not a severe error - std::cerr << "could not read Aartfaac piggyback flag for tree:" << treeID << std::endl; - } - } - } - - return bResult; -} - -bool SASConnection::saveStationSettings(int treeID, const StationTask &task, const task_diff *diff) { - bool bResult(true); - - // set the list of stations in SAS - if (diff) { - if (diff->station_ids) { - QString stations(task.getSASStationList().c_str()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.VirtualInstrument.stationList", stations); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl._hostname", stations); - } - // TODO: set station beamformers (super stations) - - // set the station antennamode - if (diff->antenna_mode) { - QString antennaSet(task.getSASAntennaSet()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaSet", antennaSet); - if (antennaSet.startsWith("HBA")) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaArray", "HBA"); - } - else { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaArray", "LBA"); - } - } - // set station RCU filter type - if (diff->filter_type) - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.bandFilter", task.getSASFilterType()); - - // set station clock frequency - if (diff->clock_frequency) { - if (task.getStationClock() == clock_160Mhz) { - //clock mode - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.clockMode","<<Clock160")) return false; - // systemClock - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.sampleClock", STR_CLOCK160_SAMPLECLOCK)) return false; - } - else { - if (!setNodeValue(treeID,"LOFAR.ObsSW.Observation.clockMode","<<Clock200")) return false; - // systemClock - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.sampleClock", STR_CLOCK200_SAMPLECLOCK)) return false; - } - } - // nr of dataslots per RSP board (called 'nrSlotsInFrame' in SAS) -// if (diff->nrOfDataslotsPerRSPBoard) -// bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.nrSlotsInFrame", QString::number(task.getNrOfDataslotsPerRSPboard())); - - const Observation *obs = dynamic_cast<const Observation *>(&task); - if (obs) { - if (diff->TBBPiggybackAllowed) - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl.tbbPiggybackAllowed", - (obs->getTBBPiggybackAllowed() ? "true" : "false")); - if (diff->AartfaacPiggybackAllowed) - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl.aartfaacPiggybackAllowed", - (obs->getAartfaacPiggybackAllowed() ? "true" : "false")); - } - } - else { - QString stations(task.getSASStationList().c_str()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.VirtualInstrument.stationList", stations); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl._hostname", stations); - // TODO: set station beamformers (super stations) - - // set the station antennamode - QString antennaSet(task.getSASAntennaSet()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaSet", antennaSet); - if (antennaSet.startsWith("HBA")) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaArray", "HBA"); - } - else { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.antennaArray", "LBA"); - } - // set station RCU filter type - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.bandFilter", task.getSASFilterType()); - - // set station clock frequency - if (task.getStationClock() == clock_160Mhz) { - //clock mode - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.clockMode","<<Clock160")) return false; - // systemClock - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.sampleClock", STR_CLOCK160_SAMPLECLOCK)) return false; - } - else { - if (!setNodeValue(treeID,"LOFAR.ObsSW.Observation.clockMode","<<Clock200")) return false; - // systemClock - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.sampleClock", STR_CLOCK200_SAMPLECLOCK)) return false; - } - // nr of dataslots per RSP board (called 'nrSlotsInFrame' in SAS) -// bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.nrSlotsInFrame", QString::number(task.getNrOfDataslotsPerRSPboard())); - //This is nonsense code as diff = NULL here, it somehow works under certain compilers because the dynamic_cast fails (obs=NULL) - // TBB piggyback allowed? - //const Observation *obs = dynamic_cast<const Observation *>(&task); - //if (obs) { - // if (diff->TBBPiggybackAllowed) - // bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl.tbbPiggybackAllowed", - // (obs->getTBBPiggybackAllowed() ? "true" : "false")); - // if (diff->AartfaacPiggybackAllowed) - // bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.StationControl.aartfaacPiggybackAllowed", - // (obs->getAartfaacPiggybackAllowed() ? "true" : "false")); - //} - } - - return bResult; - -} - - -bool SASConnection::saveInputStorageSettings(int treeID, const Task &task) { - bool bResult(true); - //For CEP4 we're skipping this. /AR - return bResult; -} - -bool SASConnection::saveOutputStorageSettings(int treeID, const Task &task, const task_diff *diff) { - bool bResult(true); - //For CEP4 we're skipping this. /AR - return bResult; -} - -bool SASConnection::saveOutputDataProducts(int treeID, const Task &task) { - bool bResult(true); - const TaskStorage *task_storage(task.storage()); - if (task_storage) { - QString mountPointsStr, locationsStr, filenamesStr, skipVectorStr; - const std::map<dataProductTypes, TaskStorage::outputDataProduct> &outputDataProdukt(task_storage->getOutputDataProducts()); - bool testMode(Controller::theSchedulerSettings.getIsTestEnvironment()); - Task::task_type type(task.getType()); - std::map<dataProductTypes, TaskStorage::outputDataProduct>::const_iterator flit; - for (dataProductTypes dp = _BEGIN_DATA_PRODUCTS_ENUM_; dp < _END_DATA_PRODUCTS_ENUM_-1; dp = dataProductTypes(dp + 1)) { - flit = outputDataProdukt.find(dp); //flit = file list iterator - if (flit != outputDataProdukt.end()) { - if (task_storage->isOutputDataProduktAssigned(dp)) { - // compile the vector strings for SAS - locationsStr = "[" + flit->second.locations.join(",") + "]"; - filenamesStr = "[" + flit->second.filenames.join(",") + "]"; - mountPointsStr = "[" + flit->second.uniqueMointPoints.join(",") + "]"; - skipVectorStr = boolVector2StringVector(flit->second.skip); - } - else { - locationsStr = "[]"; - filenamesStr = "[]"; - mountPointsStr = "[]"; - skipVectorStr = "[]"; - } - - switch (dp) { - case DP_COHERENT_STOKES: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.locations", locationsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.mountpoints", mountPointsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.filenames", filenamesStr)) bResult = false; - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.skip", skipVectorStr)) bResult = false; - } - if (testMode) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.namemask", NAMEMASK_COHERENT_STOKES_TEST)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.dirmask", DIRMASK_COHERENT_STOKES_TEST)) bResult = false; - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.namemask", NAMEMASK_COHERENT_STOKES)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.dirmask", DIRMASK_COHERENT_STOKES)) bResult = false; - } - break; - case DP_INCOHERENT_STOKES: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.locations", locationsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.mountpoints", mountPointsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.filenames", filenamesStr)) bResult = false; - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.skip", skipVectorStr)) bResult = false; - } - if (testMode) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.namemask", NAMEMASK_INCOHERENT_STOKES_TEST)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.dirmask", DIRMASK_INCOHERENT_STOKES_TEST)) bResult = false; - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.namemask", NAMEMASK_INCOHERENT_STOKES)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.dirmask", DIRMASK_INCOHERENT_STOKES)) bResult = false; - } - break; - case DP_CORRELATED_UV: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.locations", locationsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.mountpoints", mountPointsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.filenames", filenamesStr)) bResult = false; - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.skip", skipVectorStr)) bResult = false; - } - if (testMode) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.namemask", NAMEMASK_CORRELATED_TEST)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.dirmask", DIRMASK_CORRELATED_TEST)) bResult = false; - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.namemask", NAMEMASK_CORRELATED)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.dirmask", DIRMASK_CORRELATED)) bResult = false; - } - break; - case DP_INSTRUMENT_MODEL: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.locations", locationsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.mountpoints", mountPointsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.filenames", filenamesStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.skip", skipVectorStr)) bResult = false; - if (testMode) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.namemask", NAMEMASK_INSTRUMENT_MODEL_TEST)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.dirmask", DIRMASK_INSTRUMENT_MODEL_TEST)) bResult = false; - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.namemask", NAMEMASK_INSTRUMENT_MODEL)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.dirmask", DIRMASK_INSTRUMENT_MODEL)) bResult = false; - } - break; - case DP_PULSAR: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.locations", locationsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.mountpoints", mountPointsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.filenames", filenamesStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.skip", skipVectorStr)) bResult = false; - if (testMode) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.namemask", NAMEMASK_PULSAR_TEST)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.dirmask", DIRMASK_PULSAR_TEST)) bResult = false; - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.namemask", NAMEMASK_PULSAR)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.dirmask", DIRMASK_PULSAR)) bResult = false; - } - break; - case DP_SKY_IMAGE: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.locations", locationsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.mountpoints", mountPointsStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.filenames", filenamesStr)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.skip", skipVectorStr)) bResult = false; - if (testMode) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.namemask", NAMEMASK_SKY_IMAGE_TEST)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.dirmask", DIRMASK_SKY_IMAGE_TEST)) bResult = false; - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.namemask", NAMEMASK_SKY_IMAGE)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.dirmask", DIRMASK_SKY_IMAGE)) bResult = false; - } - break; - default: - continue; - } - } - else { // write empty key values in the SAS database for this unused dataproduct, to make sure no old storage locations stay behind in SAS - switch (dp) { - case DP_COHERENT_STOKES: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.locations", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.mountpoints", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.filenames", "[]")) bResult = false; - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes.skip", "[]")) bResult = false; - } - break; - case DP_INCOHERENT_STOKES: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.locations", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.mountpoints", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.filenames", "[]")) bResult = false; - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes.skip", "[]")) bResult = false; - } - break; - case DP_CORRELATED_UV: - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.locations", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.mountpoints", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.filenames", "[]")) bResult = false; - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated.skip", "[]")) bResult = false; - } - break; - case DP_INSTRUMENT_MODEL: // always pipeline - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.locations", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.mountpoints", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.filenames", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel.skip", "[]")) bResult = false; - } - break; - case DP_PULSAR: // always pipeline - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.locations", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.mountpoints", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.filenames", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar.skip", "[]")) bResult = false; - } - break; - case DP_SKY_IMAGE: // always pipeline - if (type == Task::PIPELINE) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.locations", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.mountpoints", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.filenames", "[]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage.skip", "[]")) bResult = false; - } - break; - default: - continue; - } - } - } - } - return bResult; -} - - -void SASConnection::getCampaignInfo(Task &task) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - string campaign = task.SASTree().campaign(); - task.setProjectID(campaign); - QSqlQuery query(sasDB); - // we have to use QSqlQuery prepare and bindValue functions to automatically escape the campaign name which may contain special characters such as apostrophs - query.prepare("SELECT * from getcampaign(:campaignName)"); - query.bindValue(":campaignName", QString(campaign.c_str())); - if (query.exec()) { - if (query.next()) { - task.setProjectName(query.value(query.record().indexOf("title")).toString().toStdString()); - task.setContactName(query.value(query.record().indexOf("contact")).toString().toStdString()); - task.setProjectCO_I(query.value(query.record().indexOf("co_i")).toString().toStdString()); - task.setProjectPI(query.value(query.record().indexOf("pi")).toString().toStdString()); - } - } - else { - itsProgressDialog.addError(QString("Error: The campaign info of SAS tree: ") + QString::number(task.SASTree().treeID()) + " could not be read"); - } -} - -void SASConnection::getInputStorageSettings(int treeID, Task &task) { - TaskStorage *task_storage(task.storage()); - if (task_storage) { - QVariant valueVector, enabledKey; - QString keyPrefix; - bool enabledValue(false); - std::vector<dataProductTypes> fetchDataProducts; - if (task.isPipeline()) { - processSubTypes pst(task.getProcessSubtype()); - if (pst == PST_IMAGING_PIPELINE || pst == PST_MSSS_IMAGING_PIPELINE || pst == PST_AVERAGING_PIPELINE || pst == PST_LONG_BASELINE_PIPELINE) { - fetchDataProducts.push_back(DP_CORRELATED_UV); - } - else if (pst == PST_CALIBRATION_PIPELINE) { - fetchDataProducts.push_back(DP_CORRELATED_UV); - fetchDataProducts.push_back(DP_INSTRUMENT_MODEL); - } - else if (pst == PST_PULSAR_PIPELINE) { - fetchDataProducts.push_back(DP_COHERENT_STOKES); - fetchDataProducts.push_back(DP_INCOHERENT_STOKES); - } - else { - fetchDataProducts.push_back(DP_COHERENT_STOKES); - fetchDataProducts.push_back(DP_INCOHERENT_STOKES); - fetchDataProducts.push_back(DP_CORRELATED_UV); - fetchDataProducts.push_back(DP_INSTRUMENT_MODEL); - } - } - else if (task.isObservation()) { // only fetch input data product types relevant for the task type - return; // observation has no input data products - } - else if (task.isUnknown()) { - fetchDataProducts.push_back(DP_CORRELATED_UV); - fetchDataProducts.push_back(DP_COHERENT_STOKES); - fetchDataProducts.push_back(DP_INCOHERENT_STOKES); - fetchDataProducts.push_back(DP_INSTRUMENT_MODEL); - // fetchDataProducts.push_back(DP_SKY_IMAGE); - } - for (std::vector<dataProductTypes>::const_iterator dpit = fetchDataProducts.begin(); dpit != fetchDataProducts.end(); ++dpit) { - switch (*dpit) { - case DP_COHERENT_STOKES: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Input_CoherentStokes."; - break; - case DP_CORRELATED_UV: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Input_Correlated."; - break; - case DP_INCOHERENT_STOKES: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Input_IncoherentStokes."; - break; - case DP_INSTRUMENT_MODEL: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Input_InstrumentModel."; - break; - case DP_SKY_IMAGE: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Input_SkyImage."; - break; - default: - break; - } - // now fetch the identifications from SAS and add them to the task as an input data product identification - enabledKey = getNodeValue(treeID, keyPrefix + "enabled"); - if (enabledKey.isValid()) enabledValue = enabledKey.toBool(); - task_storage->setInputDataProductEnabled(*dpit, enabledValue); - QStringList identificationsList, filenames, locations; - std::vector<bool> skipVector; - - valueVector = getNodeValue(treeID, keyPrefix + "identifications"); - if (valueVector.isValid()) { - identificationsList = valueVector.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts); - if (!identificationsList.empty()) { - task_storage->addInputDataProductID(*dpit, identificationsList); - } - } - valueVector = getNodeValue(treeID, keyPrefix + "filenames"); - if (valueVector.isValid()) { - filenames = valueVector.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts); - } - valueVector = getNodeValue(treeID, keyPrefix + "locations"); - if (valueVector.isValid()) { - locations = valueVector.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts); - } - valueVector = getNodeValue(treeID, keyPrefix + "skip"); - if (valueVector.isValid()) { - skipVector = string2VectorOfBools(valueVector.toString()); - } - if (filenames.size() == locations.size()) { - if (filenames.size() > 0) { - task_storage->setInputFilesForDataProduct(*dpit, filenames, locations, skipVector); - } - } - else { - itsProgressDialog.addError(QString("tree:") + QString::number(treeID) + " input data product type:" + DATA_PRODUCTS[*dpit] + " filenames and locations array have unequal size"); - } - } - } -} - -void SASConnection::getOutputStorageSettings(int treeID, Task &task) { - TaskStorage *task_storage(task.storage()); - if (task_storage) { - QStringList nodeList, raidList; - QString storageLocationsKey, keyPrefix; - QString outputCluster; // Added to support CEP2/4 switch /AR - QVariant enabledKey; - bool enabledValue; - task_storage->unAssignStorage(); // clear the tasks storage, we will be adding incrementally (Task::setStorage() doesn't delete existing storage locations - std::vector<dataProductTypes> fetchDataProducts; - if (task.isObservation()) { // only fetch output data product types relevant for the task type - fetchDataProducts.push_back(DP_CORRELATED_UV); - fetchDataProducts.push_back(DP_COHERENT_STOKES); - fetchDataProducts.push_back(DP_INCOHERENT_STOKES); - // fetchDataProducts.push_back(DP_INSTRUMENT_MODEL); - // fetchDataProducts.push_back(DP_SKY_IMAGE); - } - else if (task.isPipeline()) { - processSubTypes pst(task.getProcessSubtype()); - if (pst == PST_CALIBRATION_PIPELINE) { - fetchDataProducts.push_back(DP_CORRELATED_UV); - fetchDataProducts.push_back(DP_INSTRUMENT_MODEL); - } - else if (pst == PST_AVERAGING_PIPELINE || pst == PST_LONG_BASELINE_PIPELINE) { - fetchDataProducts.push_back(DP_CORRELATED_UV); - } - else if (pst == PST_IMAGING_PIPELINE || pst == PST_MSSS_IMAGING_PIPELINE) { - fetchDataProducts.push_back(DP_SKY_IMAGE); - } - else if (pst == PST_PULSAR_PIPELINE) { - fetchDataProducts.push_back(DP_PULSAR); - } - } - else if (task.isUnknown()) { - fetchDataProducts.push_back(DP_CORRELATED_UV); - fetchDataProducts.push_back(DP_COHERENT_STOKES); - fetchDataProducts.push_back(DP_INCOHERENT_STOKES); - fetchDataProducts.push_back(DP_INSTRUMENT_MODEL); - fetchDataProducts.push_back(DP_PULSAR); - fetchDataProducts.push_back(DP_SKY_IMAGE); - } - for (std::vector<dataProductTypes>::const_iterator dpit = fetchDataProducts.begin(); dpit != fetchDataProducts.end(); ++dpit) { - nodeList.clear(); - raidList.clear(); - switch (*dpit) { - case DP_COHERENT_STOKES: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Output_CoherentStokes."; - break; - case DP_CORRELATED_UV: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Output_Correlated."; - break; - case DP_INCOHERENT_STOKES: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Output_IncoherentStokes."; - break; - case DP_INSTRUMENT_MODEL: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Output_InstrumentModel."; - break; - case DP_PULSAR: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Output_Pulsar."; - break; - case DP_SKY_IMAGE: - keyPrefix = "LOFAR.ObsSW.Observation.DataProducts.Output_SkyImage."; - break; - default: - continue; - } - enabledKey = getNodeValue(treeID, keyPrefix + "enabled"); - if (enabledKey.isValid()) { - enabledValue = enabledKey.toBool(); - task_storage->setOutputDataProductEnabled(*dpit, enabledValue); - } - - storageLocationsKey = keyPrefix + "mountpoints"; - QVariant value; - - value = getNodeValue(treeID, storageLocationsKey); - if (value.isValid()) { - QStringList storageLocationList = value.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts);//string2VectorOfStrings(value.toString()); - if (!storageLocationList.empty()) { - // parse the long location string array into separate lists of nodes and raid arrays - for (QStringList::iterator it = storageLocationList.begin(); it != storageLocationList.end(); ++it) - { - nodeList.append(it->section(':',0,0)); // extracts lseXXX from "lseXXX:/dataY" - raidList.append(it->section('/',1,1,QString::SectionIncludeLeadingSep)); // extracts dataY from "lseXXX:/dataY" - } - if (!task_storage->setStorage(*dpit, nodeList, raidList)) { - itsProgressDialog.addError(QString("Warning: The storage settings of SAS tree: ") + QString::number(treeID) + " has non existing storage nodes or raid sets."); - } - task_storage->setOutputFileMountpoints(*dpit, storageLocationList); - if (task.getStatus() >= Task::SCHEDULED) { - task_storage->setOutputDataProductAssigned(*dpit, true); - } - } - else { - task_storage->clearOutputFileMountpoints(*dpit); - } - } - - QStringList filenames, locations; - std::vector<bool> skipVector; - - value = getNodeValue(treeID, keyPrefix + "filenames"); - if (value.isValid()) { - filenames = value.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts);//string2VectorOfStrings(value.toString()); - } - - value = getNodeValue(treeID, keyPrefix + "locations"); - if (value.isValid()) { - locations = value.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts);//string2VectorOfStrings(value.toString()); - } - - value = getNodeValue(treeID, keyPrefix + "skip"); - if (value.isValid()) { - skipVector = string2VectorOfBools(value.toString()); - } - - if (filenames.size() == locations.size()) { - if (skipVector.size() != (unsigned)filenames.size()) { - skipVector.assign(filenames.size(), false); - } - task_storage->setOutputFilesForDataProduct(*dpit, filenames, locations, skipVector); - } - else { - itsProgressDialog.addError(QString("tree:") + QString::number(treeID) + " output data product type:" + DATA_PRODUCTS[*dpit] + " filenames and locations array have unequal size"); - } - - // also set the output data product identifications - value = getNodeValue(treeID, keyPrefix + "identifications"); - if (value.isValid()) { - QStringList identificationsList = value.toString().remove('[').remove(']').split(',',QString::SkipEmptyParts);// string2VectorOfStrings(value.toString()); - task_storage->addOutputDataProductID(*dpit, identificationsList); - } - - // get values for storage cluster /AR - value = getNodeValue(treeID, keyPrefix + "storageClusterName"); - if (value.isValid()) { - QString cluster = value.toString(); - if (!cluster.isEmpty()) { - if (outputCluster.isEmpty()) { - outputCluster = cluster; - } - else { - if (cluster != outputCluster) { - itsProgressDialog.addError(QString("tree:") + QString::number(treeID) + " output data product type:" + DATA_PRODUCTS[*dpit] + " different output clusters are not supported"); - } - } - } - //We probably will not need to support this: task_storage->addOutputDataProductCluster(*dpit, ?); /AR - } - } - if (!outputCluster.isEmpty()) { - task.setOutputDataproductCluster(outputCluster); - } - else { - task.setOutputDataproductCluster("CEP2"); // CEP2 is default for backward compatibility /AR - } - } -} - -bool SASConnection::setTreeSchedule(int treeID, const Task &task) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if ((task.getScheduledStart().isSet()) && (task.getScheduledEnd().isSet())) { - QSqlQuery query("SELECT setSchedule(" + - itsAuthToken + "," + - QString::number(treeID) + ",'" + - task.getScheduledStart().toSASDateTimeString().c_str() + "','" + - task.getScheduledEnd().toSASDateTimeString().c_str() + "','true')", sasDB); - if (query.isActive()) { // query successfully executed? - query.finish(); - return true; - } - else { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } - } - return true; -} - -bool SASConnection::setTreeState(int treeID, int SAS_state) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT setTreeState(" + - itsAuthToken + "," + - QString::number(treeID) + ",'" + - QString::number(SAS_state) + "')", sasDB); - if (query.isActive()) { // query successfully executed? - query.finish(); - return true; - } - else { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } -} - -bool SASConnection::saveMoMinfo(int treeID, const Task &task) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - if (!task.SASTree().campaign().empty()) { - QSqlQuery query("SELECT setmominfo(" + - itsAuthToken + "," + - QString::number(treeID) + "," + QString::number(task.SASTree().momID()) + - "," + QString::number(task.SASTree().groupID()) + - ",'" + task.SASTree().campaign().c_str() + "')", sasDB); -// std::cout << query.lastQuery().toStdString() << std::endl; -// std::cout << query.lastError().text().toStdString() << std::endl; - - if (query.isActive()) { // query successfully executed? - query.finish(); - return true; - } - else { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } - } - else { - debugWarn("sis", "Could not save mom info to SAS for tree:", treeID, " because campaign is empty"); - return true; - } -} - - - - -bool SASConnection::saveDescription(int treeID, const Task &task) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("SELECT setDescription(" + - itsAuthToken + "," + - QString::number(treeID) + ",'" + - task.SASTree().description().c_str() + "')", sasDB); - if (query.isActive()) { // query successfully executed? - query.finish(); - return true; - } - else { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - return false; - } -} - -bool SASConnection::saveAnalogBeamSettings(int treeID, const Observation &task, const task_diff *diff) { - bool bResult(true); - // analog beam - const Observation::analogBeamSettings &analogBeam = task.getAnalogBeam(); - if (diff) { - // analog beam angle 1 and 2 - if (diff->ana_beam_angle1) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].angle1", QString::number(analogBeam.angle1.radian()))) bResult = false; - if (diff->ana_beam_angle2) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].angle2", QString::number(analogBeam.angle2.radian()))) bResult = false; - // analog beam coordinate system - if (diff->ana_beam_direction_type) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].directionType", BEAM_DIRECTION_TYPES[analogBeam.directionType])) bResult = false; - // analog beam start time - if (diff->ana_beam_starttime) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].startTime", QString::number(analogBeam.startTime.totalSeconds()))) bResult = false; - // analog beam duration - if (diff->ana_beam_duration) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].duration", QString::number(analogBeam.duration.totalSeconds()))) bResult = false; - } - else { - // analog beam angle 1 and 2 - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].angle1", QString::number(analogBeam.angle1.radian()))) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].angle2", QString::number(analogBeam.angle2.radian()))) bResult = false; - // analog beam coordinate system - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].directionType", BEAM_DIRECTION_TYPES[analogBeam.directionType])) bResult = false; - // analog beam start time - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].startTime", QString::number(analogBeam.startTime.totalSeconds()))) bResult = false; - // analog beam duration - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].duration", QString::number(analogBeam.duration.totalSeconds()))) bResult = false; - } - return bResult; -} - -bool SASConnection::getAnalogBeamSettings(int treeID, Observation &task) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QVariant value; - - QSqlQuery query("SELECT nodeid from getVHitemList(" + QString::number(treeID) + ",'LOFAR.ObsSW.Observation.AnaBeam[0]')", sasDB); - if (query.next()) { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].angle1"); - if (value.isValid()) task.setAnalogBeamAngle1(value.toDouble()); - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].angle2"); - if (value.isValid()) task.setAnalogBeamAngle2(value.toDouble()); - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].directionType"); - if (value.isValid()) task.setAnalogBeamDirectionType(stringToBeamDirectionType(value.toString().toStdString())); - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].duration"); - if (value.isValid()) task.setAnalogBeamDuration(value.toInt()); - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.AnaBeam[0].startTime"); - if (value.isValid()) task.setAnalogBeamStartTime(value.toInt()); - else bResult = false; - } - return bResult; -} - - -bool SASConnection::saveDataSlots(int treeID, const Observation &task) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - const dataSlotMap &dataslots = task.getDataSlots(); - QString strParentDataslotNodeID, antennaFieldName, antennaFieldName2, stationName, RSPBoardList, DataSlotList, antennaField(task.getAntennaField().c_str()); - // empty existing dataslot fields in SAS - // TODO: SASConnection::saveDataSlots, should be a delete node for VIC trees to delete the old nodes completely - - // get the node ID of the parent node (Observation.Dataslots node) in the VIC tree under which the dataslot info needs to be saved - if (query.exec("SELECT nodeid from getVHitemList(" + QString::number(treeID) + ",'LOFAR.ObsSW.Observation.Dataslots')")) { - if (query.next()) { - strParentDataslotNodeID = query.value(0).toString(); - } - } - else { - debugErr("sis","The Dataslots node doesn't exist in the VIC tree ", treeID, ", Cannot save dataslot info to this tree"); - return false; - } - query.finish(); - - // get the node ID of the dataslots node of the (default) template used for this task - QString dataSlotTemplateIDstr; -// if (itsDataslotTemplateIDstr.isEmpty()) { - query.exec("SELECT nodeid from getVTitemList(" + QString::number(task.getOriginalTreeID()) + ",'DataslotInfo')"); - if (query.next()) { - dataSlotTemplateIDstr = query.value(0).toString(); - } - else { - unsigned pid(Controller::theSchedulerSettings.getSchedulerDefaultTemplate()); - if (pid != 0) { - std::cerr << "parent default template for tree " << treeID << " does not exist anymore. Using the scheduler default template to create the DataslotInfo nodes." << std::endl; - query.exec("SELECT nodeid from getVTitemList(" + QString::number(pid) + ",'DataslotInfo')"); - if (query.next()) { - dataSlotTemplateIDstr = query.value(0).toString(); - } - } - else { - std::cerr << "could not write the DataslotInfo for tree:" << treeID << " because the parent template:" << task.getOriginalTreeID() << " does not exist" << std::endl; - bResult = false; - } - } - query.finish(); -// } -// else { -// dataSlotTemplateIDstr = itsDataslotTemplateIDstr; -// } - - if (!dataSlotTemplateIDstr.isEmpty()) { - for (dataSlotMap::const_iterator it = dataslots.begin(); it != dataslots.end(); ++it) { // iterates over all stations (antennafields) - stationName = Controller::theSchedulerSettings.getStationName(it->first).c_str(); - if (stationName.startsWith("CS")) { // core station has HBA0 and HBA1 - if (antennaField.compare("HBA_DUAL") == 0) { // antenna field is HBA_DUAL for both HBA_DUAL and HBA_DUAL_INNER antenna modes - antennaFieldName = stationName + "HBA0"; - antennaFieldName2 = stationName + "HBA1"; - } - else { - antennaFieldName = stationName + antennaField; - antennaFieldName2 = ""; - } - } - else { // non core station only has HBA (no HBA0 nor HBA1) - if (antennaField.startsWith("HBA")) { - antennaFieldName = stationName + "HBA"; - antennaFieldName2 = ""; - } - else { - antennaFieldName = stationName + antennaField; - antennaFieldName2 = ""; - } - } - RSPBoardList = "["; - DataSlotList = "["; - for (stationDataSlotMap::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) {// iterates over the RSPboards and assigned dataslots - RSPBoardList += QString::number(sit->second.second - sit->second.first + 1) + "*" + QString::number(sit->first) + ","; - DataSlotList += QString::number(sit->second.first) + ".." + QString::number(sit->second.second) + ","; - } - if (!(it->second.empty())) { // if dataslots were written in previous for loop, then delete the last comma and add a closing bracket - RSPBoardList = RSPBoardList.left(RSPBoardList.length()-1) + "]"; // deletes the last comma and adds ']' - DataSlotList = DataSlotList.left(DataSlotList.length()-1) + "]"; // deletes the last comma and adds ']' - } - else { // only add closing bracket - RSPBoardList += "]"; - DataSlotList += "]"; // deletes the last comma and adds ']' - } - - bResult &= createAndWriteDataSlotNodes(treeID, dataSlotTemplateIDstr, strParentDataslotNodeID, antennaFieldName, RSPBoardList, DataSlotList); - if (!antennaFieldName2.isEmpty()) { - bResult &= createAndWriteDataSlotNodes(treeID, dataSlotTemplateIDstr, strParentDataslotNodeID, antennaFieldName2, RSPBoardList, DataSlotList); - } - } - } - - return bResult; -} - -bool SASConnection::createAndWriteDataSlotNodes(int treeID, const QString &dataSlotTemplateIDstr, const QString &strParentDataslotNodeID, const QString &antennaFieldName, - const QString &RSPBoardList, const QString &DataSlotList) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - - // check if this antennafield for this station already exists in the SAS tree - QVariant value(getNodeValue(treeID, "LOFAR.ObsSW.Observation.Dataslots." + antennaFieldName, true)); - if (!value.isValid()) { // if the antennafield node under dataslots doesn't exist create it - QSqlQuery query(sasDB); - QString strTreeID(QString::number(treeID)); - // dataslotinfo nodes do not yet exist for this station -> create them - if (!query.exec("select * from instanciateVHleafNode(" + - dataSlotTemplateIDstr + "," + - strTreeID + "," + - strParentDataslotNodeID + ",'-1','LOFAR.ObsSW.Observation.Dataslots." + antennaFieldName + "')")) { - QString err("could not create dataslot nodes for tree:" + strTreeID + " and antennafield:" + antennaFieldName); - err += "\n" + query.lastError().text() + "\nquery:" + query.lastQuery(); - debugErr("s", err.toStdString().c_str()); - itsLastErrorString += err + "\n"; - bResult = false; - } - query.finish(); - } - // save the actual values to the dataslot info node - if (bResult) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.Dataslots." + antennaFieldName + ".RSPBoardList", RSPBoardList)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.Dataslots." + antennaFieldName + ".DataslotList", DataSlotList)) bResult = false; - } - return bResult; -} - -bool SASConnection::getCampaignsFromSAS(void) { - Controller::theSchedulerSettings.clearCampaigns(); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - campaignMap campaigns; - if (query.exec("select * from getcampaignlist()")) { - campaignInfo campaign; - while (query.next()) { - campaign.id = query.value(query.record().indexOf("id")).toUInt(); - campaign.name = query.value(query.record().indexOf("name")).toString().toStdString(); - campaign.title = query.value(query.record().indexOf("title")).toString().toStdString(); - campaign.PriInvestigator = query.value(query.record().indexOf("pi")).toString().toStdString(); - campaign.CoInvestigator = query.value(query.record().indexOf("co_i")).toString().toStdString(); - campaign.contact = query.value(query.record().indexOf("contact")).toString().toStdString(); - // store in itsCampaigns - campaigns.insert(campaignMap::value_type(campaign.name, campaign)); - } - Controller::theSchedulerSettings.setCampaigns(campaigns); - return true; - } - else { - std::cerr << query.lastError().text().toStdString() << std::endl; - return false; - } -} - -bool SASConnection::saveProcessingSettings(int treeID, const Observation &task, const task_diff *diff) { - bool bResult(true); - QString trueStr("true"), falseStr("false"); - const Observation::RTCPsettings &RTCPsettings = task.getRTCPsettings(); - if (diff) { - if (diff->RTCP_coherent_stokes_settings) { - // Coherent Stokes - if (RTCPsettings.coherentType < _END_DATA_TYPES) { - // Analogous setting for COBALT - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.which", DATA_TYPES[RTCPsettings.coherentType] )) bResult = false; - } - else { - bResult = false; - std::cerr << "ERROR: tree " << treeID << " coherent data type (which) not set!" << std::endl; - } - // Coherent Stokes settings - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.timeIntegrationFactor", QString::number(RTCPsettings.coherentTimeIntegrationFactor) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.nrChannelsPerSubband", QString::number(RTCPsettings.coherentChannelsPerSubband) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.subbandsPerFile", QString::number(RTCPsettings.coherentSubbandsPerFile) )) bResult = false; - } - if (diff->RTCP_incoherent_stokes_settings) { - // Incoherent Stokes - if (RTCPsettings.incoherentType < _END_DATA_TYPES) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.which", DATA_TYPES[RTCPsettings.incoherentType] )) bResult = false; - } - else { - bResult = false; - std::cerr << "ERROR: tree " << treeID << " incoherent data type (which) not set!" << std::endl; - } - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.timeIntegrationFactor", QString::number(RTCPsettings.incoherentTimeIntegrationFactor) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.nrChannelsPerSubband", QString::number(RTCPsettings.incoherentChannelsPerSubband) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.subbandsPerFile", QString::number(RTCPsettings.incoherentSubbandsPerFile) )) bResult = false; - } - // pencil info - if (diff->RTCP_pencil_flys_eye) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.flysEye", (RTCPsettings.flysEye ? trueStr : falseStr))) bResult = false; - if (diff->RTCP_correct_bandpass) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.correctBandPass", (RTCPsettings.correctBandPass ? trueStr : falseStr))) bResult = false; - } - if (diff->RTCP_delay_compensation) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.delayCompensation", (RTCPsettings.delayCompensation ? trueStr : falseStr))) bResult = false; - } - if (diff->RTCP_nr_bits_per_sample) - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.nrBitsPerSample", QString::number(RTCPsettings.nrBitsPerSample))) bResult = false; - if (diff->RTCP_channels_per_subband) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrChannelsPerSubband", QString::number(RTCPsettings.channelsPerSubband))) bResult = false; - } - if (diff->RTCP_coherent_dedispersion) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.coherentDedisperseChannels", (RTCPsettings.coherentDedisperseChannels ? trueStr : falseStr))) bResult = false; - } - } - else { - // coherent Stokes data - if (RTCPsettings.coherentType < _END_DATA_TYPES) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.which", DATA_TYPES[RTCPsettings.coherentType] )) bResult = false; - } - else { - bResult = false; - std::cerr << "ERROR: tree " << treeID << " coherent data type (which) not set!" << std::endl; - } - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.timeIntegrationFactor", QString::number(RTCPsettings.coherentTimeIntegrationFactor) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.nrChannelsPerSubband", QString::number(RTCPsettings.coherentChannelsPerSubband) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.subbandsPerFile", QString::number(RTCPsettings.coherentSubbandsPerFile) )) bResult = false; - // Incoherent Stokes - if (RTCPsettings.incoherentType < _END_DATA_TYPES) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.which", DATA_TYPES[RTCPsettings.incoherentType] )) bResult = false; - } - else { - bResult = false; - std::cerr << "ERROR: tree " << treeID << " incoherent stokes type (which) not set!" << std::endl; - } - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.timeIntegrationFactor", QString::number(RTCPsettings.incoherentTimeIntegrationFactor) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.nrChannelsPerSubband", QString::number(RTCPsettings.incoherentChannelsPerSubband) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.subbandsPerFile", QString::number(RTCPsettings.incoherentSubbandsPerFile) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.flysEye", (RTCPsettings.flysEye ? trueStr : falseStr))) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.correctBandPass", (RTCPsettings.correctBandPass ? trueStr : falseStr))) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.delayCompensation", (RTCPsettings.delayCompensation ? trueStr : falseStr))) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.nrBitsPerSample", QString::number(RTCPsettings.nrBitsPerSample))) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrChannelsPerSubband", QString::number(RTCPsettings.channelsPerSubband))) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.coherentDedisperseChannels", (RTCPsettings.coherentDedisperseChannels ? trueStr : falseStr))) bResult = false; - } - - return bResult; -} - -bool SASConnection::saveCobaltBlockSize(int treeID, const Observation &task) { - bool bResult(true); - BlockSize bs = calcCobaltBlockSize(task.getRTCPsettings(), task.storage()->getOutputDataProductsEnabled(), task.getStationClockFrequency()); - QString correlatorIntTime(QString::number(bs.integrationTime)), - blockSize(QString::number(bs.blockSize)), - nrBlocks(QString::number(bs.nrBlocks)), - nrSubblocks(QString::number(bs.nrSubblocks)); - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.integrationTime", correlatorIntTime)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrBlocksPerIntegration", nrBlocks)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrIntegrationsPerBlock", nrSubblocks)) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.blockSize", blockSize)) bResult = false; - return bResult; -} - -BlockSize SASConnection::calcCobaltBlockSize(Observation::RTCPsettings rtcp, TaskStorage::enableDataProdukts enabledOutputs, unsigned short clockMHz) const { - size_t factor = BlockSize::calcFactor( - enabledOutputs.correlated, - rtcp.channelsPerSubband, - rtcp.correlatorIntegrationTime, - enabledOutputs.coherentStokes, - rtcp.coherentChannelsPerSubband, - rtcp.coherentTimeIntegrationFactor, - enabledOutputs.incoherentStokes, - rtcp.incoherentChannelsPerSubband, - rtcp.incoherentTimeIntegrationFactor); - - return BlockSize(rtcp.correlatorIntegrationTime, factor, clockMHz); -} - -bool SASConnection::getProcessingSettings(int treeID, Observation &task) { - bool bResult(true); - QVariant value; - Observation::RTCPsettings RTCPsettings; - - // coherent Stokes data - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.which"); - if (value.isValid()) { - RTCPsettings.coherentType = stringToStokesType(value.toString().toStdString()); - } - else { - RTCPsettings.coherentType = DATA_TYPE_UNDEFINED; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.timeIntegrationFactor"); - if (value.isValid()) { - RTCPsettings.coherentTimeIntegrationFactor = value.toUInt(); - } - else { - RTCPsettings.coherentTimeIntegrationFactor = 0; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.nrChannelsPerSubband"); - if (value.isValid()) { - RTCPsettings.coherentChannelsPerSubband = value.toUInt(); - } - else { - RTCPsettings.coherentChannelsPerSubband = 0; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.CoherentStokes.subbandsPerFile"); - if (value.isValid()) { - RTCPsettings.coherentSubbandsPerFile = value.toUInt(); - } - else { - RTCPsettings.coherentSubbandsPerFile = 0; - bResult = false; - } - - // incoherent Stokes data - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.which"); - if (value.isValid()) { - RTCPsettings.incoherentType = stringToStokesType(value.toString().toStdString()); - } - else { - RTCPsettings.incoherentType = DATA_TYPE_UNDEFINED; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.timeIntegrationFactor"); - if (value.isValid()) { - RTCPsettings.incoherentTimeIntegrationFactor = value.toUInt(); - } - else { - RTCPsettings.incoherentTimeIntegrationFactor = 0; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.nrChannelsPerSubband"); - if (value.isValid()) { - RTCPsettings.incoherentChannelsPerSubband = value.toUInt(); - } - else { - RTCPsettings.incoherentChannelsPerSubband = 0; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.IncoherentStokes.subbandsPerFile"); - if (value.isValid()) { - RTCPsettings.incoherentSubbandsPerFile = value.toUInt(); - } - else { - RTCPsettings.incoherentSubbandsPerFile = 0; - bResult = false; - } - - // flys eye switch - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.flysEye", true); - if (value.isValid()) { - RTCPsettings.flysEye = value.toBool(); - } - else { - // backwards compatibility for moved flys eye switch - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.OLAP.PencilInfo.flysEye"); - if (value.isValid()) { - RTCPsettings.flysEye = value.toBool(); - } - else { - RTCPsettings.flysEye = false; - bResult = false; - } - } - - // other Cobalt options and settings - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.correctBandPass"); - if (value.isValid()) { - RTCPsettings.correctBandPass = value.toBool(); - } - else { - RTCPsettings.correctBandPass = false; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.delayCompensation"); - if (value.isValid()) { - RTCPsettings.delayCompensation = value.toBool(); - } - else { - RTCPsettings.delayCompensation = false; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.integrationTime"); - if (value.isValid()) { - RTCPsettings.correlatorIntegrationTime = value.toDouble(); - } - else { - RTCPsettings.correlatorIntegrationTime = 0.0; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.nrBitsPerSample", true); - if (value.isValid()) { - RTCPsettings.nrBitsPerSample = value.toInt(); - } - else { - itsProgressDialog.addError(QString("Warning: could not read Observation.nrBitsPerSample of SAS tree:" + QString::number(treeID))); - RTCPsettings.nrBitsPerSample = 16; - bResult = false; - } - - // set the number of dataslots per RSP board according to the read nrBitsPerSample - switch (RTCPsettings.nrBitsPerSample) { - default: - case 16: - task.setNrOfDataslotsPerRSPboard(MAX_DATASLOT_PER_RSP_16_BITS +1); - break; - case 8: - task.setNrOfDataslotsPerRSPboard(MAX_DATASLOT_PER_RSP_8_BITS +1); - break; - case 4: - task.setNrOfDataslotsPerRSPboard(MAX_DATASLOT_PER_RSP_4_BITS +1); - break; - } - - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.BeamFormer.coherentDedisperseChannels"); - if (value.isValid()) { - RTCPsettings.coherentDedisperseChannels = value.toBool(); - } - else { - RTCPsettings.coherentDedisperseChannels = false; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.OnlineControl.Cobalt.Correlator.nrChannelsPerSubband"); - if (value.isValid()) { - RTCPsettings.channelsPerSubband = value.toInt(); - } - else { - RTCPsettings.channelsPerSubband = 0; - bResult = false; - } - - task.setRTCPsettings(RTCPsettings); - return bResult; -} - - -bool SASConnection::getCalibrationSettings(int treeID, CalibrationPipeline &task) { - bool bResult(true); - QVariant value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Calibration.SkyModel"); - if (value.isValid()) { - task.setSkyModel(value.toString()); - } - else { - task.setSkyModel(""); - bResult = false; - } - return bResult; -} - -bool SASConnection::getDemixingSettings(int treeID, CalibrationPipeline &task) { - bool bResult(true); - QVariant value; - DemixingSettings settings; - - bool DPPP_demixer_step(false), DPPP0_demixer_step(false), DPPP_averager_step(false), DPPP0_averager_step(false); - - // first check which nodes exists and which steps are done for DPPP - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.steps", true); - if (value.isValid()) { - QString steps(value.toString()); - if (steps.contains("demixer")) { - DPPP_demixer_step = true; - settings.itsDemixingEnabled = true; - } - - if (steps.contains("averager")) { - DPPP_averager_step = true; - } - } - else { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].steps", true); - if (value.isValid()) { - QString steps(value.toString()); - if (steps.contains("demixer")) { - DPPP0_demixer_step = true; - settings.itsDemixingEnabled = true; - } - if (steps.contains("averager")) { - DPPP0_averager_step = true; - } - } - else { - itsProgressDialog.addError("Could not fetch the DPPP steps for tree:" + QString::number(treeID)); - } - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.demix_always"); - if (value.isValid()) { - settings.itsDemixAlways = value.toString().remove("[").remove("]"); - } - else { - settings.itsDemixAlways = ""; - bResult = false; - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.demix_if_needed"); - if (value.isValid()) { - settings.itsDemixIfNeeded = value.toString().remove("[").remove("]"); - } - else { - settings.itsDemixIfNeeded = ""; - bResult = false; - } - // (user supplied) demixing SkyModel - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.SkyModel"); - if (value.isValid()) { - settings.itsSkyModel = value.toString(); - } - else { - settings.itsSkyModel = ""; - bResult = false; - } - - // averaging freq step, first try fetch from DPPP.freqstep, if not existing then DPPP[0].freqstep, else from averager.freqstep -// settings.freqStep = 0; -// settings.timeStep = 0; -// settings.demixFreqStep = 0; -// settings.demixTimeStep = 0; - - if (DPPP_demixer_step) { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.freqstep"); - if (value.isValid()) { - settings.itsFreqStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.timestep"); - if (value.isValid()) { - settings.itsTimeStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.demixfreqstep"); - if (value.isValid()) { - settings.itsDemixFreqStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.demixtimestep"); - if (value.isValid()) { - settings.itsDemixTimeStep = value.toUInt(); - } - } - else if (DPPP0_demixer_step) { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.freqstep"); - if (value.isValid()) { - settings.itsFreqStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.timestep"); - if (value.isValid()) { - settings.itsTimeStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.demixfreqstep"); - if (value.isValid()) { - settings.itsDemixFreqStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.demixtimestep"); - if (value.isValid()) { - settings.itsDemixTimeStep = value.toUInt(); - } - } - else if (DPPP_averager_step) { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.averager.freqstep"); - if (value.isValid()) { - settings.itsFreqStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.averager.timestep"); - if (value.isValid()) { - settings.itsTimeStep = value.toUInt(); - } - } - else if (DPPP0_averager_step) { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].averager.freqstep"); - if (value.isValid()) { - settings.itsFreqStep = value.toUInt(); - } - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].averager.timestep"); - if (value.isValid()) { - settings.itsTimeStep = value.toUInt(); - } - } - - task.setDemixingSettings(settings); - return bResult; - -} - -bool SASConnection::saveCalibrationSettings(int treeID, const CalibrationPipeline &task, const task_diff *diff) { - bool bResult(true); - if (diff) { - if (diff->calibration_skymodel) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Calibration.SkyModel", task.skyModel())) bResult = false; - } - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Calibration.SkyModel", task.skyModel())) bResult = false; - } - return bResult; -} - -bool SASConnection::saveDemixingSettings(int treeID, const DemixingSettings &demix, const task_diff *diff) { - bool bResult(true); - if (diff) { - // first check which nodes exists and which steps are done for DPPP - bool DPPP_demixer_step(false), DPPP0_demixer_step(false), DPPP_averager_step(false), DPPP0_averager_step(false); - QVariant value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.steps", true); - if (value.isValid()) { - QString steps(value.toString()); - if (steps.contains("demixer")) { - DPPP_demixer_step = true; - } - if (steps.contains("averager")) { - DPPP_averager_step = true; - } - } - else { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].steps", true); - if (value.isValid()) { - QString steps(value.toString()); - if (steps.contains("demixer")) { - DPPP0_demixer_step = true; - } - if (steps.contains("averager")) { - DPPP0_averager_step = true; - } - } - else { - itsProgressDialog.addError("Could not fetch the DPPP steps for tree:" + QString::number(treeID)); - } - } - - if (diff->demix_always) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.demix_always", "[" + demix.demixAlways() + "]")) bResult = false; - } - if (diff->demix_if_needed) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.demix_if_needed", "[" + demix.demixIfNeeded() + "]")) bResult = false; - } - if (diff->demix_skymodel) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.SkyModel", demix.skyModel())) bResult = false; - } - if (diff->freqstep) { - bool res(false); - QString freqStep(QString::number(demix.freqStep())); - if (DPPP_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.freqstep", freqStep); - } - if (DPPP0_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.freqstep", freqStep); - } - if (DPPP_averager_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.averager.freqstep", freqStep); - } - if (DPPP0_averager_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].averager.freqstep", freqStep); - } - if ((DPPP_demixer_step || DPPP0_demixer_step || DPPP_averager_step || DPPP0_averager_step) && !res) { - itsProgressDialog.addError("failed to save DPPP freqstep for tree:" + QString::number(treeID)); - bResult = false; - } - } - if (diff->timestep) { - bool res(false); - QString timeStep(QString::number(demix.timeStep())); - if (DPPP_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.timestep", timeStep); - } - if (DPPP0_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.timestep", timeStep); - } - if (DPPP_averager_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.averager.timestep", timeStep); - } - if (DPPP0_averager_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].averager.timestep", timeStep); - } - if ((DPPP_demixer_step || DPPP0_demixer_step || DPPP_averager_step || DPPP0_averager_step) && !res) { - itsProgressDialog.addError("failed to save DPPP timestep for tree:" + QString::number(treeID)); - bResult = false; - } - } - if (diff->demix_freqstep) { - bool res(false); - QString demixFreqStep(QString::number(demix.demixFreqStep())); - if (DPPP_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.demixfreqstep", demixFreqStep); - } - if (DPPP0_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.demixfreqstep", demixFreqStep); - } - if ((DPPP_demixer_step || DPPP0_demixer_step) && !res) { - itsProgressDialog.addError("failed to save DPPP demixer.demixfreqstep for tree:" + QString::number(treeID)); - bResult = false; - } - } - if (diff->demix_timestep) { - bool res(false); - QString demixTimeStep(QString::number(demix.demixTimeStep())); - if (DPPP_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.demixtimestep", demixTimeStep); - } - if (DPPP0_demixer_step) { - res |= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.demixtimestep", demixTimeStep); - } - if ((DPPP_demixer_step || DPPP0_demixer_step) && !res) { - itsProgressDialog.addError("failed to save DPPP demixer.demixfreqstep for tree:" + QString::number(treeID)); - bResult = false; - } - } - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.demix_always", "[" + demix.demixAlways() + "]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.demix_if_needed", "[" + demix.demixIfNeeded() + "]")) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.PreProcessing.SkyModel", demix.skyModel())) bResult = false; - QString freqStep(QString::number(demix.freqStep())), - timeStep(QString::number(demix.timeStep())), - demixFreqStep(QString::number(demix.demixFreqStep())), - demixTimeStep(QString::number(demix.demixTimeStep())); - - // first check which nodes exists and which steps are done for DPPP - bool DPPP_demixer_step(false), DPPP0_demixer_step(false), DPPP_averager_step(false), DPPP0_averager_step(false); - QVariant value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.steps", true); - if (value.isValid()) { - QString steps(value.toString()); - if (steps.contains("demixer")) { - DPPP_demixer_step = true; - } - if (steps.contains("averager")) { - DPPP_averager_step = true; - } - } - else { - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].steps", true); - if (value.isValid()) { - QString steps(value.toString()); - if (steps.contains("demixer")) { - DPPP0_demixer_step = true; - } - if (steps.contains("averager")) { - DPPP0_averager_step = true; - } - } - else { - itsProgressDialog.addError("Could not fetch the DPPP steps for tree:" + QString::number(treeID)); - } - } - - if (DPPP_demixer_step) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.freqstep", freqStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.timestep", timeStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.demixfreqstep", demixFreqStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.demixer.demixtimestep", demixTimeStep); - } - if (DPPP0_demixer_step){ - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.freqstep", freqStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.timestep", timeStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.demixfreqstep", demixFreqStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].demixer.demixtimestep", demixTimeStep); - } - if (DPPP_averager_step) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.averager.timestep", timeStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP.averager.freqstep", freqStep); - } - if (DPPP0_averager_step) { - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].averager.timestep", timeStep); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.DPPP[0].averager.freqstep", freqStep); - } - } - - return bResult; -} - -bool SASConnection::savePulsarSettings(int treeID, const PulsarPipeline &pulsarPipe, const task_diff *diff) { - if (diff) { - if (!diff->pulsar_pipeline_settings) { - return true; - } - } - - bool bResult(true); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.2bf2fits_extra_opts", pulsarPipe.twoBf2fitsExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.digifil_extra_opts", pulsarPipe.digifilExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.dspsr_extra_opts", pulsarPipe.dspsrExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.prepdata_extra_opts", pulsarPipe.prepDataExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.prepfold_extra_opts", pulsarPipe.prepFoldExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.prepsubband_extra_opts", pulsarPipe.prepSubbandExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.pulsar", pulsarPipe.pulsarName()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.rfifind_extra_opts", pulsarPipe.rfiFindExtra()); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.8bit_conversion_sigma", QString::number(pulsarPipe.eightBitConversionSigma(),'g',16)); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.dynamic_spectrum_time_average", QString::number(pulsarPipe.dynamicSpectrumAvg(),'g',16)); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.rrats_dm_range", QString::number(pulsarPipe.rratsDmRange(),'g',16)); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.decode_nblocks", QString::number(pulsarPipe.decodeNblocks())); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.decode_sigma", QString::number(pulsarPipe.decodeSigma())); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.tsubint", QString::number(pulsarPipe.tsubInt())); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.nofold", pulsarPipe.noFold() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.nopdmp", pulsarPipe.noPdmp() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.norfi", pulsarPipe.noRFI() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.raw_to_8bit", pulsarPipe.rawTo8Bit() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.rrats", pulsarPipe.rrats() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.single_pulse", pulsarPipe.singlePulse() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.skip_dspsr", pulsarPipe.skipDspsr() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.skip_dynamic_spectrum", pulsarPipe.skipDynamicSpectrum() ? "true" : "false"); - bResult &= setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.skip_prepfold", pulsarPipe.skipPrepfold() ? "true" : "false"); - - return bResult; -} - -bool SASConnection::getPulsarSettings(int treeID, PulsarPipeline &pulsarPipe) { - bool bResult(true); - QVariant value; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.2bf2fits_extra_opts"); - if (value.isValid()) { - pulsarPipe.setTwoBf2fitsExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.digifil_extra_opts"); - if (value.isValid()) { - pulsarPipe.setDigifilExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.dspsr_extra_opts"); - if (value.isValid()) { - pulsarPipe.setDspsrExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.prepdata_extra_opts"); - if (value.isValid()) { - pulsarPipe.setPrepDataExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.prepfold_extra_opts"); - if (value.isValid()) { - pulsarPipe.setPrepFoldExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.prepsubband_extra_opts"); - if (value.isValid()) { - pulsarPipe.setPrepSubbandExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.pulsar"); - if (value.isValid()) { - pulsarPipe.setPulsarName(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.rfifind_extra_opts"); - if (value.isValid()) { - pulsarPipe.setRFIfindExtra(value.toString()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.8bit_conversion_sigma"); - if (value.isValid()) { - pulsarPipe.setEightBitConversionSigma(value.toDouble()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.dynamic_spectrum_time_average"); - if (value.isValid()) { - pulsarPipe.setDynamicSpectrumAvg(value.toDouble()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.rrats_dm_range"); - if (value.isValid()) { - pulsarPipe.setRratsDmRange(value.toDouble()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.decode_nblocks"); - if (value.isValid()) { - pulsarPipe.setDecodeNblocks(value.toInt()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.decode_sigma"); - if (value.isValid()) { - pulsarPipe.setDecodeSigma(value.toInt()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.tsubint"); - if (value.isValid()) { - pulsarPipe.setTsubInt(value.toInt()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.nofold"); - if (value.isValid()) { - pulsarPipe.setNoFold(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.nopdmp"); - if (value.isValid()) { - pulsarPipe.setNoPdmp(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.norfi"); - if (value.isValid()) { - pulsarPipe.setNoRFI(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.raw_to_8bit"); - if (value.isValid()) { - pulsarPipe.setRawTo8Bit(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.rrats"); - if (value.isValid()) { - pulsarPipe.setRRATS(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.single_pulse"); - if (value.isValid()) { - pulsarPipe.setSinglePulse(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.skip_dspsr"); - if (value.isValid()) { - pulsarPipe.setSkipDspsr(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.skip_dynamic_spectrum"); - if (value.isValid()) { - pulsarPipe.setSkipDynamicSpectrum(value.toBool()); - } - else bResult = false; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Pulsar.skip_prepfold"); - if (value.isValid()) { - pulsarPipe.setSkipPrepfold(value.toBool()); - } - else bResult = false; - - return bResult; -} - - -bool SASConnection::getImagingSettings(int treeID, ImagingPipeline &task) { - bool bResult(true); - QVariant value; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.slices_per_image"); - if (value.isValid()) { - task.setSlicesPerImage(value.toUInt()); - } - else { - task.setSlicesPerImage(0); - bResult = false; - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.subbands_per_image"); - if (value.isValid()) { - task.setSubbandsPerImage(value.toUInt()); - } - else { - task.setSubbandsPerImage(0); - bResult = false; - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.AWimager.npix"); - if (value.isValid()) { - task.setNrOfPixels(value.toUInt()); - } - else { - task.setNrOfPixels(0); - bResult = false; - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.AWimager.cellsize"); - if (value.isValid()) { - task.setCellSize(value.toString()); - } - else { - task.setCellSize(""); - bResult = false; - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.fov"); - if (value.isValid()) { - task.setFov(value.toFloat()); - } - else { - task.setFov(0.0); - bResult = false; - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.specify_fov"); - if (value.isValid()) { - task.setSpecifyFov(value.toBool()); - } - else { - task.setSpecifyFov(true); - bResult = false; - } - - return bResult; -} - -bool SASConnection::saveImagingSettings(int treeID, const ImagingPipeline &task, const task_diff *diff) { - bool bResult(true); - if (diff) { - if (diff->Imaging_nr_slices_per_image) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.slices_per_image", QString::number(task.slicesPerImage()) )) bResult = false; - } - if (diff->Imaging_nr_subbands_per_image) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.subbands_per_image", QString::number(task.subbandsPerImage()) )) bResult = false; - } - if (diff->Imaging_npix) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.AWimager.npix", QString::number(task.nrOfPixels()) )) bResult = false; - } - if (diff->Imaging_cellsize) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.AWimager.cellsize", task.cellSize())) bResult = false; - } - if (diff->Imaging_fov) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.fov", QString::number(task.fov(),'g',16))) bResult = false; - } - if (diff->Imaging_specify_fov) { - QString specifyFOV = task.specifyFov() ? "true" : "false"; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.specify_fov", specifyFOV)) bResult = false; - } - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.slices_per_image", QString::number(task.slicesPerImage()) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.subbands_per_image", QString::number(task.subbandsPerImage()) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.AWimager.npix", QString::number(task.nrOfPixels()) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.AWimager.cellsize", task.cellSize())) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.Imaging.fov", QString::number(task.fov(),'g',16))) bResult = false; - } - - return bResult; -} - -// TODO: Code smell OO: Should the ownership of this function be in the SASCOnnection? -// THe sasconnection should not know about the longbaseline. -bool SASConnection::getLongBaselineSettings(int treeID, LongBaselinePipeline &task) { - bool bResult(true); - QVariant value; - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.LongBaseline.subbands_per_subbandgroup"); - if (value.isValid()) { - task.setSubbandsPerSubbandGroup(value.toUInt()); - } - else { - task.setSubbandsPerSubbandGroup(0); - bResult = false; - } - - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.LongBaseline.subbandgroups_per_ms"); - if (value.isValid()) { - task.setSubbandGroupsPerMS(value.toUInt()); - } - else { - task.setSubbandGroupsPerMS(0); - bResult = false; - } - - return bResult; -} - -bool SASConnection::saveLongBaselineSettings(int treeID, const LongBaselinePipeline &task, const task_diff *diff) { - bool bResult(true); - if (diff) { - if (diff->LongBaseline_nr_sb_per_sbgroup) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.LongBaseline.subbands_per_subbandgroup", QString::number(task.subbandsPerSubbandGroup()) )) bResult = false; - } - if (diff->LongBaseline_nr_sbgroup_per_MS) { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.LongBaseline.subbandgroups_per_ms", QString::number(task.subbandGroupsPerMS()) )) bResult = false; - } - } - else { - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.LongBaseline.subbands_per_subbandgroup", QString::number(task.subbandsPerSubbandGroup()) )) bResult = false; - if (!setNodeValue(treeID, "LOFAR.ObsSW.Observation.ObservationControl.PythonControl.LongBaseline.subbandgroups_per_ms", QString::number(task.subbandGroupsPerMS()) )) bResult = false; - } - - return bResult; -} - -bool SASConnection::getScheduledTimes(int treeID, Task &task) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QVariant value; - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.startTime"); - if (value.isValid()) { - if (!value.toString().isEmpty()) { // empty value means that it is not currently set in OTDB - AstroDateTime startTime(value.toDateTime()); - if (startTime.isSet()) { - task.setScheduledStart(startTime); - } - } - } - else bResult = false; - value = getNodeValue(treeID, "LOFAR.ObsSW.Observation.stopTime"); - if (value.isValid()) { - if (!value.toString().isEmpty()) { - AstroDateTime endTime(value.toDateTime()); - if (endTime.isSet()) { - task.setScheduledEnd(endTime); - } - } - } - else bResult = false; - return bResult; -} - -//gets all 'non-scheduler' branch properties from the SAS vic tree and stores them in task -bool SASConnection::getSASTaskProperties(int treeID, Task &task) { - bool bResult(true); - // here task properties which are relevant for reservation as well as for maintenance tasks - - getCampaignInfo(task); - bResult &= getScheduledTimes(treeID, task); - - if (task.isStationTask()) { - StationTask &statTask(static_cast<StationTask &>(task)); - bResult &= getStationSettings(treeID, statTask); - if (statTask.isObservation()) { - Observation &obs(static_cast<Observation &>(statTask)); - bResult &= getAnalogBeamSettings(treeID, obs); - bResult &= getProcessingSettings(treeID, obs); - bResult &= getDigitalBeams(treeID, obs); - getOutputStorageSettings(treeID, obs); - } - } - else if (task.isPipeline()) { - Pipeline &pipeline = static_cast<Pipeline &>(task); - if (pipeline.isImagingPipeline()) { - ImagingPipeline &impipe(static_cast<ImagingPipeline &>(pipeline)); - bResult &= getImagingSettings(treeID, impipe); - } - else if (pipeline.isCalibrationPipeline()) { - CalibrationPipeline &calpipe(static_cast<CalibrationPipeline &>(pipeline)); - bResult &= getDemixingSettings(treeID, calpipe); - bResult &= getCalibrationSettings(treeID, calpipe); - } - else if (pipeline.isPulsarPipeline()) { - PulsarPipeline &pulspipe(static_cast<PulsarPipeline &>(pipeline)); - bResult &= getPulsarSettings(treeID, pulspipe); - } - else if (pipeline.isLongBaselinePipeline()) { - LongBaselinePipeline &lbpipe(static_cast<LongBaselinePipeline &>(pipeline)); - bResult &= getLongBaselineSettings(treeID, lbpipe); - } - /*bResult &= */getInputStorageSettings(treeID, task); - /*bResult &= */getOutputStorageSettings(treeID, task); -// task.storage()->recalculateCheck(); // recalculate the tasks data files, total data size and bandwidth - } - return bResult; -} - -OTDBtree SASConnection::getTreeInfo(int treeID) const { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query("select * from gettreeinfo(" + QString::number(treeID) + ", false)", sasDB); - if (query.next()) { - OTDBtree otdb_tree(query); - query.finish(); - return otdb_tree; - } - else return OTDBtree(); -} - -bool SASConnection::saveTaskToSAS(int treeID, Task &task, const task_diff *diff) { - bool bResult(true); - itsLastErrorString = ""; - Task::task_status status = task.getStatus(); - bResult &= saveSchedulerProperties(treeID, task, diff); - - if (task.isStationTask()) { //OBSERVATION, RESERVATION or MAINTENANCE - bResult &= saveStationSettings(treeID, static_cast<StationTask &>(task), diff); - - if (task.isObservation()) { - Observation &obs(static_cast<Observation &>(task)); - bResult &= saveStationSettings(treeID, obs, diff); - if (QString(obs.getAntennaModeStr()).startsWith("HBA")) { // only try to save analog beam settings when HBA mode is chosen. (Anabeam might not exist in SAS) - bResult &= saveAnalogBeamSettings(treeID, obs, diff); - } - bResult &= saveDigitalBeamSettings(treeID, obs, diff); - bResult &= saveTiedArrayBeamSettings(treeID, obs, diff); - bResult &= saveProcessingSettings(treeID, obs, diff); - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - bResult &= saveDataSlots(treeID, obs); - } - - // Cobalt Correlator BlockSize - if (status == Task::PRESCHEDULED || status == Task::SCHEDULED) { // in SCHEDULED state always update BlockSize //FIXME? Added PRESCHEDULED for CEP4 /AR - bResult &= saveCobaltBlockSize(treeID, obs); - } - else if (diff) { - if (diff->RTCP_cor_int_time) { - bResult &= saveCobaltBlockSize(treeID, obs); - } - } - } - } - else if (task.isPipeline()) { - pipelineType ptype = static_cast<Pipeline &>(task).pipelinetype(); - if (ptype == PIPELINE_IMAGING) { - bResult &= saveImagingSettings(treeID, static_cast<ImagingPipeline &>(task), diff); - } - else if (ptype == PIPELINE_CALIBRATION) { - CalibrationPipeline &calPipe(static_cast<CalibrationPipeline &>(task)); - bResult &= saveDemixingSettings(treeID, calPipe.demixingSettings(), diff); - bResult &= saveCalibrationSettings(treeID, calPipe, diff); - } - else if (ptype == PIPELINE_PULSAR) { - savePulsarSettings(treeID, static_cast<PulsarPipeline &>(task), diff); - } - else if (ptype == PIPELINE_LONGBASELINE) { - saveLongBaselineSettings(treeID, static_cast<LongBaselinePipeline &>(task), diff); - } - } - - if (diff) { //FIXME if diff than we do this, otherwise we do it any way? This seems redundant. /AR - // all the following differences can potentially change the number of output files being written, - // therefore, we update the storage keys in SAS when anyone of them has changed - if (diff->output_data_types || diff->output_storage_settings || diff->output_data_products || - diff->digital_beam_settings || diff->RTCP_coherent_stokes_settings || diff->RTCP_incoherent_stokes_settings) - bResult &= saveOutputStorageSettings(treeID, task, diff); - - if (diff->input_data_products) - bResult &= saveInputStorageSettings(treeID, task); - if (diff->scheduled_start || diff->scheduled_end) - bResult &= setTreeSchedule(treeID, task); - if (diff->description) - bResult &= saveDescription(treeID, task); - if (diff->task_status) - bResult &= setTreeState(treeID, task.SASTree().state()); - if (diff->project_ID || diff->group_ID) - bResult &= saveMoMinfo(treeID, task); - } - else { - bResult &= saveInputStorageSettings(treeID, task); - bResult &= saveOutputStorageSettings(treeID, task); - bResult &= setTreeSchedule(treeID, task); - bResult &= saveDescription(treeID, task); - bResult &= setTreeState(treeID, task.SASTree().state()); - bResult &= saveMoMinfo(treeID, task); - } - - return bResult; -} - -void SASConnection::storePublishDates(const Task *pTask) { - if (pTask->getScheduledStart().isSet()) { - itsChangedDates.push_back(pTask->getScheduledStart().date()); - } - if (pTask->getScheduledEnd().isSet()) { - itsChangedDates.push_back(pTask->getScheduledEnd().date()); - } - // also check for each task if it was moved from another week than the current week. - // If that is the case the original week (from where the task was moved) also needs to be added to the changedDates - unsigned treeID(pTask->getSASTreeID()); - if (treeID) { - for (std::map<unsigned, OTDBtree>::const_iterator it = itsSASVicTrees.begin(); it != itsSASVicTrees.end(); ++it) { - if (treeID == it->first) { - const AstroDate &startDate(it->second.startTime().date()); - const AstroDate &endDate(it->second.stopTime().date()); - // if the week number differs also push back the original start/end date - if (startDate.getWeek() != pTask->getScheduledStart().date().getWeek()) { - itsChangedDates.push_back(startDate); - } - if (endDate.getWeek() != pTask->getScheduledEnd().date().getWeek()) { - itsChangedDates.push_back(endDate); - } - - } - } - } -} - -void SASConnection::determineUploadedDateRange(void) { - if (!itsChangedDates.empty()) { - AstroDate earliest(itsChangedDates.front()), latest(itsChangedDates.front()); - for (std::vector<AstroDate>::const_iterator it = itsChangedDates.begin()+1; it != itsChangedDates.end(); ++it) { - if (*it < earliest) earliest = *it; - if (*it > latest) latest = *it; - } - itsUploadedDateRange = std::pair<AstroDate, AstroDate>(earliest, latest); - } -} - -bool SASConnection::commitScheduleToSAS(SchedulerData &data) { - bool bResult(true); - int treeID; - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - - itsProgressDialog.disableClose(); - itsProgressDialog.show(); - itsProgressDialog.setProgressPercentage(0); - size_t totalTrees(itsNewSchedulerTasks.size() + itsTreesToDelete.size() + itsChangedTasks.size()); - size_t count(0); - vector<unsigned> removeTasks; - itsChangedDates.clear(); - - // ------------------------------------STEP 2 ----------------------------------------------- - // upload changed task properties of tasks with changes - Task *pCloneTask; - if (!itsChangedTasks.empty()) { - itsProgressDialog.addText("Uploading task changes..."); - for (changedTasks::const_iterator it = itsChangedTasks.begin(); it != itsChangedTasks.end(); ++it) { - unsigned treeID(it->first); - Task *pTask = data.getTaskForChange(treeID, ID_SAS); - if (pTask) { - if (saveTaskToSAS(treeID, *pTask, &(it->second))) { // first = treeID, second is the task, third = task changes - // update itsSAStasks if changes are uploaded successfully - storePublishDates(pTask); - SAStasks::iterator sit = itsSASTasks.find(treeID); - if (sit != itsSASTasks.end()) { - delete sit->second; - itsSASTasks.erase(sit); - } - pCloneTask = cloneTask(pTask); // create a cloned task for future compare of changes in itsSASTasks - if (pCloneTask) { - itsSASTasks[treeID] = pCloneTask; - } - itsSASVicTrees[treeID] = pTask->SASTree(); - itsProgressDialog.addText(QString("successful uploaded changes for tree:") + QString::number(treeID)); - removeTasks.push_back(treeID); - } - else { - itsProgressDialog.addError(QString("failed to save changes to tree:") + QString::number(treeID)); - itsProgressDialog.addError(itsLastErrorString); - bResult = false; - } - } - itsProgressDialog.setProgressPercentage(++count/totalTrees*100); - } - // remove the correctly uploaded changedIDTasks - for (vector<unsigned>::const_iterator it = removeTasks.begin(); it != removeTasks.end(); ++it) { - itsChangedTasks.erase(*it); - } - removeTasks.clear(); - } - - // ------------------------------------STEP 2 ----------------------------------------------- - // add all new tasks to the SAS database - if (!itsNewSchedulerTasks.empty()) { - itsProgressDialog.addText("Creating trees for new tasks..."); - int parentTree; - for (std::vector<unsigned>::const_iterator it = itsNewSchedulerTasks.begin(); it != itsNewSchedulerTasks.end(); ++it) { - Task *pTask = data.getTaskForChange(*it); - if (pTask) { - // check which default template should be used for creating the tree (it could have been changed) - parentTree = Controller::theSchedulerSettings.getSASDefaultTreeID(pTask); - pTask->setOriginalTreeID(parentTree); - treeID = createNewTree(*pTask); - if (treeID != 0) { - // download the OTDBtree properties from the just created task from SAS to make sure we have an exact copy of what is in SAS - QSqlQuery query("select * from gettreeinfo(" + QString::number(treeID) + ", false)", sasDB); - if (query.next()) { - OTDBtree otdb_tree(query); - query.finish(); - pTask->setSASTree(otdb_tree); - } - storePublishDates(pTask); // have to do this BEFORE changing itsSASVicTrees below - itsSASTasks[treeID] = cloneTask(pTask); // create a cloned task for future compare of changes in itsSASTasks - itsSASVicTrees.insert(std::map<unsigned, OTDBtree>::value_type(treeID, pTask->SASTree())); - removeTasks.push_back(*it); - itsProgressDialog.addText(QString("created new tree:") + QString::number(treeID) + " for task:" + QString::number(pTask->getID())); - } - else { // error not able to create VIC tree - itsProgressDialog.addError(QString("failed to create new VIC tree for task:") + QString::number(pTask->getID())); - bResult = false; - } - itsProgressDialog.setProgressPercentage(++count/totalTrees*100); - } - } - // remove the correctly uploaded changedIDTasks - for (vector<unsigned>::const_iterator it = removeTasks.begin(); it != removeTasks.end(); ++it) { - for (std::vector<unsigned>::iterator cit = itsNewSchedulerTasks.begin(); cit != itsNewSchedulerTasks.end(); ++cit) { - if (*cit == *it) itsNewSchedulerTasks.erase(cit); - break; - } - } - removeTasks.clear(); - } - - // ------------------------------------STEP 3 ----------------------------------------------- - // delete the tasks that need to be deleted - if (!itsTreesToDelete.empty()) { - itsProgressDialog.addText("Deleting tasks..."); - } - QSqlQuery query(sasDB); - for (std::vector<unsigned>::const_iterator it = itsTreesToDelete.begin(); it != itsTreesToDelete.end(); ++it) { - if (query.exec("SELECT deleteTree(" + - itsAuthToken + "," + - QString::number(*it) + ")")) { - // store the changed dates for the auto publish functionality - SAStasks::iterator sit = itsSASTasks.find(*it); - if (sit != itsSASTasks.end()) { - storePublishDates(sit->second); - delete sit->second; - itsSASTasks.erase(sit); - } - itsSASVicTrees.erase(*it); - itsProgressDialog.addText(QString("deleted tree:") + QString::number(*it)); - } - else { - debugErr("ssss", "SAS DB ", query.lastError().text().toStdString().c_str(), - " query:", query.lastQuery().toStdString().c_str()); - itsProgressDialog.addError(QString("failed to delete tree:") + QString::number(*it) + - " (" + query.lastError().text() + ")"); - bResult = false; - } - query.finish(); - itsProgressDialog.setProgressPercentage(++count/totalTrees*100); - } - itsTreesToDelete.clear(); - - itsProgressDialog.setProgressPercentage(100); - - // TODO: update error tasks - itsUploadDialog->hide(); - - if (!bResult) { - itsProgressDialog.addError("Done with errors."); - QMessageBox::critical(0, QObject::tr("Error: could not apply all changes"), QObject::tr("Could not apply all changes to SAS database ")); - } - else { - itsProgressDialog.addText("Done."); - } - - itsProgressDialog.enableClose(); - - updateLastDownloadDate(); - - // determine and store uploaded date range for auto publish functionality - determineUploadedDateRange(); - - return bResult; -} - -std::vector<DefaultTemplate> SASConnection::getDefaultTemplates(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - std::vector<DefaultTemplate> templates; - if (!sasDB.isOpen()) { - return templates; - } - - DefaultTemplate templateInfo; - QSqlQuery query(sasDB), query2(sasDB); - if (query.exec("SELECT * from getdefaulttemplates()")) { - while (query.next()) { - templateInfo.treeID = query.value(query.record().indexOf("treeID")).toInt(); - templateInfo.name = query.value(query.record().indexOf("name")).toString(); - templateInfo.processType = query.value(query.record().indexOf("processType")).toString().toUpper(); - templateInfo.processSubtype = query.value(query.record().indexOf("processSubtype")).toString(); - templateInfo.strategy = query.value(query.record().indexOf("strategy")).toString(); - // now get the description of this default template - if (query2.exec("SELECT state,description FROM gettreeinfo('" + QString::number(templateInfo.treeID) +"',false)")) { - if (query2.next()) { - templateInfo.status = query2.value(query2.record().indexOf("state")).toInt(); - templateInfo.description = query2.value(query2.record().indexOf("description")).toString(); - } - } - query2.finish(); - templates.push_back(templateInfo); - } - } - query.finish(); - // also fetch the node ID of the dataslotsinfo node in the default template tree (needed to be able to create and save dataslot info for new trees) - -// query.exec("SELECT nodeid from getVTitemList(" + QString::number(Controller::theSchedulerSettings.getSASDefaultTreeID()) + ",'DataslotInfo')"); -// if (query.next()) { -// itsDataslotTemplateIDstr = query.value(0).toString(); -// } -// query.finish(); - - return templates; -} - -const Task *SASConnection::fetchPredecessorObservation(const QString predStr) { - std::vector<QString> predecessors(string2VectorOfStrings(predStr)); - QString isMomID, IDonly, ObsIDPrefix(Controller::theSchedulerSettings.getObservationIDprefix()); - bool fetchPredecessor; - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - QSqlQuery query(sasDB); - for (std::vector<QString>::const_iterator it = predecessors.begin(); it != predecessors.end(); ++it) { - // TODO: predecessor specified with scheduler task IDs should be translated to sas id during upload of the task - fetchPredecessor = false; - IDonly = it->right(it->size()-1); - if (it->startsWith('M')) { - isMomID = "true"; - fetchPredecessor = true; - } - else if (it->startsWith(ObsIDPrefix)) { // SAS ID used for predecessor, fetch the predecessor directly - isMomID = "false"; - fetchPredecessor = true; - } - else { - return 0; - } - - // fetch the predecessor task and push it in itsTmpSASVicTrees2 - if (fetchPredecessor) { - query.exec("SELECT * from gettreeinfo(" + IDonly + ",'" + isMomID + "')"); - if (query.next()) { - OTDBtree tree(query); - query.finish(); - // check if predecessor is indeed a VIC tree - if (tree.type() == VIC_TREE && tree.processType() == "OBSERVATION") { - std::pair<bool, Task *> retVal = getTaskFromSAS(tree.treeID(), tree); - return retVal.second; - } - else return 0; - } - } - } - return 0; -} - -/* -bool SASConnection::checkSASStatus(void) { - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - int result = connect(); - if (result == 0) { // connection ok // write permission ok - QString processType("Pipeline"), processSubType("Averaging Pipeline"), strategy(""); - SAS_task_status firstState(SAS_STATE_FINISHED); - bool empty(true); - QString query("SELECT * from getTreesInPeriod('" + QString::number(VIC_TREE) + "','" + - Controller::theSchedulerSettings.getEarliestSchedulingDay().toString().c_str() + "','" + - Controller::theSchedulerSettings.getLatestSchedulingDay().toString().c_str() + - "') WHERE state=" + QString::number(firstState)); - if (!processType.isEmpty()) { - empty = false; - query += " AND processtype='" + processType + "'"; - } - if (!processSubType.isEmpty()) { - if (!empty) { - query += " AND "; - } - query += "processsubtype='" + processSubType + "'"; - empty = false; - } - if (!strategy.isEmpty()){ - if (!empty) { - query += " AND "; - } - query += "strategy='" + strategy + "'"; - empty = false; - } - - //query += " ORDER BY starttime LIMIT 50"; - - std::cout << query.toStdString() << std::endl; - - std::map<unsigned, Task *> tasks; - QSqlQuery sqlquery(sasDB); - if (sqlquery.exec(query)) { - if (sqlquery.isActive()) { - while (sqlquery.next()) { - OTDBtree tree(sqlquery); - std::pair<bool, Task *> retVal = getTaskFromSAS(tree.treeID(), tree); - if (retVal.second) { - tasks.insert(std::map<unsigned, Task *>::value_type(tree.treeID(), retVal.second)); - } - } - sqlquery.finish(); - } - else { - sqlquery.finish(); - return -1;// could not fetch any task from SAS query not valid - } - - // gather statistics about the tasks - const CalibrationPipeline *calPipe(0); -// float factor; - QString outstr; - const Observation *predecessor(0); - if (!tasks.empty()) { - std::cout << outstr.toStdString() << "writing file 'statistics.csv'" << std::endl; - - for (std::map<unsigned, Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - - AstroDateTime timedif(it->second->SASTree().stopTime() - it->second->SASTree().startTime()); - //unsigned estdur(it->second->getDuration().totalSeconds()); - unsigned realdur(timedif.totalSeconds()); -// if (estdur >= realdur) factor = estdur / realdur; -// else factor = realdur / estdur; - - outstr += it->second->SASTree().startTime().date().toString().c_str() + QString(", ") - + QString::number(it->second->getSASTreeID()) + QString(", ") - + it->second->getProjectID() + QString(", ") - + it->second->getTaskName() + QString(", ") -// + it->second->getStatusStr() + QString(", ") -// + it->second->getDuration().toString().c_str() + QString(", ") -// + QString::number(it->second->getDuration().totalSeconds()) + ", " - + timedif.time().toString().c_str() + QString(", ") - + QString::number(timedif.totalSeconds()); -// + QString::number(factor,'f',1); - - calPipe = dynamic_cast<const CalibrationPipeline *>(it->second); - if (calPipe) { - QString demixSources = calPipe->demixingSettings().demixAlways(); - outstr += QString(", [") + demixSources.replace(',',';') + "], "; - } - else { - outstr += ", [], "; - } - - // fetch the predecessor observation - predecessor = dynamic_cast<const Observation *>(fetchPredecessorObservation(it->second->getPredecessorsString())); - if (predecessor) { // found the predecessor observation - unsigned predDur(predecessor->getDuration().totalSeconds()); - outstr += QString::number(predDur) + ", "; - if (realdur >= predDur) { - outstr += QString::number((float)realdur / predDur, 'f', 1); - } - else { - outstr += QString::number((float)predDur / realdur, 'f', 1); - } - - outstr += ", " + QString::number(predecessor->getRTCPsettings().channelsPerSubband) + ", " - + QString::number(predecessor->getRTCPsettings().correlatorIntegrationTime) + ", "; - const StationTask *pStation = static_cast<const StationTask *>(predecessor); - outstr += QString::number(pStation->getNrVirtualStations()) + ", "; - outstr += QString(pStation->getAntennaModeStr()).left(3); - - const Pipeline *pipe(dynamic_cast<const Pipeline *>(it->second)); - if (pipe) { - - const std::map<dataProductTypes, TaskStorage::inputDataProduct> &inputdata(pipe->storage()->getInputDataProducts()); - const std::map<dataProductTypes, TaskStorage::inputDataProduct>::const_iterator iit = inputdata.find(DP_CORRELATED_UV); - if (iit != inputdata.end()) { - if (!iit->second.identifications.isEmpty()) { - QString inputIdent(iit->second.identifications.at(0)); // should have only one identification for Correlated data input -// outstr += ", " + inputIdent; - const std::map<dataProductTypes, TaskStorage::outputDataProduct> &predData(predecessor->storage()->getOutputDataProducts()); - const std::map<dataProductTypes, TaskStorage::outputDataProduct>::const_iterator oit = predData.find(DP_CORRELATED_UV); - if (oit != predData.end()) { - if (!oit->second.identifications.isEmpty()) { - int beamIdx(oit->second.identifications.indexOf(inputIdent)); // which beam index? - const std::map<unsigned, DigitalBeam> &beams(predecessor->getDigitalBeams()); - const std::map<unsigned, DigitalBeam>::const_iterator bit = beams.find(beamIdx); - if (bit != beams.end()) { - outstr += ", " + QString::number(bit->second.nrSubbands()); - } - } - } - - } - } - } - } - - outstr += "\n"; - } - - - QFile file("statistics.csv"); - file.open(QIODevice::ReadWrite); - file.write(outstr.toStdString().c_str()); - file.close(); - } - - } - - } - return true; -} -*/ - - -bool SASConnection::checkSASStatus(void) { - bool bResult(true); - QSqlDatabase sasDB = QSqlDatabase::database( "SASDB" ); - SASStatusDialog * statDlg = new SASStatusDialog(); - statDlg->show(); - int result = connect(); - if (result == 0) { // connection ok // write permission ok - statDlg->addText("SAS connection OK."); - statDlg->addText("SAS write permissions OK"); - // checking functions - statDlg->addText("Checking SAS database functions:"); - QSqlQuery query(sasDB); - if (query.exec("SELECT * from getTreesInPeriod('" + - QString::number(VIC_TREE) + "','2010-01-01 00:00:00', '2010-01-01 23:59:59')")) { - statDlg->addText("function: 'getTreesInPeriod' OK"); - } - else { - statDlg->addError("function: 'getTreesInPeriod' ERROR"); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - query.finish(); - int schedulerDefaultTemplateID = Controller::theSchedulerSettings.getSchedulerDefaultTemplate(); - QString SASDefaultTreeIDstr = QString::number(schedulerDefaultTemplateID); - if (query.exec(QString("SELECT * from getvtitemlist(") + SASDefaultTreeIDstr + ",'taskID')")) { - if (query.next()) { - statDlg->addText(QString("function: 'SAS default template tree ") + SASDefaultTreeIDstr + " OK"); - int newTreeID(0); - if (query.exec(QString("SELECT * from instanciateVHtree(") + - itsAuthToken + "," + SASDefaultTreeIDstr + ")")) { - query.next(); - newTreeID = query.value(query.record().indexOf("instanciateVHtree")).toInt(); - if (newTreeID) { - statDlg->addText("function: 'instanciateVHtree' OK"); - // check getVHitemList - vector<OTDBnode> fieldList = getItemList(newTreeID, "LOFAR.ObsSW.Observation.Scheduler.taskID"); - if (fieldList.size() == 1) { // should be unique property - statDlg->addText("function: 'getVHitemList' OK"); - // check updateVTnode function - if (query.exec("SELECT updateVTnode(" + - itsAuthToken + "," + - QString::number(newTreeID) + "," + - QString::number(fieldList.front().nodeID()) + ",'1','100')")) { - // check if update ok - query.next(); - if (query.value(query.record().indexOf("updatevtnode")).toBool()) { - statDlg->addText("function: 'updateVTnode' OK"); - - // check function getSchedulerInfo - query.finish(); - int taskid(-1); - if (query.exec("SELECT * from getSchedulerInfo(" + QString::number(newTreeID) + ")")) { - query.next(); - taskid = query.value(query.record().indexOf("taskID")).toUInt(); - if (taskid == 100) { - statDlg->addText("function: 'getSchedulerInfo' OK"); - } - else { - statDlg->addError("function: 'getSchedulerInfo' did not return the expected value!"); - bResult = false; - } - } - else { - statDlg->addError("function: 'getSchedulerInfo' ERROR (Can also be caused by a wrong SAS Scheduler master template tree)"); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - } - else { - statDlg->addError("function: 'updateVTnode' ERROR"); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - } - else { - statDlg->addError("function: 'updateVTnode' ERROR"); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - - } - else { - statDlg->addError("function: 'getVHitemList' ERROR returned multiple taskID fields for one tree!"); - bResult = false; - } - // check deleteTree function - if (newTreeID) { - if (!query.exec("SELECT deleteTree(" + - itsAuthToken + "," + - QString::number(newTreeID) + ")")) { - statDlg->addError("function: 'deleteTree' ERROR"); - statDlg->addError(sasDB.lastError().text()); - } - else { - statDlg->addText("function: 'deleteTree' OK"); - } - } - } - else { - statDlg->addError("function: 'instanciateVHtree' could not create tree ERROR"); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - } - else { - statDlg->addError("function: 'instanciateVHtree' ERROR"); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - } - else { - statDlg->addError(QString("function: 'SAS default VIC template tree ") + SASDefaultTreeIDstr + " Not found. (Is the default template treeID correct?)"); -// statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - } - else { - statDlg->addError("function: 'getvtitemlist' ERROR"); - statDlg->addError(sasDB.lastError().text()); - } - } - else if (result == -1) { - // no connection to SAS database - statDlg->addError("SAS connection ERROR: "); - statDlg->addError(sasDB.lastError().text()); - bResult = false; - } - else if (result == -2) { - // connection ok but no write permissions to SAS database - statDlg->addText("SAS connection OK."); - statDlg->addError("SAS write permissions ERROR. No write permissions to database! Please check SAS User name and password."); - bResult = false; - } -// else if (result == 3) { -// statDlg->addError("SAS connection ERROR:"); -// statDlg->addError("Error: could not get clock settings from SAS database."); -// bResult = false; -// } - - if (bResult) { - statDlg->addText("Everything OK!"); - } - else { - statDlg->addText("ERRORS detected!"); - } - return bResult; -} - - -std::string getSasTextState(int sas_state) { - switch (sas_state) { - // Why not create a sas_state to state str map? - // This switch is not needed. - // a switch statement is almost always a good candidate for OO refactoring - case SAS_STATE_IDLE: - return task_states_str[Task::IDLE]; - break; - case SAS_STATE_DESCRIBED: - return task_states_str[Task::DESCRIBED]; - break; - case SAS_STATE_PREPARED: - return task_states_str[Task::PREPARED]; - break; - case SAS_STATE_APPROVED: - return task_states_str[Task::UNSCHEDULED]; - break; - case SAS_STATE_ON_HOLD: - return task_states_str[Task::ON_HOLD]; - break; - case SAS_STATE_PRESCHEDULED: - return task_states_str[Task::PRESCHEDULED]; - break; - case SAS_STATE_SCHEDULED: - return task_states_str[Task::SCHEDULED]; - break; - case SAS_STATE_QUEUED: - return task_states_str[Task::STARTING]; - break; - case SAS_STATE_ACTIVE: - return task_states_str[Task::ACTIVE]; - break; - case SAS_STATE_COMPLETING: - return task_states_str[Task::COMPLETING]; - break; - case SAS_STATE_FINISHED: - return task_states_str[Task::FINISHED]; - break; - case SAS_STATE_ABORTED: - return task_states_str[Task::ABORTED]; - break; - case SAS_STATE_ERROR: - return task_states_str[Task::ERROR]; - break; - case SAS_STATE_OBSOLETE: - return task_states_str[Task::OBSOLETE]; - break; - } - return task_states_str[Task::IDLE]; -} diff --git a/SAS/Scheduler/src/SASConnection.h b/SAS/Scheduler/src/SASConnection.h deleted file mode 100644 index 84232c96428fa3d6fffe305e0507a84f1b04393b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/SASConnection.h +++ /dev/null @@ -1,284 +0,0 @@ -/* - * SASConnection.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 8-febr-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/SASConnection.h $ - * - */ - -#ifndef SASCONNECTION_H_ -#define SASCONNECTION_H_ - -#include <vector> -#include <map> -#include <string> -#include "blocksize.h" -#include "astrodatetime.h" -#include "schedulerdata.h" -#include "schedulerdatablock.h" -#include "task.h" -#include "OTDBtree.h" -#include "OTDBnode.h" -#include "sasuploaddialog.h" -#include "sasprogressdialog.h" -#include "statehistorydialog.h" -#include "TiedArrayBeam.h" -#include "calibrationpipeline.h" -#include "pulsarpipeline.h" -#include "imagingpipeline.h" -#include "longbaselinepipeline.h" -class Controller; -class SchedulerData; -class CEPCleanMainWindow; - -#define PIC_TREE 10 -#define TEMPLATE_TREE 20 -#define VIC_TREE 30 -#define DOWNLOAD_MODE true -#define UPLOAD_MODE false - -typedef std::map<unsigned, Task *> SAStasks; -typedef std::vector<Task> ErroneousSASTasks; -typedef std::map<unsigned, task_diff> changedTasks; -// deletedDataMap: key = SAS DB name e.g. 'LOFAR_4', value vector: < tree ID, Data product type > -typedef std::map<QString, std::vector<std::pair<int, dataProductTypes> > > deletedDataMap; -// deleteVICmap: key = database name, value = stringlist of vic tree ids to delete -typedef std::map<QString, QStringList> deleteVICmap; - - -class changedIDTask { -public: - unsigned newTaskID; - unsigned oldTaskID; - task_diff diff; // to keep track of other change in this task -}; - -typedef std::vector<changedIDTask> changedIDTasks; - -class SASConnection { -public: - SASConnection(); - SASConnection(Controller *controller); - virtual ~SASConnection(); - - void init(const QString &username, const QString &password, const QString &DBName, const QString &hostname); - void setLastDownloadDate(const QDateTime &date) { itsLastDownloadDate = date; } - void cleanup(void); // do a cleanup - int connect(void); - int connect(const QString &username, const QString &password, const QString &database, const QString &host); - int testConnect(const QString &username, const QString &password, const QString &DBname, const QString &hostname); - void disconnect(void) { QSqlDatabase::database( "SASDB" ).close(); QSqlDatabase::removeDatabase( "SASDB" ); } - bool downloadAllSASTasks(void/*bool mode = DOWNLOAD_MODE*/); - bool checkSynchronizeNeeded(void); - std::vector<unsigned> getUsedSASTaskIDs(void) const;// {return itsSASTaskIDs;} - const std::pair<AstroDate, AstroDate> &getUploadedDateRange(void) const {return itsUploadedDateRange;} - - void setAutoPublishEnabled(bool enable) {itsUploadDialog->setAutoPublishEnabled(enable);} - bool autoPublish(void) const {return itsUploadDialog->autoPublish();} - // addToTreesToDelete: used by Controller when a task is deleted from the scheduler - void addToTreesToDelete(unsigned treeID, unsigned task_id); - // used by Controller when a previously deleted task is undeleted to add it back to the record of SAS tasks - void removeFromSASTaskToDelete(unsigned treeID); - // get the SAS authentication token from the SAS database - const QString &getAuthToken(void) const {return itsAuthToken;} - - bool abortTask(int treeID); // aborts a vic tree that is active or queued - bool setTaskOnHold(int treeID);// {return setTreeState(treeID, SAS_STATE_ON_HOLD);} // set the tree to the ON_HOLD state - bool setTasksOnHold(const std::vector<int> trees); // set multiple trees on hold - const SAStasks &SASTasks(void) const {return itsSASTasks;} - // opens the clean upload dialog - void showProgressUploadDialog(void); - // hides the upload progress dialog - void closeProgressUploadDialog(void) {itsProgressDialog.hide();} - SASProgressDialog &progressDialog(void) {return itsProgressDialog;} - // start checking for changes that will be committed to the SAS database and the schedule - bool startSynchronizeProcedure(const SchedulerData &scheduler_data); - // commit the schedule to the SAS database and create and alter tasks in the database - bool commitScheduleToSAS(SchedulerData &data); - // check SAS connection status, database status, database access rights, database integrity and show this in a status dialog - bool checkSASStatus(void); - // shows the history of state changes in a separate dialog - void showTaskStateHistory(int treeID); - // fetches the existing projects (campaign info) from SAS and stores them in theSchedulerSettings - bool getCampaignsFromSAS(void); - // return the number of tasks that will be deleted from SAS with the next upload - unsigned nrTaskToDeleteFromSAS(void) const {return itsTreesToDelete.size();} - // gets the current status of a task from SAS - Task::task_status getTaskStatus(int treeID) const; - // gets the scheduled start time of the specified tree - AstroDateTime getScheduledStartTime(int treeID) const; - // gets a single Task from the SAS database - std::pair<bool, Task *> getTaskFromSAS(int treeID, OTDBtree otdb_tree = OTDBtree()); - // get all default templates from SAS - std::vector<DefaultTemplate> getDefaultTemplates(void); - // add an error string to the progress dialog - void addProgressError(const QString &error) {itsProgressDialog.addError(error);} - // add an info string to the progress dialog - void addProgressInfo(const QString &msg) {itsProgressDialog.addText(msg);} - // translate MoM ID to SAS ID - unsigned momIdToSasId(unsigned momid) const {return itsMomToSasIDmap.value(momid, 0);} - // get the mom to sas ID mapping table - const QMap<unsigned, unsigned> &momToSasIDmap(void) const {return itsMomToSasIDmap;} - // translates all mom IDs in the supplied IDvector to SAS ids and directly updates the IDvector - void translateMomPredecessors(IDvector &predecessors); - - QString lastConnectionError(void) const; - OTDBtree getTreeInfo(int treeID) const; - QString getTreeParset(int treeID); // gets the complete tree (parset) as a string - QString getMetaData(int treeID); - // delete SAS trees via specification of treeIDs in stringlist - bool deleteTreesCleanup(const deleteVICmap &treeIDs, const QString &hostname, const QString &user, const QString &password); - bool markDataProductsDeleted(const deletedDataMap &data, const QString &hostname/*, const QString &user, const QString &password*/); - // gets the 'limits' value as a QVariant type (a QVariant can be converted to any other type) - QVariant getNodeValue(int aTreeID, const QString &nameFragment, bool noWarnings = false); - -private: - // gets all 'non-scheduler branch' properties of the task from the SAS VIC tree - bool alreadyDownloaded(unsigned id, id_type IDtype) const; - bool getSASTaskProperties(int treeID, Task &task); - bool getProcessingSettings(int treeID, Observation &task); - bool getCalibrationSettings(int treeID, CalibrationPipeline &task); - bool getDemixingSettings(int treeID, CalibrationPipeline &task); - bool getImagingSettings(int treeID, ImagingPipeline &task); - bool getLongBaselineSettings(int treeID, LongBaselinePipeline &task); - bool getPulsarSettings(int treeID, PulsarPipeline &pulsarPipe); - bool getStationSettings(int treeID, StationTask &task); - bool getAnalogBeamSettings(int treeID, Observation &task); - bool getDigitalBeams(int aTreeID, Observation &observation); - void getInputStorageSettings(int treeID, Task &task); - void getOutputStorageSettings(int treeID, Task &task); - bool getScheduledTimes(int treeID, Task &task); - bool getSchedulerInfo(int tree_id, Task &task); - void getCampaignInfo(Task &task); - void updateDefaultTemplates(void); - void updateMoMToSasIDmapping(void); // updates the map used for translating Mom IDs to SAS IDs - void storePublishDates(const Task *pTask); - void clearItsSASTasks(void); - const Task * fetchPredecessorObservation(const QString predStr); - // get a complete OTDB node from the SAS database - OTDBnode getNode(int treeID, const QString &nodeID) const; - // To get a list of all VIC trees of one of the following groups: - // groupType = "1": observations that are scheduled to start the next 'period' minutes - // "2": active observations ; period is ignored - // "3": observations that were finished during the last 'period' minutes -// std::vector<OTDBtree> getTreeGroup(const std::string &groupType, const std::string &period) const; - std::vector<OTDBnode> getItemList(int aTreeID, const QString &nameFragment) const; - // checks for all modified VIC trees in the sas database and if modified updates them in itsSASVicTrees - int getModifiedVICTrees(const QDateTime &afterdate); - int getAllSASTasksWithinPeriod(int treeType, const AstroDateTime &begindate, const AstroDateTime &enddate); - bool fetchAllPredecessorTasks(void); - // create a new task (observation/pipeline) from a given otdb_tree and query - Task *createNewTaskFromTree(const OTDBtree &otdb_tree, const QSqlQuery *query = 0); - // create a new vic tree from the default template tree set in the task - // (via a intermediate template tree) in the SAS database - int createNewTree(Task &task); - // create a new VIC tree from the template tree with ID baseTreeID in the SAS DB. returns the new treeId on success and 0 on failure - int instantiateVICTree(int baseTreeID); - // set a node value in a SAS template - bool setTemplateNodeByName(int treeID, const QString &parentNodeName, const QString &nodeName, const QString &valueStr) const; - // set a node value in a SAS template; preferred function if we already know the parent node id - bool setTemplateNodeByID(int treeID, const QString &parentNodeID, const QString &nodeName, const QString &valueStr) const; - // sets a single SAS node value in the database for specific treeID, and unique property name fragment - bool setNodeValue(int treeID, const QString &nameFragment, const QString &valueStr, bool warnings = true); - // sets a single SAS node value in the database for specific treeID and nodeID - bool setNodeValue(int treeID, int nodeID, const QString &valueStr) const; - // save a complete OTDBnode to the database - bool saveNode(const OTDBnode &node) const; - // save a single task to SAS - bool saveTaskToSAS(int treeID, Task &task, const task_diff *diff = 0); - // set the start and stop times of the task in the database - bool setTreeSchedule(int treeID, const Task &task) const; - // save the tree state to SAS DB according to the SAStree.state in the task - bool setTreeState(int treeID, int SAS_state) const; - // save the tree description to the SAS database according to the SAStree.state in the task - bool saveDescription(int treeID, const Task &task) const; - // save campaign info to SAS - bool saveMoMinfo(int treeID, const Task &task) const; - // sets all scheduler task properties in the SAS tree with ID treeID - bool saveSchedulerProperties(int treeID, const Task &task, const task_diff *diff = 0); - // save the settings of the analog beam to a SAS victree - bool saveAnalogBeamSettings(int treeID, const Observation &task, const task_diff *diff = 0); - // save the settings of the analog beam to a SAS template tree - bool saveAnalogBeamToSAStemplate(int treeID, int beamNodeId, const Observation::analogBeamSettings &analogBeam); - // save the settings of a single digital beam to a SAS victree - bool saveDigitalBeamToSasVicTree(int treeID, int beamNr, const DigitalBeam &digiBeam); - // save the settings of a single digital beam to a SAS template tree - bool saveDigitalBeamToSAStemplate(int treeID, const QString &beamNodeId, const DigitalBeam &digiBeam); - // stores all digital beam settings in SAS DB - bool saveDigitalBeamSettings(int treeID, Observation &task, const task_diff *diff = 0); - // stores all TAB settings in SAS DB to a template - bool saveTiedArrayBeamToSAStemplate(int treeID, const QString &TABNodeID, const TiedArrayBeam &TAB); - // save the settings of a single pencil beam to a SAS victree - bool saveTiedArrayBeamToSasVicTree(int treeID, int beamNr, int TABnr, const TiedArrayBeam &TAB); - // stores all TAB settings in SAS DB to a VIC tree - bool saveTiedArrayBeamSettings(int treeID, const Observation &task, const task_diff *diff); - // stores the processing (OLAP) settings in the SAS DB - bool saveProcessingSettings(int treeID, const Observation &task, const task_diff *diff = 0); - // stores the imaging pipeline settings in the SAS DB - bool saveImagingSettings(int treeID, const ImagingPipeline &task, const task_diff *diff = 0); - // stores the pulsar pipeline settings in the SAS DB - bool savePulsarSettings(int treeID, const PulsarPipeline &task, const task_diff *diff = 0); - // stores the pipeline calibration settings in the SAS DB - bool saveCalibrationSettings(int treeID, const CalibrationPipeline &task, const task_diff *diff = 0); - // stores the long baseline pipeline settings in the SAS DB - bool saveLongBaselineSettings(int treeID, const LongBaselinePipeline &task, const task_diff *diff); - // stores the pipeline demixing settings in the SAS DB - bool saveDemixingSettings(int treeID, const DemixingSettings &, const task_diff *diff = 0); - // stores the stations settings in the SAS DB - bool saveStationSettings(int treeID, const StationTask &task, const task_diff *diff = 0); - // saves the output storage (node) settings of the task to the SAS database - bool saveOutputStorageSettings(int treeID, const Task &task, const task_diff *diff = 0); - // saves the output data products specifications to SAS (filenames, locations, etc.) - bool saveOutputDataProducts(int treeID, const Task &task); - // saves the input storage settings for the task to the SAS database - bool saveInputStorageSettings(int treeID, const Task &task); - // save the assigned dataslots to SAS - bool saveDataSlots(int treeID, const Observation &task); - // calculate and save Cobalt BlockSize for Correlator - bool saveCobaltBlockSize(int treeID, const Observation &task); - // deletes all trees from SAS from which the treeID is in itsTreesToDelete vector - bool deleteTrees(void); - // helper function for creation and filling of dataslot nodes - bool createAndWriteDataSlotNodes(int treeID, const QString &dataSlotTemplateIDstr, const QString &strParentDataslotNodeID, const QString &antennaFieldName, - const QString &RSPBoardList, const QString &DataSlotList); - std::vector<int> getAllVICTreeIDs(void) const; - // updateLastDownloadDate updates the last SAS update time by fetching it from the SAS database - void updateLastDownloadDate(void); - void determineUploadedDateRange(void); - - // COBALT STUFF - BlockSize calcCobaltBlockSize(Observation::RTCPsettings rtcp, TaskStorage::enableDataProdukts enabledOutputs, unsigned short clockMHz) const; - -private: - SAStasks itsSASTasks; // reflects the current state of the tasks in the SAS database - std::map<unsigned, Task *> itsSASmodifiedTasks; // holds externally changed tasks and new tasks that do not yet exist in the scheduler - std::vector<unsigned> itsSASdeletedTrees; - std::map<unsigned, OTDBtree> itsSASVicTrees; // contains the metadata of all SAS trees within the schedule's period - - QMap<unsigned, unsigned> itsMomToSasIDmap; - changedTasks itsChangedTasks; - std::vector<unsigned> itsNewSchedulerTasks; - std::vector<unsigned> itsTreesToDelete; // contains SAS tree IDs not taskIDs (used for deletion of SAS trees) - std::vector<AstroDate> itsChangedDates; - std::pair<AstroDate, AstroDate> itsUploadedDateRange; - - Controller *itsController; - SASUploadDialog *itsUploadDialog; - SASProgressDialog itsProgressDialog; - StateHistoryDialog itsStateHistoryDialog; - QString itsAuthToken; - - QDateTime itsLastDownloadDate; - - QString itsSASUserName, itsSASPassword; - QString itsLastErrorString; -}; - -std::string getSasTextState(int sas_state); - -#endif /* SASCONNECTION_H_ */ diff --git a/SAS/Scheduler/src/Scheduler.cpp b/SAS/Scheduler/src/Scheduler.cpp deleted file mode 100644 index a24ae3978480bb7b9327171c44218da74e7dbe1a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Scheduler.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Scheduler.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 4-feb-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Scheduler.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "Scheduler.h" -#include "schedulerdata.h" -#include "station.h" -#include "task.h" -#include "Controller.h" -#include <cmath> -#include <vector> -#include <iostream> -#include <sstream> -#include <limits> -#include <cstdlib> -#include <QMessageBox> -using std::vector; -using std::max; -using std::min; - - -Scheduler::Scheduler() : - pData(0), data_loaded(false), userDefinedStopCriteria(false), maxNrOfOptimizeIterations(MAX_OPTIMIZE_ITERATIONS), - userAcceptedPenalty(0), minTimeBetweenTasks(MIN_TIME_BETWEEN_TASKS_JULIAN) -{ -} - -Scheduler::~Scheduler() { -} - -void Scheduler::setData(SchedulerData &data) { - pData = &data; - data_loaded = true; -} - -void Scheduler::updateSettings(void) { // updates the scheduler settings according to the settings in Controller::theSchedulerSettings - userAcceptedPenalty = Controller::theSchedulerSettings.getUserAcceptedPenalty(); - userAcceptedPenaltyEnabled = Controller::theSchedulerSettings.getUserAcceptedPenaltyEnabled(); - maxNrOptimizationsEnabled = Controller::theSchedulerSettings.getMaxNrOptimizationsEnabled(); - maxNrOfOptimizeIterations = Controller::theSchedulerSettings.getMaxNrOptimizations(); - minTimeBetweenTasks = Controller::theSchedulerSettings.getMinimumTimeBetweenTasks(); -} - -/* -void Scheduler::calculateSunSetsAndSunDowns(void) { -} - -void Scheduler::calculatePenalties(void) { - // For every task (scheduled and unscheduled) do the following: - // step 0: determine if the penalty needs to be recalculated ( Task::penaltyCalculationNeeded() ), if so: - // for every station used by the task calculate: - // x = [0:1:100] = percentage of task scheduled at daytime for that station - // y = night time weight factor (for penalty calculation [0.0, 1.0] - // curve 1: y = 1 ( in other words: task may not be scheduled during daytime) - // curve 2: y = 1-c^-x // c = 1.1 - // curve 3: y = 1-c^-x // c = 1.04 - // curve 4: y = x - // curve 5: y = c^(x-100) - 0.019800040113920 // c = 1.04 - // curve 6: y = c^(x-100) - 0.000072565715901 // c = 1.1 - // curve 7: y = 0 ( in other words: task may be scheduled at daytime without penalty) - - // penalty contribution of (partially) day time scheduling - // step 1: calculate sun set and sun down for the currently scheduled day - // step 2: calculate percentage overlap of schedule period with day time (factor x) - // step 3: calculate night time weight factor according to user chosen curve (1 to 7) (this is factor y) - // step 4: calculate penalty contribution for partially day time scheduling with: - // penalty contribution = d * y, where d is the maximum penalty for full day time scheduling - // step 5: sum all penalties of all tasks to determine the total penalty for the schedule being examined - -} -*/ - -int Scheduler::optimize(void) -{ - bestSchedule = pData->getCurrentSchedule(); // needs operator = for class NeighbourSolution - unsigned int bestPenalty = pData->getCurrentSchedule().getPenalty(); - userAcceptedPenaltyEnabled = Controller::theSchedulerSettings.getUserAcceptedPenaltyEnabled(); - userAcceptedPenalty = Controller::theSchedulerSettings.getUserAcceptedPenalty(); - maxNrOfOptimizeIterations = Controller::theSchedulerSettings.getMaxNrOptimizations(); - maxNrOptimizationsEnabled = Controller::theSchedulerSettings.getMaxNrOptimizationsEnabled(); - // c is the control parameter that determines the acceptance rate of a test schedule with a higher penalty - // We gradually force c to zero during subsequent iterations - unsigned int c = 500; //maxNrOfOptimizeIterations + 1; //(pData->getNrScheduled() + pData->getNrUnscheduled()) * MAX_TASK_PENALTY; - //unsigned int c_step = 2 * c / maxNrOfOptimizeIterations; - // unsigned int currentScheduleMaxChangeCount = pData->getNrOfConflicts(); - // bool allowUnscheduleFixedTasks = Controller::theSchedulerSettings.getAllowUnscheduleFixedTasks(); - unsigned iteration(0), taskID; // , predTaskID, successorTaskID; - bool scheduleChanged(false); - Task * pTask(0); - while (true) { - scheduleChanged = false; - // check stopping criteria - if (userAcceptedPenaltyEnabled && (bestPenalty <= userAcceptedPenalty)) { - pData->setCurrentSchedule(bestSchedule); - return 1; // user accepted penalty reached - } - if (maxNrOptimizationsEnabled && (iteration == maxNrOfOptimizeIterations)) { - pData->setCurrentSchedule(bestSchedule); - return 2; // max number of optimizations reached - } - testSchedule = pData->getCurrentSchedule(); // make a copy of the current schedule - // calculate a neighbour schedule - // SIMULATED ANNEALING ALGORITHM - // choose a random task to reschedule from the conflicting tasks - taskID = testSchedule.getRandomScheduledTaskID(); - if (taskID) { - pTask = testSchedule.getTaskForChange(taskID); - } - else return 3; // there are no more scheduled tasks that may be changed - - // now try an alteration of the current schedule - if (pTask->getFixedDay()) { - if (!pTask->getFixedTime()) { // if task only fixed on day not on time - if (testSchedule.tryShiftTaskWithinDay(pTask->getID(), true)) { - scheduleChanged = true; - } - } - } - else if (pTask->getFixedTime()) { // task only fixed on time not on day - if (testSchedule.tryMoveTaskToAdjacentDay(pTask->getID(), true)) { - scheduleChanged = true; - } - } - else { - if (testSchedule.shiftTask(pTask->getID(), true)) { - scheduleChanged = true; - } - } - - if (!scheduleChanged) { // if the schedule didn't change then we try to unschedule the random task - if (testSchedule.unscheduleTask(pTask->getID())) { - scheduleChanged = true; - } - else { - ++iteration; // increase the iteration counter to prevent the possibility of an endless loop - } - } - - if (scheduleChanged) { - // now check if other unscheduled tasks can be fit in to the changed schedule - testSchedule.tryScheduleUnscheduledTasks(); - //testSchedule.addChangedTasks(changedTask); - // keep track of the best schedule so far. - testSchedule.calculatePenalty(); - if (testSchedule.getPenalty() < bestSchedule.getPenalty()) { - bestSchedule = testSchedule; - bestPenalty = bestSchedule.getPenalty(); - //pData->setCurrentSchedule(bestSchedule); // move to best schedule - } - - double acceptanceValue = static_cast<double>(rand()-1) / RAND_MAX; - double currentValue = exp((static_cast<double>(pData->getPenalty()) - static_cast<double>(testSchedule.getPenalty())) / c); - - debugInfo("sisisisi", "iteration: ",iteration+1, ", last penalty: ", testSchedule.getPenalty(), ", current penalty: ", pData->getPenalty(), - ", best schedule penalty: ", bestSchedule.getPenalty()); - - if (testSchedule.getPenalty() <= pData->getPenalty()) { - pData->setCurrentSchedule(testSchedule);// accept schedule if it has a lower penalty - } - else if (currentValue > acceptanceValue) { // move to new schedule with a certain probability - pData->setCurrentSchedule(testSchedule); - //currentScheduleMaxChangeCount = pData->getNrOfConflicts(); - } - // force the control parameter stepwise towards zero during iterations - if (c > 50) {c -= 2;} - - emit optimizeIterationFinished(++iteration); - } - } // while (true) - return false; -} - -bool Scheduler::createStartSchedule(void) -{ - if (data_loaded) { - // if (!(pData->checkTasksForErrors())) { - pData->unscheduleAll(); - if (pData->getNrUnscheduled()) { - pData->sortUnscheduledTasks2Priority(); - pData->scheduleFixedTasks(); - pData->tryScheduleUnscheduledTasks(); - unsigned int penalty = pData->calcCurrentPenalty(); - debugInfo("sisisi", "start schedule created. # scheduled: ", - pData->getNrScheduled(), ", # unscheduled: ", pData->getNrUnscheduled(), ", total penalty: ", penalty); - return true; - } - else { - QMessageBox::warning(0, tr("No tasks could be unscheduled"), - tr("There are no tasks that may be unscheduled. Cannot create a start schedule."),tr("Close")); - return true; - } - } - else return false; -} - -bool Scheduler::tryRescheduleTask(unsigned task_id, const AstroDateTime &new_start) { - return pData->rescheduleTask(task_id, new_start); -} - -bool Scheduler::rescheduleAbortedTask(unsigned task_id, const AstroDateTime &new_start) { - return pData->rescheduleAbortedTask(task_id, new_start); -} - -bool Scheduler::checkFilterConflict(unsigned taskToCheck, station_filter_type filter) { - //std::vector<unsigned int>::const_iterator task_it = task_ids.begin(); - const Observation *pTask = pData->getScheduledObservation(taskToCheck); - if (pTask) { - if (pTask->getFilterType() == filter) return false; // no conflict if filters are the same - } - else { - // task was not found in scheduled tasks -> no conflicts possible - debugWarn("sis","Task with ID: ",taskToCheck, "is not scheduled. Therefore, there are no filter conflicts!"); - return false; - } - return true; -} - -bool Scheduler::checkClockFrequencyConflict(unsigned task_id, station_clock clock) { - const Observation *pTask = pData->getScheduledObservation(task_id); - if (pTask) { - if (pTask->getStationClock() == clock) { - return false; // no conflict if filters are the same - } - else { - return true; // conflicting clock frequency settings - } - } - else { - // task was not found in scheduled tasks -> no conflicts possible - debugWarn("sis","Task with ID: ",task_id, "is not scheduled. Therefore, there are no filter conflicts!"); - return false; - } -} - -bool Scheduler::checkTaskTypeConflict(unsigned taskToCheck, Task::task_type type) { - const Task *pTask = pData->getScheduledTask(taskToCheck); - if (pTask) { - Task::task_type ttype = pTask->getType(); - switch (type) { - case Task::OBSERVATION: - if (ttype == Task::MAINTENANCE) return true; // no other tasks possible when Maintenance is being performed - return false; - break; - case Task::RESERVATION: - if (ttype == Task::MAINTENANCE) return true; // no other tasks possible when Maintenance is being performed - return false; - break; - case Task::MAINTENANCE: - return 1; // maintenance cannot be scheduled when other task type is scheduled - break; - case Task::PIPELINE: - if (ttype == Task::MAINTENANCE) return true; // no other tasks possible when Maintenance is being performed - return false; - break; - case Task::SYSTEM: - if (ttype == Task::MAINTENANCE) return true; // no other tasks possible when Maintenance is being performed - return false; - break; - case Task::UNKNOWN: - if (ttype == Task::MAINTENANCE) return true; // no other tasks possible when Maintenance is being performed - return false; - break; - default: - debugWarn("sis", "Task with ID: ",taskToCheck, "has an unknown task type specification"); - break; - } - } - else { - // task was not found in scheduled tasks -> no conflicts possible - debugWarn("sis","Task with ID: ",taskToCheck, "is not scheduled. Therefore, there are no task type conflicts!"); - } - return false; -} - diff --git a/SAS/Scheduler/src/Scheduler.h b/SAS/Scheduler/src/Scheduler.h deleted file mode 100644 index 4dad81d81907abb6ad746b8950c16eee34925c00..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Scheduler.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Scheduler.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 4-feb-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Scheduler.h $ - * - */ - -#ifndef SCHEDULER_H_ -#define SCHEDULER_H_ - -#include <QObject> -#include <vector> -#include "station.h" -#include "task.h" -#include "schedulerdatablock.h" -#include "neighboursolution.h" -//#include "schedulersettings.h" - - -class SchedulerData; - -class Scheduler : public QObject { - - Q_OBJECT - -public: - Scheduler(); - virtual ~Scheduler(); - - bool createStartSchedule(void); // creates a start schedule - int optimize(void); // starts optimizing the schedule - void setData(SchedulerData &data); // loads the data in the scheduler - - // sorts the unscheduled tasks according to priority (MOVED TO schedulerDataBlock) - //void sortUnscheduledTasks2Priority(); - - // check if the task with ID taskToCheck conflicts with the specified filter setting - bool checkFilterConflict(unsigned taskToCheck, station_filter_type filter); - // check if the task with ID taskToCheck conflicts with the specified station clock setting - bool checkClockFrequencyConflict(unsigned task_id, station_clock clock); - // check if the task with ID taskToCheck conflicts with the specified task type - bool checkTaskTypeConflict(unsigned taskToCheck, Task::task_type type); -// void logConflicts(unsigned int taskID, std::vector<unsigned int> &possible_conflicts); - //void scheduleFixedTasks(void); // schedules tasks marked with fixed day or fixed time -// void calculatePenalties(void); -// void calculateSunSetsAndSunDowns(void); - void setMinimumTimeBetweenTasks(const AstroTime &min_time) {minTimeBetweenTasks = min_time;} - void setMaxOptimizationIterations(unsigned max_optimizations) {maxNrOfOptimizeIterations = max_optimizations;} - void updateSettings(void); // updates the scheduler settings according to the settings in Controller::theSchedulerSettings - bool tryRescheduleTask(unsigned task_id, const AstroDateTime &new_start); - bool rescheduleAbortedTask(unsigned task_id, const AstroDateTime &new_start); - -private: - bool tryMoveTaskToAdjacentDay(Task *task); - bool tryShiftTask(Task *task, SchedulerDataBlock &testSchedule); - bool tryShiftTaskWithinDay(Task *task); - - -signals: - void dataContainsErrors(void); - void optimizeIterationFinished(unsigned); - -private: - SchedulerData *pData; - NeighbourSolution testSchedule, bestSchedule; - std::vector<SchedulerDataBlock> possibleSolutions; - bool data_loaded; - bool userDefinedStopCriteria; - bool userAcceptedPenaltyEnabled; - bool maxNrOptimizationsEnabled; - unsigned maxNrOfOptimizeIterations; - unsigned userAcceptedPenalty; - AstroTime minTimeBetweenTasks; -}; - -#endif /* SCHEDULER_H_ */ - diff --git a/SAS/Scheduler/src/SpinBox.cpp b/SAS/Scheduler/src/SpinBox.cpp deleted file mode 100644 index 0e688a23687211162d58e09abfc8c13cb40bab96..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/SpinBox.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SpinBox.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 16-jun-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/SpinBox.cpp $ - * - */ - -#include "SpinBox.h" - -SpinBox::SpinBox(QWidget *parent) - : QSpinBox(parent), itsUndefined(false), itsPreviousUndefined(false), itsPreviousValue(0), itsDefaultValue(0) -{ -} - -SpinBox::~SpinBox() -{ - -} - -void SpinBox::setValue(int value) { - this->blockSignals(true); - setSpecialValueText(""); - QSpinBox::setValue(value); - itsPreviousValue = value; - itsUndefined = false; - this->blockSignals(false); -} - - -void SpinBox::setUndefined(bool enabled = true) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - itsPreviousValue = -1; - // NOTE: if the current value is equal to the minimum value then the special value text is shown - setSpecialValueText(MULTIPLE_VALUE_TEXT); - QSpinBox::setValue(minimum()); - } - else { - setSpecialValueText(""); - QSpinBox::setValue(itsDefaultValue); - } - this->blockSignals(false); -} - -void SpinBox::focusInEvent(QFocusEvent* event) -{ - if (itsUndefined) { - this->blockSignals(true); - itsPreviousUndefined = true; - QSpinBox::setValue(itsDefaultValue); - setSpecialValueText(""); - itsPreviousValue = value(); - this->blockSignals(false); - } - - // You might also call the parent method. - QSpinBox::focusInEvent(event); -} - -void SpinBox::focusOutEvent(QFocusEvent* event) -{ - checkValueChange(); - // You might also call the parent method. - QSpinBox::focusOutEvent(event); -} - -void SpinBox::checkValueChange(void) { - if (itsUndefined) { - if (itsPreviousValue == value()) { // was undefined and did not change - // NOTE: if the current value is equal to the minimum value then the special value text is shown - setSpecialValueText(MULTIPLE_VALUE_TEXT); - this->blockSignals(true); - QSpinBox::setValue(minimum()); - this->blockSignals(false); - } - else { - itsUndefined = false; - setSpecialValueText(""); - } - itsPreviousValue = value(); - } -} diff --git a/SAS/Scheduler/src/SpinBox.h b/SAS/Scheduler/src/SpinBox.h deleted file mode 100644 index f0673fe9f6f537e8bfc98b8bcefb73eedbaea29a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/SpinBox.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SpinBox.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 16-jun-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/SpinBox.h $ - * - */ - -#ifndef SPINBOX_H -#define SPINBOX_H - -#include "lofar_scheduler.h" -#include <QSpinBox> - -class SpinBox : public QSpinBox -{ - Q_OBJECT - -public: - SpinBox(QWidget *parent = 0); - ~SpinBox(); - - - void setValue(int value); - void setUndefined(bool enabled); - void setDefaultValue(int value) {itsDefaultValue = value;} - inline bool isUndefined(void) {return itsUndefined;} - bool hasBeenChanged(void) const { - if (itsUndefined) return false; - else if (itsPreviousUndefined) return true; - else if (itsPreviousValue != value()) return true; - else return false; - } - void resetChangeDetect(void) { itsPreviousValue = value(); } - -protected: - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkValueChange(void); -private: - bool itsUndefined, itsPreviousUndefined; - int itsPreviousValue, itsDefaultValue; -}; - -#endif // SPINBOX_H diff --git a/SAS/Scheduler/src/Storage.cpp b/SAS/Scheduler/src/Storage.cpp deleted file mode 100644 index 3409b95f0afb2bf3e622b29734c9db9121dfb160..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Storage.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Storage.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 5-aug-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Storage.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "Storage.h" -#include <QDateTime> -#include "astrodatetime.h" -#include "Controller.h" -#include <map> -#include <algorithm> -#include <cmath> - -using std::map; -using std::min; -using std::max; - -Storage::Storage() { -} - -Storage::~Storage() { -} - -bool storageLocationsContains(const storageLocationOptions &locs, int node_id, int raid_id) { - for (std::vector<std::pair<int, nodeStorageOptions> >::const_iterator it = locs.begin(); it != locs.end(); ++it) { - if (it->first == node_id) { - for (std::vector<storageOption>::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { - if (sit->raidID == raid_id) return true; - } - } - } - return false; -} - -bool Storage::addStorageNode(const std::string &nodeName, int nodeID) { - if (itsStorageNodes.find(nodeID) == itsStorageNodes.end()) { - itsStorageNodes[nodeID] = StorageNode(nodeName, nodeID); - return true; - } - else return false; -} - -void Storage::addStoragePartition(int nodeID, unsigned short partitionID, const std::string &path, const double &capacity, const double &free_space) { - QDateTime cT = QDateTime::currentDateTime().toUTC(); - AstroDateTime now(cT.date().day(), cT.date().month(), cT.date().year(), - cT.time().hour(), cT.time().minute(), cT.time().second()); - itsStorageNodes[nodeID].addPartition(partitionID, path, now, capacity, free_space); -} - -void Storage::clearStorageClaims(void) { - for (storageNodesMap::iterator it = itsStorageNodes.begin(); it != itsStorageNodes.end(); ++it) { - it->second.clearClaims(); - } - itsTaskStorageNodes.clear(); - itsLastStorageCheckResult.clear(); -} - -void Storage::initStorage(void) { - itsStorageNodes.clear(); - QDateTime cT = QDateTime::currentDateTime().toUTC(); - const hostPartitionsMap &partitions = Controller::theSchedulerSettings.getStoragePartitions(); - const storageHostsMap &nodes = Controller::theSchedulerSettings.getStorageNodes(); - const double &storageNodeBW = Controller::theSchedulerSettings.getStorageNodeBandWidth(); - StorageNode node; - AstroDateTime now(cT.date().day(), cT.date().month(), cT.date().year(), - cT.time().hour(), cT.time().minute(), cT.time().second()); - storageHostsMap::const_iterator nit; - for (hostPartitionsMap::const_iterator it = partitions.begin(); it != partitions.end(); ++it) { - nit = nodes.find(it->first); - if (nit != nodes.end()) { - node.initNode(nit->second, now, storageNodeBW); - for (dataPathsMap::const_iterator pit = it->second.begin(); pit != it->second.end(); ++pit) { - node.addPartition(pit->first, pit->second.first, now, pit->second.second[0], pit->second.second[3]); - } - itsStorageNodes[it->first] = node; - node.clear(); - } - } -} - - -// function checkAssignedTaskStorage is used for checking if the given task it's claims are registered at the storage nodes assigned to the task -// assuming it is not possible to assign storage to a task if a conflict arises from it, the function doesn't check if the size and bandwidth requirements are fulfilled. -// it assumes that if the task has been registered at the assigned storage nodes that everything is fine. -std::vector<storageResult> Storage::checkAssignedTaskStorage(Task *pTask, dataProductTypes dataProduct) { - if (pTask->hasStorage()) { - const storageMap &storageLocations = pTask->storage()->getStorageLocations(); - storageNodesMap::const_iterator snit; - storageMap::const_iterator stit = storageLocations.find(dataProduct); - itsLastStorageCheckResult.clear(); - unsigned int taskID(pTask->getID()); - if (stit != storageLocations.end()) { - for (storageVector::const_iterator sit = stit->second.begin(); sit != stit->second.end(); ++sit) { - snit = itsStorageNodes.find(sit->first); - if (snit != itsStorageNodes.end()) { - if (!snit->second.checkClaim(taskID, dataProduct, sit->second)) { - itsLastStorageCheckResult.push_back(storageResult(dataProduct, sit->first, sit->second, CONFLICT_NO_STORAGE_ASSIGNED)); - pTask->setConflict(CONFLICT_NO_STORAGE_ASSIGNED); - } - } - else { - itsLastStorageCheckResult.push_back(storageResult(dataProduct, sit->first, sit->second, CONFLICT_STORAGE_NODE_INEXISTENT)); - pTask->setConflict(CONFLICT_STORAGE_NODE_INEXISTENT); - } - } - } - else { - std::cerr << "Storage::checkAssignedTaskStorage, Warning: data product " << DATA_PRODUCTS[dataProduct] << " not specified for task:" << pTask->getID() << std::endl; - } - } - return itsLastStorageCheckResult; -} - - -storageLocationOptions Storage::getStorageLocationOptions(dataProductTypes dataProduct, const AstroDateTime &startTime, const AstroDateTime &endTime, - const double &fileSize, const double &bandWidth, unsigned minNrFiles, sortMode sort_mode, const std::vector<int> &nodes) { - storageLocationOptions locations; - itsLastStorageCheckResult.clear(); - nodeStorageOptions node_options; - std::vector<std::pair<int, task_conflict> > checkResult; // raidID, conflict - // randomize the storage nodes sequence so that storage nodes with the same number of claims are selected at random - std::vector<int> randomizedStorageNodes; - storageNodesMap::const_iterator sit; - for (std::vector<int>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) { - sit = itsStorageNodes.find(*it); - if (sit != itsStorageNodes.end()) { - if (sit->second.mayBeUsed()) { - randomizedStorageNodes.push_back(*it); - } - } - } - std::random_shuffle( randomizedStorageNodes.begin(), randomizedStorageNodes.end() ); - - for (std::vector<int>::const_iterator it = randomizedStorageNodes.begin(); it != randomizedStorageNodes.end(); ++it) { - sit = itsStorageNodes.find(*it); - checkResult.clear(); - node_options = sit->second.getPossibleRaidArrays(startTime, endTime, fileSize, bandWidth, minNrFiles, checkResult); - if (!node_options.empty()) { - locations.push_back(storageLocationOptions::value_type(sit->first, node_options)); - } - if (!checkResult.empty()) { - for (std::vector<std::pair<int, task_conflict> >::const_iterator chit = checkResult.begin(); chit != checkResult.end(); ++chit) { - itsLastStorageCheckResult.push_back(storageResult(dataProduct, sit->first, chit->first, chit->second)); - } - } - } - // sorting requested? - if (sort_mode == SORT_USAGE) { - bool inserted; - storageLocationOptions sortedLocs; - for (storageLocationOptions::const_iterator slit = locations.begin(); slit != locations.end(); ++slit) { - inserted = false; - for (storageLocationOptions::iterator svit = sortedLocs.begin(); svit != sortedLocs.end(); ++svit) { - if (itsStorageNodes.find(slit->first)->second.nrClaims() < itsStorageNodes.find(svit->first)->second.nrClaims()) { - sortedLocs.insert(svit, storageLocationOptions::value_type(*slit)); - inserted = true; - break; - } - } - if (!inserted) { - sortedLocs.push_back(storageLocationOptions::value_type(*slit)); - } - } - return sortedLocs; - } - - return locations; -} - -void Storage::setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts) { - std::vector<int>::const_iterator it; - storageNodesMap::iterator sit = itsStorageNodes.begin(); - while (sit != itsStorageNodes.end()) { - it = find(allowedStorageHosts.begin(),allowedStorageHosts.end(),sit->second.getID()); - if (it != allowedStorageHosts.end()) { - sit->second.setMayBeUsed(true); - } - else { - sit->second.setMayBeUsed(false); - } - ++sit; - } -} diff --git a/SAS/Scheduler/src/Storage.h b/SAS/Scheduler/src/Storage.h deleted file mode 100644 index 5f1fa89b38181227eb5ed85021b5c862978ff55f..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/Storage.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Storage.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 5-aug-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/Storage.h $ - * - */ - -#ifndef STORAGE_H_ -#define STORAGE_H_ - -#include <map> -#include <vector> -#include "lofar_scheduler.h" -#include "storage_definitions.h" -#include "StorageNode.h" -#include "task.h" -#include "schedulersettings.h" - - -class Storage { -public: - Storage(); - virtual ~Storage(); - - void initStorage(void); - bool addStorageNode(const std::string &nodeName, int nodeID);// {itsStorageNodes.insert(storageNodesMap::value_type(nodeID, nodeName));} - void addStoragePartition(int nodeID, unsigned short partitionID, const std::string &path, const double &capacity, const double &free_space); - void clearStorageClaims(void); // removes all claims from all storage nodes - std::vector<storageResult> checkAssignedTaskStorage(Task *pTask, dataProductTypes dataProduct); - // returns the possible storage locations for the claim.key = node ID, value vector of raidID,free space pairs - storageLocationOptions getStorageLocationOptions(dataProductTypes dataProduct, const AstroDateTime &startTime, const AstroDateTime &endTime, - const double &fileSize, const double &bandWidth, unsigned minNrFiles, sortMode sort_mode, const std::vector<int> &nodes = std::vector<int>()); - // returns the last storage check results from calling getStorageLocationOptions - const std::vector<storageResult> &getLastStorageCheckResult(void) const {return itsLastStorageCheckResult;} - void setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts); - const storageNodesMap &storageNodes(void) const {return itsStorageNodes;} - -private: - std::map<unsigned, std::vector<int> > itsTaskStorageNodes; // key:taskID, value: vector holding the storage node IDs used by the task - storageNodesMap itsStorageNodes; - std::vector<storageResult> itsLastStorageCheckResult; -}; - -bool storageLocationsContains(const storageLocationOptions &locs, int node_id, int raid_id); - -#endif /* STORAGE_H_ */ diff --git a/SAS/Scheduler/src/StorageNode.cpp b/SAS/Scheduler/src/StorageNode.cpp deleted file mode 100644 index 2eb6e29dbda65b46898759f24b718b5f5e7a3996..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/StorageNode.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/* - * StorageNode.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 22-jun-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/StorageNode.cpp $ - * - */ - -#include "StorageNode.h" -#include "Controller.h" -#include <limits> -#include <QDateTime> -#include <cmath> - -StorageNode::StorageNode() -: itsID(0), itsStatus(0), itsclaimID(0) -{ -} - -StorageNode::StorageNode(const std::string &name, int nodeID) -: itsName(name), itsID(nodeID), itsStatus(0), itsclaimID(0) -{ -} - -StorageNode::~StorageNode() { -} - -void StorageNode::initNode(const StorageHost &host, const AstroDateTime &now, const double &totalBandWidth) { - itsStoragePartitions.clear(); - itsClaims.clear(); - itsRemainingSpace.clear(); - itsRemainingBandwidth.clear(); - itsName = host.itsName; - itsID = host.itsID; - itsStatus = host.itsStatus; - itsMayBeUsed = host.itsMayBeUsed; - itsRemainingBandwidth.push_back(nodeBandWidthLogPoint(0, now, 0, totalBandWidth)); -} - -bool StorageNode::addPartition(int raidID, const std::string &partition, const AstroDateTime &now, const double &byte_capacity, const double &free_space) { - storagePartitionsMap::iterator it = itsStoragePartitions.find(raidID); - if (it != itsStoragePartitions.end()) { - return false; // partition ID already taken - } - // partition ID not taken -> add the partition -// std::cout << "node:" << itsName << ", adding partition " << raidID << ", name:" << partition << ", capacity:" << byte_capacity << ", free spacve: " << free_space << std::endl; - itsStoragePartitions[raidID] = std::pair<std::string, double>(partition, byte_capacity); -// std::pair<double, double> valPair = std::pair<double, double>(free_space, Controller::theSchedulerSettings.getRaidMaxWriteSpeed()); - itsRemainingSpace[raidID].clear(); // clears or creates this raidID entry in itsremainingspacemap - itsRemainingSpace[raidID].push_back(capacityLogPoint(0, 0, now, free_space, Controller::theSchedulerSettings.getRaidMaxWriteSpeed())); // set the current values for size and bandwidth - return true; -} - -void StorageNode::clearClaims(void) { - itsclaimID = 0; - itsClaims.clear(); - std::vector<capacityLogPoint> newCapacityVec; - capacityTimeMap newRemainingSpaceMap; - for (capacityTimeMap::iterator it = itsRemainingSpace.begin(); it != itsRemainingSpace.end(); ++it) { - newCapacityVec.clear(); - newCapacityVec.push_back(it->second.front()); - newRemainingSpaceMap[it->first] = newCapacityVec; - } - itsRemainingSpace = newRemainingSpaceMap; - - nodeBandWidthVector newbwvec; - newbwvec.push_back(itsRemainingBandwidth.front()); - itsRemainingBandwidth = newbwvec; -} - - -/* -bool StorageNode::setCurrentValues(int raidID, const AstroDateTime &now, const double &byte_capacity, const double &bandwidth) { -// capacityTimeMap::iterator it = itsRemainingSpace.find(raidID); -// if (it != itsRemainingSpace.end()) { -// QDateTime cT = QDateTime::currentDateTime().toUTC(); -// AstroDateTime now(cT.date().day(), cT.date().month(), cT.date().year(), -// cT.time().hour(), cT.time().minute(), cT.time().second()); -// it->second.clear(); -// capacityTimeMap; - std::pair<double, double> valPair = std::pair<double, double>(byte_capacity, bandwidth); - itsRemainingSpace[raidID].push_back(std::pair<AstroDateTime, std::pair<double, double> >(now, valPair)); - return true; -// } -// else return false; -} -*/ - -task_conflict StorageNode::checkBandWidth(const AstroDateTime &start, const AstroDateTime &end, const double &totalBW_kbs) const { - //first check if total bandwidth of this node is not exceeded - if (totalBW_kbs > itsRemainingBandwidth.front().remainingNodeBW) { - return CONFLICT_STORAGE_NODE_BANDWIDTH; - } - for (nodeBandWidthVector::const_iterator it = itsRemainingBandwidth.begin(); it != itsRemainingBandwidth.end(); ++it) { - if ((it->time >= start) && (it->time <= end)) { - if (it->remainingNodeBW < totalBW_kbs) - return CONFLICT_STORAGE_NODE_BANDWIDTH; - } - if (it->time > end) break; - } - return CONFLICT_NO_CONFLICT; -} - -task_conflict StorageNode::checkSpaceAndWriteSpeed(const AstroDateTime &startTime, const AstroDateTime &endTime, const double &claimSize, const double &writeSpeed, int raidID) const { - capacityTimeMap::const_iterator cit = itsRemainingSpace.find(raidID); -// std::cout << "checking storage node: " << itsName << std::endl << "partition: " << raidID << std::endl << "claim size for this node: " -// << claimSize << std::endl << "writeSpeed for this node: " << writeSpeed << std::endl << "start time: " << startTime.toString() << std::endl -// << "end time: " << endTime.toString() << std::endl; - if (cit != itsRemainingSpace.end()) { -// std::cout << "first free space log: " << cit->second.front().time.toString() << ", space remaining" << cit->second.front().remainingDiskSpacekB << "kB, disk write speed remaining" << cit->second.front().remainingDiskWriteBW << "MByte/s"; - if (startTime > cit->second.front().time) { // start time of observation needs to be after 'now' which is the first time in itsRemainingSpace - for (std::vector<capacityLogPoint>::const_iterator sit = cit->second.begin(); sit != cit->second.end(); ++sit) { -// std::cout << sit->time.toString() << ", free space:" << sit->remainingDiskSpacekB << "kB, write speed remaining:" << sit->remainingDiskWriteBW << "MB/s" << std::endl; - if (startTime >= sit->time) { // found the last time that is earlier than the requested start time - while (sit < cit->second.end()) { // iterate over the following free space log-points to check if space stays sufficient during the task's duration - if (claimSize > sit->remainingDiskSpacekB) { - return CONFLICT_STORAGE_NODE_SPACE; // insufficient space - } - else if (writeSpeed > sit->remainingDiskWriteBW) { -// std::cerr << "conflict write speed: " << "requested: " << writeSpeed << ", " << "node remaining write speed at " << sit->time.toString().c_str() << ": " << sit->remainingDiskWriteBW << std::endl; - return CONFLICT_STORAGE_WRITE_SPEED; // requested write speed to high - } - else if ((sit++)->time > endTime) return CONFLICT_NO_CONFLICT; - } - return CONFLICT_NO_CONFLICT; // if only the initial entry is logged in itsRemainingSpace we should arrive here. - } - } - return CONFLICT_NO_CONFLICT; // if only the initial entry is logged in itsRemainingSpace we should arrive here. - } - else return CONFLICT_STORAGE_TIME_TOO_EARLY; // Error: start time of observation before now - } - else return CONFLICT_RAID_ARRRAY_NOT_FOUND; // Error: partition not found -} - -// return the ids of the raid arrays that meet the specified bandwidth (kbit/sec) and claimSize within the timespan defined by startTime and endTime -nodeStorageOptions StorageNode::getPossibleRaidArrays(const AstroDateTime &startTime, const AstroDateTime &endTime, const double &fileSize, - const double &bandWidth, unsigned minNrFiles, std::vector<std::pair<int, task_conflict> > &result) const { - bool conflict(false); - result.clear(); - nodeStorageOptions locations; - double minBWreq = minNrFiles * bandWidth; // kbit/sec - double minSizeReq = minNrFiles * fileSize; - storagePartitionsMap::const_iterator spit; -// bool debugOut(false); -// qDebug() << "node: " << itsName.c_str() << " looking for free space: " << minSizeReq << " and bandwidth: " << minBWreq; -// std::cout << "node: " << itsName.c_str() << " looking for free space: " << minSizeReq << " and bandwidth: " << minBWreq << std::endl; -// if (itsName.compare("locus001") == 0) debugOut = true; - -// if (debugOut) { -// std::cout << "storage node id:" << itsID << std::endl -// << "itsRemainingBandwidth size:" << itsRemainingBandwidth.size() << std::endl -// << "itsRemainingSpace size:" << itsRemainingSpace.size() << std::endl -// << "itsClaims size:" << itsClaims.size() << std::endl; -// } - - // check if start time of observation is later than first time in itsRemainingBandwidth - if (startTime > itsRemainingBandwidth.front().time) { // start time of observation needs to be after 'now' which is the first time in itsRemainingSpace - // first check if enough total bandwidth to this node is remaining - if (itsRemainingBandwidth.size() > 1) { -// std::cout << "number of log points in itsRemainingBandwidth:" << itsRemainingBandwidth.size() << std::endl; - for (nodeBandWidthVector::const_iterator it = itsRemainingBandwidth.begin(); it != itsRemainingBandwidth.end()-2; ++it) { -// if (debugOut) { -// std::cout << "log point time:" << it->time.toString() << "BW:" << it->remainingNodeBW << "kbit/s" << std::endl; -// } - if (startTime <= (it+1)->time) { // found the first log point later than the start time of the observation - while (endTime > it->time) { -// if (debugOut) { -// std::cout << "log point time:" << it->time.toString() << "BW:" << it->remainingNodeBW << "kbit/s" << std::endl; -// } - if (minBWreq > it->remainingNodeBW) { -// if (debugOut) { -// std::cout << " not enough total bandwidth to this storage node: " << itsName.c_str() << std::endl; -// } - result.push_back(std::pair<int, task_conflict>(-1, CONFLICT_STORAGE_NODE_BANDWIDTH)); - return locations; // don't check the raid arrays because there is not enough total bandwidth - } - if (++it == itsRemainingBandwidth.end()) break; // iterate to next logpoint in itsRemainingBandWidth - } - break; // break out of for loop (no conflicts so far) - } - } - } - else { // only one element in itsRemainingBandwidth - if (minBWreq > itsRemainingBandwidth.front().remainingNodeBW) { -// if (debugOut) -// std::cout << " not enough total bandwidth to this storage node: " << itsName.c_str() << std::endl; - result.push_back(std::pair<int, task_conflict>(-1, CONFLICT_STORAGE_NODE_BANDWIDTH)); - return locations; // don't check the raid arrays because there is not enough total bandwidth - } - } - // start checking the raid arrays -// if (debugOut) std::cout << "start checking raid arrays" << std::endl; - - short unsigned fillPercentage(Controller::theSchedulerSettings.getStorageFillPercentage()); - double lowerLimitFreekB; - for (capacityTimeMap::const_iterator cit = itsRemainingSpace.begin(); cit != itsRemainingSpace.end(); ++cit) { // iterates over the raid arrays - spit = itsStoragePartitions.find(cit->first); - if (spit != itsStoragePartitions.end()) { - lowerLimitFreekB = spit->second.second * (double) (100.0-fillPercentage) / 100.0; - } - else { - lowerLimitFreekB = 0; - } - conflict = false; - // do check on space and bandwidth on the first entry in itsRemainingSpace (first entry is the total capacity and total bandwidth of this array - double smallest_free = cit->second.front().remainingDiskSpacekB; - double lowest_write_speed = cit->second.front().remainingDiskWriteBW; - if (minSizeReq > smallest_free) { - conflict = true; // not enough space -// if (debugOut) -// std::cout << " not enough total free space on raid: " << cit->first << std::endl; - result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_NODE_SPACE)); -// break; // insufficient space - } - else if (minBWreq > lowest_write_speed * 8) { // minBWreq (kbit/s), lowest_write_speed (kbyte/sec) -// if (debugOut) -// std::cout << " not enough write bandwidth on raid: " << cit->first << std::endl; - result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_WRITE_SPEED)); - conflict = true; // not enough bandwidth -// break; - } - if (!conflict) { -// if (debugOut) { -// std::cout << "nr of log points:" << cit->second.size() << std::endl; -// } -// if (cit->second.size() >= 2) { - bool pastEnd(false); - for (std::vector<capacityLogPoint>::const_iterator logpointIt = cit->second.begin(); logpointIt != cit->second.end(); ++logpointIt) { - - if (!pastEnd && (startTime >= logpointIt->time)) { // found first entry that has a time before start ti - while (logpointIt < cit->second.end()) { // iterate over the following free space log-points to check if space stays sufficient during the task's duration -// if (claimSize > sit->remainingDiskSpacekB) { - - // check if disk usage limit is reached - if (logpointIt->remainingDiskSpacekB < lowerLimitFreekB) { - conflict = true; - result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_NODE_SPACE)); - break; - } - -// if (startTime <= (logpointIt + 1)->time) { // found the first log point which has a time later than startTime of the task -// if (debugOut) -// std::cout << "start:" << startTime.toString() << ", log time:" << (logpointIt + 1)->time.toString() << std::endl; - // do check on space and bandwidth for logPoint - smallest_free = std::min(smallest_free, logpointIt->remainingDiskSpacekB); - lowest_write_speed = std::min(lowest_write_speed, logpointIt->remainingDiskWriteBW); - if (minSizeReq > smallest_free) { - conflict = true; // not enough space -// if (debugOut) -// std::cout << "(1)node: " << itsName.c_str() << " raid: " << cit->first << " not enough space at: " << logpointIt->time.toString().c_str() << ", space available:" << logpointIt->remainingDiskSpacekB << std::endl; - result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_NODE_SPACE)); - break; // insufficient space - } - else if (minBWreq > lowest_write_speed * 8) { // minBWreq (kbit/s), lowest_write_speed (kbyte/sec) -// if (debugOut) -// std::cout << "(2)node: " << itsName.c_str() << " raid: " << cit->first << " not enough bandwidth at: " << logpointIt->time.toString().c_str() << ", write speed available:" << logpointIt->remainingDiskWriteBW << std::endl; - result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_NODE_BANDWIDTH)); - conflict = true; // not enough bandwidth - break; - } - else if (logpointIt->time >= endTime) { - pastEnd = true; - break; //reach the end time of the task - } - else { - if (++logpointIt == cit->second.end()){ - pastEnd = true; - break; - } - } -// while (endTime > (++logpointIt)->time) { // repeat checks upto the end of the task -// // do check on space and bandwidth for logPoint +1 -// smallest_free = std::min(smallest_free, (logpointIt + 1)->remainingDiskSpacekB); -// lowest_write_speed = std::min(lowest_write_speed, (logpointIt + 1)->remainingDiskWriteBW); -// if (minSizeReq > smallest_free) { -// conflict = true; // not enough space -//// if (debugOut) -//// std::cout << "(3)node: " << itsName.c_str() << " raid: " << cit->first << " not enough space at: " << (logpointIt + 1)->time.toString().c_str() << ", space available:" << (logpointIt + 1)->remainingDiskSpacekB << ", logpoint taskID:" << logpointIt->taskID << std::endl; -// result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_NODE_SPACE)); -// break; // insufficient space -// } -// else if (minBWreq > lowest_write_speed * 8) { // minBWreq (kbit/s), lowest_write_speed (kbyte/sec) -//// if (debugOut) -//// std::cout << "(4)node: " << itsName.c_str() << " raid: " << cit->first << " not enough bandwidth at: " << (logpointIt + 1)->time.toString().c_str() << ", write speed available:" << (logpointIt + 1)->remainingDiskWriteBW << std::endl; -// result.push_back(std::pair<int, task_conflict>(cit->first, CONFLICT_STORAGE_NODE_BANDWIDTH)); -// conflict = true; // not enough bandwidth -// break; -// } -// if (logpointIt == cit->second.end()) break; // prevent infinite loop -// } -// break; // no conflicts break out of for loop - } - } - else break; // past end, break out of for loop - } -// } - // ELSE only one lop point means no claims yet for this raid array - } - // if no conflict then enough space and bandwidth are available - if (!conflict) { -// std::cout << "node: " << itsName << " has suitable raid: " << cit->first << std::endl; - unsigned nrFiles = std::min(static_cast<unsigned>(smallest_free / fileSize), static_cast<unsigned>(lowest_write_speed * 8 / bandWidth)); // nr files size calimSize which would fit on this raid array according to remaining space and write speed - locations.push_back(storageOption(cit->first, smallest_free, nrFiles)); - } - } - } - else { - result.push_back(std::pair<int, task_conflict>(-1, CONFLICT_STORAGE_TIME_TOO_EARLY)); - } - if (!locations.empty()) { - sort(locations.begin(), locations.end(), cmp_FreeSpace()); // sort according to smallest free space from small to large - } - return locations; -} - -// adds the task without checking (use checkSpace function before this one on all required storage nodes before adding the task -bool StorageNode::addClaim(unsigned taskID, const AstroDateTime &startTime, const AstroDateTime &endTime, dataProductTypes dataProduct, - const double &claimSize, const double &bandWidth, int raidID) { - // update the total bandwidth remaining vector - - storagePartitionsMap::iterator it = itsStoragePartitions.find(raidID); // check if the raidIDbelongs to this node - if (it != itsStoragePartitions.end()) { - - bool inserted(false); - nodeBandWidthLogPoint newLogPoint; - if (startTime > itsRemainingBandwidth.front().time) { // startTime > now? - newLogPoint.taskID = taskID; - - unsigned idx; - nodeBandWidthVector::iterator vit; - - for (idx = 0; idx < itsRemainingBandwidth.size(); ++idx) { - vit = itsRemainingBandwidth.begin() + idx; - if (taskID == vit->taskID) { // already a log point at this node for this task (from another file / subband) - vit->nodeBWdiff += bandWidth; - vit->remainingNodeBW -= bandWidth; - // now search for the end log point of this task - while ((++idx < itsRemainingBandwidth.size()) && (vit->time <= endTime)) { - vit = itsRemainingBandwidth.begin() + idx; - if (taskID == vit->taskID) { // this is the end -time log point. free up the bandwidth again -// vit->remainingNodeBW += bandWidth; - vit->nodeBWdiff -= bandWidth; - inserted = true; - break; - } - else { - vit->remainingNodeBW -= bandWidth; - } - } - break; - } - if (startTime < vit->time) { // next element (at position idx) is later than the startTime of the task to be inserted - newLogPoint.time = startTime; - newLogPoint.remainingNodeBW = (vit-1)->remainingNodeBW - bandWidth; - newLogPoint.nodeBWdiff = bandWidth; - vit = itsRemainingBandwidth.insert(vit, newLogPoint); // vit now points to the newly inserted element - // now continue subtracting the used bandwidth from the later elements in itsRemainingBandwidth upto the end time of the task - while ((++idx < itsRemainingBandwidth.size()) && (vit->time <= endTime)) { - vit = itsRemainingBandwidth.begin() + idx; - vit->remainingNodeBW -= bandWidth; - } - vit = itsRemainingBandwidth.begin() + idx; - newLogPoint.time = endTime; - newLogPoint.remainingNodeBW = (vit-1)->remainingNodeBW + bandWidth; - newLogPoint.nodeBWdiff = -bandWidth; // at the end of the task the used bandwidth is freed, hence the minus sign - itsRemainingBandwidth.insert(vit, newLogPoint); - inserted = true; - break; - } - } - if (!inserted) { - // insert start time log point -// vit = itsRemainingBandwidth.begin(); - newLogPoint.time = startTime; - newLogPoint.remainingNodeBW = itsRemainingBandwidth.back().remainingNodeBW - bandWidth; - newLogPoint.nodeBWdiff = bandWidth; - itsRemainingBandwidth.push_back(newLogPoint); - // insert end time log point - newLogPoint.time = endTime; - newLogPoint.remainingNodeBW = vit->remainingNodeBW; - newLogPoint.nodeBWdiff = -bandWidth; // at the end of the task the used bandwidth is freed, hence the minus sign - itsRemainingBandwidth.push_back(newLogPoint); - } - -/* - if (itsName == "locus003") { - std::cout << std::setprecision(16) << "locus003" << std::endl; - std::cout << "task:" << taskID << ", dataproduct:" << DATA_PRODUCTS[dataProduct] << ", raidID: " << raidID << std::endl; - for (nodeBandWidthVector::iterator nbit = itsRemainingBandwidth.begin(); nbit != itsRemainingBandwidth.end(); ++nbit) { - std::cout << "time:" << nbit->time.toString() << ", task:" << nbit->taskID << ", remaining:" << nbit->remainingNodeBW << ", diff:" << nbit->nodeBWdiff << std::endl; - } - } -*/ - /* - for (nodeBandWidthVector::iterator vit = itsRemainingBandwidth.begin(); vit < itsRemainingBandwidth.end()-1; ++vit) { - if (startTime < vit->time) { // next element (at position vit) is later than startTime of task to be inserted - // insert element at position pointed to by vit - newLogPoint.time = startTime; - newLogPoint.remainingNodeBW = vit->remainingNodeBW - bandWidth; - newLogPoint.nodeBWdiff = bandWidth; - vit = itsRemainingBandwidth.insert(vit, newLogPoint); // vit now points to the newly inserted element - // update all later elements their size and bandwidth - ++vit; // go to element after newly inserted element - while ((vit < itsRemainingBandwidth.end()) && (vit->time <= endTime)) { // continue to end of task updating total remaining bandwidth - vit->remainingNodeBW -= bandWidth; - ++vit; - } - // now add the end-time log point of the task - newLogPoint.time = endTime; - newLogPoint.remainingNodeBW = vit->remainingNodeBW; - newLogPoint.nodeBWdiff = -bandWidth; // at the end of the task the used bandwidth is freed, hence the minus sign - itsRemainingBandwidth.insert(vit, newLogPoint); - inserted = true; - break; - } - } - */ -/* - if (!inserted) { - // not yet inserted means either there is only one element in the vector (which is the total size and bandwidth), in which case the task has to be inserted after the first element - // or the startTime of this task is later than the last element in the vector, in which case the task has to be added at the end of the vector - // either case this means that the task should be inserted at the back of the vector - // startTime logpoint: - newLogPoint.time = startTime; - newLogPoint.remainingNodeBW = itsRemainingBandwidth.front().remainingNodeBW - bandWidth; - newLogPoint.nodeBWdiff = bandWidth; - itsRemainingBandwidth.push_back(newLogPoint); - // endTime logpoint: - newLogPoint.time = endTime; - newLogPoint.remainingNodeBW = itsRemainingBandwidth.front().remainingNodeBW; - newLogPoint.nodeBWdiff = -bandWidth; - itsRemainingBandwidth.push_back(newLogPoint); - } -*/ - // add the claim to the itsClaims vector - itsClaims.push_back(storageClaim(taskID, ++itsclaimID, raidID, dataProduct, claimSize, bandWidth, startTime, endTime)); - } - - inserted = false; - capacityTimeMap::iterator cit = itsRemainingSpace.find(raidID); - if (cit != itsRemainingSpace.end()) { -// std::cout << "space map for node:" << itsName << ", adding claim for task: " << taskID << std::endl; -// for (std::vector<capacityLogPoint>::const_iterator spaceit = cit->second.begin(); spaceit != cit->second.end(); ++spaceit) { -// std::cout << spaceit->time.toString() << ", " << "task:" << spaceit->taskID << ", space:" << spaceit->remainingDiskSpacekB << std::endl; -// } - -// bool inserted(false); - capacityLogPoint newCapacityLogPoint(taskID, itsclaimID, startTime, 0, 0); - for (std::vector<capacityLogPoint>::iterator vit = cit->second.begin()+1; vit < cit->second.end()-1; ++vit) { - if (startTime < vit->time) { // next element is later than startTime of task to be inserted - // insert element at position pointed to by vit - newCapacityLogPoint.remainingDiskSpacekB = (vit-1)->remainingDiskSpacekB - claimSize; - newCapacityLogPoint.remainingDiskWriteBW = (vit-1)->remainingDiskWriteBW - bandWidth / 8; // diskwrite speed units kbyte/s, bandWidth units kbit/sec - vit = cit->second.insert(vit, newCapacityLogPoint); // vit now points to the newly inserted logpoint - // update all later elements their size and bandwidth (vit now points to the newly inserted element - while (++vit != cit->second.end()) { // subtract claimed disk space from elements after this - vit->remainingDiskSpacekB -= claimSize; - vit->remainingDiskWriteBW -= bandWidth / 8; // diskwrite speed units kbyte/s, bandWidth units kbit/sec - } - inserted = true; - break; - } - } - if (!inserted) { - // not yet inserted that means either there is only one element in the vector (which is the total size and bandwidth), in which case the task has to be inserted after the first element - // or the startTime of this task is later than the last element in the vector, in which case the task has to be added at the end of the vector - // either case this means that the task should be inserted at the back of the vector - newCapacityLogPoint.remainingDiskSpacekB = cit->second.back().remainingDiskSpacekB - claimSize; - newCapacityLogPoint.remainingDiskWriteBW = cit->second.back().remainingDiskWriteBW - (bandWidth / 8); // diskwrite speed units kbyte/s, bandWidth units kbit/sec - - cit->second.push_back(newCapacityLogPoint); - } -// std::cout << "after insertion task:" << taskID << " size of claim:" << claimSize << std::endl; -// for (std::vector<capacityLogPoint>::const_iterator spaceit = cit->second.begin(); spaceit != cit->second.end(); ++spaceit) { -// std::cout << spaceit->time.toString() << ", " << "task:" << spaceit->taskID << ", space:" << spaceit->remainingDiskSpacekB << std::endl; -// } - - } - else { - qWarning() << "StorageNode::addClaim, storageNode: " << itsName.c_str() << ", task:" << taskID << " raid: " << raidID << " was not found in the remainingSpace map"; - return false; - } - } - else { - qWarning() << "StorageNode::addClaim, storageNode: " << itsName.c_str() << ", task:" << taskID << " asking for raid: " << raidID << " which is not on this storage node"; - return false; - } - return true; -} - -void StorageNode::removeClaim(unsigned taskID) { - capacityTimeMap::iterator cit; - size_t claimIdx = 0; - double bandWidthCorrection(0), spaceCorrection(0); - bool correctBandWidth(false); - while (claimIdx < itsClaims.size()) { - const storageClaim &claim = itsClaims.at(claimIdx); - if (claim.taskID == taskID) { - // directly update itsRemainingSpace log to remove the task from the different raid arrays - cit = itsRemainingSpace.find(claim.raidID); // find the raid array for this claim in itsRemainingSpace - if (cit != itsRemainingSpace.end()) { - size_t idx = 0; - while (idx < cit->second.size()) { - capacityLogPoint &logPoint = cit->second.at(idx); - if (logPoint.claimID == claim.claimID) { // is this the logpoint belonging to this claim? - bandWidthCorrection += claim.claimBandWidth; - spaceCorrection += claim.claimByteSize; - correctBandWidth = true; - // erase the element - cit->second.erase(cit->second.begin()+idx); - } - else if (correctBandWidth) { - logPoint.remainingDiskSpacekB -= spaceCorrection; // correct space - if (logPoint.time <= claim.endTime) { // bandwidth should only be updated upto the end of the task - logPoint.remainingDiskWriteBW -= bandWidthCorrection; - } - ++idx; - } - else ++idx; - } - } - // erase the claim from itsClaims - itsClaims.erase(itsClaims.begin()+claimIdx); - } - else ++claimIdx; - // search for more of this task's claims in itsClaims, continue for loop - } - - //also update the node's total bandwidth log - size_t i=0; - while (i < itsRemainingBandwidth.size()) { - nodeBandWidthLogPoint &logpoint = itsRemainingBandwidth.at(i); - if (logpoint.taskID == taskID) { - bandWidthCorrection += logpoint.nodeBWdiff; - // only correct the bandwidth for the logpoints in between the task start (-bandwidth) and task end time (+bandwidth) - // if we are past both logpoints these two should cancel each other out (bandWidthCorrection ~0). - // After the task's end logpoint we don't want to correct the bandwidth for the following logpoints - fabs(bandWidthCorrection) < 0.01 ? correctBandWidth = true : correctBandWidth = false; - // erase the element - itsRemainingBandwidth.erase(itsRemainingBandwidth.begin() + i); - } - else if (correctBandWidth) { - logpoint.remainingNodeBW -= bandWidthCorrection; // correct the bandwidth for removed logpoints - ++i; - } - else ++i; - } -} - -bool StorageNode::checkClaim(unsigned int taskID, dataProductTypes dataProduct, int raidID) const { - for (storageClaimsVector::const_iterator it = itsClaims.begin(); it != itsClaims.end(); ++it) { - if ((it->taskID == taskID) && (it->dataProductType == dataProduct) && (it->raidID == raidID)) return true; - } - return false; -} -/* -const double &StorageNode::getSpaceAtTime(int raidID, const AstroDateTime &time) { - -} -*/ diff --git a/SAS/Scheduler/src/StorageNode.h b/SAS/Scheduler/src/StorageNode.h deleted file mode 100644 index 06e052c8b60d8088d23bba425184ffbae2a3afc1..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/StorageNode.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * StorageNode.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 22-jun-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/StorageNode.h $ - * - */ - -#ifndef STORAGENODE_H_ -#define STORAGENODE_H_ - -#include <string> -#include <map> -#include <vector> -#include "lofar_scheduler.h" -#include "storage_definitions.h" -#include "astrodatetime.h" -#include "taskstorage.h" -#include "DataMonitorConnection.h" - -class storageClaim { -public: - storageClaim(unsigned task_id, unsigned claim_id, int raid_id, dataProductTypes dataProduct, const double &claim_size, const double &bandwidth, const AstroDateTime &start, const AstroDateTime &end) - : taskID(task_id), claimID(claim_id), dataProductType(dataProduct), raidID(raid_id), claimByteSize(claim_size), claimBandWidth(bandwidth), starttime(start), endTime(end) - { } - unsigned taskID, claimID; - dataProductTypes dataProductType; - int raidID; - double claimByteSize; - double claimBandWidth; - AstroDateTime starttime, endTime; -}; - -class capacityLogPoint { // used for logging the remaining disk space and disk write bandwidth for each raid array -public: - capacityLogPoint(void) {} - capacityLogPoint(unsigned task_id, unsigned claim_id, const AstroDateTime &log_time, const double &remaining_disk_space, const double &remaining_disk_write_speed) - : taskID(task_id), claimID(claim_id), time(log_time), remainingDiskSpacekB(remaining_disk_space), remainingDiskWriteBW(remaining_disk_write_speed) { } - unsigned taskID, claimID; - AstroDateTime time; - double remainingDiskSpacekB, remainingDiskWriteBW; -}; - -// // capacityTimeMap: keeps track of available individual raid capacity and write speed of raid array -// key raidID, value = remaining capacity Log point -typedef std::map<int, std::vector<capacityLogPoint> > capacityTimeMap; - -// class that represents a single log point in the storage node's total bandwidth log vector (nodeBandWidthVector itsRemainingBandwidth) -class nodeBandWidthLogPoint { -public: - nodeBandWidthLogPoint(void) {} - nodeBandWidthLogPoint(unsigned task_id, const AstroDateTime &log_time, const double &bandwidth_diff, const double &remaining_node_bw) - : taskID(task_id), time(log_time), nodeBWdiff(bandwidth_diff), remainingNodeBW(remaining_node_bw) { } - unsigned taskID; // the taskID that caused this log point (multiple log points can have same taskID (on for each individual task file written to this storage node) - AstroDateTime time; // the time of the log point - double nodeBWdiff; // the difference in total bandwidth caused by this task log point (negative at task end-time log point) - double remainingNodeBW; // the remaining total bandwidth for this storage node at time 'time' -}; - -typedef std::vector<storageClaim> storageClaimsVector; - -// nodeBandWidthVector keeps track of the remaining total bandwidth to this storage node -typedef std::vector<nodeBandWidthLogPoint> nodeBandWidthVector; - - -class StorageNode { -public: - StorageNode(); - StorageNode(const std::string &name, int nodeID); - virtual ~StorageNode(); - - const std::string &name(void) const {return itsName;} - int getID() const {return itsID;} - int getStatus() const {return itsStatus;} - const capacityTimeMap &getRemainingSpace(void) const {return itsRemainingSpace;} - const nodeBandWidthVector &getRemainingNodeBandwidth(void) const {return itsRemainingBandwidth;} - const storagePartitionsMap &getStorageLocations(void) const {return itsStoragePartitions;} - const storageClaimsVector &getStorageClaims(void) const {return itsClaims;} - bool mayBeUsed(void) const {return itsMayBeUsed;} - size_t nrClaims(void) const {return itsClaims.size();} - - void initNode(const StorageHost &host, const AstroDateTime &now, const double &totalBandWidth); // bandWidth units kbit/sec - bool addPartition(int raidID, const std::string &partition, const AstroDateTime &now, const double &byte_capacity, const double &free_space); - // check bandwidth requirements don't exceed the nodes bandwidth in the specified (start,end) period - task_conflict checkBandWidth(const AstroDateTime &start, const AstroDateTime &end, const double &totalBW_kbs) const; - // check if space is available to add the requested task to the claims of this storage node using the specified raid array (claimSize units: kByte, bandWidth units kbit/sec) - task_conflict checkSpaceAndWriteSpeed(const AstroDateTime &start, const AstroDateTime &end, const double &claimSize, const double &writeSpeed, int raidID) const; - // return the ids of the raid arrays that meet the specified bandwidth (kbit/sec) and fileSize (kByte) within the timespan defined by startTime and endTime - nodeStorageOptions getPossibleRaidArrays(const AstroDateTime &startTime, const AstroDateTime &endTime, - const double &fileSize, const double &bandWidth, unsigned minNrFiles, std::vector<std::pair<int, task_conflict> > &result) const; - // addFile adds a single file to raid with id equal to raidID to this node (claimSize units: kByte, bandWidth units kbit/sec) - bool addClaim(unsigned taskID, const AstroDateTime &start, const AstroDateTime &end, dataProductTypes dp, const double &claimSize, const double &bandWidth, int raidID); - void removeClaim(unsigned taskID); - bool checkClaim(unsigned int taskID, dataProductTypes dataProduct, int raidID) const; - void clearClaims(void); - void setName(const std::string &name) {itsName = name;} - void setID(int id) {itsID = id;} - void setStatus(int status) {itsStatus = status;} - void setMayBeUsed(bool enabled) {itsMayBeUsed = enabled;} - void clear(void) {itsStoragePartitions.clear(); itsClaims.clear(); itsRemainingSpace.clear();} - -private: - std::string itsName; - int itsID; - int itsStatus; - bool itsMayBeUsed; - unsigned itsclaimID; // used for internal bookkeeping to match logpoints to claims - storagePartitionsMap itsStoragePartitions; - storageClaimsVector itsClaims; - capacityTimeMap itsRemainingSpace; - nodeBandWidthVector itsRemainingBandwidth; // units:kbit/sec -}; - -class cmp_FreeSpace -{ -public: - bool operator() (const storageOption &s1, const storageOption &s2) const - { - return s1.remainingSpacekB < s2.remainingSpacekB; - } -}; - -#endif /* STORAGENODE_H_ */ diff --git a/SAS/Scheduler/src/TiedArrayBeam.cpp b/SAS/Scheduler/src/TiedArrayBeam.cpp deleted file mode 100644 index c64adff7175716f5c75833d081dd8f903158d3cd..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/TiedArrayBeam.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * task.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Dec 6, 2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/TiedArrayBeam.cpp $ - * - */ - -#include "TiedArrayBeam.h" - - -TiedArrayBeam::~TiedArrayBeam() { - // TODO Auto-generated destructor stub -} - -QDataStream& operator>> (QDataStream &in, TiedArrayBeam &tiedArrayBeam) { - in >> tiedArrayBeam.itsAngle1 >> tiedArrayBeam.itsAngle2 >> tiedArrayBeam.itsIsCoherent >> tiedArrayBeam.itsDispersionMeasure; - return in; -} - -QDataStream& operator<< (QDataStream &out, const TiedArrayBeam &tiedArrayBeam) { - out << tiedArrayBeam.itsAngle1 << tiedArrayBeam.itsAngle2 << tiedArrayBeam.itsIsCoherent << tiedArrayBeam.itsDispersionMeasure; - return out; -} - -bool TiedArrayBeam::operator!=(const TiedArrayBeam & right) const { - return ((itsAngle1 != right.angle1()) || - (itsAngle2 != right.angle2()) || - (itsIsCoherent != right.isCoherent()) || - (itsDispersionMeasure != right.dispersionMeasure())); -} - -void TiedArrayBeam::clear(void) { - itsAngle1 = 0.0; - itsAngle2 = 0.0; - itsIsCoherent = false; - itsDispersionMeasure = 0.0; -} diff --git a/SAS/Scheduler/src/TiedArrayBeam.h b/SAS/Scheduler/src/TiedArrayBeam.h deleted file mode 100644 index 47f2e3ef43030c10bf001d63586216e63209f220..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/TiedArrayBeam.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * task.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Dec 6, 2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/TiedArrayBeam.h $ - * - */ - -#include "lofar_scheduler.h" -#include <QDataStream> - -#ifndef TIEDARRAYBEAM_H_ -#define TIEDARRAYBEAM_H_ - -class TiedArrayBeam { -public: - TiedArrayBeam() : - itsAngle1(0.0), itsAngle2(0.0), itsIsCoherent(false), itsDispersionMeasure(0.0) { } - TiedArrayBeam(const double &angle1, const double &angle2, bool coherent, const float &dm) : - itsAngle1(angle1), itsAngle2(angle2), itsIsCoherent(coherent), itsDispersionMeasure(dm) { } - virtual ~TiedArrayBeam(); - - friend QDataStream& operator>> (QDataStream &in, TiedArrayBeam &tiedArrayBeam); - friend QDataStream& operator<< (QDataStream &out, const TiedArrayBeam &tiedArrayBeam); - - bool operator!=(const TiedArrayBeam & right) const; - bool operator==(const TiedArrayBeam & right) const {return (!(*this != right));} - - bool isCoherent(void) const {return itsIsCoherent;} - const double &angle1(void) const {return itsAngle1;} - const double &angle2(void) const {return itsAngle2;} - const double &dispersionMeasure(void) const {return itsDispersionMeasure;} - - void clear(void); - void setAngle1(const double &angle) {itsAngle1 = angle;} - void setAngle2(const double &angle) {itsAngle2 = angle;} - void setCoherent(bool coherent) {itsIsCoherent = coherent;} - void setDispersionMeasure(const double &dm) {itsDispersionMeasure = dm;} - -private: - double itsAngle1, itsAngle2; - bool itsIsCoherent; - double itsDispersionMeasure; -}; - -#endif /* TIEDARRAYBEAM_H_ */ diff --git a/SAS/Scheduler/src/TimeEdit.cpp b/SAS/Scheduler/src/TimeEdit.cpp deleted file mode 100644 index f1aa731cc18551ee293ba2569cfbddf05e050928..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/TimeEdit.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * TimeEdit.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/TimeEdit.cpp $ - * - */ - -#include "TimeEdit.h" -#include <QFocusEvent> -#include "astrotime.h" - -TimeEdit::TimeEdit(QWidget *parent) - : QTimeEdit(parent), itsUndefined(false) -{ - itsPreviousTime = time(); - QObject::connect(this,SIGNAL(timeChanged(const QTime &)), this, SLOT(checkTimeChange(void))); -} - -TimeEdit::~TimeEdit() { -} - -void TimeEdit::setTime(const QTime &time) { - this->blockSignals(true); - QTimeEdit::setTime(time); - itsPreviousTime = time; - setSpecialValueText(""); - itsUndefined = false; - this->blockSignals(false); -} - -void TimeEdit::setUndefined(bool enabled) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - itsPreviousTime = time(); - // NOTE: if minimum time equals the time then the special value text is shown - setSpecialValueText(itsSpecialValueText); - QTimeEdit::setTime(minimumTime()); - } - else { - setSpecialValueText(""); - QTimeEdit::setTime(itsPreviousTime); - } - this->blockSignals(false); -} - -void TimeEdit::focusInEvent(QFocusEvent* event) -{ - this->blockSignals(true); - if (itsUndefined) { - QTimeEdit::setTime(itsDefaultTime); - setSpecialValueText(""); - itsPreviousTime = time(); - } - - QTimeEdit::focusInEvent(event); - this->blockSignals(false); -} - -void TimeEdit::focusOutEvent(QFocusEvent* event) -{ - checkTimeChange(); - QTimeEdit::focusOutEvent(event); -} - -void TimeEdit::checkTimeChange(void) { - this->blockSignals(true); - if (itsUndefined) { - if (itsPreviousTime == time()) { - // NOTE: if minimum time equals the time then the special value text is shown - setSpecialValueText(itsSpecialValueText); - QTimeEdit::setTime(minimumTime()); - } - else { - itsUndefined = false; - setSpecialValueText(""); - } - } - this->blockSignals(false); -} diff --git a/SAS/Scheduler/src/TimeEdit.h b/SAS/Scheduler/src/TimeEdit.h deleted file mode 100644 index 51ad3a6212ecb31def0ede4f6a49c4073de7f908..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/TimeEdit.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * TimeEdit.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 6-jan-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/TimeEdit.h $ - * - */ - -#include <QTimeEdit> -#include "astrotime.h" -#include "lofar_scheduler.h" - -#ifndef TIMEEDIT_H_ -#define TIMEEDIT_H_ - -class TimeEdit : public QTimeEdit { - - Q_OBJECT - -public: - TimeEdit(QWidget *parent); - virtual ~TimeEdit(); - - void setTime(const QTime &t); - void setMultipleValue(void) {itsSpecialValueText = MULTIPLE_VALUE_TEXT; setUndefined(true);} - void setUndefined(bool enabled = true); - void setDefaultTime(const AstroTime &t) {itsDefaultTime.setHMS(t.getHours(),t.getMinutes(),t.getSeconds());} - inline bool isUndefined(void) {return itsUndefined;} - inline bool hasBeenChanged(void) const {return (!itsUndefined && itsPreviousTime != time());} - void resetChangeDetect(void) {itsPreviousTime = time();} - - -protected: - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkTimeChange(void); - -private: - bool itsUndefined; - QString itsSpecialValueText; - QTime itsPreviousTime, itsDefaultTime; -}; - -#endif /* TIMEEDIT_H_ */ diff --git a/SAS/Scheduler/src/astrodate.cpp b/SAS/Scheduler/src/astrodate.cpp deleted file mode 100644 index 273910b9884f5b2225ee04fc8d2776d140e9ebe7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/astrodate.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/* - * astrodate.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 13, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/astrodate.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "astrodate.h" -#include <string> -#include <stdlib.h> -#include <cmath> -using std::string; -#ifdef DEBUG_SCHEDULER -#include <iostream> -#endif - -const char * DAY_NAMES_ENG[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; -const char * DAY_SHORT_NAMES_ENG[7] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; -const char * MONTH_SHORT_NAMES_ENG[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; -const char * MONTH_NAMES_ENG[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; - -AstroDate::AstroDate() : - day(0), week(0), month(0), year(0), mod_julian_day(0) -{ - //mod_julian_day = JUL_GREG_CALENDAR_EPOCH; -} -/* -AstroDate::AstroDate(const AstroDate &other) : - day(0), week(0), month(0), year(0), mod_julian_day(0) -{ - this->day = other.day; - this->month = other.month; - this->year = other.year; - this->week = other.week; - this->mod_julian_day = other.mod_julian_day; -} -*/ - -AstroDate::AstroDate(const QDate &date) { - day = date.day(); - month = date.month(); - year = date.year(); -// week = date.weekNumber(); - calculateModifiedJulianDay(); // also calculates ISO week number -} - - -AstroDate::AstroDate(const char *chr) : - day(0), week(0), month(0), year(0), mod_julian_day(0) -{ - setDateStr(QString(chr)); -} - -AstroDate::AstroDate(const QString &dateStr) : - day(0), week(0), month(0), year(0), mod_julian_day(0) -{ - setDateStr(dateStr); -} - -AstroDate::AstroDate(const std::string &dateStr) : - day(0), week(0), month(0), year(0), mod_julian_day(0) -{ - setDateStr(dateStr); -} - -AstroDate::AstroDate(unsigned int julian_day) : - day(0), week(0), month(0), year(0), mod_julian_day(0) -{ - set_MJDay(julian_day); -// calculateGregorianDate(); -} - -AstroDate::AstroDate(quint8 d, quint8 mnth, quint16 yr) : - day(d), week(0), month(mnth), year(yr), mod_julian_day(0) -{ - calculateModifiedJulianDay(); -} - -AstroDate::~AstroDate() { -} - -/* -ostream& operator<< (ostream &out, const AstroDate &date) { - out << day << month << year << mod_julian_day; - return out; -} -*/ - -AstroDate & AstroDate::operator=(const QString &date) { - year = 0; - month = 0; - day = 0; - week = 0; - mod_julian_day = 0; - setDateStr(date); - return *this; -} - -AstroDate & AstroDate::operator=(int modJulian) { - mod_julian_day = modJulian; - calculateGregorianDate(); - calcISOWeekNr(); - return *this; -} - -AstroDate &AstroDate::operator++() { - ++mod_julian_day; - calculateGregorianDate(); - calcISOWeekNr(); - return *this; -} - -const AstroDate AstroDate::operator++(int) { - AstroDate copy(*this); - ++(*this); - return copy; -} - -AstroDate &AstroDate::operator--() { - --mod_julian_day; - calculateGregorianDate(); - calcISOWeekNr(); - return *this; -} - -const AstroDate AstroDate::operator--(int) { - AstroDate copy(*this); - --(*this); - return copy; -} - - -AstroDate &AstroDate::operator+=(AstroDate const &other) -{ - this->mod_julian_day += other.toJulian(); - calculateGregorianDate(); - calcISOWeekNr(); - return *this; -} - -AstroDate &AstroDate::operator-=(AstroDate const &other) -{ - this->mod_julian_day -= other.toJulian(); - calculateGregorianDate(); - calcISOWeekNr(); - return *this; -} - -bool AstroDate::operator==(const AstroDate &right) const { - if ((this->year == right.year) && (this->month == right.month) && (this->day == right.day)) - return true; - else return false; -} - -bool AstroDate::operator==(int right) const { - if (this->mod_julian_day == right) - return true; - else return false; -} - -bool AstroDate::operator!=(const AstroDate & right) const { - return !(*this == right); -} - -bool AstroDate::operator>(const AstroDate &right) const { - if (this->year > right.year) return true; - else if ((this->year == right.year) && (this->month > right.month)) return true; - else if ((this->year == right.year) && (this->month == right.month) && (this->day > right.day)) return true; - else return false; -} - -bool AstroDate::operator<(const AstroDate &right) const { - if (this->year < right.year) return true; - else if ((this->year == right.year) && (this->month < right.month)) return true; - else if ((this->year == right.year) && (this->month == right.month) && (this->day < right.day)) return true; - else return false; -} - -bool AstroDate::operator>=(const AstroDate &right) const { - if ( (*this > right) || (*this == right) ) return true; - else return false; -} - -bool AstroDate::operator<=(const AstroDate &right) const { - if ( (*this < right) || (*this == right) )return true; - else return false; -} - - -bool AstroDate::setDay(quint8 day) { -// sets the day value. Days can range from 0 to 31 - if (day > 0 && day <= 31) { - this->day = day; - calculateModifiedJulianDay(); - return true; - } - else { - return false; - } -} - - -bool AstroDate::setMonth(quint8 month) { -// sets the month value. Month can range from 0 to 12 - if (month > 0 && month <= 12) { - this->month = month; - calculateModifiedJulianDay(); - return true; - } - else { - return false; - } -} - -void AstroDate::setYear(quint16 year) { - this->year = year; - calculateModifiedJulianDay(); -} - -void AstroDate::setDateStr(const QString &dateStr) { - QDate date(QDate::fromString(dateStr, "yyyy-MM-dd")); - year = date.year(); - month = date.month(); - day = date.day(); - calculateModifiedJulianDay(); -} - -void AstroDate::set_MJDay(quint16 val_MJD) { - mod_julian_day = val_MJD; - calculateGregorianDate(); - calcISOWeekNr(); -} - -AstroDate AstroDate::addDays(quint16 days) const { - AstroDate result(*this); - result.set_MJDay(result.toJulian() + days); - result.calculateGregorianDate(); - result.calcISOWeekNr(); - return result; -} - -AstroDate AstroDate::subtractDays(quint16 days) const { - AstroDate result(*this); - result.set_MJDay(result.toJulian() - days); - result.calculateGregorianDate(); - result.calcISOWeekNr(); - return result; -} - -void AstroDate::calculateGregorianDate(void) { - // Updates the Gregorian data from the Modified Julian Date - // taken from http://www.astro.uu.nl/~strous/AA/en/reken/juliaansedag.html - double J = mod_julian_day + J2000_EPOCH; - double p = floor(J + 0.5); // eq. 3 - double s1 = p + 68569 ; // eq. 4 - double n = floor(4 * s1 / 146097); // eq. 5 - double s2 = s1 - floor((146097 * n + 3) / 4); // eq. 6 - double i = floor(4000 * (s2 + 1) / 1461001); // eq. 7 - double s3 = s2 - floor(1461 * i / 4) + 31; // eq. 8 - double q = floor(80 * s3 / 2447); // eq 9 - double e = s3 - floor(2447*q/80); // eq. 10 - double s4 = floor(q/11); // eq. 11 - day = static_cast<unsigned short int>(e + J - p + 0.5); - month = static_cast<unsigned short int>(q + 2 - 12 * s4); -// year = static_cast<unsigned int>(100 * (n - 49) + i + s4 + 4713 + 1858) ; - year = static_cast<unsigned int>(100 * (n - 49) + i + s4); -// year = 100 * (n - 49) + i + s4; -} - -void AstroDate::calculateModifiedJulianDay(void) { - // updates the Modified Julian data from the Gregorian date - // taken from : http://www.astro.uu.nl/~strous/AA/en/reken/juliaansedag.html - if (day!=0 && month!=0 && year!=0) { - double m = month, j = year, d = day; - if (m < 3) { m += 12; --j; } // step 1 - - //A = Y/100 - //B = A/4 - //C = 2-A+B - - //double E = floor(365.25 * (j+4716)); - //double F = floor(30.6001 * (M+1)); - mod_julian_day = static_cast<int>(2 - floor(j/100) + floor(j/400) + d + floor(365.25 * (j+4716)) + floor(30.6001 * (m + 1)) - 1524 - J2000_EPOCH); - - calcISOWeekNr(); - - //double c = 2 - floor(j/100) + floor(j/400); // step 2 - //mod_julian_day = static_cast<unsigned int>(floor(floor(1461 * (j + 4716) / 4) + floor(153 * (m + 1) / 5) + d + c - 1524.5)); // step 3, Julian Day number - } -} - -unsigned int AstroDate::getDayOfTheWeek(void) const { - return (mod_julian_day + static_cast<int>(J2000_EPOCH)) % 7; -} - -const char *AstroDate::getDayString(void) const { - return DAY_NAMES_ENG[getDayOfTheWeek()]; -} - -bool AstroDate::isLeapYear(unsigned int year) const { - if (year % 400 == 0) return true; - else if (year % 100 == 0) return false; - else if (year % 4 == 0) return true; - else return false; -} - -void AstroDate::calcISOWeekNr(void) { - int J = mod_julian_day + static_cast<int>(J2000_EPOCH); - int d4 = (J+31741 - (J % 7)) % 146097 % 36524 % 1461; - int L = d4 / 1460; - int d1 = ((d4-L) % 365) + L; - week = d1/7 + 1; -} - -std::string AstroDate::toString(short mode) const { - char str[25]; - switch (mode) { - case 1: - sprintf(str, "%4.4u-%2.2u-%2.2u", getYear(), getMonth(), getDay()); // appropriate for sorting - break; - case 0: - default: - sprintf(str, "%4.4u-%2.2u-%2.2u", getYear(), getMonth(), getDay()); - break; - } - std::string strdate(str); - return strdate; -} diff --git a/SAS/Scheduler/src/astrodate.h b/SAS/Scheduler/src/astrodate.h deleted file mode 100644 index 1d442ed585f94c7fb3cb89f80b8c7c101b5c0096..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/astrodate.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * astrodate.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 13, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/astrodate.h $ - * - */ - -#ifndef ASTRODATE_H_ -#define ASTRODATE_H_ - -#include <string> -#include <fstream> -#include <QDataStream> -#include <QDate> -#include "lofar_utils.h" - -extern const char * DAY_NAMES_ENG[7]; -extern const char * DAY_SHORT_NAMES_ENG[7]; -extern const char * MONTH_SHORT_NAMES_ENG[12]; -extern const char * MONTH_NAMES_ENG[12]; - -class AstroDate { -public: - AstroDate(); - virtual ~AstroDate(); - AstroDate(const char *chr); - AstroDate(const QDate &); - AstroDate(const QString &); - AstroDate(const std::string &str); - AstroDate(unsigned int); - AstroDate(quint8 day, quint8 month, quint16 year); - - // overloaded operators - friend QDataStream& operator<< (QDataStream &out, const AstroDate &date); // used for writing binary file - friend QDataStream& operator>> (QDataStream &in, AstroDate &date); // used for reading binary file - - AstroDate &operator=(const QString &); - AstroDate &operator=(int modJulian); - AstroDate &operator++(); - const AstroDate operator++(int); - AstroDate &operator--(); - const AstroDate operator--(int); - AstroDate &operator+=(AstroDate const &other); - AstroDate &operator-=(AstroDate const &other); - bool operator==(const AstroDate &right) const; - bool operator!=(const AstroDate & right) const; - bool operator==(int right) const; - bool operator>(const AstroDate &right) const; - bool operator<(const AstroDate &right) const; - bool operator>=(const AstroDate &right) const; - bool operator<=(const AstroDate &right) const; - - // Get methods - inline QDate toQDate(void) const { return QDate(year, month, day); } - inline bool isSet(void) const { if(mod_julian_day) return true; else return false; } - const AstroDate &getDate(void) const {return *this;} - inline quint16 toJulian() const {return mod_julian_day;} - inline quint16 get_MJDay(void) const {return mod_julian_day;} - std::string toString(short mode = 0) const; - inline quint8 getDay() const {return day;} - inline quint8 getWeek() const {return week;} - inline quint8 getMonth() const {return month;} - inline quint16 getYear() const {return year;} - // get the day of the week number (monday = 0) - unsigned int getDayOfTheWeek(void) const; - const char *getDayString(void) const; - bool isLeapYear(unsigned int year) const; - - // Set methods - void clearDate(void) {day = 0; week = 0; month = 0; year = 0; mod_julian_day = 0;} - void setDateStr(const QString &); - void setDateStr(const std::string &str) {setDateStr(QString(str.c_str()));} - void set_MJDay(quint16 val_MJD); - bool setDay(quint8 day); - bool setMonth(quint8 month); - void setYear(quint16 year); - - //arithmetic - AstroDate addDays(quint16 days) const; - AstroDate subtractDays(quint16 days) const; - - void calculateGregorianDate(void); - void calculateModifiedJulianDay(void); - -private: - void calcISOWeekNr(void); - -private: - quint8 day; - quint8 week; - quint8 month; - quint16 year; - quint16 mod_julian_day; // contains the Modified Julian Day number (only full days, at 0:00 hours) -}; - -inline AstroDate const operator+(AstroDate const &l_hand, AstroDate const &r_hand) -{ - return AstroDate(l_hand) += r_hand; -} - -inline AstroDate const operator-(AstroDate const &l_hand, AstroDate const &r_hand) -{ - return AstroDate(l_hand) -= r_hand; -} - -inline QDataStream& operator<< (QDataStream &out, const AstroDate &date) { - out << (quint8) date.day << (quint8) date.month << (quint16) date.year << (quint16) date.mod_julian_day; - return out; -} - -inline QDataStream& operator>> (QDataStream &in, AstroDate &date) { - in >> date.day >> date.month >> date.year >> date.mod_julian_day; - return in; -} - -#endif /* ASTRODATE_H_ */ diff --git a/SAS/Scheduler/src/astrodatetime.cpp b/SAS/Scheduler/src/astrodatetime.cpp deleted file mode 100644 index eb1d1acb4d5756f424ae53c380f91c87c1d31940..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/astrodatetime.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/* - * astrodatetime.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 27-jan-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/astrodatetime.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "astrodatetime.h" -#include <QDateTime> -#include <string> -#include <sstream> -#include <iostream> -#include <stdlib.h> -#include <cmath> -#include <cstdio> -using std::string; -using std::cerr; -using std::cout; -using std::endl; - -AstroDateTime::AstroDateTime() -{ -} - -AstroDateTime::AstroDateTime(const std::string &date_time) -{ - setDateTime(date_time); -} - -AstroDateTime::AstroDateTime(const QString &date_time) -{ - setDateTime(date_time); -} - -AstroDateTime::AstroDateTime(double mod_julian) -{ - set_MJDay(static_cast<unsigned>(mod_julian)); - setJulianTime(mod_julian - floor(mod_julian)); -} - -AstroDateTime::AstroDateTime(int julian_day, double &time) -{ - set_MJDay(julian_day); - setJulianTime(time); -} - -AstroDateTime::AstroDateTime(int julian_day) -{ - this->set_MJDay(julian_day); -} - -AstroDateTime::AstroDateTime(const AstroDate &date, const AstroTime &time) -{ - this->setDay(date.getDay()); - this->setMonth(date.getMonth()); - this->setYear(date.getYear()); - this->setSeconds(time.getSeconds()); - this->setMinutes(time.getMinutes()); - this->setHours(time.getHours()); - calculateModifiedJulianDate(); -} - -AstroDateTime::AstroDateTime(const QDateTime &date) { - this->setDay(date.date().day()); - this->setMonth(date.date().month()); - this->setYear(date.date().year()); - this->setSeconds(date.time().second()); - this->setMinutes(date.time().minute()); - this->setHours(date.time().hour()); - calculateModifiedJulianDate(); -} - -AstroDateTime::AstroDateTime(AstroTime const &time) -{ - this->setJulianTime(time.getJulianTime()); -} - -AstroDateTime::AstroDateTime(unsigned short day, unsigned short month, unsigned int year, int hours, short int minutes, short int seconds) { - this->setDay(day); - this->setMonth(month); - this->setYear(year); - this->setSeconds(seconds); - this->setMinutes(minutes); - this->setHours(hours); - calculateModifiedJulianDate(); -} - -AstroDateTime::~AstroDateTime() -{ - -} - -QDataStream& operator<< (QDataStream &out, const AstroDateTime &date_time) { - out << date_time.getDate() << date_time.getTime(); - return out; -} - -QDataStream& operator>> (QDataStream &in, AstroDateTime &date_time) { - AstroDate date; - AstroTime time; - in >> date >> time; - date_time.setDate(date); - date_time.setTime(time); - return in; -} - -AstroDateTime AstroDateTime::addDays(unsigned int days) const { - AstroDateTime result(*this); - result.set_MJDay(static_cast<unsigned>(result.toJulian()) + days); - return result; -} - -AstroDateTime AstroDateTime::subtractDays(unsigned int days) const { - AstroDateTime result(*this); - result.set_MJDay(static_cast<unsigned>(result.toJulian()) - days); - return result; -} - -AstroDateTime AstroDateTime::addHours(unsigned int hours) const { - AstroDateTime result(*this); - unsigned days = hours / 24; - if (days >= 1) { - result = result.addDays(days); - hours %= (days * 24); - } - - result.setTime(static_cast<AstroTime>(result).addHours(hours)); - if (result.getHours() >= 24) { - result.setDay(result.getDay() + 1); - result.setHours(result.getHours() - 24); - } - return result; -} - -AstroDateTime AstroDateTime::subtractHours(unsigned int hours) const { - AstroDateTime result(*this); - unsigned days = hours / 24; - if (days >= 1) { - result = result.subtractDays(days); - hours %= (days * 24); - } - - result.setTime(static_cast<AstroTime>(result).subtractHours(hours)); - return result; -} - - -AstroDateTime AstroDateTime::addMinutes(unsigned int mins) const { - AstroDateTime result(*this); - unsigned hours = mins / 60; - if (hours >= 1) { - result = result.addHours(hours); - mins %= (hours * 60); - } - - result.setTime(static_cast<AstroTime>(result).addMinutes(mins)); - return result; -} - -AstroDateTime AstroDateTime::addSeconds(unsigned int seconds) const { - AstroDateTime result(*this); - int hrs = seconds / 3600; - if (hrs >= 1) { - result = result.addHours(hrs); - seconds -= hrs * 3600; - } - int mins = seconds / 60; - if (mins >= 1) { - result = result.addMinutes(mins); - seconds -= mins * 60; - } - int temp = result.getSeconds() + seconds; - if (temp >= 60) { - result.setSeconds(temp - 60); - result = result.addMinutes(1); - } - else { - result.setSeconds(temp); - } - result.calculateJulianTime(); - return result; -} - -AstroDateTime AstroDateTime::subtractMinutes(unsigned mins) const { - AstroDateTime result(*this); - unsigned hours = mins / 60; - if (hours >= 1) { - result = result.subtractHours(hours); - mins %= (hours * 60); - } - - result.setTime(static_cast<AstroTime>(result).subtractMinutes(mins)); - return result; -} - -AstroDateTime AstroDateTime::subtractSeconds(unsigned seconds) const { - AstroDateTime result(*this); - unsigned hours = seconds / 3600; - if (hours >= 1) { - result = result.subtractHours(hours); - seconds %= (hours * 3600); - } - - result.setTime(static_cast<AstroTime>(result).subtractSeconds(seconds)); - return result; -} - -AstroDateTime AstroDateTime::addWeeks(unsigned int weeks) const { - AstroDateTime result(*this); - result = result.addDays(weeks*7); - return result; -} - -AstroDateTime AstroDateTime::subtractWeeks(unsigned int weeks) const { - AstroDateTime result(*this); - result = result.subtractDays(weeks*7); - return result; -} - -void AstroDateTime::calculateGregorianDateTime(void) { - calculateGregorianDate(); - calculateHMS(); -} - - -AstroTime AstroDateTime::toLST(void) const { - double fT = (get_MJDay() - 0.5) / 36525.0; - double fT0 = 6.697374558 + (2400.051336 * fT) + (0.000025862 * fT * fT); - - while (fT0 > 24) { - fT0 -= 24; - } - while (fT0 < 0) { - fT0 += 24; - } - - double fUT = (double)getHours() + (double)getMinutes() / 60.0 + (double)getSeconds() / 3600.0; - - fUT = fUT * 1.002737909; - double fGST = fUT + fT0; - while (fGST > 24) - { - fGST -= 24; - } - - // fGST is the Greenwich Sidereal Time in decimal hours - return AstroTime((fGST + 0.45795352) / 24.0 ); // 0.45795352 is the longitude of CS002 in decimal hours -} - - -AstroDateTime AstroDateTime::UTfromLST(const AstroTime &lstTime, const AstroDate &calendarDate) { - - bool bPrevDay(false), bNextDay(false); - - double fT = (calendarDate.get_MJDay() - 0.5) / 36525.0; - double fT0 = 6.697374558 + (2400.051336 * fT) + (0.000025862 * fT * fT); - - // put in 24 hours: - while (fT0 > 24) { - fT0 -= 24; - } - while (fT0 < 0) { - fT0 += 24; - } - - double fGST = lstTime.getJulianTime() * 24.0 - 0.45795352; // 0.45795352 is the longitude of CS002 in decimal hours - - fGST = fGST - fT0; - - while (fGST > 24) { - fGST -= 24; - bNextDay = true; - } - while (fGST < 0) { - fGST += 24; - bPrevDay = true; - } - - double fUT = fGST * 0.9972695666779660; // 1 / 1.002737909 = 0.9972695666779660 - - - AstroDateTime dUT(calendarDate, AstroTime(fUT / 24.0)); - - if (bNextDay) { - dUT = dUT.addDays(1); - } - else if (bPrevDay) { - dUT = dUT.subtractDays(1); - } - - return dUT; -} - -void AstroDateTime::calculateModifiedJulianDate(void){ - calculateJulianTime(); - calculateModifiedJulianDay(); -} - -bool AstroDateTime::operator=(const QString &date_time) { - return setDateTime(date_time); -} - -bool AstroDateTime::operator=(const QDateTime &date_time) { - setDay(date_time.date().day()); - setMonth(date_time.date().month()); - setYear(date_time.date().year()); - setHours(date_time.time().hour()); - setMinutes(date_time.time().minute()); - setSeconds(date_time.time().second()); - calculateModifiedJulianDate(); - return true; -} - -bool AstroDateTime::operator=(const double &mod_julian) { - if (mod_julian >= 0.0) { - set_MJDay(static_cast<unsigned>(floor(mod_julian))); - setJulianTime(mod_julian - floor(mod_julian)); - calculateGregorianDateTime(); - return true; - } - else return false; -} - -bool AstroDateTime::operator==(const AstroDateTime &right) const { - if ((this->getDate() == right.getDate()) && (this->getTime() == right.getTime())) { return true; } - else return false; -} - -bool AstroDateTime::operator!=(const AstroDateTime & right) const { - if ((this->getDate() != right.getDate()) || (this->getTime() != right.getTime())) { return true; } - else return false; -} - -bool AstroDateTime::operator>(const AstroDateTime &right) const { - if (this->getDate() > right.getDate()) { return true; } - else if ((this->getDate() == right.getDate()) && (this->getTime() > right.getTime())) { return true; } - else return false; -} - -bool AstroDateTime::operator<(const AstroDateTime &right) const { - if (this->getDate() < right.getDate()) { return true; } - else if ((this->getDate() == right.getDate()) && (this->getTime() < right.getTime())) { return true; } - else return false; -} - -bool AstroDateTime::operator>=(const AstroDateTime &right) const { - if (this->getDate() > right.getDate()) { return true; } - else if ((this->getDate() == right.getDate()) && (this->getTime() >= right.getTime())) { return true; } - else return false; -} - -bool AstroDateTime::operator<=(const AstroDateTime &right) const { - if (this->getDate() < right.getDate()) { return true; } - else if ((this->getDate() == right.getDate()) && (this->getTime() <= right.getTime())) { return true; } - else return false; -} - -AstroDateTime &AstroDateTime::operator+=(const AstroDateTime &other) { - double result = this->toJulian() + other.toJulian(); - int MJday = static_cast<int>(result); - this->set_MJDay(MJday); - this->setJulianTime(result - MJday); - return *this; -} - -AstroDateTime &AstroDateTime::operator-=(const AstroTime &other) { - double dValue(this->toJulian() - other.toJulian()); - int days(static_cast<int>(dValue)); - this->set_MJDay(days); - this->setJulianTime(dValue - days); - return (*this); -} - -AstroDateTime &AstroDateTime::operator+=(const AstroTime &other) { - double sum(this->toJulian() + other.toJulian()); - int days(static_cast<int>(sum)); // i.e. floor of sum = days - this->set_MJDay(days); - this->setJulianTime(sum - days); // remainder sum - days is julian time that needs to be set - return (*this); -} - -AstroTime AstroDateTime::operator-=(const AstroDateTime &other) { - double result = this->toJulian() - other.toJulian(); - return AstroTime(result); -} - -// this function will return the absolute time difference -AstroTime AstroDateTime::timeDifference(const AstroDateTime &other) const { - double tj(this->toJulian()), oj(other.toJulian()); - if (oj > tj) { - return AstroTime(oj - tj); - } - else return AstroTime(tj - oj); -} - -void AstroDateTime::setDate(const AstroDate &date) { - this->setDay(date.getDay()); - this->setMonth(date.getMonth()); - this->setYear(date.getYear()); - this->set_MJDay(date.toJulian()); -} - -void AstroDateTime::setTime(const AstroTime &time) { - this->setHours(time.getHours()); - this->setMinutes(time.getMinutes()); - this->setSeconds(time.getSeconds()); - this->setJulianTime(time.toJulian()); -} - -bool AstroDateTime::setDateTime(const QString &date_time) { - if (!date_time.isEmpty()) { - QDateTime dt(QDateTime::fromString(date_time, "yyyy-MM-dd hh:mm:ss")); - const QDate &date(dt.date()); - const QTime &time(dt.time()); - setYear(date.year()); - setMonth(date.month()); - setDay(date.day()); - setHours(time.hour()); - setMinutes(time.minute()); - setSeconds(time.second()); - calculateModifiedJulianDay(); - calculateJulianTime(); - return true; - } - else { - debugErr("s","AstroDateTime::setDateTime: no date specified!"); - return false; - } -} - -std::string AstroDateTime::toString(void) const { - if (isSet()) { - char str[25]; - sprintf(str, "%4.4u-%2.2u-%2.2u %2.2i:%2.2i:%2.2i", getYear(), getMonth(), getDay(), getHours(), getMinutes(), getSeconds()); - std::string strdate(str); - return strdate; - } - return ""; -} - -std::string AstroDateTime::toSASDateTimeString(void) const { - if (isSet()) { - char str[25]; - sprintf(str, "%4.4u-%2.2u-%2.2u %2.2i:%2.2i:%2.2i", getYear(), getMonth(), getDay(), getHours(), getMinutes(), getSeconds()); - std::string strdate(str); - return strdate; - } - return ""; -} diff --git a/SAS/Scheduler/src/astrodatetime.h b/SAS/Scheduler/src/astrodatetime.h deleted file mode 100644 index 45906af8b7737185c2f2e2eac79b941aeef247a4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/astrodatetime.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * astrodatetime.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 27-jan-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/astrodatetime.h $ - * - */ - -#ifndef ASTRODATETIME_H_ -#define ASTRODATETIME_H_ - -#include <string> -#include <fstream> -#include <QDateTime> -#include "astrotime.h" -#include "astrodate.h" - -class AstroDateTime : public AstroTime, public AstroDate -{ -public: - AstroDateTime(); - AstroDateTime(const std::string &); - AstroDateTime(const QString &); - AstroDateTime(double mod_julian); - AstroDateTime(int julian_day, double &time); - AstroDateTime(const AstroDate &date, const AstroTime &time = AstroTime(0.0)); - AstroDateTime(const QDateTime &); - AstroDateTime(unsigned short day, unsigned short month, unsigned int year, int hours, short int minutes, short int seconds); - AstroDateTime(AstroTime const &time); - AstroDateTime(int julian_day); - - static AstroDateTime UTfromLST(const AstroTime &lstTime, const AstroDate &calendarDate); - - virtual ~AstroDateTime(); - - friend QDataStream& operator<< (QDataStream &out, const AstroDateTime &date_time); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, AstroDateTime &date_time); // used for reading binary data from file - - bool operator=(const QString &date_time); - bool operator=(const double &mod_julian); - bool operator=(const QDateTime &date_time); - bool operator==(const AstroDateTime &right) const; - bool operator>(const AstroDateTime &right) const; - bool operator<(const AstroDateTime &right) const; - bool operator>=(const AstroDateTime &right) const; - bool operator<=(const AstroDateTime &right) const; - bool operator>(const AstroDate &right) const {return (static_cast<AstroDate>(*this) > right);} - bool operator<(const AstroDate &right) const {return (static_cast<AstroDate>(*this) < right);} - bool operator>=(const AstroDate &right) const {return (static_cast<AstroDate>(*this) >= right);} - bool operator<=(const AstroDate &right) const {return (static_cast<AstroDate>(*this) <= right);} - bool operator>(const double &right) const {return (this->toJulian() > right);} - bool operator<(const double &right) const {return (this->toJulian() < right);} - bool operator>=(const double &right) const {return (this->toJulian() >= right);} - bool operator<=(const double &right) const {return (this->toJulian() <= right);} - bool operator!=(const AstroDateTime & right) const; - AstroDateTime &operator+=(const AstroDateTime &other); - AstroDateTime &operator+=(const AstroTime &other); - AstroTime operator-=(const AstroDateTime &other); - AstroDateTime &operator-=(const AstroTime &other); - // calculate the total time difference in hhhh:mm:ss (instead of date and time difference) - AstroTime timeDifference(const AstroDateTime &other) const; - AstroTime time(void) const {return static_cast<AstroTime>(*this);} - AstroDate date(void) const {return static_cast<AstroDate>(*this);} - AstroTime toLST(void) const; - inline QDateTime toQDateTime(void) const {return QDateTime(toQDate(), toQTime());} - - AstroDateTime addDays(unsigned int days) const; - AstroDateTime addHours(unsigned int hours) const; - AstroDateTime addMinutes(unsigned int mins) const; - AstroDateTime addSeconds(unsigned int seconds) const; - AstroDateTime addWeeks(unsigned int weeks) const; - AstroDateTime subtractDays(unsigned int days) const; - AstroDateTime subtractMinutes(unsigned int mins) const; - AstroDateTime subtractHours(unsigned int hours) const; - AstroDateTime subtractWeeks(unsigned int weeks) const; - AstroDateTime subtractSeconds(unsigned int seconds) const; - - // Get methods - bool isSet(void) const { if (this->getDate().isSet() || this->getTime().isSet()) return true; else return false; } - double toJulian(void) const {return (this->get_MJDay() + this->getJulianTime());} - std::string toString(void) const; - std::string toSASDateTimeString(void) const; - - // Set methods - void clear(void) {clearDate(); clearTime();} - bool setDateTime(const std::string &date_time) {return setDateTime(QString(date_time.c_str()));} - bool setDateTime(const QString &date_time); - void setDate(const AstroDate &date); - void setTime(const AstroTime &time); - -private: - void calculateModifiedJulianDate(void); - void calculateGregorianDateTime(void); -}; - -inline AstroDateTime const operator+(AstroDateTime const &l_hand, AstroDateTime const &r_hand) -{ - return AstroDateTime(l_hand) += r_hand; -} - -inline AstroDateTime const operator-(AstroDateTime const &l_hand, AstroDateTime const &r_hand) -{ - return AstroDateTime(l_hand) -= r_hand; -} - -inline AstroDateTime const operator+(AstroDateTime const &l_hand, AstroTime const &r_hand) -{ - return AstroDateTime(l_hand) += r_hand; -} - -inline AstroDateTime const operator-(AstroDateTime const &l_hand, AstroTime const &r_hand) -{ - return AstroDateTime(l_hand) -= r_hand; -} - -inline const AstroDateTime &maxdate(const AstroDateTime &first, const AstroDateTime &second) { - if (first >= second) return first; - else return second; -} - -inline const AstroDateTime &mindate(const AstroDateTime &first, const AstroDateTime &second) { - if (first <= second) return first; - else return second; -} - -#endif /* ASTRODATETIME_H_ */ diff --git a/SAS/Scheduler/src/astrotime.cpp b/SAS/Scheduler/src/astrotime.cpp deleted file mode 100644 index a7c3f062d95e20a7bcac9cd63f7cfff47ab4d1f7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/astrotime.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - * astrotime.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 27-jan-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/astrotime.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "lofar_utils.h" -#include "astrotime.h" -#include "astrodatetime.h" -#include "Controller.h" -#include <QTime> -#include <string> -#include <iostream> -#include <stdlib.h> -#include <cmath> -using std::string; -using std::cout; -using std::endl; - -AstroTime::AstroTime() : - hours(0), minutes(0), seconds(0), julian_time(0.0) -{ -} - -AstroTime::AstroTime(const double &time) : - julian_time(time) -{ - calculateHMS(); -} - -// needed to be able to subtract two AstroDateTimes and get a duration as AstroTime (hours possible greater than 24) -AstroTime::AstroTime(const AstroDateTime &other) { - hours = other.getHours(); - minutes= other.getMinutes(); - seconds = other.getSeconds(); - julian_time = other.getJulianTime(); -} - -AstroTime::AstroTime(const QTime &time) { - hours = time.hour(); - minutes = time.minute(); - seconds = time.second(); - calculateJulianTime(); -} - -AstroTime::AstroTime(const char *time) : - hours(0), minutes(0), seconds(0), julian_time(0.0) -{ - setTimeStr(QString(time)); -} - -AstroTime::AstroTime(const std::string &time) : - hours(0), minutes(0), seconds(0), julian_time(0.0) -{ - setTimeStr(time); -} - - -AstroTime::AstroTime(const QString &time) : - hours(0), minutes(0), seconds(0), julian_time(0.0) -{ - setTimeStr(time); -} - -AstroTime::AstroTime(qint32 hour, qint8 min, qint8 sec) : - hours(hour), minutes(min), seconds(sec), julian_time(0.0) -{ - calculateJulianTime(); -} - -AstroTime::~AstroTime() -{ - -} - -AstroTime &AstroTime::operator=(const QString &time) { - seconds = 0; - minutes = 0; - hours = 0; - julian_time = 0; - setTimeStr(time); - return *this; -} - -AstroTime &AstroTime::operator=(const AstroDateTime &other) { - julian_time = other.toJulian(); - calculateHMS(); - return *this; -} - -AstroTime &AstroTime::operator+=(const AstroTime &right) { - this->julian_time += right.toJulian(); - calculateHMS(); - return *this; -} - -AstroTime &AstroTime::operator-=(AstroTime const &right) { - this->julian_time -= right.toJulian(); - calculateHMS(); - return *this; -} - -bool AstroTime::operator==(const AstroTime &right) const { - return (fabs(julian_time - right.getJulianTime()) < SMALLEST_DETECTABLE_TIME_DIF); -} - -bool AstroTime::operator!=(const AstroTime & right) const { - return !(*this == right); -} - -bool AstroTime::operator>(const AstroTime &right) const { - return (julian_time - right.getJulianTime()) > SMALLEST_DETECTABLE_TIME_DIF; -} - -bool AstroTime::operator<(const AstroTime &right) const { - return (julian_time - right.getJulianTime()) < -SMALLEST_DETECTABLE_TIME_DIF; -} - -bool AstroTime::operator>=(const AstroTime &right) const { - if ( (*this == right) || (*this > right) ) return true; - else return false; -} - -bool AstroTime::operator<=(const AstroTime &right) const { - if ( (*this == right) || (*this < right) ) return true; - else return false; -} - -AstroTime AstroTime::addHours(unsigned int hrs) const { - AstroTime result(*this); -// hrs %= 24; - result.setHours(result.getHours() + hrs); -// if (result.getHours() >= 24) { -// result.setHours(result.getHours() - 24); -// } - result.calculateJulianTime(); - return result; -} - -AstroTime AstroTime::subtractHours(unsigned int hrs) const { - AstroTime result(*this); -// hrs %= 24; - result.setHours(result.getHours() - hrs); -// if (result.getHours() < 0) { -// result.setHours(result.getHours() + 24); -// } - result.calculateJulianTime(); - return result; -} - -AstroTime AstroTime::addMinutes(unsigned int mins) const { - AstroTime result(*this); - int hrs = mins / 60; - if (hrs >= 1) { - result = result.addHours(hrs); - mins -= hrs * 60; - } - int temp = result.getMinutes() + mins; - if (temp >= 60) { - result.setMinutes(temp - 60); - result = result.addHours(1); - } - else { - result.setMinutes(temp); - } - result.calculateJulianTime(); - return result; -} - -AstroTime AstroTime::subtractMinutes(unsigned int mins) const { - AstroTime result(*this); - int hrs = mins / 60; - if (hrs >= 1) { - result = result.subtractHours(hrs); - mins -= hrs * 60; - } - int temp = result.getMinutes() - mins; - if (temp < 0) { - result.setMinutes(temp + 60); - result = result.subtractHours(1); - } - else { - result.setMinutes(temp); - } - result.calculateJulianTime(); - return result; -} - -AstroTime AstroTime::addSeconds(unsigned int seconds) const { - AstroTime result(*this); - int hrs = seconds / 3600; - if (hrs >= 1) { - result = result.addHours(hrs); - seconds -= hrs * 3600; - } - int mins = seconds / 60; - if (mins >= 1) { - result = result.addMinutes(mins); - seconds -= mins * 60; - } - int temp = result.getSeconds() + seconds; - if (temp >= 60) { - result.setSeconds(temp - 60); - result = result.addMinutes(1); - } - else { - result.setSeconds(temp); - } - result.calculateJulianTime(); - return result; -} - -AstroTime AstroTime::subtractSeconds(unsigned int seconds) const { - AstroTime result(*this); - int hrs = seconds / 3600; - if (hrs >= 1) { - result = result.subtractHours(hrs); - seconds -= hrs * 3600; - } - int mins = seconds / 60; - if (mins >= 1) { - result = result.subtractMinutes(mins); - seconds -= mins * 60; - } - int temp = result.getSeconds() - seconds; - if (temp < 0) { - result.setSeconds(temp + 60); - result = result.subtractMinutes(1); - } - else { - result.setSeconds(temp); - } - result.calculateJulianTime(); - return result; -} - -void AstroTime::setJulianTime(double jt) { - julian_time = jt;// - floor(jt); - calculateHMS(); -} - -void AstroTime::calculateHMS(void) { - double h = julian_time * 24.0; // add 12 hours because J2000 EPOCH has its zero at noon - hours = static_cast<int>(floor(h)); - - double m = (h - hours) * 60.0; - minutes = static_cast<int>(m); - - seconds = static_cast<int>((m - minutes)*60.0 + 0.5); - if (seconds >= 60) { - minutes += 1; - seconds -= 60; - } - if (minutes >= 60) { - ++hours; - minutes -= 60; - } - while (hours < 0) { hours += 24;} -} - -bool AstroTime::setTimeStr(const QString &timeStr) { - if (!timeStr.isEmpty()) { - QString t(timeStr.trimmed()); - int pos = t.indexOf(':'); - int pos1 = t.indexOf(':',pos+1); - hours = t.left(pos).toInt(); - minutes = t.mid(pos+1, pos1 - pos -1).toInt(); - seconds = t.mid(pos1+1).toInt(); - calculateJulianTime(); - return true; - } - else return false; -} - -void AstroTime::calculateJulianTime(void) { - julian_time = static_cast<double>(seconds) / 86400 + - static_cast<double>(minutes) / 1440 + - static_cast<double>(hours) / 24;// + - // static_cast<double>(carryDays); -} - -bool AstroTime::setMinutes(qint8 minutes) { -// sets the minutes value. Minutes can range from 0 to 59 - if (minutes <= 59) { - this->minutes = minutes; - return true; - } - else return false; -} - -bool AstroTime::setSeconds(qint8 seconds) { - // sets the seconds value. Seconds can range from 0 to 59 - if (seconds <= 59) { - this->seconds = seconds; - return true; - } - else return false; -} - -std::string AstroTime::toString(short mode) const { - char str[15]; - switch(mode) { - case 1: - sprintf(str, "%2.2i:%2.2i:%2.2i", hours, minutes, seconds); // always two digits for hours - break; - case 3: - sprintf(str, "%i:%2.2i:%2.2i", hours, minutes, seconds); // display hours without lead zeros - break; - default: - sprintf(str, "%4.4i:%2.2i:%2.2i", hours, minutes, seconds); // display 4 digit hours - break; - } - std::string strtime(str); - return strtime; -} diff --git a/SAS/Scheduler/src/astrotime.h b/SAS/Scheduler/src/astrotime.h deleted file mode 100644 index 2118fa5fdcf3364f9b128fa6a8cc2876e307e5d2..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/astrotime.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * astrotime.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 27-jan-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/astrotime.h $ - * - */ - -#ifndef ASTROTIME_H_ -#define ASTROTIME_H_ - -#include <string> -#include <fstream> -#include <QDataStream> -#include <QTime> - -#define SMALLEST_DETECTABLE_TIME_DIF 1.15e-5 // almost equal to one julian second - -class AstroDateTime; - -class AstroTime -{ -public: - AstroTime(); - AstroTime(const double &time); - AstroTime(const AstroDateTime &); - AstroTime(const QTime &); - AstroTime(const char *chr); - AstroTime(const std::string &); - AstroTime(const QString &); - AstroTime(qint32 hours, qint8 minutes, qint8 seconds); - virtual ~AstroTime(); - - // overloaded operators - friend QDataStream& operator<< (QDataStream &out, const AstroTime &time); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, AstroTime &time); // used for reading binary data from file - - AstroTime &operator=(const AstroDateTime &); - AstroTime &operator=(const QString &); - AstroTime &operator+=(const AstroTime &right); - AstroTime &operator-=(const AstroTime &right); - bool operator==(const AstroTime &right) const; - bool operator!=(const AstroTime & right) const; - bool operator>(const AstroTime &right) const; - bool operator<(const AstroTime &right) const; - bool operator>=(const AstroTime &right) const; - bool operator<=(const AstroTime &right) const; - - AstroTime addHours(unsigned int hrs) const; - AstroTime subtractHours(unsigned int hrs) const; - AstroTime addMinutes(unsigned int mins) const; - AstroTime subtractMinutes(unsigned int mins) const; - AstroTime addSeconds(unsigned int seconds) const; - AstroTime subtractSeconds(unsigned int seconds) const; - - QTime toQTime(void) const {return QTime(hours, minutes, seconds);} - - void calculateJulianTime(void); // updates the julian attribute to correspond to the time - void calculateHMS(void); // updates the hours, minutes and seconds to reflect the julian time - void clearTime(void) {hours = 0; minutes = 0; seconds = 0; julian_time = 0.0;} - - // Get methods - int getHours() const {return hours;} - short int getMinutes() const {return minutes;} - short int getSeconds() const {return seconds;} - int totalSeconds() const {return /*carryDays * 86400 + */hours * 3600 + minutes * 60 + seconds;} - double toJulian(void) const {return julian_time;} - double getJulianTime(void) const {return julian_time;} - const AstroTime &getTime(void) const {return *this;} - std::string toString(short mode = 0) const; - bool isSet(void) const { if ((hours == 0) && (minutes == 0) && (seconds == 0) /*& (carryDays == 0)*/) return false; else return true; } - - // Set methods - bool setTimeStr(const QString &time); - bool setTimeStr(const std::string &time) {return setTimeStr(QString(time.c_str()));} - void setHours(qint16 hours) { this->hours = hours; } - bool setMinutes(qint8 minutes); - bool setSeconds(qint8 seconds); - void setJulianTime(double jt); - -private: - qint32 hours; // hours (counts beyond 24) - qint8 minutes; // minutes (Solar Time) - qint8 seconds; // seconds (Solar Time) - double julian_time; // julian date -}; - -inline const AstroTime operator-(const AstroTime &l_hand, const AstroTime &r_hand) { - return AstroTime(l_hand) -= r_hand; -} - -inline const AstroTime operator+(const AstroTime &l_hand, const AstroTime &r_hand) { - return AstroTime(l_hand) += r_hand; -} - -inline QDataStream& operator<< (QDataStream &out, const AstroTime &time) { - out << (qint32) time.hours - << (qint8) time.minutes - << (qint8) time.seconds - << time.julian_time; - return out; -} - -inline QDataStream& operator>> (QDataStream &in, AstroTime &time) { - in >> time.hours >> time.minutes >> time.seconds >> time.julian_time; - return in; -} - -#endif /* ASTROTIME_H_ */ diff --git a/SAS/Scheduler/src/blocksize.cpp b/SAS/Scheduler/src/blocksize.cpp deleted file mode 100644 index 7e7385dbae98470ad4d68c09c2103be9c59baa2a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/blocksize.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "blocksize.h" - -#include <cmath> - -const double BlockSize::MAXBLOCKSIZE = 1.3; - -const double BlockSize::MINBLOCKSIZE = 0.6; - -#ifdef _WIN32 - double round(double value) - { - return floor(value + 0.5); - } - -#endif - diff --git a/SAS/Scheduler/src/blocksize.h b/SAS/Scheduler/src/blocksize.h deleted file mode 100644 index ed6d88416b68d56d1903f38a3e20148f2e2d01f9..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/blocksize.h +++ /dev/null @@ -1,270 +0,0 @@ -/* - * blocksize.h - * - * Author : Jan David Mol - * e-mail : mol@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 29 July 2013 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/blocksize.h $ - * - */ - -#ifndef COBALT_BLOCKSIZE_H_ -#define COBALT_BLOCKSIZE_H_ - -#include <algorithm> -#include <iostream> -#include <cmath> -#include <math.h> - -#ifdef _WIN32 - double round(double value); - -#endif - -// Return the greatest common divider (GCD) of two numbers -// Return the greatest common divider (GCD) of two numbers -inline unsigned gcd(unsigned a, unsigned b) -{ - unsigned tmp; - - while (b != 0) { - tmp = a; - a = b; - b = tmp % a; - } - - return a; -} - -// Return the least common multiple (LCM) of two numbers -inline unsigned lcm(unsigned a, unsigned b) -{ - if (a == 0) return 0; - if (b == 0) return 0; - - return a / gcd(a, b) * b; -} - - -class BlockSize { -public: - // The number of integrations to combine into a single block - const size_t nrSubblocks; - -private: - // The block size must be a multiple of `factor' - const size_t factor; - - // The clock speed, to convert between samples and time - const size_t clockMHz; -public: - // The calculated block size - const size_t blockSize; - - // The number of blocks - const size_t nrBlocks; - - // The resulting integration time - const double integrationTime; - - // Calculate the required factor based on observation parameters - static size_t calcFactor( - bool correlatedEnabled, - unsigned correlatorChannelsPerSubband, - double requestedIntegrationTime, - - bool coherentStokesEnabled, - unsigned coherentChannelsPerSubband, - unsigned coherentTimeIntegrationFactor, - - bool incoherentStokesEnabled, - unsigned incoherentChannelsPerSubband, - unsigned incoherentTimeIntegrationFactor - ) - { - /* - * Determine common factors needed for the block Size. - * - * The Cobalt GPU kernels require the Cobalt.blockSize to be a multiple - * of several values in order to: - * 1) divide the work evenly over threads and blocks. - * 2) prevent integration of samples from crossing blockSize boundaries. - */ - - unsigned factor = 1; - - if (correlatedEnabled) { - // Add required multiples for the Correlator - - // 16 is number of PPF taps (FIR_Filter.cu) - factor = lcm(factor, 16 * correlatorChannelsPerSubband); - - // each subblock needs at least 16 samples per channel (Correlator.cu) - factor = lcm(factor, 16 * correlatorChannelsPerSubband * _nrSubblocks(requestedIntegrationTime)); - } - - if (coherentStokesEnabled) { - // Add required multiples for the CS Beamformer - - // 16 * 256 (DelayAndBandPass.cu) - factor = lcm(factor, 16 * 256); - - // 1024 is the maxNrThreadsPerBlock (CoherentStokesKernel.cc) - // Note that coherenthannelsPerSubband is always a power of 2 < 1024 - factor = lcm(factor, 1024 * coherentTimeIntegrationFactor); - - (void)coherentChannelsPerSubband; - } - - if (incoherentStokesEnabled) { - // Add required multiples for the IS Beamformer - - // 16 * 256 (DelayAndBandPass.cu) - factor = lcm(factor, 16 * 256); - - // integration should fit (IncoherentStokes.cu) - factor = lcm(factor, incoherentTimeIntegrationFactor * incoherentChannelsPerSubband); - } - - return factor; - } - - BlockSize(double requestedIntegrationTime, size_t factor = 12288, size_t clockMHz = 200) - : - // For integration time < MINBLOCKSIZE, combine subblocks into a bigger block - nrSubblocks(_nrSubblocks(requestedIntegrationTime)), - - factor(factor), - - clockMHz(clockMHz), - - // Calculate the block size (adjusted for combining subblocks - blockSize(_blockSize(nrSubblocks * requestedIntegrationTime)), - - // Calculate the number of blocks to integrate over - nrBlocks(_nrBlocks(requestedIntegrationTime, blockSize)), - - integrationTime(samples2time(blockSize / nrSubblocks * nrBlocks)) - { - } - -private: - static size_t _nrSubblocks(double integrationTime) - { - if (integrationTime < MINBLOCKSIZE) { - return std::max(size_t(1), static_cast<size_t>(round(((MAXBLOCKSIZE + MINBLOCKSIZE) / 2.0) / integrationTime))); - } - - return 1UL; - } - - size_t _nrBlocks(double integrationTime, size_t blockSize) - { - // Convert the requested integration time to #samples - const size_t integrationSamples = time2samples(integrationTime); - return std::max(size_t(1), static_cast<size_t>( - round(1.0 * integrationSamples / blockSize))); - } - - size_t _blockSize(double integrationTime) - { - const size_t integrationSamples = time2samples(integrationTime); -// const size_t minSamples = time2samples(MINBLOCKSIZE); - - size_t bestBlockSize = 0; - size_t bestNrBlocks = 0; - size_t bestDiff(0); - - for (size_t factorsPerBlock = 1; true; ++factorsPerBlock) { - const size_t blockSize = factorsPerBlock * factor; - - // Discard invalid block sizes - if (blockSize < time2samples(MINBLOCKSIZE)) - continue; - - // blockSize only increases, so we can stop once - // blocks become too big - if (blockSize > time2samples(MAXBLOCKSIZE)) - break; - - // Calculate the number of blocks we'd use - const size_t n = _nrBlocks(integrationTime, blockSize); - - // Calculate the error w.r.t. the requested integration time - const size_t diff = udiff(integrationSamples, n * blockSize); - - //cout << n << " * " << blockSize << " -> error = " << diff << endl; - - /* - * We prefer this configuration, if either: - * 1. it is the first viable configuration - * 2. it results in a smaller total error in integration time - * 3. it results in a <1% error, and uses fewer blocks - */ - if (bestBlockSize == 0 - || diff <= bestDiff - || (diff < 0.01 * integrationSamples && n < bestNrBlocks)) { - // beaten our record - bestBlockSize = blockSize; - bestNrBlocks = n; - bestDiff = diff; - } - } - - // Return the best configuration, or default to the - // minimal block size to cover very small integration - // times. - return bestBlockSize; - } - - // The blocks have a minimum size, below which the overhead - // per block becomes too unwieldy. - static const double MINBLOCKSIZE; // = 0.6; - - // The maximum block size is given by the amount of data that - // still fits into one GPU. - static const double MAXBLOCKSIZE; // = 1.3; - - size_t time2samples(double t) const { - return static_cast<size_t>(t * clockMHz * 1e6 / 1024); - } - - double samples2time(size_t n) const { - return n / (clockMHz * 1e6 / 1024); - } - - static size_t udiff(size_t a, size_t b) { - return a >= b ? a - b : b - a; - } -}; - -/* -int main() -{ - // test various configurations - for(double i = 0.0; i < 30.0; i += (i < 10 ? 0.05 : 0.5)) { - size_t factor = BlockSize::calcFactor( - true, 64, i, - false, 0, 0, - false, 0, 0); - - BlockSize bs(i, factor); - - cout << "A request of " << i << " s becomes " << bs.integrationTime << " s (block size " << bs.blockSize << ", nr blocks " << bs.nrBlocks << ", nr subblocks " << bs.nrSubblocks << ")" << endl; - } - - // test stability - double intTime = 1.5; - for (size_t i = 0; i < 10; ++i) { - BlockSize bs(intTime, 16 * 64); - cout << intTime << " -> " << bs.integrationTime << " (" << bs.nrBlocks << " * " << bs.blockSize << ")" << endl; - intTime = bs.integrationTime; - } -} -*/ - - -#endif // COBALT_BLOCKSIZE_H_ diff --git a/SAS/Scheduler/src/calibrationpipeline.cpp b/SAS/Scheduler/src/calibrationpipeline.cpp deleted file mode 100644 index ca5fbd56d6bcff75f5d333e64fd9126d156042c8..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/calibrationpipeline.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * calibrationpipeline.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/calibrationpipeline.cpp $ - * - */ - -#include "calibrationpipeline.h" - -CalibrationPipeline::CalibrationPipeline() - : Pipeline() -{ - itsPipelineType = PIPELINE_CALIBRATION; - itsSASTree.setProcessSubtype(PST_CALIBRATION_PIPELINE); -} - -CalibrationPipeline::CalibrationPipeline(unsigned task_id) - : Pipeline(task_id) -{ - itsPipelineType = PIPELINE_CALIBRATION; - itsSASTree.setProcessSubtype(PST_CALIBRATION_PIPELINE); -} - -CalibrationPipeline::CalibrationPipeline(const QSqlQuery &query, const OTDBtree &SAS_tree) -: Pipeline(query, SAS_tree) -{ - itsPipelineType = PIPELINE_CALIBRATION; -} - -CalibrationPipeline::CalibrationPipeline(unsigned id, const OTDBtree &SAS_tree) -: Pipeline(id, SAS_tree) -{ - itsPipelineType = PIPELINE_CALIBRATION; -} - -QDataStream& operator<< (QDataStream &out, const CalibrationPipeline &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const Pipeline &>(task); - - out << task.itsDemixingSettings << task.itsSkyModel; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, CalibrationPipeline &task) { - if (in.status() == QDataStream::Ok) { - in >> static_cast<Pipeline &>(task); - - in >> task.itsDemixingSettings >> task.itsSkyModel; - - task.calculateDataFiles(); - } - return in; -} - -void CalibrationPipeline::calculateDataSize(void) { - itsStorage->itsTotalDataSizekBytes = 0.0; - itsStorage->itsTotalBandWidth = 0.0; - if (itsStorage->itsEnabledOutputData.correlated) { // pipeline will write reduced correlated data - dataFileMap::const_iterator dit(itsStorage->itsInputDataFiles.find(DP_CORRELATED_UV)); - if (dit != itsStorage->itsInputDataFiles.end()) { - unsigned reductionFactor = itsDemixingSettings.itsFreqStep * itsDemixingSettings.itsTimeStep; - const double &inputSize(dit->second.first); - double outputFileSize(0.0); - if (reductionFactor) { - double data_size(inputSize / reductionFactor); - outputFileSize = data_size + data_size/64 * (1 + reductionFactor) + data_size/2; - } - itsStorage->itsOutputDataFiles[DP_CORRELATED_UV] = std::pair<double, unsigned>(outputFileSize ,dit->second.second); - } - } - if (itsStorage->itsEnabledOutputData.instrumentModel) { - // number of files always equal to number of input (correlated) files (nr files equals nr of subbands) - // i.e. for each input correlated file specified to the pipeline as an input data product the pipeline generated an output instrumentmodel file - // instrument data files get determined when the task goes to the SCHEDULED state (see Controller::doScheduleChecks() ) - dataFileMap::const_iterator dit(itsStorage->itsInputDataFiles.find(DP_CORRELATED_UV)); // the number of instrumentModel files created equals the number of input correlated files - if (dit != itsStorage->itsInputDataFiles.end()) { - // TODO: add correct size calculation for instrument model - itsStorage->itsOutputDataFiles[DP_INSTRUMENT_MODEL] = std::pair<double, unsigned>(1000.0, dit->second.second); // for now we set the size of one file to 1MB, which is about correct (small files) - } - } - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator it = itsStorage->itsOutputDataFiles.begin(); it != itsStorage->itsOutputDataFiles.end(); ++it) { - itsStorage->itsTotalDataSizekBytes += it->second.first * it->second.second; - } - itsStorage->itsTotalBandWidth = (itsStorage->itsTotalDataSizekBytes * 8) / itsDuration.totalSeconds(); // kbit/sec -} - - -/* - * diff check for difference between this task and other task. - * return true if difference - * parameter dif - */ -bool CalibrationPipeline::diff(const Task *other, task_diff &dif) const { - bool pipelineDif(Pipeline::diff(other, dif)); - - const CalibrationPipeline *otherPipe = dynamic_cast<const CalibrationPipeline *>(other); - if (otherPipe) { - const DemixingSettings &otherDemix(otherPipe->demixingSettings()); - dif.demix_always = itsDemixingSettings.itsDemixAlways != otherDemix.demixAlways() ? true : false; - dif.demix_if_needed = itsDemixingSettings.itsDemixIfNeeded != otherDemix.demixIfNeeded() ? true : false; - dif.demix_skymodel = itsDemixingSettings.itsSkyModel != otherDemix.skyModel() ? true : false; - dif.demix_freqstep = itsDemixingSettings.itsDemixFreqStep != otherDemix.demixFreqStep() ? true : false; - dif.demix_timestep = itsDemixingSettings.itsDemixTimeStep != otherDemix.demixTimeStep() ? true : false; - dif.freqstep = itsDemixingSettings.itsFreqStep != otherDemix.freqStep() ? true : false; - dif.timestep = itsDemixingSettings.itsTimeStep != otherDemix.timeStep() ? true : false; - dif.calibration_skymodel = itsSkyModel != otherPipe->itsSkyModel ? true : false; - - return (pipelineDif || dif.demix_always || dif.demix_if_needed || dif.demix_skymodel || - dif.demix_freqstep || dif.demix_timestep || dif.freqstep || dif.timestep || dif.calibration_skymodel); - } - else return pipelineDif; -} - -QString CalibrationPipeline::diffString(const task_diff &dif) const { - QString difstr(Pipeline::diffString(dif)); - if (!difstr.isEmpty()) difstr += ","; - - if (dif.demix_always) difstr += QString(SAS_item_names[TP_DEMIX_ALWAYS]) + ","; - if (dif.demix_if_needed) difstr += QString(SAS_item_names[TP_DEMIX_IF_NEEDED]) + ","; - if (dif.demix_skymodel) difstr += QString(SAS_item_names[TP_DEMIX_SKYMODEL]) + ","; - if (dif.demix_freqstep) difstr += QString(SAS_item_names[TP_DEMIX_FREQSTEP]) + ","; - if (dif.demix_timestep) difstr += QString(SAS_item_names[TP_DEMIX_TIMESTEP]) + ","; - if (dif.freqstep) difstr += QString(SAS_item_names[TP_AVG_FREQSTEP]) + ","; - if (dif.timestep) difstr += QString(SAS_item_names[TP_AVG_TIMESTEP]) + ","; - if (dif.calibration_skymodel) difstr += QString(SAS_item_names[TP_CALIBRATION_SKYMODEL]) + ","; - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} diff --git a/SAS/Scheduler/src/calibrationpipeline.h b/SAS/Scheduler/src/calibrationpipeline.h deleted file mode 100644 index 84471a90f1543456b9c2e4ed204c6d35ed6e96d6..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/calibrationpipeline.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * calibrationpipeline.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/calibrationpipeline.h $ - * - */ - -#ifndef CALIBRATIONPIPELINE_H -#define CALIBRATIONPIPELINE_H - -#include "pipeline.h" -#include "demixingsettings.h" -#include "OTDBtree.h" - -class CalibrationPipeline : public Pipeline -{ -public: - CalibrationPipeline(); - CalibrationPipeline(unsigned); - CalibrationPipeline(const QSqlQuery &query, const OTDBtree &SAS_tree); - CalibrationPipeline(unsigned id, const OTDBtree &SAS_tree); - - friend QDataStream& operator<< (QDataStream &out, const CalibrationPipeline &task); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, CalibrationPipeline &task); // used for reading data from binary file - - virtual void clone(const Task *other) { - if (this != other) { - const CalibrationPipeline *pOther = dynamic_cast<const CalibrationPipeline *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *pOther; - taskID = myTaskID; - } - } - } - - // getters - DemixingSettings &demixingSettings(void) {return itsDemixingSettings;} - const DemixingSettings &demixingSettings(void) const {return itsDemixingSettings;} - const QString &skyModel(void) const {return itsSkyModel;} - bool demixingEnabled(void) const {return itsDemixingSettings.demixingEnabled();} - - inline void setSkyModel(const QString &skymodel) {itsSkyModel = skymodel;} - - // setters - void setDemixingSettings(const DemixingSettings &demix) {itsDemixingSettings = demix;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - - virtual void calculateDataSize(void); - -private: - DemixingSettings itsDemixingSettings; - QString itsSkyModel; -}; - -#endif // CALIBRATIONPIPELINE_H diff --git a/SAS/Scheduler/src/conflictdialog.cpp b/SAS/Scheduler/src/conflictdialog.cpp deleted file mode 100644 index 78e12a7b5a626535dbb0a19168c2bb7a333e7a41..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/conflictdialog.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * conflictdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 2-sep-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/conflictdialog.cpp $ - * - */ - -#include "conflictdialog.h" -#include "Controller.h" - -ConflictDialog::ConflictDialog(const Controller *controller) - : itsController(controller) -{ - ui.setupUi(this); - // setup conflicts tree - ui.treeWidgetConflicts->setColumnCount(5); - QStringList header; - header << "Task" << "Conflict" << "System" << "Start time" << "End time"; - ui.treeWidgetConflicts->setHeaderLabels(header); - ui.treeWidgetConflicts->header()->resizeSection(0, 70); - ui.treeWidgetConflicts->header()->resizeSection(1, 150); - ui.treeWidgetConflicts->header()->resizeSection(2, 55); - ui.treeWidgetConflicts->header()->resizeSection(3, 55); - ui.treeWidgetConflicts->header()->resizeSection(4, 55); -#if QT_VERSION >= 0x050000 - ui.treeWidgetConflicts->header()->setSectionResizeMode(QHeaderView::ResizeToContents); -#else - ui.treeWidgetConflicts->header()->setResizeMode(QHeaderView::ResizeToContents); -#endif -} - -ConflictDialog::~ConflictDialog() -{ - -} - -void ConflictDialog::addConflict(const Task *task, task_conflict conflict) { - QStringList itemcolums; - QString conflictStr; - // task id and name - itemcolums << "(" + QString::number(task->getID()) + ") " + task->getTaskName(); - // conflict description - if ((conflict >= CONFLICT_NO_CONFLICT) && (conflict < _END_CONFLICTS_)) { - conflictStr = TASK_CONFLICTS[conflict]; - } - else { - conflictStr = tr("Unknown conflict"); - } - itemcolums << conflictStr; - // scheduled start and end time - itemcolums << ""; - itemcolums << task->getScheduledStart().toString().c_str(); - itemcolums << task->getScheduledEnd().toString().c_str(); - - QTreeWidgetItem *item = new QTreeWidgetItem(ui.treeWidgetConflicts, itemcolums); - item->setData(0, Qt::UserRole,task->getID()); - item->setData(1, Qt::UserRole, TAB_SCHEDULE); - -// itsConflictTreeItems[task->getID()].append(item); -} - -void ConflictDialog::addStorageConflict(const Task *task, dataProductTypes dataProduct, const std::vector<storageResult> &results) { - for (std::vector<storageResult>::const_iterator it = results.begin(); it != results.end(); ++it) { - addStorageConflict(task, dataProduct, it->conflict, it->storageNodeID, it->storageRaidID); - } -} - -void ConflictDialog::addStorageConflict(const Task *task, dataProductTypes dataProduct, task_conflict conflict, int node_id, int raid_id) { - QStringList itemcolums; - QString conflictStr; - - // task id and name - itemcolums << "(" + QString::number(task->getID()) + ") " + task->getTaskName(); - // conflict description - if ((conflict >= CONFLICT_NO_CONFLICT) && (conflict < _END_CONFLICTS_)) { - conflictStr = QString(DATA_PRODUCTS[dataProduct]) + ":" + TASK_CONFLICTS[conflict]; - } - else { - conflictStr = QString(DATA_PRODUCTS[dataProduct]) + ":" + tr("Unknown conflict"); - } - itemcolums << conflictStr; - - // Storage node (system) - QString strStorageNode; - if (node_id != 0) { - strStorageNode = itsController->getStorageNodeName(node_id).c_str(); - if (raid_id != 0) { - strStorageNode += itsController->getStorageRaidName(node_id, raid_id).c_str(); - } - itemcolums << strStorageNode; - } - else { - itemcolums << ""; - } - - // scheduled start and end time - itemcolums.append(task->getScheduledStart().toString().c_str()); - itemcolums.append(task->getScheduledEnd().toString().c_str()); - - QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, itemcolums); - item->setData(0, Qt::UserRole,task->getID()); - item->setData(1, Qt::UserRole, TAB_STORAGE); - - // get the details of the storage conflict from the task - if (task->hasStorage()) { - const std::vector<storageResult> &taskConflicts = task->storage()->getStorageCheckResult(); - - for (std::vector<storageResult>::const_iterator it = taskConflicts.begin(); it != taskConflicts.end(); ++it) { - strStorageNode = itsController->getStorageNodeName(it->storageNodeID).c_str(); - itemcolums.clear(); - itemcolums << ""; - itemcolums << QString(DATA_PRODUCTS[dataProduct]) + ":" + TASK_CONFLICTS[it->conflict]; - itemcolums << strStorageNode + itsController->getStorageRaidName(it->storageNodeID, it->storageRaidID).c_str(); - QTreeWidgetItem *subitem = new QTreeWidgetItem(item, itemcolums); - subitem->setData(0, Qt::UserRole,task->getID()); - subitem->setData(1, Qt::UserRole, TAB_STORAGE); - - } - } - - ui.treeWidgetConflicts->insertTopLevelItem(0,item); - -// itsConflictTreeItems[task->getID()].append(item); -} - - -void ConflictDialog::addDataSlotConflict(const Task *task, task_conflict conflict, const std::string &station_name, unsigned otherTask_id) { - QStringList itemcolums; - // task id and name - itemcolums << "(" + QString::number(task->getID()) + ") " + task->getTaskName(); - // conflict description - if (conflict == CONFLICT_BITMODE) { - itemcolums << "Bit mode differs from task " + QString::number(otherTask_id) + " running on same station"; - } - else if (conflict == CONFLICT_OUT_OF_DATASLOTS) { - itemcolums << "All data slots are occupied on station"; - } - else { - itemcolums << tr("Unknown conflict"); - } - - // Station (system) - itemcolums << station_name.c_str(); - - // scheduled start and end time - itemcolums << task->getScheduledStart().toString().c_str() << task->getScheduledEnd().toString().c_str(); - - // add the task - QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, itemcolums); - item->setData(0, Qt::UserRole, task->getID()); - item->setData(1, Qt::UserRole, TAB_SCHEDULE); - - // add the other conflicting task as a child item - const Task *otherTask = itsController->getTask(otherTask_id); - if (otherTask) { - itemcolums.clear(); - itemcolums << "(" + QString::number(otherTask->getID()) + ") " + otherTask->getTaskName() - << "" << station_name.c_str() - << otherTask->getScheduledStart().toString().c_str() - << otherTask->getScheduledEnd().toString().c_str(); - QTreeWidgetItem *subitem = new QTreeWidgetItem(item, itemcolums); - subitem->setData(0, Qt::UserRole,task->getID()); - subitem->setData(1, Qt::UserRole, TAB_STORAGE); - } - - ui.treeWidgetConflicts->insertTopLevelItem(0,item); - - -// itsConflictTreeItems[task->getID()].append(item); -} - -void ConflictDialog::manualSolveConflict(void) const { - QList<QTreeWidgetItem*> selectItems(ui.treeWidgetConflicts->selectedItems()); - if (!selectItems.isEmpty()) { - itsController->showTaskDialog(selectItems.first()->data(0, Qt::UserRole).toUInt(), static_cast<tabIndex>(selectItems.first()->data(1, Qt::UserRole).toUInt())); - } -} - diff --git a/SAS/Scheduler/src/conflictdialog.h b/SAS/Scheduler/src/conflictdialog.h deleted file mode 100644 index 6ed701403c1ca89cd9da0166619670344b454b6f..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/conflictdialog.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * conflictdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 2-sep-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/conflictdialog.h $ - * - */ - -#ifndef CONFLICTDIALOG_H -#define CONFLICTDIALOG_H - -#include <QDialog> -#include "ui_conflictdialog.h" -#include <map> -#include "taskstorage.h" - -class Controller; - -// conflictTreeMap: key = task ID, value = list of column items for conflict tree widget -typedef std::map<unsigned, QList<QTreeWidgetItem *> > conflictTreeMap; - -class ConflictDialog : public QDialog -{ - Q_OBJECT - -public: - ConflictDialog(const Controller *controller); - ~ConflictDialog(); - - void addConflict(const Task *task, task_conflict conflict); - void addStorageConflict(const Task *task, dataProductTypes dataProduct, task_conflict conflict, int node_id = 0, int raid_id = 0); - void addStorageConflict(const Task *task, dataProductTypes dataProduct, const std::vector<storageResult> &results); - void addDataSlotConflict(const Task *task, task_conflict conflict, const std::string &station_name, unsigned otherTask_id = 0); - void clearAllConflicts(void) {/*itsConflictTreeItems.clear();*/ui.treeWidgetConflicts->clear();} - -private: - void clearConflict(); - -private slots: - void manualSolveConflict(void) const; - -private: - Ui::ConflictDialogClass ui; - const Controller *itsController; -// conflictTreeMap itsConflictTreeItems; -}; - -#endif // CONFLICTDIALOG_H diff --git a/SAS/Scheduler/src/conflictdialog.ui b/SAS/Scheduler/src/conflictdialog.ui deleted file mode 100644 index a1a11062e35c5ce115e04b9f66c306bfa4863fc1..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/conflictdialog.ui +++ /dev/null @@ -1,155 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>ConflictDialogClass</class> - <widget class="QDialog" name="ConflictDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>868</width> - <height>361</height> - </rect> - </property> - <property name="windowTitle"> - <string>Resource Conflicts</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="4" column="0" colspan="5"> - <widget class="QTreeWidget" name="treeWidgetConflicts"> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - <item row="0" column="1" colspan="2"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Solve selected conflicts</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QPushButton" name="pb_manualSolve"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Manual</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Select</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QComboBox" name="comboBox"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - </widget> - </item> - <item row="2" column="3" colspan="2"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="2"> - <widget class="QPushButton" name="pb_AutoSolve"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Automatic</string> - </property> - </widget> - </item> - <item row="5" column="4"> - <widget class="QPushButton" name="pb_Close"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Close</string> - </property> - <property name="flat"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pb_Close</sender> - <signal>clicked()</signal> - <receiver>ConflictDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>858</x> - <y>351</y> - </hint> - <hint type="destinationlabel"> - <x>451</x> - <y>336</y> - </hint> - </hints> - </connection> - <connection> - <sender>pb_manualSolve</sender> - <signal>clicked()</signal> - <receiver>ConflictDialogClass</receiver> - <slot>manualSolveConflict()</slot> - <hints> - <hint type="sourcelabel"> - <x>129</x> - <y>40</y> - </hint> - <hint type="destinationlabel"> - <x>243</x> - <y>7</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <slot>manualSolveConflict()</slot> - </slots> -</ui> diff --git a/SAS/Scheduler/src/dataslotdialog.cpp b/SAS/Scheduler/src/dataslotdialog.cpp deleted file mode 100644 index 54dfa97cbec8213de3288683a1b5e90a9d5f9d08..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/dataslotdialog.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * dataslotdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : June 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/dataslotdialog.cpp $ - * - */ - -#include "dataslotdialog.h" -#include "Controller.h" -#include <string> -#include <QString> - -DataSlotDialog::DataSlotDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); -} - -DataSlotDialog::~DataSlotDialog() -{ - -} - -void DataSlotDialog::clear() { - ui.textDataSlots->clear(); -} - -void DataSlotDialog::loadData(const dataSlotMap &dataSlots) { - ui.textDataSlots->clear(); - QString text; - std::string stationName; - for (dataSlotMap::const_iterator it = dataSlots.begin(); it != dataSlots.end(); ++it) { - stationName = Controller::theSchedulerSettings.getStationName(it->first); - if (!stationName.empty()) { - text += QString(stationName.c_str()) + ":\n"; - for (stationDataSlotMap::const_iterator sit = it->second.begin(); sit != it->second.end(); ++ sit) { - text += "RSP board " + QString::number(sit->first) + ": [" + QString::number(sit->second.first) + ".." + QString::number(sit->second.second) + "]\n"; - } - text += "\n"; - } - } - if (text.isEmpty()) { - ui.textDataSlots->setPlainText("No dataslots assigned for this task"); - } - else { - ui.textDataSlots->setPlainText(text); - } -} - diff --git a/SAS/Scheduler/src/dataslotdialog.h b/SAS/Scheduler/src/dataslotdialog.h deleted file mode 100644 index dac19546194fb46c110c9b6e5f285e0fe55114be..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/dataslotdialog.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * dataslotdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : June 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/dataslotdialog.h $ - * - */ - -#ifndef DATASLOTDIALOG_H -#define DATASLOTDIALOG_H - -#include <QDialog> -#include "ui_dataslotdialog.h" -#include "task.h" -#include "stationtask.h" - -class DataSlotDialog : public QDialog -{ - Q_OBJECT - -public: - DataSlotDialog(QWidget *parent = 0); - ~DataSlotDialog(); - - void clear(); - void loadData(const dataSlotMap &dataSlots); - -private: - Ui::DataSlotDialogClass ui; -}; - -#endif // DATASLOTDIALOG_H diff --git a/SAS/Scheduler/src/dataslotdialog.ui b/SAS/Scheduler/src/dataslotdialog.ui deleted file mode 100644 index 022714e417fbf2f6f6b13cc6af45acbf82f7843d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/dataslotdialog.ui +++ /dev/null @@ -1,87 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>DataSlotDialogClass</class> - <widget class="QDialog" name="DataSlotDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>280</width> - <height>270</height> - </rect> - </property> - <property name="minimumSize"> - <size> - <width>280</width> - <height>170</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="windowTitle"> - <string>Data slots</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="2"> - <widget class="QPlainTextEdit" name="textDataSlots"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButtonClose"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Close</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButtonClose</sender> - <signal>clicked()</signal> - <receiver>DataSlotDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>262</x> - <y>252</y> - </hint> - <hint type="destinationlabel"> - <x>169</x> - <y>151</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/debug_lofar.cpp b/SAS/Scheduler/src/debug_lofar.cpp deleted file mode 100644 index 14ab998151d9c05ad9725e7d4c50b0dbbb5f5d69..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/debug_lofar.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * debug_lofar.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 27, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/debug_lofar.cpp $ - * - */ - -#include "lofar_scheduler.h" -#ifdef DEBUG_SCHEDULER -#include <stdio.h> -#include <stdarg.h> -#include <iostream> -#endif - -void debugInfo( std::string szTypes, ... ) { -#ifdef DEBUG_SCHEDULER - va_list vl; - size_t i; - - va_start( vl, szTypes ); - - std::cout << "Info: "; - for( i = 0; i != szTypes.size(); ++i ) { - union Printable_t { - int i; - float f; - char c; - char *s; - } Printable; - - switch( szTypes.at(i) ) { // Type to expect. - case 'i': - Printable.i = va_arg( vl, int ); - std::cout << Printable.i; - break; - - case 'f': - Printable.f = va_arg( vl, double ); - std::cout << Printable.f; - break; - - case 'c': - Printable.c = va_arg( vl, int ); - std::cout << Printable.c; - break; - - case 's': - Printable.s = va_arg( vl, char * ); - std::cout << Printable.s; - break; - - default: - break; - } - } - std::cout << std::endl; - va_end( vl ); -#endif -} - -void debugWarn( std::string szTypes, ... ) { -#ifdef DEBUG_SCHEDULER - va_list vl; - size_t i; - - va_start( vl, szTypes ); - - std::cout << "Warning: "; - for( i = 0; i != szTypes.size(); ++i ) { - union Printable_t { - int i; - float f; - char c; - char *s; - } Printable; - - switch( szTypes.at(i) ) { // Type to expect. - case 'i': - Printable.i = va_arg( vl, int ); - std::cout << Printable.i; - break; - - case 'f': - Printable.f = va_arg( vl, double ); - std::cout << Printable.f; - break; - - case 'c': - Printable.c = va_arg( vl, int ); - std::cout << Printable.c; - break; - - case 's': - Printable.s = va_arg( vl, char * ); - std::cout << Printable.s; - break; - - default: - break; - } - } - std::cout << std::endl; - va_end( vl ); -#endif -} - -void debugErr( std::string szTypes, ... ) { -#ifdef DEBUG_SCHEDULER - va_list vl; - size_t i; - - va_start( vl, szTypes ); - - std::cerr << "Error: "; - for( i = 0; i != szTypes.size(); ++i ) { - bool stop = false; - // for( i = 0; va_arg(vl,int) != -1; ++i ) { - union Printable_t { - int i; - unsigned int u; - double f; - char c; - char *s; - } Printable; - - switch( szTypes.at(i) ) { // Type to expect. - case 'i': - Printable.i = va_arg( vl, int ); - if (Printable.i) { std::cerr << Printable.i; } - else { stop = true; break;} - break; - - case 'u': - Printable.u = va_arg( vl, unsigned int ); - if (Printable.u) { std::cerr << Printable.u; } - else { stop = true; break;} - break; - - case 'f': - Printable.f = va_arg( vl, double ); - if (Printable.f) { std::cerr << Printable.f; } - else { stop = true; break;} - break; - - case 'c': - Printable.c = va_arg( vl, int ); - if (Printable.c) { std::cerr << Printable.c; } - else { stop = true; break;} - break; - - case 's': - Printable.s = va_arg( vl, char * ); - if (Printable.s) { std::cerr << Printable.s; } - else { stop = true; break;} - break; - - default: - break; - } - if (stop) break; - } - std::cerr << std::endl; - va_end( vl ); -#endif -} - - diff --git a/SAS/Scheduler/src/demixingsettings.cpp b/SAS/Scheduler/src/demixingsettings.cpp deleted file mode 100644 index 0ec568ce9ec4d0e9657b92b704ac3153cb4c9a56..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/demixingsettings.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "demixingsettings.h" - -QStringList DemixingSettings::demixAlwaysList(void) const { - QStringList lst; - if (!itsDemixAlways.isEmpty()) { - lst = itsDemixAlways.split(','); - } - return lst; -} - -QStringList DemixingSettings::demixIfNeededList(void) const { - QStringList lst; - if (!itsDemixIfNeeded.isEmpty()) { - lst = itsDemixIfNeeded.split(','); - } - return lst; -} diff --git a/SAS/Scheduler/src/demixingsettings.h b/SAS/Scheduler/src/demixingsettings.h deleted file mode 100644 index f42e9e33a8ca0bb53bccd505b5c20cb1ad29c7d4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/demixingsettings.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef DEMIXINGSETTINGS_H -#define DEMIXINGSETTINGS_H - -#include <QDataStream> -#include <QString> -#include <QStringList> - -class DemixingSettings -{ -public: - DemixingSettings() : itsDemixingEnabled(false), itsFreqStep(64), itsTimeStep(10), itsDemixFreqStep(64), itsDemixTimeStep(10) { } - - // getters - inline const QString &demixAlways(void) const {return itsDemixAlways;} - QStringList demixAlwaysList(void) const; - inline const QString &demixIfNeeded(void) const {return itsDemixIfNeeded;} - QStringList demixIfNeededList(void) const; - inline const QString &skyModel(void) const {return itsSkyModel;} - inline quint16 demixFreqStep(void) const {return itsDemixFreqStep;} - inline quint16 demixTimeStep(void) const {return itsDemixTimeStep;} - inline quint16 freqStep(void) const {return itsFreqStep;} - inline quint16 timeStep(void) const {return itsTimeStep;} - inline bool demixingEnabled(void) const {return itsDemixingEnabled;} - - // setters - inline void setDemixingEnabled(bool enabled) {itsDemixingEnabled = enabled;} - inline void setDemixAlways(const QString &demix_sources) {itsDemixAlways = demix_sources;} - inline void setDemixIfNeeded(const QString &demix_sources) {itsDemixIfNeeded = demix_sources;} - inline void setDemixFreqStep(quint16 freqstep) {itsDemixFreqStep = freqstep;} - inline void setDemixTimeStep(quint16 timestep) {itsDemixTimeStep = timestep;} - inline void setAvgFreqStep(quint16 freqstep) {itsFreqStep = freqstep;} - inline void setAvgTimeStep(quint16 timestep) {itsTimeStep = timestep;} - inline void setDemixSkyModel(const QString &sky_model) {itsSkyModel = sky_model;} - - friend QDataStream& operator>> (QDataStream &in, DemixingSettings &d) { - in >> d.itsDemixingEnabled - >> d.itsDemixAlways >> d.itsDemixIfNeeded >> d.itsSkyModel - >> d.itsFreqStep >> d.itsTimeStep >> d.itsDemixFreqStep >> d.itsDemixTimeStep; - return in; - } - - friend QDataStream& operator<< (QDataStream &out, const DemixingSettings &d) { - out << d.itsDemixingEnabled - << d.itsDemixAlways << d.itsDemixIfNeeded << d.itsSkyModel - << d.itsFreqStep << d.itsTimeStep << d.itsDemixFreqStep << d.itsDemixTimeStep; - return out; - } - -public: - bool itsDemixingEnabled; - QString itsDemixAlways, itsDemixIfNeeded, itsSkyModel; - quint16 itsFreqStep, itsTimeStep, itsDemixFreqStep, itsDemixTimeStep; -}; - -#endif // DEMIXINGSETTINGS_H diff --git a/SAS/Scheduler/src/digitalbeamdialog.cpp b/SAS/Scheduler/src/digitalbeamdialog.cpp deleted file mode 100644 index 9b5838e16025e09ce2163d95a1e922dfbb9bed3a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/digitalbeamdialog.cpp +++ /dev/null @@ -1,464 +0,0 @@ -/* - * digitalbeamdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 8-june-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/digitalbeamdialog.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "digitalbeamdialog.h" -#include "lofar_utils.h" -#include "taskdialog.h" -#include <QMessageBox> -#include <limits> - -DigitalBeamDialog::DigitalBeamDialog(QWidget *parent) - : QDialog(parent), itsParentTaskDialog(static_cast<TaskDialog *>(parent)), itsBeamNr(-1), change(false) -{ - this->blockSignals(true); - ui.setupUi(this); - // load coordinate system combo box - QStringList items; - for (short i = _BEGIN_DIRECTION_TYPES; i < _END_DIRECTION_TYPES; ++i) { - items << BEAM_DIRECTION_TYPES[i]; - } - ui.comboBoxCoordinateSystem->addItems(items); - ui.comboBoxCoordinateSystem->setCurrentIndex(0); - - // load angle units combo box - items.clear(); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - ui.comboBoxAngleUnits->addItems(items); - ui.comboBoxAngleUnits->setCurrentIndex(0); - ui.labelAngle1->setText("Right Asc.:"); - ui.labelAngle2->setText("Declination:"); - - ui.lineEditAngle1->setToolTip("hh:mm:ss.s (hours:minutes:seconds)"); - ui.lineEditAngle2->setToolTip("+dd:mm:ss.s (degrees:minutes:seconds)"); - ui.lineEditAngle1->setInputMask("00:00:00.0000000"); - ui.lineEditAngle2->setInputMask("#00:00:00.0000000"); - - ui.lineEditTabRingSize->setInputMask("0.000000000000000"); - - connect(ui.comboBoxAngleUnits, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(switchToNewAngleUnits(const QString &))); - connect(ui.comboBoxCoordinateSystem, SIGNAL(currentIndexChanged(int)), this, SLOT(switchToNewCoordinates(int))); - connect(ui.lineEditSubbands, SIGNAL(textChanged(const QString &)), this, SLOT(updateSubbandLineEdit(const QString &))); - connect(ui.buttonBoxCancelOK, SIGNAL(accepted()), this, SLOT(accept())); - connect(ui.buttonBoxCancelOK, SIGNAL(rejected()), this, SLOT(reject())); - ui.lineEditTarget->setFocus(); - this->blockSignals(false); -} - -DigitalBeamDialog::~DigitalBeamDialog() { -} - -void DigitalBeamDialog::setReadOnly(bool read_only) { - ui.comboBoxCoordinateSystem->setEnabled(!read_only); - ui.lineEditTarget->setReadOnly(read_only); - ui.lineEditAngle1->setReadOnly(read_only); - ui.lineEditAngle2->setReadOnly(read_only); - ui.lineEditSubbands->setReadOnly(read_only); - ui.timeEditStartTime->setReadOnly(read_only); - ui.lineEditDuration->setReadOnly(read_only); - ui.spinBoxNrTabRings->setReadOnly(read_only); - ui.lineEditTabRingSize->setReadOnly(read_only); - ui.pushButtonSelectSource->setEnabled(!read_only); - ui.buttonBoxCancelOK->clear(); - if (read_only) { - ui.buttonBoxCancelOK->addButton(QDialogButtonBox::Close); - } - else { - ui.buttonBoxCancelOK->addButton(QDialogButtonBox::Ok); - ui.buttonBoxCancelOK->addButton(QDialogButtonBox::Cancel); - } -} - -void DigitalBeamDialog::accept(void) { - // target name - std::string newTarget = ui.lineEditTarget->text().toStdString(); - if (newTarget != itsBeam.target()) { - itsBeam.setTarget(newTarget); - change = true; - } - - // subband list - if (itsBeam.subbandsStr() != ui.lineEditSubbands->text()) { - change = true; - bool error(false); - std::vector<unsigned> newSubbands = StringList2VectorOfUint(ui.lineEditSubbands->text(), error); - if (!newSubbands.empty()) { - itsBeam.setSubbandList(newSubbands); - } - else { - QMessageBox::critical(this,tr("Error in subband list"), tr("There is an error in the subband list, please correct it")); - return; - } - } - - // start time and duration - AstroTime newStartTime(ui.timeEditStartTime->time().hour(), ui.timeEditStartTime->time().minute(), ui.timeEditStartTime->time().second()); - if (newStartTime != itsBeam.startTime()) { - itsBeam.setStartTime(newStartTime); - change = true; - } - AstroTime newDuration(ui.lineEditDuration->text()); - if (newDuration != itsBeam.duration()) { - itsBeam.setDuration(newDuration); - change = true; - } - - // nr TAB rings - int nrTabRings(ui.spinBoxNrTabRings->value()); - if (nrTabRings != itsBeam.nrTabRings()) { - itsBeam.setNrTabRings(nrTabRings); - change = true; - } - - // ring Tab size - const double &tabRingSize(ui.lineEditTabRingSize->text().toDouble()); - if (fabs(tabRingSize - itsBeam.tabRingSize()) > std::numeric_limits<double>::epsilon()) { - itsBeam.setTabRingSize(tabRingSize); - change = true; - } - - if (change) { - itsParentTaskDialog->setDigitalBeam(itsBeamNr, itsBeam, change); - } - - QDialog::accept(); -} - -void DigitalBeamDialog::reset(void) { - this->blockSignals(true); - itsBeamNr = -1; - this->setWindowTitle("Digital Beam"); - ui.comboBoxCoordinateSystem->setCurrentIndex(0); - ui.comboBoxAngleUnits->setCurrentIndex(0); - ui.lineEditTarget->setText(""); - ui.lineEditAngle1->setText("00:00:00.0"); - ui.lineEditAngle2->setText("000:00:00.0"); - ui.timeEditStartTime->setTime(QTime(0,0,0)); -// ui.lineEditDuration->setTime(QTime(0,0,0)); - ui.lineEditDuration->setInputMask("0000:00:00"); - ui.lineEditSubbands->setText("[]"); - ui.lineEditTabRingSize->setText("0.0"); - ui.spinBoxNrTabRings->setValue(0); - itsBeam.clear(); - change = false; - ui.lineEditTarget->setFocus(); - this->blockSignals(false); -} - - -void DigitalBeamDialog::setDuration(const AstroTime &time) { - ui.lineEditDuration->setText(time.toString().c_str()); -} - -void DigitalBeamDialog::updateSubbandLineEdit(const QString &text) { - QString newText(text); - // get current length, needed when a user typed a non permitted character which will be removed, to update to correct cursorposition afterwards - int oldLength = newText.length(); - // get current cursor position - int cursorIdx = ui.lineEditSubbands->cursorPosition(); - // replace all single or multiple dots by double dots - if (itsSubbandString.length() > newText.length()) { // user deleted something possibly a dot? - for (int i = newText.length()-1; i > 0; --i) { // remove single dots - if (newText[i] == '.' && newText[i-1] != '.' && newText[i+1] != '.') { - newText.remove(i,1); - } - } - } - else { // convert single dots to double dots - newText.replace(QRegExp("\\.+"),".."); - } - // check for ..d(d).. which is an error - int errIdx = newText.indexOf(QRegExp("\\.{2,2}\\d+\\.{2,2}")); // ..number.. - if (errIdx != -1) { - newText.remove(newText.indexOf("..",errIdx+2),2); - QApplication::beep(); - } - //check for ,.. - errIdx = newText.indexOf(QRegExp(",\\.{2,2}")); // ,.. - if (errIdx != -1) { - newText.remove(newText.indexOf("..",errIdx),2); - QApplication::beep(); - } - //check for .., - errIdx = newText.indexOf(QRegExp("\\.{2,2},")); // .., - if (errIdx != -1) { - newText.remove(newText.indexOf(',',errIdx),1); - QApplication::beep(); - } - errIdx = newText.indexOf(QRegExp(",{2}")); // more than one comma - if (errIdx != -1) { - newText.remove(newText.indexOf(',',errIdx),1); - QApplication::beep(); - } - // check brackets - newText.remove(QRegExp("[^.,0-9]")); - newText.prepend('['); - newText.append(']'); - // remove . and , from index 1 and length-1 - while ((newText.at(1) == QChar(',')) | (newText.at(1) == QChar('.'))) newText.remove(1,1); - - // now update with new text - itsSubbandString = newText; -// ui.lineEditSubbands->blockSignals(true); - ui.lineEditSubbands->setText(newText); - if (oldLength == newText.length()) { - ui.lineEditSubbands->setCursorPosition(cursorIdx); // return to previous cursorposition - } - else if (oldLength < newText.length()) { // '.' (dot) was automatically inserted - ui.lineEditSubbands->setCursorPosition(cursorIdx+1); // user typed an invalid character that was removed - } - else { - ui.lineEditSubbands->setCursorPosition(cursorIdx-1); - } -// ui.lineEditSubbands->blockSignals(false); -} - -void DigitalBeamDialog::loadBeamSettings(unsigned beamNr, const DigitalBeam &beam) { - itsBeamNr = beamNr; - itsBeam = beam; - this->setWindowTitle(QString("Digital Beam ") + QString::number(beamNr+1)); - ui.lineEditTarget->setText(beam.target().c_str()); - const AstroTime &beamStartTime(beam.startTime()); - ui.timeEditStartTime->setTime(QTime(beamStartTime.getHours(),beamStartTime.getMinutes(),beamStartTime.getSeconds())); - ui.lineEditDuration->setText(beam.duration().toString().c_str()); - ui.lineEditSubbands->setText(beam.subbandsStr()); - ui.comboBoxCoordinateSystem->setCurrentIndex(beam.directionType()); - setAngleCoordinateSystem(beam.directionType()); - // set the correct option in comboboxAngleUnits - for (short i =0; i < ui.comboBoxAngleUnits->count(); ++i) { - if (ui.comboBoxAngleUnits->itemText(i).compare(ANGLE_PAIRS[beam.units()]) == 0) { - ui.comboBoxAngleUnits->setCurrentIndex(i); - break; - } - } - setAngles(beam.units(), itsBeam.angle1(), itsBeam.angle2()); - ui.spinBoxNrTabRings->setValue(itsBeam.nrTabRings()); - ui.lineEditTabRingSize->setText(QString::number(itsBeam.tabRingSize(),'g',15)); - - ui.lineEditTarget->setFocus(); - change = false; -} - -void DigitalBeamDialog::setAngleCoordinateSystem(const beamDirectionType &coordinateSystem) { - QStringList items; - ui.comboBoxAngleUnits->clear(); - switch (coordinateSystem) { - default: - case DIR_TYPE_J2000: // Right ascension & declination - case DIR_TYPE_B1950: - case DIR_TYPE_ICRS: - case DIR_TYPE_ITRF: - case DIR_TYPE_TOPO: - case DIR_TYPE_APP: - ui.labelAngle1->setText("Right Asc.:"); - ui.labelAngle2->setText("Declination:"); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_HADEC: - ui.labelAngle1->setText("Hour angle:"); - ui.labelAngle2->setText("Declination:"); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_AZELGEO: - ui.labelAngle1->setText("Azimuth:"); - ui.labelAngle2->setText("Elevation:"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_SUN: - case DIR_TYPE_MOON: - case DIR_TYPE_PLUTO: - case DIR_TYPE_NEPTUNE: - case DIR_TYPE_URANUS: - case DIR_TYPE_SATURN: - case DIR_TYPE_JUPITER: - case DIR_TYPE_MARS: - case DIR_TYPE_VENUS: - case DIR_TYPE_MERCURY: - ui.labelAngle1->setText("Angle 1:"); - ui.labelAngle2->setText("Angle 2:"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - break; - case DIR_TYPE_GALACTIC: - case DIR_TYPE_ECLIPTIC: - case DIR_TYPE_COMET: - ui.labelAngle1->setText("Longitude:"); - ui.labelAngle2->setText("Latitude:"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - } - - ui.comboBoxAngleUnits->addItems(items); -} - -void DigitalBeamDialog::setAngles(const anglePairs &angleUnits, const Angle &angle1, const Angle &angle2) { - switch (angleUnits) { - case ANGLE_PAIRS_HMS_DMS: - ui.lineEditAngle1->setToolTip("hh:mm:ss.s (hours:minutes:seconds)"); - ui.lineEditAngle2->setToolTip("+dd:mm:ss.s (degrees:minutes:seconds)"); - ui.lineEditAngle1->setInputMask("00:00:00.0000000"); - ui.lineEditAngle2->setInputMask("#00:00:00.0000000"); - ui.lineEditAngle1->setText(angle1.HMSstring().c_str()); - ui.lineEditAngle2->setText(angle2.DMSstring().c_str()); - break; - case ANGLE_PAIRS_DMS_DMS: - ui.lineEditAngle1->setToolTip("ddd:mm:ss.s (degrees:minutes:seconds)"); - ui.lineEditAngle2->setToolTip("+dd:mm:ss.s (degrees:minutes:seconds)"); - ui.lineEditAngle1->setInputMask("000:00:00.000000"); - ui.lineEditAngle2->setInputMask("#00:00:00.000000"); - ui.lineEditAngle1->setText(angle1.DMSstring().c_str()); - ui.lineEditAngle2->setText(angle2.DMSstring().c_str()); - break; - case ANGLE_PAIRS_RADIANS: - ui.lineEditAngle1->setToolTip("radians"); - ui.lineEditAngle2->setToolTip("radians"); - ui.lineEditAngle1->setInputMask("0.000000000000000"); - ui.lineEditAngle2->setInputMask("#0.000000000000000"); - ui.lineEditAngle1->setText(QString::number(angle1.radian(),'g',15)); - ui.lineEditAngle2->setText(QString::number(angle2.radian(),'g',15)); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - ui.lineEditAngle1->setToolTip("degrees"); - ui.lineEditAngle2->setToolTip("degrees"); - ui.lineEditAngle1->setInputMask("000.000000000000000"); - ui.lineEditAngle2->setInputMask("#00.000000000000000"); - ui.lineEditAngle1->setText(QString::number(angle1.degree(),'g',15)); - ui.lineEditAngle2->setText(QString::number(angle2.degree(),'g',15)); - break; - default: - break; - } -} - -void DigitalBeamDialog::switchToNewAngleUnits(const QString &newUnits) { - ui.lineEditAngle1->blockSignals(true); - ui.lineEditAngle2->blockSignals(true); - for (short i = 0; i < END_ANGLE_PAIRS; ++i) { - if (newUnits.compare(ANGLE_PAIRS[i]) == 0) { - itsBeam.setUnits(static_cast<anglePairs>(i)); - break; - } - } - setAngles(itsBeam.units(), itsBeam.angle1(), itsBeam.angle2()); - ui.lineEditAngle1->blockSignals(false); - ui.lineEditAngle2->blockSignals(false); - change = true; -} - -void DigitalBeamDialog::switchToNewCoordinates(int newCoordinates) { - ui.lineEditAngle1->blockSignals(true); - ui.lineEditAngle2->blockSignals(true); - itsBeam.setDirectionType(static_cast<beamDirectionType>(newCoordinates)); - setAngleCoordinateSystem(itsBeam.directionType()); - switch (itsBeam.directionType()) { - default: - case DIR_TYPE_J2000: // Right ascension & declination - case DIR_TYPE_B1950: - case DIR_TYPE_ICRS: - case DIR_TYPE_ITRF: - case DIR_TYPE_TOPO: - case DIR_TYPE_APP: - itsBeam.setUnits(ANGLE_PAIRS_HMS_DMS); - break; - case DIR_TYPE_HADEC: - itsBeam.setUnits(ANGLE_PAIRS_HMS_DMS); - break; - case DIR_TYPE_AZELGEO: - itsBeam.setUnits(ANGLE_PAIRS_DMS_DMS); - break; - case DIR_TYPE_SUN: - case DIR_TYPE_MOON: - case DIR_TYPE_PLUTO: - case DIR_TYPE_NEPTUNE: - case DIR_TYPE_URANUS: - case DIR_TYPE_SATURN: - case DIR_TYPE_JUPITER: - case DIR_TYPE_MARS: - case DIR_TYPE_VENUS: - case DIR_TYPE_MERCURY: - itsBeam.setUnits(ANGLE_PAIRS_DMS_DMS); - break; - case DIR_TYPE_GALACTIC: - case DIR_TYPE_ECLIPTIC: - case DIR_TYPE_COMET: - itsBeam.setUnits(ANGLE_PAIRS_DMS_DMS); - break; - } - setAngles(itsBeam.units(), itsBeam.angle1(), itsBeam.angle2()); - ui.lineEditAngle1->blockSignals(false); - ui.lineEditAngle2->blockSignals(false); - change = true; -} - -void DigitalBeamDialog::getAngle1(QString newValue) { - Angle newAngle; - switch(itsBeam.units()) { - case ANGLE_PAIRS_HMS_DMS: - newAngle.setHMSangleStr(newValue.toStdString()); - break; - case ANGLE_PAIRS_DMS_DMS: - newAngle.setDMSangleStr(newValue.toStdString()); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - newAngle.setDegreeAngle(newValue.toDouble()); - break; - case ANGLE_PAIRS_RADIANS: - newAngle.setRadianAngle(newValue.toDouble()); - break; - default: - break; - } - if (newAngle != itsBeam.angle1()) { - itsBeam.setAngle1(newAngle); - change = true; - } -} - -void DigitalBeamDialog::getAngle2(QString newValue) { - Angle newAngle; - switch(itsBeam.units()) { - case ANGLE_PAIRS_HMS_DMS: - newAngle.setDMSangleStr(newValue.toStdString()); - break; - case ANGLE_PAIRS_DMS_DMS: - newAngle.setDMSangleStr(newValue.toStdString()); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - newAngle.setDegreeAngle(newValue.toDouble()); - break; - case ANGLE_PAIRS_RADIANS: - newAngle.setRadianAngle(newValue.toDouble()); - break; - default: - break; - } - if (newAngle != itsBeam.angle2()) { - itsBeam.setAngle2(newAngle); - change = true; - } -} diff --git a/SAS/Scheduler/src/digitalbeamdialog.h b/SAS/Scheduler/src/digitalbeamdialog.h deleted file mode 100644 index 0a633b9b8598f60e955cd406bf0490080dd651fb..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/digitalbeamdialog.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * digitalbeamdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 8-june-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/digitalbeamdialog.h $ - * - */ - -#ifndef DIGITALBEAMDIALOG_H -#define DIGITALBEAMDIALOG_H - -#include <QDialog> -#include "ui_digitalbeamdialog.h" -#include "task.h" -#include "Angle.h" -#include "DigitalBeam.h" - -class TaskDialog; - -class DigitalBeamDialog : public QDialog -{ - Q_OBJECT - -public: - DigitalBeamDialog(QWidget *parent = 0); - ~DigitalBeamDialog(); - - void reset(void); - void loadBeamSettings(unsigned beamNr, const DigitalBeam &beam); - void setReadOnly(bool read_only); - void setBeamNr(unsigned beamNr) {itsBeamNr = beamNr;} - void setDuration(const AstroTime &time); - -private: - void setAngleCoordinateSystem(const beamDirectionType &coordinateSystem); - void setAngles(const anglePairs &angleUnits, const Angle &angle1, const Angle &angle2); - - -private slots: - void switchToNewAngleUnits(const QString &newUnits); - void switchToNewCoordinates(int newCoordinates); - void getAngle1(QString); - void getAngle2(QString); - void accept(void); - void updateSubbandLineEdit(const QString &); - -private: - Ui::DigitalBeamDialogClass ui; - TaskDialog *itsParentTaskDialog; - DigitalBeam itsBeam; - unsigned itsBeamNr; - bool change; - QString itsSubbandString; - // anglePairs itsBeam.units; - // Angle itsAngle1, itsAngle2; -}; - -#endif // DIGITALBEAMDIALOG_H diff --git a/SAS/Scheduler/src/digitalbeamdialog.ui b/SAS/Scheduler/src/digitalbeamdialog.ui deleted file mode 100644 index 9fd8de54c99f3434cd962ed381ea40af44411543..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/digitalbeamdialog.ui +++ /dev/null @@ -1,323 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>DigitalBeamDialogClass</class> - <widget class="QDialog" name="DigitalBeamDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>380</width> - <height>367</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>380</width> - <height>367</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>380</width> - <height>367</height> - </size> - </property> - <property name="windowTitle"> - <string>Digital Beam</string> - </property> - <property name="sizeGripEnabled"> - <bool>false</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="13" column="0"> - <widget class="QLabel" name="labelSubbands"> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="text"> - <string>Subbands:</string> - </property> - </widget> - </item> - <item row="11" column="0"> - <widget class="QLabel" name="labelAngle2"> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Angle 2:</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelCoordinates"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="text"> - <string>Coordinates:</string> - </property> - </widget> - </item> - <item row="15" column="0"> - <widget class="QLabel" name="labelStartTime"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="text"> - <string>Start time:</string> - </property> - </widget> - </item> - <item row="13" column="1" colspan="5"> - <widget class="QLineEdit" name="lineEditSubbands"> - <property name="toolTip"> - <string>Comma separated list of subbands between brackets e.g.: -[1,3,5..9,11]</string> - </property> - </widget> - </item> - <item row="11" column="1" colspan="4"> - <widget class="QLineEdit" name="lineEditAngle2"/> - </item> - <item row="0" column="1" colspan="3"> - <widget class="QComboBox" name="comboBoxCoordinateSystem"> - <property name="toolTip"> - <string>Coordinate system</string> - </property> - </widget> - </item> - <item row="16" column="1" colspan="3"> - <widget class="QLineEdit" name="lineEditDuration"> - <property name="toolTip"> - <string>the duration of this beam (hhhh:mm:ss)</string> - </property> - <property name="inputMask"> - <string>9999:99:99; </string> - </property> - <property name="text"> - <string>0000:00:00</string> - </property> - </widget> - </item> - <item row="16" column="0"> - <widget class="QLabel" name="labelStartTime_2"> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="text"> - <string>Duration:</string> - </property> - </widget> - </item> - <item row="19" column="4" colspan="2"> - <widget class="QDialogButtonBox" name="buttonBoxCancelOK"> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelAngleUnits"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>25</height> - </size> - </property> - <property name="text"> - <string>Angle units:</string> - </property> - </widget> - </item> - <item row="1" column="1" colspan="3"> - <widget class="QComboBox" name="comboBoxAngleUnits"> - <property name="toolTip"> - <string>Display units for the angles</string> - </property> - </widget> - </item> - <item row="2" column="1" colspan="4"> - <widget class="QLineEdit" name="lineEditTarget"> - <property name="minimumSize"> - <size> - <width>110</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Target denomination</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelTarget"> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="text"> - <string>Target:</string> - </property> - </widget> - </item> - <item row="2" column="5"> - <widget class="QPushButton" name="pushButtonSelectSource"> - <property name="minimumSize"> - <size> - <width>90</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>90</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>Select source from online Simbad database</string> - </property> - <property name="text"> - <string>Select source</string> - </property> - </widget> - </item> - <item row="3" column="1" colspan="4"> - <widget class="QLineEdit" name="lineEditAngle1"> - <property name="readOnly"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelAngle1"> - <property name="maximumSize"> - <size> - <width>77</width> - <height>25</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Angle 1:</string> - </property> - </widget> - </item> - <item row="17" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>nr. TAB rings:</string> - </property> - </widget> - </item> - <item row="17" column="1" colspan="3"> - <widget class="QSpinBox" name="spinBoxNrTabRings"> - <property name="maximum"> - <number>12</number> - </property> - </widget> - </item> - <item row="15" column="1" colspan="3"> - <widget class="QTimeEdit" name="timeEditStartTime"> - <property name="toolTip"> - <string>Start time (hh:mm::ss) of this beam relative to the start of this observation</string> - </property> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - <item row="18" column="1" colspan="4"> - <widget class="QLineEdit" name="lineEditTabRingSize"/> - </item> - <item row="18" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>TAB ring size:</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>lineEditAngle1</sender> - <signal>textEdited(QString)</signal> - <receiver>DigitalBeamDialogClass</receiver> - <slot>getAngle1(QString)</slot> - <hints> - <hint type="sourcelabel"> - <x>192</x> - <y>106</y> - </hint> - <hint type="destinationlabel"> - <x>206</x> - <y>107</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditAngle2</sender> - <signal>textEdited(QString)</signal> - <receiver>DigitalBeamDialogClass</receiver> - <slot>getAngle2(QString)</slot> - <hints> - <hint type="sourcelabel"> - <x>185</x> - <y>140</y> - </hint> - <hint type="destinationlabel"> - <x>224</x> - <y>136</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <slot>getAngle1(QString)</slot> - <slot>getAngle2(QString)</slot> - </slots> -</ui> diff --git a/SAS/Scheduler/src/doublespinbox.cpp b/SAS/Scheduler/src/doublespinbox.cpp deleted file mode 100644 index 97c59425db7dc80759910cf230f7cb0f4489ec2a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/doublespinbox.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * doublespinbox.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 24-jun-2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/doublespinbox.cpp $ - * - */ - -#include "doublespinbox.h" - -DoubleSpinBox::DoubleSpinBox(QWidget *parent) - : QDoubleSpinBox(parent), itsUndefined(false), itsPreviousUndefined(false), itsPreviousValue(0), itsDefaultValue(0) -{ -} - -DoubleSpinBox::~DoubleSpinBox() -{ - -} - -void DoubleSpinBox::setValue(double value) { - this->blockSignals(true); - setSpecialValueText(""); - QDoubleSpinBox::setValue(value); - itsPreviousValue = value; - itsUndefined = false; - this->blockSignals(false); -} - - -void DoubleSpinBox::setUndefined(bool enabled = true) { - this->blockSignals(true); - itsUndefined = enabled; - if (enabled) { - itsPreviousValue = -1; - // NOTE: if the current value is equal to the minimum value then the special value text is shown - setSpecialValueText(MULTIPLE_VALUE_TEXT); - QDoubleSpinBox::setValue(minimum()); - } - else { - setSpecialValueText(""); - QDoubleSpinBox::setValue(itsDefaultValue); - } - this->blockSignals(false); -} - -void DoubleSpinBox::focusInEvent(QFocusEvent* event) -{ - if (itsUndefined) { - itsPreviousUndefined = true; - QDoubleSpinBox::setValue(itsDefaultValue); - setSpecialValueText(""); - itsPreviousValue = value(); - } - - // You might also call the parent method. - QDoubleSpinBox::focusInEvent(event); -} - -void DoubleSpinBox::focusOutEvent(QFocusEvent* event) -{ - checkValueChange(); - // You might also call the parent method. - QDoubleSpinBox::focusOutEvent(event); -} - -void DoubleSpinBox::checkValueChange(void) { - if (itsUndefined) { - if (itsPreviousValue == value()) { // was undefined and did not change - // NOTE: if the current value is equal to the minimum value then the special value text is shown - setSpecialValueText(MULTIPLE_VALUE_TEXT); - this->blockSignals(true); - QDoubleSpinBox::setValue(minimum()); - this->blockSignals(false); - } - else { - itsUndefined = false; - setSpecialValueText(""); - } - itsPreviousValue = value(); - } -} diff --git a/SAS/Scheduler/src/doublespinbox.h b/SAS/Scheduler/src/doublespinbox.h deleted file mode 100644 index cdd69313ecf0f4df569cbaff34294d6d6d0250c6..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/doublespinbox.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SpinBox.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 24-jun-2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/doublespinbox.h $ - * - */ - -#ifndef DOUBLESPINBOX_H -#define DOUBLESPINBOX_H - -#include "lofar_scheduler.h" -#include <QDoubleSpinBox> - -class DoubleSpinBox : public QDoubleSpinBox -{ - Q_OBJECT - -public: - DoubleSpinBox(QWidget *parent = 0); - ~DoubleSpinBox(); - - - void setValue(double value); - void setUndefined(bool enabled); - void setDefaultValue(double value) {itsDefaultValue = value;} - inline bool isUndefined(void) {return itsUndefined;} - bool hasBeenChanged(void) const { - if (itsUndefined) return false; - else if (itsPreviousUndefined) return true; - else if (itsPreviousValue != value()) return true; - else return false; - } - void resetChangeDetect(void) { itsPreviousValue = value(); } - -protected: - void focusInEvent(QFocusEvent*); - void focusOutEvent(QFocusEvent*); - -protected slots: - void checkValueChange(void); -private: - bool itsUndefined, itsPreviousUndefined; - double itsPreviousValue, itsDefaultValue; -}; - -#endif // DOUBLESPINBOX_H diff --git a/SAS/Scheduler/src/graphicstoragescene.cpp b/SAS/Scheduler/src/graphicstoragescene.cpp deleted file mode 100644 index 200be58a6e67e2bf078bdaee2d3f81dbfa372266..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/graphicstoragescene.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * graphicstoragescene.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Nov 12, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/graphicstoragescene.cpp $ - * - */ - -#include "graphicstoragescene.h" - - -GraphicStorageScene::GraphicStorageScene(Controller *controller) -: itsParentView(0), itsController(controller) -{ -} - -GraphicStorageScene::~GraphicStorageScene() -{ - -} diff --git a/SAS/Scheduler/src/graphicstoragescene.h b/SAS/Scheduler/src/graphicstoragescene.h deleted file mode 100644 index 9bbd3f9455e1cb71336d2c8ddc523db08aaf3415..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/graphicstoragescene.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GraphicResourceScene.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Nov 12, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/graphicstoragescene.h $ - * - */ - -#ifndef GRAPHICSTORAGESCENE_H -#define GRAPHICSTORAGESCENE_H - -#include <QWidget> -#include "ui_graphicstoragescene.h" -#include <QGraphicsScene> -#include "GraphicTimeLine.h" - -class Controller; - -class GraphicStorageScene : public QGraphicsScene -{ - Q_OBJECT - -public: - GraphicStorageScene(Controller *controller); - ~GraphicStorageScene(); - - int getTimeLineWidth(void) {return static_cast<int>(itsTimeLine->getWidth());} - int getTimeLineZeroPos(void) const {return itsTimeLineZeroPos;} - -private: - Ui::GraphicStorageSceneClass ui; - QGraphicsView *itsParentView; - Controller *itsController; - GraphicTimeLine *itsTimeLine; - int itsTimeLineZeroPos; // corresponds to time line zero position -}; - -#endif // GRAPHICSTORAGESCENE_H diff --git a/SAS/Scheduler/src/graphicstoragescene.ui b/SAS/Scheduler/src/graphicstoragescene.ui deleted file mode 100644 index 46a62c86a6a361cce2a6376123aa574046f5a186..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/graphicstoragescene.ui +++ /dev/null @@ -1,19 +0,0 @@ -<ui version="4.0" > - <class>GraphicStorageSceneClass</class> - <widget class="QWidget" name="GraphicStorageSceneClass" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle" > - <string>GraphicStorageScene</string> - </property> - </widget> - <layoutdefault spacing="6" margin="11" /> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/icons/Symbol-Information.png b/SAS/Scheduler/src/icons/Symbol-Information.png deleted file mode 100644 index 2a2a29ca9939e077b076a900c747451a63a683ee..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/Symbol-Information.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/add_task.png b/SAS/Scheduler/src/icons/add_task.png deleted file mode 100644 index e90fcd2c99d9ff882b8fe7e2d0579d9290e9c9e3..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/add_task.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/align-left.png b/SAS/Scheduler/src/icons/align-left.png deleted file mode 100644 index fcb3edebcd09830221e276a9668f36eaa041b314..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/align-left.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/back.png b/SAS/Scheduler/src/icons/back.png deleted file mode 100644 index fdb06e9b0d0206c1355dc2e40bcaaa18e6df1391..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/back.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/clock.png b/SAS/Scheduler/src/icons/clock.png deleted file mode 100644 index 971702529482ec27bdf18990207c7014a66714e7..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/clock.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/close.png b/SAS/Scheduler/src/icons/close.png deleted file mode 100644 index c3665d456d9c115e92c9e52d2d99fb55c70facbd..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/close.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/close16x16.png b/SAS/Scheduler/src/icons/close16x16.png deleted file mode 100644 index a98aed36eaa720c5dfc8ab2dd9a2b3ec0ed1a693..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/close16x16.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/connect_datamonitor.png b/SAS/Scheduler/src/icons/connect_datamonitor.png deleted file mode 100644 index 736b538a13bc2661aac5e575ee32a92063172284..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/connect_datamonitor.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/create_initial_schedule.png b/SAS/Scheduler/src/icons/create_initial_schedule.png deleted file mode 100644 index 77853b1b44b77cf19c9c528699a2e7955eb339f5..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/create_initial_schedule.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/cross.png b/SAS/Scheduler/src/icons/cross.png deleted file mode 100644 index 445702cc8560ed0f7b7f43929eabc810695daa4e..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/cross.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/delete_task.png b/SAS/Scheduler/src/icons/delete_task.png deleted file mode 100644 index 8b148875cba13ab1ba0c174adcd265e9ded8e34b..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/delete_task.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/download.png b/SAS/Scheduler/src/icons/download.png deleted file mode 100644 index 680aaff8e4e576be78e5654ff822735f34c70a87..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/download.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/empty_trash.png b/SAS/Scheduler/src/icons/empty_trash.png deleted file mode 100644 index eebd749222f7e07394621b18d4e35b8eed3d3240..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/empty_trash.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/equalize.png b/SAS/Scheduler/src/icons/equalize.png deleted file mode 100644 index 431af9729e0fea3478899d1e706acdbc65aab34e..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/equalize.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/equalize_old.png b/SAS/Scheduler/src/icons/equalize_old.png deleted file mode 100644 index 57014111dbd4bad605d45d7650ea497ff6f2b6f5..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/equalize_old.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/find.png b/SAS/Scheduler/src/icons/find.png deleted file mode 100644 index 0700205d984d7c3fbd5cbd982e30f411cbf42096..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/find.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/full_trash.png b/SAS/Scheduler/src/icons/full_trash.png deleted file mode 100644 index 271ed8edcd3e185f34edc533ff34843c04db2abd..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/full_trash.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/load-balancing.png b/SAS/Scheduler/src/icons/load-balancing.png deleted file mode 100644 index 0a044a19eca5f1b8b8391e28e9b2c5fac1a93d86..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/load-balancing.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/new_schedule.png b/SAS/Scheduler/src/icons/new_schedule.png deleted file mode 100644 index c5391136cc0107091363179f6fb08c23c71ffa59..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/new_schedule.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/next.png b/SAS/Scheduler/src/icons/next.png deleted file mode 100644 index eeaf14efef00755762498579b8be99a9fc2d9ff2..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/next.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/open.png b/SAS/Scheduler/src/icons/open.png deleted file mode 100644 index d4699b4e2901ebe1ca93231e6236048565e78bcb..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/open.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/optimize.png b/SAS/Scheduler/src/icons/optimize.png deleted file mode 100644 index 51a380463c645a262361c9ecbb993c049cb0500a..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/optimize.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/optimize_OLD.png b/SAS/Scheduler/src/icons/optimize_OLD.png deleted file mode 100644 index 9f2618b317a3ac7bc305708514f57dfd76dbadcb..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/optimize_OLD.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/printer.png b/SAS/Scheduler/src/icons/printer.png deleted file mode 100644 index b6dc88dd19bd533b51cd9ca051299f2b738c6f78..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/printer.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/publish.png b/SAS/Scheduler/src/icons/publish.png deleted file mode 100644 index 69af88c3b79e53172cf910919c2ca36bfdf55790..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/publish.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/redo.png b/SAS/Scheduler/src/icons/redo.png deleted file mode 100644 index 80c0e111e4d85bd827c8c65a9e0f9978454e8d20..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/redo.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/remove.png b/SAS/Scheduler/src/icons/remove.png deleted file mode 100644 index bf40bbfcd4f7329623cebe21b10de777cb07b77d..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/remove.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/save.png b/SAS/Scheduler/src/icons/save.png deleted file mode 100644 index 59c53630dbcc4f04424d082f19570d297fed77d9..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/save.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/settings.png b/SAS/Scheduler/src/icons/settings.png deleted file mode 100644 index 13bbd81206fcbc04bcdffa757c1a4b2f3128723a..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/settings.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/settings_OLD.png b/SAS/Scheduler/src/icons/settings_OLD.png deleted file mode 100644 index 2f63e5e62adfd822209310dd84d3945aed89d667..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/settings_OLD.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/synchronize.png b/SAS/Scheduler/src/icons/synchronize.png deleted file mode 100644 index 6417d28c740cc92feb73c4fa2ba94830bd489fcf..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/synchronize.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/taskcolormode.png b/SAS/Scheduler/src/icons/taskcolormode.png deleted file mode 100644 index 5ea9d49baf9988db6c0e521ebcbbc2246232f04c..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/taskcolormode.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/undo.png b/SAS/Scheduler/src/icons/undo.png deleted file mode 100644 index 653c3796f2842c07ee96f4793a37b7abef9562ab..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/undo.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/zoomin.png b/SAS/Scheduler/src/icons/zoomin.png deleted file mode 100644 index 10b5d05ba3502b3d8d13007b39c3a369bb37fa38..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/zoomin.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/zoomin_old.png b/SAS/Scheduler/src/icons/zoomin_old.png deleted file mode 100644 index f0ed5165ba53b232b2777dd9e83a1a5c6c4daed8..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/zoomin_old.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/zoomout.png b/SAS/Scheduler/src/icons/zoomout.png deleted file mode 100644 index e96f72291300c499c994431de8ea34415666a1ea..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/zoomout.png and /dev/null differ diff --git a/SAS/Scheduler/src/icons/zoomout_old.png b/SAS/Scheduler/src/icons/zoomout_old.png deleted file mode 100644 index ac0d2da1b15cc4781ece1538246f84abe45e131d..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/icons/zoomout_old.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/back.png b/SAS/Scheduler/src/images/back.png deleted file mode 100644 index fdb06e9b0d0206c1355dc2e40bcaaa18e6df1391..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/back.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/close.png b/SAS/Scheduler/src/images/close.png deleted file mode 100644 index c3665d456d9c115e92c9e52d2d99fb55c70facbd..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/close.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/close16x16.png b/SAS/Scheduler/src/images/close16x16.png deleted file mode 100644 index a98aed36eaa720c5dfc8ab2dd9a2b3ec0ed1a693..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/close16x16.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/movie_track.png b/SAS/Scheduler/src/images/movie_track.png deleted file mode 100644 index 69af88c3b79e53172cf910919c2ca36bfdf55790..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/movie_track.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/next.png b/SAS/Scheduler/src/images/next.png deleted file mode 100644 index eeaf14efef00755762498579b8be99a9fc2d9ff2..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/next.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/printer.png b/SAS/Scheduler/src/images/printer.png deleted file mode 100644 index b6dc88dd19bd533b51cd9ca051299f2b738c6f78..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/printer.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/remove.png b/SAS/Scheduler/src/images/remove.png deleted file mode 100644 index bf40bbfcd4f7329623cebe21b10de777cb07b77d..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/remove.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/timeline_day.png b/SAS/Scheduler/src/images/timeline_day.png deleted file mode 100644 index d530160c8ef60019cdee89be53c109ab7153ee08..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/timeline_day.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/timeline_day_long.png b/SAS/Scheduler/src/images/timeline_day_long.png deleted file mode 100644 index 5f20b5b6277785d465b98828934861ded1bd9a4c..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/timeline_day_long.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/zoomin.png b/SAS/Scheduler/src/images/zoomin.png deleted file mode 100644 index f0ed5165ba53b232b2777dd9e83a1a5c6c4daed8..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/zoomin.png and /dev/null differ diff --git a/SAS/Scheduler/src/images/zoomout.png b/SAS/Scheduler/src/images/zoomout.png deleted file mode 100644 index ac0d2da1b15cc4781ece1538246f84abe45e131d..0000000000000000000000000000000000000000 Binary files a/SAS/Scheduler/src/images/zoomout.png and /dev/null differ diff --git a/SAS/Scheduler/src/imagingpipeline.cpp b/SAS/Scheduler/src/imagingpipeline.cpp deleted file mode 100644 index 364f1d138abd6ec99178e73ead0db6fe37eccf94..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/imagingpipeline.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * imagingpipeline.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/imagingpipeline.cpp $ - * - */ - -#include "imagingpipeline.h" - -ImagingPipeline::ImagingPipeline() - : Pipeline(), itsSpecifyFOV(true), itsSlicesPerImage(1), itsSubbandsPerImage(1), itsNrOfPixels(1024), itsFov(0) -{ - itsPipelineType = PIPELINE_IMAGING; - itsSASTree.setProcessSubtype(PST_IMAGING_PIPELINE); -} - -ImagingPipeline::ImagingPipeline(unsigned task_id) - : Pipeline(task_id), itsSpecifyFOV(true), itsSlicesPerImage(1), itsSubbandsPerImage(1), itsNrOfPixels(1024), itsFov(0) -{ - itsPipelineType = PIPELINE_IMAGING; - itsSASTree.setProcessSubtype(PST_IMAGING_PIPELINE); -} - -ImagingPipeline::ImagingPipeline(const QSqlQuery &query, const OTDBtree &SAS_tree) - : Pipeline(query, SAS_tree), itsSpecifyFOV(true), itsSlicesPerImage(1), itsSubbandsPerImage(1), itsNrOfPixels(1024), itsFov(0) -{ - itsPipelineType = PIPELINE_IMAGING; -} - -ImagingPipeline::ImagingPipeline(unsigned id, const OTDBtree &SAS_tree) - : Pipeline(id, SAS_tree), itsSpecifyFOV(true), itsSlicesPerImage(1), itsSubbandsPerImage(1), itsNrOfPixels(1024), itsFov(0) -{ - itsPipelineType = PIPELINE_IMAGING; -} - -ImagingPipeline::ImagingPipeline(bool specifyFOV, quint16 slicesPerImage, quint16 subbandsPerImage, quint16 nrOfPixels, - const double &fov, const QString &cellSize) - : Pipeline(), itsSpecifyFOV(specifyFOV), itsSlicesPerImage(slicesPerImage), itsSubbandsPerImage(subbandsPerImage), - itsNrOfPixels(nrOfPixels), itsFov(fov), itsCellSize(cellSize) -{ - itsPipelineType = PIPELINE_IMAGING; - itsSASTree.setProcessSubtype(PST_IMAGING_PIPELINE); -} - -QDataStream& operator>> (QDataStream &in, ImagingPipeline &task) { - if (in.status() == QDataStream::Ok) { - in >> static_cast<Pipeline &>(task); - in >> task.itsSpecifyFOV >> task.itsSlicesPerImage >> task.itsSubbandsPerImage - >> task.itsNrOfPixels >> task.itsCellSize >> task.itsFov; - task.calculateDataFiles(); - } - return in; -} - -QDataStream& operator<< (QDataStream &out, const ImagingPipeline &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const Pipeline &>(task); - out << task.itsSpecifyFOV << task.itsSlicesPerImage << task.itsSubbandsPerImage - << task.itsNrOfPixels << task.itsCellSize << task.itsFov; - } - return out; -} - -void ImagingPipeline::calculateDataSize(void) { - itsStorage->itsTotalDataSizekBytes = 0.0; - itsStorage->itsTotalBandWidth = 0.0; - - if (itsStorage->itsEnabledOutputData.skyImage) { - // nrImages = input_nrSubbands (= nr correlated ms input files) / ( nrSlicesPerImage * nrSubbandsPerImage ) - dataFileMap::const_iterator dit(itsStorage->itsInputDataFiles.find(DP_CORRELATED_UV)); - if (dit != itsStorage->itsInputDataFiles.end()) { - if ((itsSlicesPerImage != 0) && (itsSubbandsPerImage != 0)) { - unsigned nrInputSubbands(dit->second.second); - if (fmod((float)(nrInputSubbands), (float)itsSubbandsPerImage * itsSlicesPerImage) == 0) { - unsigned nrImages(nrInputSubbands / (itsSubbandsPerImage * itsSlicesPerImage)); - itsStorage->itsOutputDataFiles[DP_SKY_IMAGE] = std::pair<double, unsigned>(1000.0, nrImages); // TODO: add correct size calculation for SkyImage (See RedMine #3045) - clearConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - else setConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - else setConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - } - - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator it = itsStorage->itsOutputDataFiles.begin(); it != itsStorage->itsOutputDataFiles.end(); ++it) { - itsStorage->itsTotalDataSizekBytes += it->second.first * it->second.second; - } - - itsStorage->itsTotalBandWidth = (itsStorage->itsTotalDataSizekBytes * 8) / itsDuration.totalSeconds(); // kbit/sec -} - -bool ImagingPipeline::diff(const Task *other, task_diff &dif) const { - bool pipelineDif(Pipeline::diff(other, dif)); - - const ImagingPipeline *otherPipe = dynamic_cast<const ImagingPipeline *>(other); - if (otherPipe) { - dif.Imaging_nr_slices_per_image = itsSlicesPerImage != otherPipe->slicesPerImage() ? true : false; - dif.Imaging_nr_subbands_per_image = itsSubbandsPerImage != otherPipe->subbandsPerImage() ? true : false; - dif.Imaging_specify_fov = itsSpecifyFOV != otherPipe->specifyFov() ? true : false; - dif.Imaging_fov = itsFov != otherPipe->fov() ? true : false; - dif.Imaging_cellsize = itsCellSize != otherPipe->cellSize() ? true : false; - dif.Imaging_npix = itsNrOfPixels != otherPipe->nrOfPixels() ? true : false; - - return (pipelineDif || dif.Imaging_nr_slices_per_image || dif.Imaging_nr_subbands_per_image - || dif.Imaging_specify_fov || dif.Imaging_fov || dif.Imaging_npix || dif.Imaging_cellsize); - } - else return pipelineDif; -} - -QString ImagingPipeline::diffString(const task_diff &dif) const { - QString difstr(Pipeline::diffString(dif)); - if (!difstr.isEmpty()) difstr += ","; - - if (dif.Imaging_nr_slices_per_image) difstr += QString(SAS_item_names[TP_IMAGING_SLICES_PER_IMAGE]) + ","; - if (dif.Imaging_nr_subbands_per_image) difstr += QString(SAS_item_names[TP_IMAGING_SUBBANDS_PER_IMAGE]) + ","; - if (dif.Imaging_specify_fov) difstr += QString(SAS_item_names[TP_IMAGING_SPECIFY_FOV]) + ","; - if (dif.Imaging_fov) difstr += QString(SAS_item_names[TP_IMAGING_FOV]) + ","; - if (dif.Imaging_cellsize) difstr += QString(SAS_item_names[TP_IMAGING_CELLSIZE]) + ","; - if (dif.Imaging_npix) difstr += QString(SAS_item_names[TP_IMAGING_NPIX]) + ","; - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} diff --git a/SAS/Scheduler/src/imagingpipeline.h b/SAS/Scheduler/src/imagingpipeline.h deleted file mode 100644 index 8e76778c7e4497851c5cfbf71be50cbb9a8e83a1..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/imagingpipeline.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * imagingpipeline.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/imagingpipeline.h $ - * - */ - -#ifndef IMAGINGPIPELINE_H -#define IMAGINGPIPELINE_H - -#include "pipeline.h" - -class ImagingPipeline : public Pipeline -{ -public: - ImagingPipeline(); - ImagingPipeline(unsigned task_id); - ImagingPipeline(const QSqlQuery &query, const OTDBtree &SAS_tree); - ImagingPipeline(unsigned id, const OTDBtree &SAS_tree); - - ImagingPipeline(bool specifyFOV, quint16 slicesPerImage, quint16 subbandsPerImage, quint16 nrOfPixels, - const double &fov, const QString &cellSize); - - virtual void clone(const Task *other) { - if (this != other) { - const ImagingPipeline *pOther = dynamic_cast<const ImagingPipeline *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *pOther; - taskID = myTaskID; - } - } - } - - friend QDataStream& operator>> (QDataStream &in, ImagingPipeline &im); - friend QDataStream& operator<< (QDataStream &out, const ImagingPipeline &im); - - // getters - inline bool specifyFov(void) const {return itsSpecifyFOV;} - inline quint16 slicesPerImage(void) const {return itsSlicesPerImage;} - inline quint16 subbandsPerImage(void) const {return itsSubbandsPerImage;} - inline quint16 nrOfPixels(void) const {return itsNrOfPixels;} - inline const double &fov(void) const {return itsFov;} - inline const QString &cellSize(void) const {return itsCellSize;} - - // setters - void setSpecifyFov(bool enabled) {itsSpecifyFOV = enabled;} - void setSlicesPerImage(quint16 value) {itsSlicesPerImage = value;} - void setSubbandsPerImage(quint16 value) {itsSubbandsPerImage = value;} - void setNrOfPixels(quint16 value) {itsNrOfPixels = value;} - void setFov(const double &fov) {itsFov = fov;} - void setCellSize(const QString &cellsize) {itsCellSize = cellsize;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - - virtual void calculateDataSize(void); - -private: - bool itsSpecifyFOV; - quint16 itsSlicesPerImage, itsSubbandsPerImage, itsNrOfPixels; - double itsFov; - QString itsCellSize; -}; - -#endif // IMAGINGPIPELINE_H diff --git a/SAS/Scheduler/src/lofar_scheduler.h b/SAS/Scheduler/src/lofar_scheduler.h deleted file mode 100644 index b96fbc85aa5e82a674c9bc6b3a2242182f0c0d0d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/lofar_scheduler.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - * lofar_scheduler.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 20, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/lofar_scheduler.h $ - * - */ - -#ifndef LOFAR_SCHEDULER_H_ -#define LOFAR_SCHEDULER_H_ - -#define SCHEDULER_VERSION "v2.6" - -#define HAS_SAS_CONNECTION -#define DEBUG_SCHEDULER - -// undefine to compile away the debug output: -//#define QT_NO_DEBUG_OUTPUT - -//#undef Q_OS_UNIX -//#define Q_OS_WIN - -#include <vector> -#include <map> -#include <string> -#include <limits> - -#define FILE_WRITE_VERSION 10 - -#define J2000_EPOCH 2451545LL -// pi -#define PI 3.14159265358979323846264338327950288419716939937510 -#define PI_DIV2 1.57079632679489661923132169163975144209858469968755 -#define TWO_PI 6.28318530717958647692528676655900576839433879875021 - -#define RAD2GRAD 57.29577951308232087679815481410517033240547246656432 // 180/pi -#define GRAD2RAD 0.01745329251994329576923690768488612713442871888542 // pi/180 -// TODO: Ask Josh if the following constant is WSRT related and should thus be changed in a station dependent variable -// Sine of sun rise and sun set elevation for elevation = -0.7 deg -#define SINSUNRISESETEL -1.22170008352471688802e-2 -// Earth's rotation per hour in radians (needed for hour angle calculations) -//#define EARTH_RAD_PER_HOUR 2.61799387799149436539e-1 -//#define EARTH_RAD_PER_HOUR 15 -#define DU_LST_LINEAR 24.06570982441908 -#define DU_LST_CONST 18.697374558336 -#define LST_DU_LINEAR 4.15528975427151E-02 - -#define MINIMUM_CORRELATOR_INTEGRATION_TIME 0.1 // minimum correlator integration time in seconds (typically minimum is 0.1 sec) - -#define CLOCK160_SAMPLESPERSECOND 155648 -#define STR_CLOCK160_SAMPLESPERSECOND "155648" -#define CLOCK160_SAMPLECLOCK 160 -#define STR_CLOCK160_SAMPLECLOCK "160" -#define CLOCK200_SAMPLESPERSECOND 196608 -#define STR_CLOCK200_SAMPLESPERSECOND "196608" -#define CLOCK200_SAMPLECLOCK 200 -#define STR_CLOCK200_SAMPLECLOCK "200" - -// dataslot and RSP board limits -//#define MAX_DATASLOTS_2_BITS 1952 -#define MAX_DATASLOTS_4_BITS 976 -#define MAX_DATASLOTS_8_BITS 488 -#define MAX_DATASLOTS_16_BITS 244 -#define MAX_DATASLOT_PER_RSP_4_BITS 243 -#define MAX_DATASLOT_PER_RSP_8_BITS 121 -#define MAX_DATASLOT_PER_RSP_16_BITS 60 - -#define STORAGE_NODE_kbps 2000000 // units: kbit/sec -#define STORAGE_RAID_WRITE_KBS 4000000 // units: kByte/sec -#define STORAGE_FILL_PECENTAGE 90 -//#define DEFAULT_NAME_MASK "L${YEAR}_${MSNUMBER}/SB${SUBBAND}.MS" - -#define MULTIPLE_VALUE_TEXT "(MIXED)" -#define NOT_SET_TEXT "not set" - -// the file name masks and directory masks for the different output data products (data types) -#define NAMEMASK_COHERENT_STOKES "L${OBSID}_SAP${SAP}_B${BEAM}_S${STOKES}_P${PART}_bf.h5" -#define NAMEMASK_INCOHERENT_STOKES "L${OBSID}_SAP${SAP}_B${BEAM}_S${STOKES}_P${PART}_bf.h5" -#define NAMEMASK_CORRELATED "L${OBSID}_SAP${SAP}_SB${SUBBAND}_uv.MS" -#define NAMEMASK_INSTRUMENT_MODEL "L${OBSID}_SAP${SAP}_SB${SUBBAND}_inst.INST" -// TODO: Pulsar Pipeline: set the correct file name mask -#define NAMEMASK_PULSAR "L${OBSID}_SAP${SAP}_B${BEAM}_bf.tar.gz" -#define NAMEMASK_SKY_IMAGE "L${OBSID}_SBG${SBG}_sky.h5" -#define NAMEMASK_COHERENT_STOKES_TEST "T${OBSID}_SAP${SAP}_B${BEAM}_S${STOKES}_P${PART}_bf.h5" -#define NAMEMASK_INCOHERENT_STOKES_TEST "T${OBSID}_SAP${SAP}_B${BEAM}_S${STOKES}_P${PART}_bf.h5" -#define NAMEMASK_CORRELATED_TEST "T${OBSID}_SAP${SAP}_SB${SUBBAND}_uv.MS" -#define NAMEMASK_INSTRUMENT_MODEL_TEST "T${OBSID}_SAP${SAP}_SB${SUBBAND}_inst.INST" -// TODO: Pulsar Pipeline: set the correct file name mask for test -#define NAMEMASK_PULSAR_TEST "T${OBSID}_SAP${SAP}_B${BEAM}_bf.tar.gz" -#define NAMEMASK_SKY_IMAGE_TEST "T${OBSID}_SBG${SBG}_sky.IM" -#define NAMEMASK_TRIGGER_TEST "T${OBSID}_SAP${SAP}_B${BEAM}_S${STOKES}_P${PART}_bf.trigger" -#define DIRMASK_COHERENT_STOKES "L${OBSID}" -#define DIRMASK_INCOHERENT_STOKES "L${OBSID}" -#define DIRMASK_CORRELATED "L${OBSID}" -#define DIRMASK_TRIGGER "L${OBSID}" -#define DIRMASK_INSTRUMENT_MODEL "L${OBSID}" -#define DIRMASK_PULSAR "L${OBSID}" -#define DIRMASK_SKY_IMAGE "L${OBSID}" -#define DIRMASK_COHERENT_STOKES_TEST "L${OBSID}" -#define DIRMASK_INCOHERENT_STOKES_TEST "L${OBSID}" -#define DIRMASK_CORRELATED_TEST "L${OBSID}" -#define DIRMASK_TRIGGER_TEST "L${OBSID}" -#define DIRMASK_INSTRUMENT_MODEL_TEST "L${OBSID}" -#define DIRMASK_PULSAR_TEST "L${OBSID}" -#define DIRMASK_SKY_IMAGE_TEST "L${OBSID}" - - -class campaignInfo { -public: - unsigned id; - std::string name; - std::string title; - std::string PriInvestigator; - std::string CoInvestigator; - std::string contact; -}; - -typedef std::map<std::string ,campaignInfo> campaignMap; - -// DEFINE CONVENIENT TYPES - -// tableChanges will contain all changes made by the user in the table view -// its structure is: pair < pair< taskID, column>, change string> > -// first.first = task ID -// first.second = column -// second = changed value - -#define PROGRAM_DEFAULT_SETTINGS_FILENAME ".default_settings.set" -#define PROGRAM_PREFERENCES_FILENAME ".scheduler_preferences.pre" - -// The following two defines must be kept 'synchronized' -#define MIN_TIME_BETWEEN_TASKS_GREGORIAN AstroTime("00:15:00") -#define MIN_TIME_BETWEEN_TASKS_JULIAN 0.01041666666666666667 // approximately equals AstroTime("00:15:00") - -#define MAX_STATION_ID 20 -#define MAX_UNSIGNED std::numeric_limits<unsigned int>::max() -#define MAX_TASK_ID MAX_UNSIGNED - -#define MAX_DURATION_HOURS 1000 - -#define MAX_OPTIMIZE_ITERATIONS 1000 // the default maximum number of optimize iterations after which the optimizer will stop - -#define MAX_FILES_PER_STORAGE_NODE 20 // the default value for the maximum number of files to write per task to one storage node - -#define MAX_TASK_PENALTY 100 -#define MAX_DAY_TIME_PENALTY 100 // the maximum penalty assigned to a task when it is fully scheduled at day time -#define UNSCHEDULED_TASK_PENALTY 100 - -#define MIN_NR_SUBBANDS 0 -#define MAX_NR_SUBBANDS 248 - -#define SHIFT_RIGHT true -#define SHIFT_LEFT false - -void debugInfo( std::string szTypes, ... ); // debug info -void debugWarn( std::string szTypes, ... ); // debug warning -void debugErr( std::string szTypes, ...); // debug error - -// x = [0:1:100] = percentage of task scheduled at daytime -// y = night time weight factor (for penalty calculation [0.0, 1.0] -// curve 1: y = 1 ( in other words: task may not have overlap with daytime) -// curve 2: y = 1-c^-X // c = 1.1 -// curve 3: y = 1-c^-x // c = 1.04 -// curve 4: y = x -// curve 5: y = c^(x-100) - 0.019800040113920 // c = 1.04 -// curve 6: y = c^(x-100) - 0.000072565715901 // c = 1.1 -// curve 7: y = 0 ( in other words: task may be scheduled at daytime without penalty) - -// ATTENTION: The sequence of the following enumeration of data headers determines the column sequence of -// the scheduler's table view (amongst others) -enum data_headers { - TASK_ID = 0, - SAS_ID, - MOM_ID, - GROUP_ID, - PROJECT_ID, - TASK_NAME, - PLANNED_START, - PLANNED_END, - TASK_DURATION, - TASK_TYPE, - TASK_STATUS, - CLUSTER_NAME, - UNSCHEDULED_REASON, - TASK_DESCRIPTION, - STATION_ID, - RESERVATION_NAME, - PRIORITY, - FIXED_DAY, - FIXED_TIME, - FIRST_POSSIBLE_DATE, - LAST_POSSIBLE_DATE, - WINDOW_MINIMUM_TIME, - WINDOW_MAXIMUM_TIME, - ANTENNA_MODE, - CLOCK_FREQUENCY, - FILTER_TYPE, - NR_OF_SUBBANDS, - CONTACT_NAME, - CONTACT_PHONE, - CONTACT_EMAIL, - PREDECESSORS, - PRED_MIN_TIME_DIF, - PRED_MAX_TIME_DIF, - NIGHT_TIME_WEIGHT_FACTOR, - STORAGE_SIZE, - _END_DATA_HEADER_ENUM_ -}; -// define the labels of the columns (sequence has to match the sequence of the data_headers enumeration above. -#define NR_DATA_HEADERS _END_DATA_HEADER_ENUM_ -extern const char * DATA_HEADERS[NR_DATA_HEADERS]; - -typedef std::map <unsigned int, std::vector<data_headers> > errorTasksMap; - -enum selector_types { - SEL_ALL_TASKS, - SEL_OBSERVATIONS, - SEL_MAINTENANCE, - SEL_RESERVATION, - SEL_SYSTEM, - SEL_CALIBRATOR_PIPELINES, - SEL_TARGET_PIPELINES, - SEL_IMAGING_PIPELINES, - SEL_LONGBASELINE_PIPELINES, - SEL_PREPROCESSING_PIPELINES, - SEL_PULSAR_PIPELINES, - SEL_UNKNOWN -}; - -#endif /* LOFAR_SCHEDULER_H_ */ diff --git a/SAS/Scheduler/src/lofar_utils.cpp b/SAS/Scheduler/src/lofar_utils.cpp deleted file mode 100644 index 432f02212b236799039c92f49f2cc4c46e884ec1..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/lofar_utils.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/* - * lofar_utils.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 26-mrt-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/lofar_utils.cpp $ - * - */ - -#include "lofar_utils.h" -#include <iostream> // for std::setprecision() -#include <iomanip> // for std::setprecision() -#include <vector> -#include <algorithm> -#include <QStringList> -#include <sstream> -using std::stringstream; - -std::string trimBlanks(std::string const & s) -{ - if(s.empty()) return s; - int startIndex = s.find_first_not_of(" "); - if (startIndex != -1) { - return s.substr(startIndex, (s.find_last_not_of(" ") - startIndex + 1)); - } - else return std::string(""); -} - -std::string int2String(int i, const char *format) { - std::string str; - if (format) { - char buffer [50]; - sprintf (buffer, format, i); - str = buffer; - } - else { - std::stringstream out; - out << i; - str = out.str(); - } - return str; -} - -int string2Int(const std::string &s) { - int i(0); - std::istringstream myStream(s); - myStream >> i; - return i; -} - -std::string double2String(const long double &d, const char *format) { - std::string str; - if (format) { - char buffer [50]; - sprintf (buffer, format, d); - str = buffer; - } - else { - std::stringstream out; - out << std::setprecision(16) << d; - str = out.str(); - } - return str; -} - -long double string2Double(const std::string &s) { - long double d(0.0); - std::istringstream myStream(s); - myStream >> d; - return d; -} - -void write_string(std::ostream& out, const std::string & str) -{ - size_t size = str.length(); - out.write(reinterpret_cast<const char*>(&size), sizeof(size)); // write the length of the string - if (size) - out.write(str.c_str(), size); // writes only the characters without terminating null -} - -void read_string(std::istream& in, std::string & str) -{ - size_t size; - in.read(reinterpret_cast<char *>(&size), sizeof(size)); - char * pbuf = new char [size+1]; - if (size) - in.read(pbuf, size); - pbuf[size] = '\0'; - str = pbuf; - delete [] pbuf; -} - -void read_string(std::istream& in, QString & str) -{ - size_t size; - in.read(reinterpret_cast<char *>(&size), sizeof(size)); - char * pbuf = new char [size+1]; - if (size) - in.read(pbuf, size); - pbuf[size] = '\0'; - str = pbuf; - delete [] pbuf; -} - -// convert a vector containing unsigned numbers to a string that contains the list of numbers -// e.g. input vector contains 1,2,3,6,8,9 then the output string will be -// '[1..3,6,8,9]' (without the quotes) -QString Vector2StringList(const std::vector<unsigned> &vec) { - std::vector<unsigned> tmpVec(vec); - // sort the vector - std::sort(tmpVec.begin(),tmpVec.end()); - if (!tmpVec.empty()) { - QString outStr("["); - unsigned dsstart, dsstop, dsnext; - size_t idx; - if (tmpVec.size() >= 2) { - for (idx = 0; idx < tmpVec.size()-2; ++idx) { - dsstop = dsstart = tmpVec.at(idx); - dsnext = tmpVec.at(idx+1); - while (dsnext == dsstop + 1) { - dsstop = dsnext; - if (++idx == tmpVec.size()-1) break; // breaks out of loop if at end of element list - dsnext = tmpVec.at(idx+1); - } - if (dsstop == dsstart) { // single element - outStr += QString::number(dsstart) + ","; - } - else { // range - outStr += QString::number(dsstart) + ".." + QString::number(dsstop) + ","; - } - } - - if (idx < tmpVec.size()-1) { // adds the last two elements if necessary - outStr += QString::number(tmpVec.at(tmpVec.size()-2)) + "," - + QString::number(tmpVec.back()); - } - else if (idx < tmpVec.size()) { // adds the last element is necessary - outStr += QString::number(tmpVec.back()); - } - else { // delete the last comma - outStr = outStr.left(outStr.size()-1); - } - } - else if (tmpVec.size() == 1) { - outStr += QString::number(tmpVec.back()); - } - outStr += "]"; - return outStr; - } - else return QString(); -} - -// convert a list in a single string to a QStringList -std::vector<QString> string2VectorOfStrings(const QString &inputStr, const QChar &separator) { - std::vector<QString> strList; - QString tmp; - - if (!inputStr.isEmpty()) { - tmp = inputStr.trimmed(); - tmp.remove(QChar('"')); // remove all quotes from the string - tmp.remove(QChar('[')); - tmp.remove(QChar(']')); - QStringList strQList = tmp.split(separator, QString::SkipEmptyParts); - for (QStringList::const_iterator it = strQList.begin(); it != strQList.end(); ++it) { - strList.push_back(*it); - } - } - return strList; -} - -// convert a list of integers in a single string (e.g. [1,0,0,1,1] to a vector of bools -std::vector<bool> string2VectorOfBools(const QString &inputStr, const QChar &separator) { - std::vector<bool> strList; - QString tmp; - - if (!inputStr.isEmpty()) { - tmp = inputStr.trimmed(); - tmp.remove(QChar('"')); // remove all quotes from the string - tmp.remove(QChar('[')); - tmp.remove(QChar(']')); - QStringList strQList = tmp.split(separator, QString::SkipEmptyParts); - for (QStringList::const_iterator it = strQList.begin(); it != strQList.end(); ++it) { - strList.push_back(static_cast<bool>(it->toInt())); - } - } - return strList; -} - -QString stringListToVectorString(const QStringList &stringlist, bool noBrackets) { - if (!stringlist.empty()) { - QString outputStr; - if (!noBrackets) { - outputStr = "["; - } - for (int i = 0; i < stringlist.size()-1; ++i) { - outputStr += stringlist.at(i) + ","; - } - outputStr += stringlist.back(); - if (!noBrackets) { - outputStr += "]"; - } - return outputStr; - } - else { - if (noBrackets) return QString(); - else return QString("[]"); - } -} - -QString boolVector2StringVector(const std::vector<bool> &boolVec) { - if (!boolVec.empty()) { - QString outputStr("["); - for (unsigned i = 0; i < boolVec.size()-1; ++i) { - outputStr += QString::number(static_cast<int>(boolVec.at(i))) + ","; - } - outputStr += QString::number(static_cast<int>(boolVec.back())) + "]"; - return outputStr; - } - else return (QString("[]")); -} - -std::vector<unsigned> StringList2VectorOfUint(const QString &inputStr, bool &error, bool unique, bool sort) { - error = false; - std::vector<unsigned> vec; - QStringList strList; - QString tmp; - if (!inputStr.isEmpty()) { - tmp = inputStr.trimmed(); - if (tmp.size() > 2) { - tmp = tmp.remove("[").remove("]"); - strList = tmp.split(',',QString::SkipEmptyParts); - // we should now have a stringlist containing either individual numbers or a single ranges of numbers expressed as n..m - int pos; - unsigned sbstart, sbend, n1,n2; - for (QStringList::const_iterator it = strList.begin(); it != strList.end(); ++it) { - if ((pos = it->indexOf("..")) != -1) { // this is a range - n1 = it->left(pos).toUInt(); - n2 = it->mid(pos+2).toUInt(); - sbstart = std::min(n1,n2); - sbend = std::max(n1,n2); - for (unsigned sb = sbstart; sb <= sbend; ++sb) { - if (unique) { - if (std::find(vec.begin(), vec.end(), sb) != vec.end()) { - error = true; - } - } - vec.push_back(sb); - } - } - else { - if (unique) { - if (std::find(vec.begin(), vec.end(), it->toUInt()) != vec.end()) { - error = true; - } - } - vec.push_back(it->toUInt()); - } - } - } - } - // sort the vector - if (sort) { - std::sort(vec.begin(),vec.end()); - } - return vec; -} - - -std::string humanReadableUnits(const quint64 &inputsize, bool size_or_bandwidth, const QChar &units) { - std::stringstream sstr(""); - sstr << std::fixed << std::setprecision(1); - if (size_or_bandwidth == SIZE_UNITS) { - if (units == 'M') { - if (inputsize >= 1073741824) { - sstr << (float)inputsize / 1073741824; - return (sstr.str() + " PB"); - } - else if (inputsize >= 1048576) { - sstr << (float)inputsize / 1048576; - return (sstr.str() + " TB"); - } - else if (inputsize >= 1024) { - sstr << (float)inputsize / 1024; - return (sstr.str() + " GB"); - } - else { - sstr << inputsize; - return (sstr.str() + " MB"); - } - } - else { // if (units == 'k') - if (inputsize >= 1073741824) { - sstr << (float)inputsize / 1073741824; - return (sstr.str() + " TB"); - } - else if (inputsize >= 1048576) { - sstr << (float)inputsize / 1048576; - return (sstr.str() + " GB"); - } - else if (inputsize >= 1024) { - sstr << (float)inputsize / 1024; - return (sstr.str() + " MB"); - } - else { - sstr << inputsize; - return (sstr.str() + " kB"); - } - } - } - else { // bandwidth units - if (inputsize >= 1000000000) { - sstr << (float)inputsize / 1000000000; - return (sstr.str() + " Tbit/s"); - } - else if (inputsize >= 1000000) { - sstr << (float)inputsize / 1000000; - return (sstr.str() + " Gbit/s"); - } - else if (inputsize >= 1000) { - sstr << (float)inputsize / 1000; - return (sstr.str() + " Mbit/s"); - } - else { - sstr << inputsize; - return (sstr.str() + " kbit/s"); - } - } -} - - -std::string humanReadableUnits(const long double &inputsize, bool size_or_bandwidth, const QChar &units) { - std::stringstream sstr(""); - sstr << std::fixed << std::setprecision(1); - if (size_or_bandwidth == SIZE_UNITS) { - if (units == 'M') { - if (inputsize >= 1073741824.0) { - sstr << (float)inputsize / 1073741824.0; - return (sstr.str() + " PB"); - } - else if (inputsize >= 1048576.0) { - sstr << (float)inputsize / 1048576.0; - return (sstr.str() + " TB"); - } - else if (inputsize >= 1024.0) { - sstr << (float)inputsize / 1024.0; - return (sstr.str() + " GB"); - } - else { - sstr << inputsize; - return (sstr.str() + " MB"); - } - } - else { // if (units == 'k') - if (inputsize >= 1073741824.0) { - sstr << (float)inputsize / 1073741824.0; - return (sstr.str() + " TB"); - } - else if (inputsize >= 1048576.0) { - sstr << (float)inputsize / 1048576.0; - return (sstr.str() + " GB"); - } - else if (inputsize >= 1024.0) { - sstr << (float)inputsize / 1024.0; - return (sstr.str() + " MB"); - } - else { - sstr << inputsize; - return (sstr.str() + " kB"); - } - } - } - else { // bandwidth units - if (inputsize >= 1000000000.0) { - sstr << (float)inputsize / 1000000000.0; - return (sstr.str() + " Tbit/s"); - } - else if (inputsize >= 1000000.0) { - sstr << (float)inputsize / 1000000.0; - return (sstr.str() + " Gbit/s"); - } - else if (inputsize >= 1000.0) { - sstr << (float)inputsize / 1000.0; - return (sstr.str() + " Mbit/s"); - } - else { - sstr << inputsize; - return (sstr.str() + " kbit/s"); - } - } -} - diff --git a/SAS/Scheduler/src/lofar_utils.h b/SAS/Scheduler/src/lofar_utils.h deleted file mode 100644 index b23ce2c0b3107edbfc49cd013fda3ceecbf4ce24..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/lofar_utils.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * lofar_utils.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Mar 27, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/lofar_utils.h $ - * - */ - -#ifndef LOFAR_UTILS_H_ -#define LOFAR_UTILS_H_ - -#include <string> -#include <fstream> -#include <iostream> -#include <sstream> -#include <QString> -#include <QStringList> -#include <QDataStream> -#include "lofar_scheduler.h" - -#define SIZE_UNITS true -#define BANDWIDTH_UNITS false - -std::string trimBlanks(std::string const & s); - -template<typename T> -void write_primitive(std::ostream& out, const T& t) -{ - out.write(reinterpret_cast<const char*>(&t), sizeof(T)); -} - -template<typename T> -void read_primitive(std::istream& in, T& t) -{ - in.read(reinterpret_cast<char*>(&t), sizeof(T)); -} - -std::string int2String(int i, const char *format = 0); -int string2Int(const std::string &s); -std::string double2String(const long double &d, const char *format = 0); -long double string2Double(const std::string &s); -void write_string(std::ostream& out, const std::string & str); -void read_string(std::istream& in, std::string & str); -void read_string(std::istream& in, QString & str); -QString Vector2StringList(const std::vector<unsigned> &vec); -std::vector<QString> string2VectorOfStrings(const QString &inputStr, const QChar &separator = QChar(',')); -std::vector<bool> string2VectorOfBools(const QString &inputStr, const QChar &separator = QChar(',')); -QString stringListToVectorString(const QStringList &stringlist, bool noBrackets = false); -QString boolVector2StringVector(const std::vector<bool> &boolVec); -std::vector<unsigned> StringList2VectorOfUint(const QString &inputStr, bool &error, bool unique = true, bool sort = true); -// convert to human readable units. input can be kilobytes 'k' or Megabytes 'M' for sizes (i.e. size_or_bandwidth = SIZE_UNITS. -// for bandwidth only kbit/s can be used as input and the optional parameter units is not used -std::string humanReadableUnits(const long double &kilobytes, bool size_or_bandwidth = SIZE_UNITS, const QChar &units = 'k'); -std::string humanReadableUnits(const quint64 &kilobytes, bool size_or_bandwidth = SIZE_UNITS, const QChar &units = 'k'); - -inline QDataStream & operator>>(QDataStream &in, std::string &str) { - QString qstr; - in >> qstr; - str = qstr.toStdString(); - return in; -} - -inline QDataStream & operator<<(QDataStream &out, const std::string &str) { - out << QString(str.c_str()); - return out; -} - - -#endif /* LOFAR_UTILS_H_ */ diff --git a/SAS/Scheduler/src/longbaselinepipeline.cpp b/SAS/Scheduler/src/longbaselinepipeline.cpp deleted file mode 100644 index aff2906c207fc62984a114924b841b87acc1d5ef..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/longbaselinepipeline.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * LongBaselinePipeline.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/longbaselinepipeline.cpp $ - * - */ - -#include "longbaselinepipeline.h" - -LongBaselinePipeline::LongBaselinePipeline() - : Pipeline(), itsSubbandGroupsPerMS(1), itsSubbandsPerSubbandGroup(1) -{ - itsPipelineType = PIPELINE_LONGBASELINE; - itsSASTree.setProcessSubtype(PST_LONG_BASELINE_PIPELINE); -} - -LongBaselinePipeline::LongBaselinePipeline(unsigned task_id) - : Pipeline(task_id), itsSubbandGroupsPerMS(1), itsSubbandsPerSubbandGroup(1) -{ - itsPipelineType = PIPELINE_LONGBASELINE; - itsSASTree.setProcessSubtype(PST_LONG_BASELINE_PIPELINE); -} - -LongBaselinePipeline::LongBaselinePipeline(const QSqlQuery &query, const OTDBtree &SAS_tree) - : Pipeline(query, SAS_tree), itsSubbandGroupsPerMS(1), itsSubbandsPerSubbandGroup(1) -{ - itsPipelineType = PIPELINE_LONGBASELINE; -} - -LongBaselinePipeline::LongBaselinePipeline(unsigned id, const OTDBtree &SAS_tree) - : Pipeline(id, SAS_tree), itsSubbandGroupsPerMS(1), itsSubbandsPerSubbandGroup(1) -{ - itsPipelineType = PIPELINE_LONGBASELINE; -} - -LongBaselinePipeline::LongBaselinePipeline(quint16 subbandGroupsPerMS, quint16 subbandsPerSubbandGroup) - : Pipeline(), itsSubbandGroupsPerMS(subbandGroupsPerMS), itsSubbandsPerSubbandGroup(subbandsPerSubbandGroup) -{ - itsPipelineType = PIPELINE_LONGBASELINE; - itsSASTree.setProcessSubtype(PST_LONG_BASELINE_PIPELINE); -} - -QDataStream& operator>> (QDataStream &in, LongBaselinePipeline &task) { - if (in.status() == QDataStream::Ok) { - in >> static_cast<Pipeline &>(task); - in >> task.itsSubbandGroupsPerMS >> task.itsSubbandsPerSubbandGroup; - task.calculateDataFiles(); - } - return in; -} - -QDataStream& operator<< (QDataStream &out, const LongBaselinePipeline &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const Pipeline &>(task); - out << task.itsSubbandGroupsPerMS << task.itsSubbandsPerSubbandGroup; - } - return out; -} - -void LongBaselinePipeline::calculateDataSize(void) { - itsStorage->itsTotalDataSizekBytes = 0.0; - itsStorage->itsTotalBandWidth = 0.0; - - if (itsStorage->itsEnabledOutputData.correlated) { - // nrImages = (= nr correlated ms input files) / ( nrSubbandGroups * nrSubbandsPerMS ) - dataFileMap::const_iterator dit(itsStorage->itsInputDataFiles.find(DP_CORRELATED_UV)); - if (dit != itsStorage->itsInputDataFiles.end()) { - if ((itsSubbandGroupsPerMS != 0) && (itsSubbandsPerSubbandGroup != 0)) { - unsigned nrInputFiles(dit->second.second); - if (fmod((float)(nrInputFiles), (float)itsSubbandsPerSubbandGroup * itsSubbandGroupsPerMS) == 0) { - unsigned nrOutputFiles(nrInputFiles / (itsSubbandsPerSubbandGroup * itsSubbandGroupsPerMS)); - itsStorage->itsOutputDataFiles[DP_CORRELATED_UV] = std::pair<double, unsigned>(1000.0, nrOutputFiles); // TODO: add correct size calculation for the MS - clearConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - else setConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - else setConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - } - - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator it = itsStorage->itsOutputDataFiles.begin(); it != itsStorage->itsOutputDataFiles.end(); ++it) { - itsStorage->itsTotalDataSizekBytes += it->second.first * it->second.second; - } - - itsStorage->itsTotalBandWidth = (itsStorage->itsTotalDataSizekBytes * 8) / itsDuration.totalSeconds(); // kbit/sec -} - -bool LongBaselinePipeline::diff(const Task *other, task_diff &dif) const { - bool pipelineDif(Pipeline::diff(other, dif)); - - const LongBaselinePipeline *otherPipe = dynamic_cast<const LongBaselinePipeline *>(other); - if (otherPipe) { - dif.LongBaseline_nr_sbgroup_per_MS = itsSubbandGroupsPerMS != otherPipe->subbandGroupsPerMS() ? true : false; - dif.LongBaseline_nr_sb_per_sbgroup = itsSubbandsPerSubbandGroup != otherPipe->subbandsPerSubbandGroup() ? true : false; - - return (pipelineDif || dif.LongBaseline_nr_sbgroup_per_MS || dif.LongBaseline_nr_sb_per_sbgroup); - } - else return pipelineDif; -} - -QString LongBaselinePipeline::diffString(const task_diff &dif) const { - QString difstr(Pipeline::diffString(dif)); - if (!difstr.isEmpty()) difstr += ","; - - if (dif.LongBaseline_nr_sbgroup_per_MS) difstr += QString(SAS_item_names[TP_LONGBASELINE_SBGROUP_PER_MS]) + ","; - if (dif.LongBaseline_nr_sb_per_sbgroup) difstr += QString(SAS_item_names[TP_LONGBASELINE_SB_PER_SBGROUP]) + ","; - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} diff --git a/SAS/Scheduler/src/longbaselinepipeline.h b/SAS/Scheduler/src/longbaselinepipeline.h deleted file mode 100644 index 443d624c43dcb4aee91ef4f6e46aa56150632366..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/longbaselinepipeline.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * LongBaselinePipeline.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/longbaselinepipeline.h $ - * - */ - -#ifndef LongBaselinePipeline_H -#define LongBaselinePipeline_H - -#include "pipeline.h" - -class LongBaselinePipeline : public Pipeline -{ -public: - LongBaselinePipeline(); - LongBaselinePipeline(unsigned task_id); - LongBaselinePipeline(const QSqlQuery &query, const OTDBtree &SAS_tree); - LongBaselinePipeline(unsigned id, const OTDBtree &SAS_tree); - - LongBaselinePipeline(quint16 subbandGroupsPerMS, quint16 subbandsPerSubbandGroup); - - virtual void clone(const Task *other) { - if (this != other) { - const LongBaselinePipeline *pOther = dynamic_cast<const LongBaselinePipeline *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *pOther; - taskID = myTaskID; - } - } - } - - friend QDataStream& operator>> (QDataStream &in, LongBaselinePipeline &im); - friend QDataStream& operator<< (QDataStream &out, const LongBaselinePipeline &im); - - // getters - inline quint16 subbandGroupsPerMS(void) const {return itsSubbandGroupsPerMS;} - inline quint16 subbandsPerSubbandGroup(void) const {return itsSubbandsPerSubbandGroup;} - - // setters - void setSubbandGroupsPerMS(quint16 value) {itsSubbandGroupsPerMS = value;} - void setSubbandsPerSubbandGroup(quint16 value) {itsSubbandsPerSubbandGroup = value;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - - virtual void calculateDataSize(void); - -private: - quint16 itsSubbandGroupsPerMS, itsSubbandsPerSubbandGroup; -}; - -#endif // LongBaselinePipeline_H diff --git a/SAS/Scheduler/src/main.cpp b/SAS/Scheduler/src/main.cpp deleted file mode 100644 index be8e741fdffa76caaf619c65d0912e90fb58ee46..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * main.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 29, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/main.cpp $ - * - */ - - -#include "schedulerLib.h" - -//todo: -//#define SCHEDULER_TEST - -int main(int argc, char *argv[]) -{ - return main_function(argc, argv); -} diff --git a/SAS/Scheduler/src/neighboursolution.cpp b/SAS/Scheduler/src/neighboursolution.cpp deleted file mode 100644 index 1ab6d25be30ff6a410f7d923dd5c36a6a71b3a4c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/neighboursolution.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * neighboursolution.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 23, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/neighboursolution.cpp $ - * - */ - -#include <vector> -#include "neighboursolution.h" - -NeighbourSolution::NeighbourSolution() { -} - -NeighbourSolution::~NeighbourSolution() { -} - - -NeighbourSolution & NeighbourSolution::operator= (const SchedulerDataBlock &rhs) { - if (this != &rhs) { - *(static_cast<SchedulerDataBlock *>(this)) = rhs; - } - return *this; -} - -NeighbourSolution & NeighbourSolution::operator= (const NeighbourSolution &rhs) { - if (this != &rhs) { - *(static_cast<SchedulerDataBlock *>(this)) = rhs; - } - return *this; -} - -void NeighbourSolution::setChangedTasks(const std::vector<Task> & changedTasks) { - this->changedTasks = changedTasks; - calculateDeltaPenalty(); -} - -void NeighbourSolution::calculateDeltaPenalty() { - int penalty = 0; - for (std::vector<Task>::iterator it = changedTasks.begin(); it != changedTasks.end(); ++it) { - penalty += it->getPenalty(); - } -} - diff --git a/SAS/Scheduler/src/neighboursolution.h b/SAS/Scheduler/src/neighboursolution.h deleted file mode 100644 index 084c5e7dc5248469afd6761e6bb17bf486cdbf63..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/neighboursolution.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * neighboursolution.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 23, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/neighboursolution.h $ - * - */ - -#ifndef NEIGHBOURSOLUTION_H_ -#define NEIGHBOURSOLUTION_H_ - -#include "schedulerdatablock.h" -#include "task.h" - -class NeighbourSolution : public SchedulerDataBlock { -public: - NeighbourSolution(); - virtual ~NeighbourSolution(); - - NeighbourSolution & operator= (const SchedulerDataBlock &); - NeighbourSolution & operator= (const NeighbourSolution &); - - void addChangedTask(Task &task) { changedTasks.push_back(task); } - void setChangedTasks(const std::vector<Task> & changedTasks); - int getDeltaPenalty(void) const { return deltaPenalty; } - -private: - void calculateDeltaPenalty(); - -private: - std::vector<Task> changedTasks; - int deltaPenalty; -}; - -#endif /* NEIGHBOURSOLUTION_H_ */ diff --git a/SAS/Scheduler/src/observation.cpp b/SAS/Scheduler/src/observation.cpp deleted file mode 100644 index 96163df7c1bf6b755871c6154848064fe379c59c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/observation.cpp +++ /dev/null @@ -1,572 +0,0 @@ -/* - * observation.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/observation.cpp $ - * - */ - -#include "observation.h" -#include "Controller.h" -#include "taskstorage.h" - -Observation::Observation() - : StationTask(Task::OBSERVATION), itsReservation(0), itsNightTimeCurve(4), itsNrOfSubbands(0), itsTBBPiggybackAllowed(true), itsAartfaacPiggybackAllowed(true), itsStorage(0) -{ - itsStorage = new TaskStorage(this); - itsAnalogBeam.directionType = DIR_TYPE_J2000; -} - -Observation::Observation(unsigned id) - : StationTask(id, Task::OBSERVATION), itsReservation(0), itsNightTimeCurve(4), itsNrOfSubbands(0), itsTBBPiggybackAllowed(true), itsAartfaacPiggybackAllowed(true), itsStorage(0) -{ - itsStorage = new TaskStorage(this); - itsAnalogBeam.directionType = DIR_TYPE_J2000; -} - -Observation::Observation(const Observation &other) - : StationTask(other), itsReservation(other.itsReservation), itsAnalogBeam(other.itsAnalogBeam), - itsDigitalBeams(other.itsDigitalBeams), itsNightTimeCurve(other.itsNightTimeCurve), - itsNrOfSubbands(other.itsNrOfSubbands), itsTBBPiggybackAllowed(other.itsTBBPiggybackAllowed), itsAartfaacPiggybackAllowed(other.itsAartfaacPiggybackAllowed), - itsRTCPsettings(other.itsRTCPsettings), itsStorage(0) -{ - itsStorage = new TaskStorage(this, other.itsStorage); -} - -Observation::Observation(unsigned id, const OTDBtree &SAS_tree) - : StationTask(id, SAS_tree, Task::OBSERVATION), itsReservation(0), itsNightTimeCurve(4), itsNrOfSubbands(0), itsTBBPiggybackAllowed(true), itsAartfaacPiggybackAllowed(true), itsStorage(0) -{ - itsStorage = new TaskStorage(this); - itsAnalogBeam.directionType = DIR_TYPE_J2000; -} - -Observation::Observation(const QSqlQuery &query, const OTDBtree &SAS_tree) - : StationTask(query, SAS_tree, Task::OBSERVATION), itsReservation(0), itsNightTimeCurve(4), itsNrOfSubbands(0), itsTBBPiggybackAllowed(true), itsAartfaacPiggybackAllowed(true), itsStorage(0) -{ - itsStorage = new TaskStorage(this); - itsStorage->itsStorageSelectionMode = static_cast<storage_selection_mode>(query.value(query.record().indexOf("storageSelectionMode")).toInt()); - itsNightTimeCurve = query.value(query.record().indexOf("nightTimeWeightFactor")).toUInt(); - itsReservation = query.value(query.record().indexOf("reservation")).toUInt(); - itsAnalogBeam.directionType = DIR_TYPE_J2000; // default initialize value -} - -Observation::~Observation() { - delete itsStorage; -} - -QDataStream& operator<< (QDataStream &out, const Observation &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const StationTask &>(task); - - out << task.itsReservation - << task.itsAnalogBeam; - - // itsDigitalBeams - out << (quint32) task.itsDigitalBeams.size(); - for (std::map<unsigned, DigitalBeam>::const_iterator dit = task.itsDigitalBeams.begin(); dit != task.itsDigitalBeams.end(); ++dit) { - out << (quint16) dit->first // digital beam number - << dit->second; - } - - out << task.itsNightTimeCurve - << task.itsNrOfSubbands - << task.itsTBBPiggybackAllowed - << task.itsAartfaacPiggybackAllowed - << task.itsRTCPsettings - << *task.itsStorage; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, Observation &task) { - if (in.status() == QDataStream::Ok) { - in >> static_cast<StationTask &>(task); - - in >> task.itsReservation - >> task.itsAnalogBeam; - - // itsDigitalBeams - quint16 beamNr; - task.itsDigitalBeams.clear(); - DigitalBeam digBeam; - quint32 nrOfObjects; - in >> nrOfObjects; // number of digital beams - for (quint32 i = 0; i < nrOfObjects; ++i) { - digBeam.clear(); // resets the digiBeam - in >> beamNr >> digBeam; // digital beam number, digital beam object - task.itsDigitalBeams.insert(std::map<unsigned, DigitalBeam>::value_type(beamNr, digBeam)); - } - - in >> task.itsNightTimeCurve - >> task.itsNrOfSubbands - >> task.itsTBBPiggybackAllowed - >> task.itsAartfaacPiggybackAllowed - >> task.itsRTCPsettings; - - // itsStorage - delete task.itsStorage; - task.itsStorage = new TaskStorage(&task); - in >> *task.itsStorage; - - // calculate some info - task.calcTotalSubbands(); - task.calculateDataFiles(); // calculates the estimate for the total data size for this task - task.generateFileList(); - } - return in; -} - -Observation & Observation::operator=(const Task &other) { - if (this != &other) { - const StationTask *pOther = dynamic_cast<const StationTask *>(&other); - if (pOther) { - StationTask::operator=(other); - const Observation *pOtherObs = dynamic_cast<const Observation *>(&other); - if (pOtherObs) { - itsReservation = pOtherObs->itsReservation; - itsAnalogBeam = pOtherObs->itsAnalogBeam; - itsDigitalBeams = pOtherObs->itsDigitalBeams; - itsNightTimeCurve = pOtherObs->itsNightTimeCurve; - itsNrOfSubbands = pOtherObs->itsNrOfSubbands; - itsTBBPiggybackAllowed = pOtherObs->itsTBBPiggybackAllowed; - itsAartfaacPiggybackAllowed = pOtherObs->itsAartfaacPiggybackAllowed; - itsRTCPsettings = pOtherObs->itsRTCPsettings; - delete itsStorage; - itsStorage = new TaskStorage(this, pOtherObs->storage()); - } - } - } - return *this; -} - -QString Observation::getDigitalBeamSubbandStr(unsigned beam) const { - std::map<unsigned, DigitalBeam>::const_iterator it; - if ((it = itsDigitalBeams.find(beam)) != itsDigitalBeams.end()) { - return it->second.subbandsStr(); - } - else return QString(); -} - -unsigned Observation::nrRingTABs(void) const { - unsigned nrTabs(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - nrTabs += it->second.nrRingTABs(); - } - return nrTabs; -} - -unsigned Observation::nrTABrings(void) const { - unsigned nrTabRings(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - nrTabRings += it->second.nrTABrings(); - } - return nrTabRings; -} - -unsigned Observation::nrManualTABs(void) const { - unsigned nrTabs(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - nrTabs += it->second.nrManualTABs(); - } - return nrTabs; -} - -unsigned Observation::nrIncoherentTABs(void) const { - unsigned nrIncoherent(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - nrIncoherent += it->second.nrIncoherentTABs(); - } - return nrIncoherent; -} - -unsigned Observation::nrCoherentTABs(void) const { - unsigned nrCoherent(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - nrCoherent += it->second.nrCoherentTABs(); - } - return nrCoherent; -} - -void Observation::setSubbandNotationChange(unsigned beamNr, bool change) { - std::map<unsigned, DigitalBeam>::iterator it = itsDigitalBeams.find(beamNr); - if (it != itsDigitalBeams.end()) { - it->second.setSubbandNotationChange(change); - } -} - -void Observation::resetBeamDurations(void) { - for (std::map<unsigned, DigitalBeam>::iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - it->second.clearDuration(); - } -} - -// calculates the total number of subbands used by this task -void Observation::calcTotalSubbands(void) { - itsNrOfSubbands = 0; - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - itsNrOfSubbands += it->second.nrSubbands(); - } -} - -// calculates the estimated total output data size in kBytes -void Observation::calculateDataFiles(void) { - if (itsDuration.totalSeconds() > 0) { - calculateDataSize(); - } - else { - itsStorage->itsOutputDataFiles.clear(); - } -} - -void Observation::calculateDataSize(void) { - itsStorage->itsTotalDataSizekBytes = 0.0; - itsStorage->itsTotalBandWidth = 0.0; - - double SamplesPerSecond; - unsigned sizeOfFComplex(8), nrOfPolarizations(2), sizeOfShort(2); - unsigned totalFilesCoherent(0), totalFilesCoherentMin(0), totalFilesCoherentSummed(0), totalFilesIncoherent(0), totalFilesIncoherentSummed(0), - nrTabRings(0), nrCoherent(0), nrIncoherent(0), maxNrSubbandsCoherent(0), maxNrSubbandsIncoherent(0); - - if (itsClockFrequency == clock_160Mhz) SamplesPerSecond = CLOCK160_SAMPLESPERSECOND; - else SamplesPerSecond = CLOCK200_SAMPLESPERSECOND; - if (itsStorage->itsEnabledOutputData.coherentStokes || itsStorage->itsEnabledOutputData.incoherentStokes) { // = complex voltages i.e. Beamformed data product - // calculate the total number of Tied Array Beams (TAB) - (itsRTCPsettings.coherentType == DATA_TYPE_STOKES_IQUV) || (itsRTCPsettings.coherentType == DATA_TYPE_XXYY) ? nrCoherent = 4 : nrCoherent = 1; - itsRTCPsettings.incoherentType == DATA_TYPE_STOKES_IQUV ? nrIncoherent = 4 : nrIncoherent = 1; - for (std::map<unsigned, DigitalBeam>::const_iterator dbit = itsDigitalBeams.begin(); dbit != itsDigitalBeams.end(); ++dbit) { - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(dbit->second.tiedArrayBeams()); - for (std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.begin(); tit != tiedArrayBeams.end(); ++tit) { - if (tit->second.isCoherent()) { // coherent TAB, use coherentStokes.which parameter for the number of Stokes - maxNrSubbandsCoherent = std::max(maxNrSubbandsCoherent, dbit->second.nrSubbands()); - totalFilesCoherentMin = nrCoherent; - totalFilesCoherentSummed += totalFilesCoherentMin; - totalFilesCoherent += nrCoherent * static_cast<unsigned>(ceil(static_cast <float>(dbit->second.nrSubbands()) / itsRTCPsettings.coherentSubbandsPerFile)); - } - else { // incoherent TAB, use incoherentStokes.which parameter for the number of Stokes - totalFilesIncoherentSummed += nrIncoherent; - totalFilesIncoherent += nrIncoherent * static_cast<unsigned>(ceil(static_cast <float>(dbit->second.nrSubbands()) / itsRTCPsettings.incoherentSubbandsPerFile)); - maxNrSubbandsIncoherent = std::max(maxNrSubbandsIncoherent, dbit->second.nrSubbands()); - } - } - // add files due to nrTabs and tabRingSize specified in the digital beam (these are always coherent)+ - if (itsStorage->itsEnabledOutputData.coherentStokes) { - nrTabRings = dbit->second.nrTabRings(); - if (nrTabRings > 0) { - maxNrSubbandsCoherent = std::max(maxNrSubbandsCoherent, dbit->second.nrSubbands()); - totalFilesCoherentMin = (3 * nrTabRings * (nrTabRings + 1) + 1) * nrCoherent; - totalFilesCoherentSummed += totalFilesCoherentMin; - totalFilesCoherent += totalFilesCoherentMin * static_cast<unsigned>(ceil(static_cast <float>(dbit->second.nrSubbands()) / itsRTCPsettings.coherentSubbandsPerFile)); - } - // add files due to fly's eye - if (itsRTCPsettings.flysEye) { - maxNrSubbandsCoherent = std::max(maxNrSubbandsCoherent, dbit->second.nrSubbands()); - totalFilesCoherentMin = itsNrVirtualStations * nrCoherent; - totalFilesCoherentSummed += totalFilesCoherentMin; - totalFilesCoherent += totalFilesCoherentMin * static_cast<unsigned>(ceil(static_cast <float>(dbit->second.nrSubbands()) / itsRTCPsettings.coherentSubbandsPerFile)); - } - } - } - - if ((itsStorage->itsEnabledOutputData.coherentStokes) && totalFilesCoherent > 0) { - unsigned nrSubbandsPerFile = std::min((unsigned)itsRTCPsettings.coherentSubbandsPerFile, maxNrSubbandsCoherent); - double sizePerSubband; - if (itsRTCPsettings.coherentType == DATA_TYPE_XXYY) { - sizePerSubband = (SamplesPerSecond * 4) * itsDuration.totalSeconds() / 1024; - itsStorage->itsOutputDataFiles[DP_COHERENT_STOKES] = std::pair<double, unsigned>((double) nrSubbandsPerFile * sizePerSubband, totalFilesCoherent); // size per file, number of files - } - else { - sizePerSubband = (SamplesPerSecond * 4) / itsRTCPsettings.coherentTimeIntegrationFactor * itsDuration.totalSeconds() / 1024; - itsStorage->itsOutputDataFiles[DP_COHERENT_STOKES] = std::pair<double, unsigned>((double) nrSubbandsPerFile * sizePerSubband, totalFilesCoherent); // size per file, number of files - } - itsStorage->itsTotalDataSizekBytes += totalFilesCoherentSummed * maxNrSubbandsCoherent * sizePerSubband; - } - else { - itsStorage->itsOutputDataFiles.erase(DP_COHERENT_STOKES); - } - - if (itsStorage->itsEnabledOutputData.incoherentStokes && (totalFilesIncoherent > 0)) { - int channelIntegrationFactor = itsRTCPsettings.incoherentChannelsPerSubband > 0 ? itsRTCPsettings.channelsPerSubband / itsRTCPsettings.incoherentChannelsPerSubband : 1; - unsigned nrSubbandsPerFile = std::min((unsigned)itsRTCPsettings.incoherentSubbandsPerFile, maxNrSubbandsIncoherent); - double sizePerSubband = (SamplesPerSecond * 4) / itsRTCPsettings.incoherentTimeIntegrationFactor / channelIntegrationFactor * itsDuration.totalSeconds() / 1024; - itsStorage->itsOutputDataFiles[DP_INCOHERENT_STOKES] = std::pair<double, unsigned>((double) nrSubbandsPerFile * sizePerSubband, totalFilesIncoherent); // size per file, number of files - itsStorage->itsTotalDataSizekBytes += totalFilesIncoherentSummed * maxNrSubbandsIncoherent * sizePerSubband; - } - else { - itsStorage->itsOutputDataFiles.erase(DP_INCOHERENT_STOKES); - } - } - if (itsStorage->itsEnabledOutputData.correlated) { // UV data - // baselines * polarizations * samples * channels * (bytes/sample + overhead) - // where baselines = #stations * (#stations + 1) / 2 - // #stations can vary depending on superstations, splitted core stations, etc. - unsigned nrOfBaseLines = itsNrVirtualStations * (itsNrVirtualStations + 1)/2; - double integratedSeconds = floor(itsDuration.totalSeconds() / itsRTCPsettings.correlatorIntegrationTime); - - double headerSize(512); - double dataSize(nrOfBaseLines * itsRTCPsettings.channelsPerSubband * nrOfPolarizations * nrOfPolarizations * sizeOfFComplex); - dataSize = ceil(dataSize / 512) * 512; - double nSampleSize(nrOfBaseLines * itsRTCPsettings.channelsPerSubband * sizeOfShort); - nSampleSize = ceil(nSampleSize / 512) * 512; - double overhead(600000); // bytes - double fileSize(((dataSize + nSampleSize + headerSize) * integratedSeconds + overhead) / 1024); - itsStorage->itsOutputDataFiles[DP_CORRELATED_UV] = std::pair<double, unsigned>(fileSize, itsNrOfSubbands); - itsStorage->itsTotalDataSizekBytes += fileSize * itsNrOfSubbands; - } - else { - itsStorage->itsOutputDataFiles.erase(DP_CORRELATED_UV); - } - - // also remove any left-overs from possibly previously specified output data types that now have been switched off. - if (!itsStorage->itsEnabledOutputData.coherentStokes) { - itsStorage->itsOutputDataFiles.erase(DP_COHERENT_STOKES); - } - if (!itsStorage->itsEnabledOutputData.incoherentStokes) { - itsStorage->itsOutputDataFiles.erase(DP_INCOHERENT_STOKES); - } - - itsStorage->itsTotalBandWidth = (itsStorage->itsTotalDataSizekBytes * 8) / itsDuration.totalSeconds(); // kbit/sec -} - - -void Observation::setNightTimeWeightFactor(unsigned short curve) { - if ((curve >=1) & (curve <= 7)) { - itsNightTimeCurve = curve; - penaltyCalculationNeeded = true; - } - else { -//#ifdef DEBUG_SCHEDULER -// std::cerr << "Warning: night time weight factor must be integer between 1 and 7" << std::endl; -//#endif - } -} - - -bool Observation::diff(const Task *other, task_diff &dif) const { - bool stationTaskDif(StationTask::diff(other, dif)); - - const Observation *pOther = dynamic_cast<const Observation *>(other); - if (pOther) { - bool storageDif(itsStorage->diff(pOther->storage(), dif)); - - itsReservation != pOther->getReservation() ? dif.reservation = true : dif.reservation = false; - itsNightTimeCurve != pOther->getNightTimeWeightFactor() ? dif.night_time_weight_factor = true : dif.night_time_weight_factor = false; - itsAnalogBeam.angle1 != pOther->getAnalogBeam().angle1 ? dif.ana_beam_angle1 = true : dif.ana_beam_angle1 = false; - itsAnalogBeam.angle2 != pOther->getAnalogBeam().angle2 ? dif.ana_beam_angle2 = true : dif.ana_beam_angle2 = false; - itsAnalogBeam.directionType != pOther->getAnalogBeam().directionType ? dif.ana_beam_direction_type = true : dif.ana_beam_direction_type = false; - itsAnalogBeam.duration != pOther->getAnalogBeam().duration ? dif.ana_beam_duration = true : dif.ana_beam_duration = false; - itsAnalogBeam.startTime != pOther->getAnalogBeam().startTime ? dif.ana_beam_starttime = true : dif.ana_beam_starttime = false; - - // check the digital beams - dif.tiedarray_beam_settings = false; - const std::map<unsigned, DigitalBeam> &otherDigiBeams = pOther->getDigitalBeams(); - std::map<unsigned, DigitalBeam>::const_iterator oit; - if (otherDigiBeams.size() != itsDigitalBeams.size()) { - dif.digital_beam_settings = true; - } - else { - dif.digital_beam_settings = false; - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - oit = otherDigiBeams.find(it->first); - if (oit != otherDigiBeams.end()) { - if ((it->second.target() != oit->second.target()) || - (it->second.angle1() != oit->second.angle1()) || - (it->second.angle2() != oit->second.angle2()) || - (it->second.directionType() != oit->second.directionType()) || - (it->second.nrTABrings() != oit->second.nrTABrings()) || - (fabs(it->second.tabRingSize() - oit->second.tabRingSize()) > std::numeric_limits<double>::epsilon()) || - (it->second.duration() != oit->second.duration()) || - (it->second.startTime() != oit->second.startTime()) || - (it->second.subbandList() != oit->second.subbandList())) { - dif.digital_beam_settings = true; - break; - } - } - else { - dif.digital_beam_settings = true; - break; - } - } - } - - // check differences in tied array beams (which are properties of the digital beams) - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - oit = otherDigiBeams.find(it->first); - if (oit != otherDigiBeams.end()) { - // tied array beams of this digital beam - if (it->second.tiedArrayBeams() != oit->second.tiedArrayBeams()) {dif.tiedarray_beam_settings = true; break; } - } - else { - dif.tiedarray_beam_settings = true; - break; - } - } - dif.TBBPiggybackAllowed = itsTBBPiggybackAllowed != pOther->itsTBBPiggybackAllowed ? true : false; - dif.AartfaacPiggybackAllowed = itsAartfaacPiggybackAllowed != pOther->itsAartfaacPiggybackAllowed ? true : false; - // RTCP settings - dif.RTCP_correct_bandpass = itsRTCPsettings.correctBandPass != pOther->getRTCPsettings().correctBandPass ? true : false; - dif.RTCP_cor_int_time = itsRTCPsettings.correlatorIntegrationTime != pOther->getRTCPsettings().correlatorIntegrationTime ? true : false; - dif.RTCP_delay_compensation = itsRTCPsettings.delayCompensation != pOther->getRTCPsettings().delayCompensation ? true : false; - dif.RTCP_nr_bits_per_sample = itsRTCPsettings.nrBitsPerSample != pOther->getRTCPsettings().nrBitsPerSample ? true : false; - dif.RTCP_channels_per_subband = itsRTCPsettings.channelsPerSubband != pOther->getRTCPsettings().channelsPerSubband ? true : false; - dif.RTCP_pencil_flys_eye = itsRTCPsettings.flysEye != pOther->getRTCPsettings().flysEye ? true : false; - dif.RTCP_coherent_dedispersion = itsRTCPsettings.coherentDedisperseChannels != pOther->getRTCPsettings().coherentDedisperseChannels ? true : false; - - if ((itsRTCPsettings.coherentChannelsPerSubband != pOther->getRTCPsettings().coherentChannelsPerSubband) || - (itsRTCPsettings.coherentType != pOther->getRTCPsettings().coherentType) || - (itsRTCPsettings.coherentTimeIntegrationFactor != pOther->getRTCPsettings().coherentTimeIntegrationFactor) || - (itsRTCPsettings.coherentSubbandsPerFile != pOther->getRTCPsettings().coherentSubbandsPerFile)) - dif.RTCP_coherent_stokes_settings = true; - else dif.RTCP_coherent_stokes_settings = false; - if ((itsRTCPsettings.incoherentChannelsPerSubband != pOther->getRTCPsettings().incoherentChannelsPerSubband) || - (itsRTCPsettings.incoherentType != pOther->getRTCPsettings().incoherentType) || - (itsRTCPsettings.incoherentTimeIntegrationFactor != pOther->getRTCPsettings().incoherentTimeIntegrationFactor) || - (itsRTCPsettings.incoherentSubbandsPerFile != pOther->getRTCPsettings().incoherentSubbandsPerFile)) - dif.RTCP_incoherent_stokes_settings = true; - else dif.RTCP_incoherent_stokes_settings = false; - - // task_id on its own should not be detected as a change, only when other properties of that task need to be saved will task_id (if different) also be saved. - - return (stationTaskDif || storageDif || dif.reservation || dif.night_time_weight_factor - || dif.ana_beam_angle1 || dif.ana_beam_angle2 || dif.ana_beam_direction_type || dif.ana_beam_duration || dif.ana_beam_starttime - || dif.digital_beam_settings || dif.tiedarray_beam_settings || dif.RTCP_correct_bandpass || dif.RTCP_cor_int_time || dif.RTCP_delay_compensation - || dif.RTCP_nr_bits_per_sample || dif.RTCP_channels_per_subband || dif.RTCP_pencil_flys_eye || dif.RTCP_coherent_dedispersion - || dif.RTCP_coherent_stokes_settings || dif.RTCP_incoherent_stokes_settings || dif.TBBPiggybackAllowed || dif.AartfaacPiggybackAllowed); - } - return stationTaskDif; -} - -QString Observation::diffString(const task_diff &dif) const { - QString difstr(StationTask::diffString(dif)); - if (!difstr.isEmpty()) difstr += ","; - - if (dif.night_time_weight_factor) difstr += QString(SAS_item_names[TP_NIGHT_TIME_WEIGHT_FACTOR]) + ","; - if (dif.reservation) difstr += QString(SAS_item_names[TP_RESERVATION]) + ","; - if (dif.ana_beam_angle1 | dif.ana_beam_angle2 | dif.ana_beam_direction_type | dif.ana_beam_duration | dif.ana_beam_starttime) - difstr += QString(SAS_item_names[TP_ANA_BEAM_SETTINGS]) + ","; - if (dif.digital_beam_settings) difstr += QString(SAS_item_names[TP_DIGI_BEAM_SETTINGS]) + ","; - if (dif.tiedarray_beam_settings) difstr += QString(SAS_item_names[TP_TAB_SETTINGS]) + ","; - if (dif.RTCP_correct_bandpass) difstr += QString(SAS_item_names[TP_RTCP_BANDPASS_CORR]) + ","; - if (dif.RTCP_cor_int_time) difstr += QString(SAS_item_names[TP_RTCP_COR_INT_TIME]) + ","; - if (dif.RTCP_delay_compensation) difstr += QString(SAS_item_names[TP_RTCP_DELAY_COMP]) + ","; - if (dif.RTCP_nr_bits_per_sample) difstr += QString(SAS_item_names[TP_RTCP_BITS_PER_SAMPLE]) + ","; - if (dif.RTCP_channels_per_subband) difstr += QString(SAS_item_names[TP_RTCP_CHANNELS_PER_SUBBAND]) + ","; - if (dif.RTCP_pencil_flys_eye) difstr += QString(SAS_item_names[TP_RTCP_FLYS_EYE]) + ","; - if (dif.RTCP_coherent_dedispersion) difstr += QString(SAS_item_names[TP_RTCP_COHERENT_DEDISPERSION]) + ","; - if (dif.RTCP_incoherent_stokes_settings) difstr += QString(SAS_item_names[TP_RTCP_INCOHERENT_STOKES_SETTINGS]) + ","; - if (dif.RTCP_coherent_stokes_settings) difstr += QString(SAS_item_names[TP_RTCP_COHERENT_STOKES_SETTINGS]) + ","; - if (dif.TBBPiggybackAllowed) difstr += QString(SAS_item_names[TP_TBB_PIGGYBACK]) + ","; - if (dif.AartfaacPiggybackAllowed) difstr += QString(SAS_item_names[TP_AARTFAAC_PIGGYBACK]) + ","; - - difstr += itsStorage->diffString(dif); - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} - -void Observation::doCalculatePenalty() { - - // x = [0:1:100] = percentage of task scheduled at daytime - // y = night time weight factor (for penalty calculation [0.0, 1.0] - // curve 1: y = 1 ( in other words: task may not be scheduled during daytime) - // curve 2: y = 1-c^-x // c = 1.1 - // curve 3: y = 1-c^-x // c = 1.04 - // curve 4: y = x - // curve 5: y = c^(x-100) - 0.019800040113920 // c = 1.04 - // curve 6: y = c^(x-100) - 0.000072565715901 // c = 1.1 - // curve 7: y = 0 ( in other words: task may be scheduled at daytime without penalty) - - // penalty contribution of (partially) day time scheduling - itsPenalty = 0; - if (!itsStations.empty()) { - double dayOverlap(0), wf(0); - - if (itsDuration > 0.5) { // no penalty for scheduling during day if duration is more than 12 hours - penaltyCalculationNeeded = false; - return; - } - - if ( (scheduledStart >= Controller::theSchedulerSettings.getEarliestSchedulingDay()) & - (scheduledEnd <= Controller::theSchedulerSettings.getLatestSchedulingDay()) ) { - - for (taskStationsMap::const_iterator it = itsStations.begin(); it != itsStations.end(); ++it) { - double startDaySunRise = Controller::theSchedulerSettings.getStationSunRise(it->second, scheduledStart); - double startDaySunSet = Controller::theSchedulerSettings.getStationSunSet(it->second, scheduledStart); - double endDaySunRise = Controller::theSchedulerSettings.getStationSunRise(it->second, scheduledEnd); - double endDaySunSet = Controller::theSchedulerSettings.getStationSunSet(it->second, scheduledEnd); - - dayOverlap = 0; - - //step 1: calculate overlap with day time at both start and end of observation - - if ((scheduledStart > startDaySunRise) & (scheduledStart < startDaySunSet)) { // start during day? - if (scheduledEnd < startDaySunSet) { // ends also during same day? - dayOverlap = itsDuration.toJulian(); - } - else { // ends during night - dayOverlap = startDaySunSet - scheduledStart.toJulian(); - } - } - - if ((scheduledEnd > endDaySunRise) & (scheduledEnd < endDaySunSet)) { // end during day? - if (scheduledStart > endDaySunRise) { // starts also during same day? - dayOverlap = itsDuration.toJulian(); - } - else { - dayOverlap += scheduledEnd.toJulian() - endDaySunRise; - } - } - // step 2: calculate overlap percentage according to task duration - double overlapRatio = dayOverlap / itsDuration.toJulian(); - - // step 3: calculate night time weight factor according to user chosen curve (1 to 7) (this is factor y) - //TODO re-determine the different night time weight factor curves to work with ratio overlap in stead of percentage overlap - switch (itsNightTimeCurve) { - case 1: - wf = 1; - break; - case 2: - wf = 1 - pow(1.1, -overlapRatio); - break; - case 3: - wf = 1 - pow(1.04, -overlapRatio); - break; - case 4: - default: - wf = overlapRatio; - break; - case 5: - wf = pow(1.04, overlapRatio - 100) - 0.019800040113920; - break; - case 6: - wf = pow(1.1, overlapRatio - 100) - 0.000072565715901; - break; - case 7: - wf = 0; - break; - } - // step 4: calculate penalty contribution for partially day time scheduling with: - // penalty contribution = d * y, where d is the maximum penalty for full day time scheduling - - itsPenalty += static_cast<int>(MAX_DAY_TIME_PENALTY * wf); - } - itsPenalty /= itsStations.size(); - penaltyCalculationNeeded = false; - } - else { - debugWarn("sis","Task: ",taskID, " penalty calculation aborted because task is out of schedule bounds"); - } - } - else { - debugWarn("sis","Task: ",taskID, " penalty calculation aborted because task does not have stations defined"); - } -} - - diff --git a/SAS/Scheduler/src/observation.h b/SAS/Scheduler/src/observation.h deleted file mode 100644 index 6144dd5945f6fcbe71c49eef12969d3538bcb050..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/observation.h +++ /dev/null @@ -1,248 +0,0 @@ -/* - * observation.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/observation.h $ - * - */ - -#ifndef OBSERVATION_H -#define OBSERVATION_H - -#include "stationtask.h" -#include "Angle.h" -#include "DigitalBeam.h" -#include "taskstorage.h" - -class Observation : public StationTask -{ - friend class TaskStorage; - -public: - enum ref_frame { - J2000, - B1950, - REF_FRAME_END - }; - - class analogBeamSettings { - friend QDataStream& operator>> (QDataStream &in, analogBeamSettings &beam) { - if (in.status() == QDataStream::Ok) { - in >> beam.angle1; - in >> beam.angle2; - quint8 beamDirType; - in >> beamDirType; - beam.directionType = (beamDirectionType) beamDirType; - in >> beam.duration; - in >> beam.startTime; - } - return in; - } - - friend QDataStream& operator<< (QDataStream &out, const analogBeamSettings &beam) { - if (out.status() == QDataStream::Ok) { - out << beam.angle1 - << beam.angle2 - << (quint8) beam.directionType - << beam.duration - << beam.startTime; - } - return out; - } - - public: - Angle angle1; - Angle angle2; - beamDirectionType directionType; - AstroTime startTime; - AstroTime duration; - }; - - class RTCPsettings { - public: - RTCPsettings() : correctBandPass(false), delayCompensation(false), coherentDedisperseChannels(false), flysEye(false), - channelsPerSubband(64), coherentChannelsPerSubband(0), incoherentChannelsPerSubband(0), - coherentSubbandsPerFile(512), incoherentSubbandsPerFile(512), coherentType(DATA_TYPE_STOKES_I), incoherentType(DATA_TYPE_STOKES_I), - coherentTimeIntegrationFactor(1), incoherentTimeIntegrationFactor(1), correlatorIntegrationTime(1.0), nrBitsPerSample(16) - { } - - friend QDataStream& operator>> (QDataStream &in, RTCPsettings &rtcp) { - in >> rtcp.correctBandPass >> rtcp.delayCompensation >> rtcp.coherentDedisperseChannels >> rtcp.flysEye - >> rtcp.channelsPerSubband >> rtcp.coherentChannelsPerSubband >> rtcp.incoherentChannelsPerSubband - >> rtcp.coherentSubbandsPerFile >> rtcp.incoherentSubbandsPerFile; - quint8 data_type; - in >> data_type; - rtcp.coherentType = (dataTypes) data_type; - in >> data_type; - rtcp.incoherentType = (dataTypes) data_type; - in >> rtcp.coherentTimeIntegrationFactor >> rtcp.incoherentTimeIntegrationFactor - >> rtcp.correlatorIntegrationTime >> rtcp.nrBitsPerSample; - return in; - } - - friend QDataStream& operator<< (QDataStream &out, const RTCPsettings &rtcp) { - out << rtcp.correctBandPass << rtcp.delayCompensation << rtcp.coherentDedisperseChannels << rtcp.flysEye - << rtcp.channelsPerSubband << rtcp.coherentChannelsPerSubband << rtcp.incoherentChannelsPerSubband - << rtcp.coherentSubbandsPerFile << rtcp.incoherentSubbandsPerFile - << (quint8)rtcp.coherentType << (quint8)rtcp.incoherentType - << rtcp.coherentTimeIntegrationFactor << rtcp.incoherentTimeIntegrationFactor - << rtcp.correlatorIntegrationTime << rtcp.nrBitsPerSample; - - return out; - } - - bool operator!=(const RTCPsettings &other) const { - return ((correctBandPass != other.correctBandPass) || - (delayCompensation != other.delayCompensation) || - (coherentDedisperseChannels != other.coherentDedisperseChannels) || - (flysEye != other.flysEye) || - (channelsPerSubband != other.channelsPerSubband) || - (coherentChannelsPerSubband != other.coherentChannelsPerSubband) || - (incoherentChannelsPerSubband != other.incoherentChannelsPerSubband) || - (coherentSubbandsPerFile != other.coherentSubbandsPerFile) || - (incoherentSubbandsPerFile != other.incoherentSubbandsPerFile) || - (coherentType != other.coherentType) || - (incoherentType != other.incoherentType) || - (coherentTimeIntegrationFactor != other.coherentTimeIntegrationFactor) || - (incoherentTimeIntegrationFactor != other.incoherentTimeIntegrationFactor) || - (correlatorIntegrationTime != other.correlatorIntegrationTime) || - (nrBitsPerSample != other.nrBitsPerSample)); - } - - bool correctBandPass, delayCompensation, coherentDedisperseChannels; - bool flysEye; - quint16 channelsPerSubband, coherentChannelsPerSubband, incoherentChannelsPerSubband, coherentSubbandsPerFile, incoherentSubbandsPerFile; - dataTypes coherentType, incoherentType; - quint16 coherentTimeIntegrationFactor, incoherentTimeIntegrationFactor; - double correlatorIntegrationTime; - quint8 nrBitsPerSample; - - }; - - Observation(); - Observation(const Observation &); - Observation(unsigned task_id); - Observation(unsigned id, const OTDBtree &SAS_tree); - Observation(const QSqlQuery &query, const OTDBtree &SAS_tree); - - ~Observation(); - - virtual Observation & operator=(const Task &other); - - friend QDataStream& operator<< (QDataStream &out, const Observation &task); - friend QDataStream& operator>> (QDataStream &in, Observation &task); - - virtual void clone(const Task *other) { - if (this != other) { - const Observation *pOther = dynamic_cast<const Observation *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *other; - taskID = myTaskID; - } - } - } - - // getters - const std::map<unsigned, DigitalBeam> &getDigitalBeams(void) const {return itsDigitalBeams;} - QString getDigitalBeamSubbandStr(unsigned beam) const; - const analogBeamSettings &getAnalogBeam(void) const {return itsAnalogBeam;} - const superStationMap &getSuperStations(void) const {return itsSuperStations;} - unsigned getNrOfDataslotsPerRSPboard(void) const {return itsNrOfDataslotsPerRSPboard;} - unsigned getNrOfBeams(void) const { return itsDigitalBeams.size(); } - unsigned short getNightTimeWeightFactor(void) const { return itsNightTimeCurve; } - const RTCPsettings & getRTCPsettings(void) const {return itsRTCPsettings;} - unsigned getReservation() const { return itsReservation; } // returns the reservation ID (0 = not part of reservation) - bool getTBBPiggybackAllowed(void) const {return itsTBBPiggybackAllowed;} - bool getAartfaacPiggybackAllowed(void) const {return itsAartfaacPiggybackAllowed;} - unsigned short getBitMode(void) const {return itsRTCPsettings.nrBitsPerSample;} - unsigned getNrOfSubbands(void) const { return itsNrOfSubbands; } - unsigned nrRingTABs(void) const; - unsigned nrTABrings(void) const; - unsigned nrManualTABs(void) const; - unsigned totalNrTABs(void) const {return nrRingTABs() + nrManualTABs();} - unsigned nrIncoherentTABs(void) const; - unsigned nrCoherentTABs(void) const; - virtual const std::vector<storageResult> &getStorageCheckResult(void) const { return itsStorage->getStorageCheckResult(); } - - // setters - inline void setAnalogBeamSettings(const analogBeamSettings &analog_beam) {itsAnalogBeam = analog_beam;} - inline void setAnalogBeamDirectionType(const beamDirectionType &dirType) {itsAnalogBeam.directionType = dirType;} - inline void setAnalogBeamAngle1(const double &radian) {itsAnalogBeam.angle1.setRadianAngle(radian);} - inline void setAnalogBeamAngle2(const double &radian) {itsAnalogBeam.angle2.setRadianAngle(radian);} - inline void setAnalogBeamAngle1(const Angle &angle) {itsAnalogBeam.angle1 = angle;} - inline void setAnalogBeamAngle2(const Angle &angle) {itsAnalogBeam.angle2 = angle;} - inline void setAnalogBeamStartTime(int seconds) {itsAnalogBeam.startTime.clearTime(); itsAnalogBeam.startTime.addSeconds(seconds);} - inline void setAnalogBeamDuration(int seconds) {itsAnalogBeam.duration.clearTime(); itsAnalogBeam.duration.addSeconds(seconds);} - inline void setNrOfDataslotsPerRSPboard(unsigned nrDataslotsPerRSPboard) {itsNrOfDataslotsPerRSPboard = nrDataslotsPerRSPboard;} - inline void setTBBPiggybackAllowed(bool TBBPiggybackAllowed) {itsTBBPiggybackAllowed = TBBPiggybackAllowed;} - inline void setAartfaacPiggybackAllowed(bool aartfaacPiggybackAllowed) {itsAartfaacPiggybackAllowed = aartfaacPiggybackAllowed;} - inline void setRTCPsettings(const RTCPsettings &RTCP_settings) {itsRTCPsettings = RTCP_settings; /*itsRecalcStorageNeeded = true;*/} - - inline void setChannelsPerSubband(unsigned channels) {itsRTCPsettings.channelsPerSubband = channels;} - inline void setBitsPerSample(unsigned short bits_per_sample) {itsRTCPsettings.nrBitsPerSample = bits_per_sample;} - inline void setIncoherentDataType(dataTypes data_type) {itsRTCPsettings.incoherentType = data_type;} - inline void setCoherentDataType(dataTypes data_type) {itsRTCPsettings.coherentType = data_type;} - inline void setIncoherentTimeIntegration(unsigned ti_factor) {itsRTCPsettings.incoherentTimeIntegrationFactor = ti_factor;} - inline void setCoherentTimeIntegration(unsigned ti_factor) {itsRTCPsettings.coherentTimeIntegrationFactor = ti_factor;} - inline void setCoherentChannelsPerSubband(unsigned cps) {itsRTCPsettings.coherentChannelsPerSubband = cps;} - inline void setIncoherentChannelsPerSubband(unsigned cps) {itsRTCPsettings.incoherentChannelsPerSubband = cps;} - inline void setCoherentSubbandsPerFile(unsigned subbands_per_file) {itsRTCPsettings.coherentSubbandsPerFile = subbands_per_file;} - inline void setIncoherentSubbandsPerFile(unsigned subbands_per_file) {itsRTCPsettings.incoherentSubbandsPerFile = subbands_per_file;} - inline void setBandPassCorrection(bool enabled) {itsRTCPsettings.correctBandPass = enabled;} - inline void setDelayCompensation(bool enabled) {itsRTCPsettings.delayCompensation = enabled;} - - inline void setCorrelatorIntegrationTime(const double &integration_time) {itsRTCPsettings.correlatorIntegrationTime = integration_time;} - inline void setFlysEye(bool enabled) {itsRTCPsettings.flysEye = enabled;} - inline void setCoherentDedispersion(bool enabled) {itsRTCPsettings.coherentDedisperseChannels = enabled;} - // sets the properties a digital beam. If the beam does not yet exist it will be created - void resetBeamDurations(void); - void setDigitalBeam(unsigned beamNr, const DigitalBeam &beam) {itsDigitalBeams[beamNr] = beam; calcTotalSubbands(); /*itsRecalcStorageNeeded = true;*/} - void setDigitalBeams(const std::map<unsigned, DigitalBeam> &digitalBeams) {itsDigitalBeams = digitalBeams; calcTotalSubbands(); /*itsRecalcStorageNeeded = true;*/} - void clearDigitalBeams(void) {itsDigitalBeams.clear(); itsNrOfSubbands = 0; /*itsRecalcStorageNeeded = true;*/} - void deleteDigitalBeam(unsigned beamNr) {itsDigitalBeams.erase(beamNr); calcTotalSubbands(); /*itsRecalcStorageNeeded = true;*/} // deletes the digital beam with index beamNr - void setSubbandNotationChange(unsigned beamNr, bool change); - void setNightTimeWeightFactor(unsigned short curve); - inline void setReservation(unsigned reservationID) {itsReservation = reservationID;} - - const std::map<dataProductTypes, TaskStorage::outputDataProduct> &generateFileList(void) {return itsStorage->generateFileList();} - - // calculate the output data sizes for observations - virtual void calculateDataFiles(void); - inline bool hasStorage(void) const {return itsStorage != 0;} - TaskStorage *storage(void) {return itsStorage;} - const TaskStorage *storage(void) const {return itsStorage;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - -private: - virtual void doCalculatePenalty(); - -private: - // calculates the total number of subbands used by this task and stores it in itsNrOfSubbands - void calcTotalSubbands(void); - // calculates the amount of data files and their sizes that will be written to the storage nodes - void calculateDataSize(void); - -private: - quint32 itsReservation; - analogBeamSettings itsAnalogBeam; - std::map<unsigned, DigitalBeam> itsDigitalBeams; - quint8 itsNightTimeCurve; // (curve 1-7) the weight factor curve is used to calculate the penalty for daytime scheduling - quint16 itsNrOfSubbands; // the total number of sub bands used by this task - bool itsTBBPiggybackAllowed, itsAartfaacPiggybackAllowed; - - // RTCP settings - RTCPsettings itsRTCPsettings; - - // storage settings - TaskStorage *itsStorage; -}; - -#endif // OBSERVATION_H diff --git a/SAS/Scheduler/src/parsettreeviewer.cpp b/SAS/Scheduler/src/parsettreeviewer.cpp deleted file mode 100644 index 2b901dbe4e06510f333256f5f5eb54d75e0a09d9..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/parsettreeviewer.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * parsettreeviewer.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 10-June-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/parsettreeviewer.cpp $ - * Description : The parset tree viewer is a dialog that shows the complete SAS OTDB tree of a single observation - * - */ - -#include "parsettreeviewer.h" - -ParsetTreeViewer::ParsetTreeViewer(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); - ui.treeWidget->setColumnCount(2); - ui.treeWidget->setColumnWidth(0,400); - QStringList labels; - labels << "Node / Key" << "Value"; - ui.treeWidget->setHeaderLabels(labels); -} - -ParsetTreeViewer::~ParsetTreeViewer() -{ - -} - -QString ParsetTreeViewer::commaWordWrap(const QString &str, int wrapLength, const QChar &wrapChar) const { - QString tempStr = str; - int len = str.length(), pos = (wrapLength > 1) ? wrapLength-1:1, tempPos; - while (pos < len-1) { - - tempPos = pos; - while (tempStr.at(tempPos) != wrapChar && tempPos > 0) { - tempPos--; - } - if (tempPos > 0) pos = tempPos; - - tempStr.insert(pos+1, '\n'); - pos += wrapLength+1; - } - - return tempStr; -} - -void ParsetTreeViewer::view(QString parset, const OTDBtree &otdb_tree) { - if (!parset.isEmpty()) { - ui.treeWidget->clear(); - parset.remove("LOFAR."); - parset.remove("ObsSW."); - QStringList lines(parset.split("\n", QString::SkipEmptyParts)); - lines.sort(); - - if (otdb_tree.treeID()) { - // add meta data from the OTDB tree - lines += QString("current status in SAS=") + sasStateString(otdb_tree.state()).c_str(); - lines += QString("actual start time=") + otdb_tree.startTime().toString().c_str(); - lines += QString("actual stop time=") + otdb_tree.stopTime().toString().c_str(); - lines += QString("creation date=") + otdb_tree.creationDate().toString().c_str(); - lines += QString("modified date=") + otdb_tree.modificationDate().toString().c_str(); - lines += QString("SAS ID=") + QString::number(otdb_tree.treeID()); - lines += QString("group ID=") + QString::number(otdb_tree.groupID()); - lines += QString("MoM ID=") + QString::number(otdb_tree.momID()); - lines += QString("parent template=") + QString::number(otdb_tree.originalTree()); - lines += QString("campaign=") + otdb_tree.campaign().c_str(); - lines += QString("processType=") + otdb_tree.processType(); - lines += QString("processSubType=") + PROCESS_SUBTYPES[otdb_tree.processSubType()]; - lines += QString("strategy=") + otdb_tree.strategy(); - } - - QStringList key_value_pair, prev_line, current_line, item_pair; - QTreeWidgetItem *newItem; - QList<QTreeWidgetItem *> parents, prevParents; - QString value, tooltip; - int idx, nrElements; - for (QStringList::iterator it = lines.begin()+1; it != lines.end(); ++it) { - key_value_pair = it->split('='); // key_value_pair.first() = full node/key parset name, key_value_pair.last() = value - if (key_value_pair.size() > 1) { - value = key_value_pair.last(); - } - else value = ""; - current_line = key_value_pair.first().split('.'); - prevParents = parents; - parents.clear(); - idx = 0; - nrElements = current_line.size(); - while (idx < nrElements) { // while not arrived at last element and not beyond the length of the previous line - if (idx < prev_line.size()) { // if not beyond the number of elements in the previous line - if (current_line.at(idx) != prev_line.at(idx)) { // if the item on this position is different from the item on that position of the previous line - // insert element - if (idx+1 == nrElements) { - item_pair << current_line.at(idx) << value; - tooltip = commaWordWrap(item_pair.first() + " = " + value,100); - } - else { - item_pair << current_line.at(idx); - tooltip = item_pair.first(); - } - - if (parents.empty()) newItem = new QTreeWidgetItem(ui.treeWidget, item_pair); - else newItem = new QTreeWidgetItem(parents.last(), item_pair); - newItem->setToolTip(0,tooltip); - newItem->setToolTip(1,tooltip); - parents.push_back(newItem); - item_pair.clear(); - } - else parents.push_back(prevParents.at(idx)); - } - else { - // insert element - if (idx+1 == nrElements) { - item_pair << current_line.at(idx) << value; - tooltip = commaWordWrap(item_pair.first() + " = " + value,100); - } - else { - item_pair << current_line.at(idx); - tooltip = item_pair.first(); - } - - if (parents.empty()) newItem = new QTreeWidgetItem(ui.treeWidget, item_pair); - else newItem = new QTreeWidgetItem(parents.last(), item_pair); - newItem->setToolTip(0,tooltip); - newItem->setToolTip(1,tooltip); - parents.push_back(newItem); - item_pair.clear(); - } - ++idx; - } - prev_line = current_line; - } - this->show(); - } -} diff --git a/SAS/Scheduler/src/parsettreeviewer.h b/SAS/Scheduler/src/parsettreeviewer.h deleted file mode 100644 index 3513c74294a28d17057dc23cd26205f9a8a01b97..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/parsettreeviewer.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * parsettreeviewer.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 10-June-2011 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/parsettreeviewer.h $ - * Description : The parset tree viewer is a dialog that shows the complete SAS OTDB tree of a single observation - * - */ - -#ifndef PARSETTREEVIEWER_H -#define PARSETTREEVIEWER_H - -#include <QDialog> -#include "ui_parsettreeviewer.h" -#include "OTDBtree.h" - -class ParsetTreeViewer : public QDialog -{ - Q_OBJECT - -public: - ParsetTreeViewer(QWidget *parent = 0); - ~ParsetTreeViewer(); - - void view(QString parset, const OTDBtree &otdb_tree = OTDBtree()); - -private: - QString commaWordWrap(const QString &str, int wrapLength, const QChar &wrapChar = ',') const; - - -private: - Ui::ParsetTreeViewerClass ui; -}; - -#endif // PARSETTREEVIEWER_H diff --git a/SAS/Scheduler/src/parsettreeviewer.ui b/SAS/Scheduler/src/parsettreeviewer.ui deleted file mode 100644 index 80dd9185f119eb614f32ccaa0b2e991ae906fb21..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/parsettreeviewer.ui +++ /dev/null @@ -1,68 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>ParsetTreeViewerClass</class> - <widget class="QDialog" name="ParsetTreeViewerClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>818</width> - <height>712</height> - </rect> - </property> - <property name="windowTitle"> - <string>ParsetTreeViewer</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="2"> - <widget class="QTreeWidget" name="treeWidget"> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButton"> - <property name="text"> - <string>Close</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButton</sender> - <signal>clicked()</signal> - <receiver>ParsetTreeViewerClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>789</x> - <y>693</y> - </hint> - <hint type="destinationlabel"> - <x>803</x> - <y>707</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/pipeline.cpp b/SAS/Scheduler/src/pipeline.cpp deleted file mode 100644 index 6cbb5030516410964bf63537085bfba8ba218363..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/pipeline.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * pipeline.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/pipeline.cpp $ - * - */ - -#include "pipeline.h" - -Pipeline::Pipeline() - : Task(), itsStorage(0), itsPipelineType(PIPELINE_UNKNOWN) -{ - itsTaskType = Task::PIPELINE; - itsStorage = new TaskStorage(this); -} - -Pipeline::Pipeline(const Pipeline &other) - : Task(other), itsStorage(0), itsPipelineType(other.pipelinetype()) -{ - itsTaskType = Task::PIPELINE; - itsStorage = new TaskStorage(this, other.storage()); -} - -Pipeline::Pipeline(unsigned task_id) - : Task(task_id), itsStorage(0), itsPipelineType(PIPELINE_UNKNOWN) -{ - itsTaskType = Task::PIPELINE; - itsStorage = new TaskStorage(this); - itsStorage->setOwner(this); -} - -Pipeline::Pipeline(const QSqlQuery &query, const OTDBtree &SAS_tree) -: Task(query, SAS_tree), itsPipelineType(PIPELINE_UNKNOWN) -{ - itsTaskType = Task::PIPELINE; - itsStorage = new TaskStorage(this); - itsStorage->itsStorageSelectionMode = static_cast<storage_selection_mode>(query.value(query.record().indexOf("storageSelectionMode")).toInt()); -} - -Pipeline::Pipeline(unsigned id, const OTDBtree &SAS_tree) -: Task(id, SAS_tree), itsPipelineType(PIPELINE_UNKNOWN) -{ - itsTaskType = Task::PIPELINE; - itsStorage = new TaskStorage(this); -} - -Pipeline::~Pipeline() -{ - delete itsStorage; -} - - -QDataStream& operator<< (QDataStream &out, const Pipeline &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const Task &>(task); - - // itsStorage - out << *task.itsStorage; - // itsPipelineType - out << (quint8) task.itsPipelineType; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, Pipeline &task) { - if (in.status() == QDataStream::Ok) { - in >> static_cast<Task &>(task); - - // itsStorage - delete task.itsStorage; - task.itsStorage = new TaskStorage(&task); - in >> *task.itsStorage; - // itsPipelineType - quint8 type; - in >> type; - task.itsPipelineType = (pipelineType) type; - } - return in; -} - - -// calculates the estimated total output data size in kBytes -void Pipeline::calculateDataFiles(void) { - if (itsDuration.totalSeconds() > 0) { - calculateDataSize(); - } - else { - itsStorage->itsOutputDataFiles.clear(); - } -} -/* -void Pipeline::calculateDataSize(void) { - itsStorage->itsTotalDataSizekBytes = 0.0; - itsStorage->itsTotalBandWidth = 0.0; - if (itsStorage->itsEnabledOutputData.correlated) { // pipeline will write reduced correlated data - dataFileMap::const_iterator dit(itsStorage->itsInputDataFiles.find(DP_CORRELATED_UV)); - if (dit != itsInputDataFiles.end()) { - unsigned reductionFactor = itsDemixingSettings.freqStep * itsDemixingSettings.timeStep; - const double &inputSize(dit->second.first); - double outputFileSize(0.0); - if (reductionFactor) { - double data_size(inputSize / reductionFactor); - outputFileSize = data_size + data_size/64 * (1 + reductionFactor) + data_size/2; - } - itsOutputDataFiles[DP_CORRELATED_UV] = std::pair<double, unsigned>(outputFileSize ,dit->second.second); - } - } - if (itsEnabledOutputData.instrumentModel) { - // number of files always equal to number of input (correlated) files (nr files equals nr of subbands) - // i.e. for each input correlated file specified to the pipeline as an input data product the pipeline generated an output instrumentmodel file - // instrument data files get determined when the task goes to the SCHEDULED state (see Controller::doScheduleChecks() ) - dataFileMap::const_iterator dit(itsInputDataFiles.find(DP_CORRELATED_UV)); // the number of instrumentModel files created equals the number of input correlated files - if (dit != itsInputDataFiles.end()) { - // TODO: add correct size calculation for instrument model - itsOutputDataFiles[DP_INSTRUMENT_MODEL] = std::pair<double, unsigned>(1000.0, dit->second.second); // for now we set the size of one file to 1MB, which is about correct (small files) - } - } - // TODO: pulsar integration: set the correct number of ouptut files and file size estimate for the pulsar pipeline - if (itsEnabledOutputData.pulsar) { - unsigned totalNrOutputFiles(0); - // the number of pulsar outputfiles is equal to the sum of coherent and incoherent input files - dataFileMap::const_iterator dit(itsInputDataFiles.find(DP_COHERENT_STOKES)); // the number of pulsar outputfiles created for now set equal to the number of input coherent - if (dit != itsInputDataFiles.end()) { - // itsRTCPsettings.coherentType for the pulsar pipeline is set to the predecessor it's coherent data type in Controller::setInputFilesForPipeline - if (itsRTCPsettings.coherentType == DATA_TYPE_XXYY) { // for complex voltages the 'polarizations' XXYY are tarred into one output file - totalNrOutputFiles += dit->second.second / 4; - } - else { - totalNrOutputFiles += dit->second.second; - } - } - dit = itsInputDataFiles.find(DP_INCOHERENT_STOKES); - if (dit != itsInputDataFiles.end()) { - totalNrOutputFiles += dit->second.second; - } - - itsOutputDataFiles[DP_PULSAR] = std::pair<double, unsigned>(1000.0, totalNrOutputFiles); - } - if (itsEnabledOutputData.skyImage) { - // nrImages = input_nrSubbands (= nr correlated ms input files) / ( nrSlicesPerImage * nrSubbandsPerImage ) - dataFileMap::const_iterator dit(itsInputDataFiles.find(DP_CORRELATED_UV)); - if (dit != itsInputDataFiles.end()) { - if ((itsImagingSettings.slicesPerImage != 0) && (itsImagingSettings.subbandsPerImage != 0)) { - unsigned nrInputSubbands(dit->second.second); - if (fmod((float)(nrInputSubbands), (float)itsImagingSettings.subbandsPerImage * itsImagingSettings.slicesPerImage) == 0) { - unsigned nrImages(nrInputSubbands / (itsImagingSettings.subbandsPerImage * itsImagingSettings.slicesPerImage)); - itsOutputDataFiles[DP_SKY_IMAGE] = std::pair<double, unsigned>(1000.0, nrImages); // TODO: add correct size calculation for SkyImage (See RedMine #3045) - clearConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - else setConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - else setConflict(CONFLICT_NON_INTEGER_OUTPUT_FILES); - } - } - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator it = itsOutputDataFiles.begin(); it != itsOutputDataFiles.end(); ++it) { - itsTotalDataSizekBytes += it->second.first * it->second.second; - } - itsTotalBandWidth = (itsTotalDataSizekBytes * 8) / itsDuration.totalSeconds(); // kbit/sec -} -*/ - -bool Pipeline::diff(const Task *other, task_diff &dif) const { - bool taskDif(Task::diff(other, dif)); - - const Pipeline *otherPipe(dynamic_cast<const Pipeline *>(other)); - if (otherPipe) { - bool storageDif(itsStorage->diff(otherPipe->storage(), dif)); - return (taskDif || storageDif); - } - else return taskDif; -} - - -// TODO: I have seen this exact function on three other classes -// Copy paste code smell -QString Pipeline::diffString(const task_diff &dif) const { - QString difstr(Task::diffString(dif)); - - if (!difstr.isEmpty()) difstr += ","; - - difstr += itsStorage->diffString(dif); - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} - diff --git a/SAS/Scheduler/src/pipeline.h b/SAS/Scheduler/src/pipeline.h deleted file mode 100644 index fc25dd20e9fc11d10c7c5d0ee1c2d7ab83b6d6b9..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/pipeline.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * pipeline.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/pipeline.h $ - * - */ - -#ifndef PIPELINE_H -#define PIPELINE_H - -#include "storage_definitions.h" -#include "taskstorage.h" -#include "task.h" -#include "demixingsettings.h" -#include "OTDBtree.h" - -class Pipeline : public Task -{ -public: - friend class TaskStorage; - - Pipeline(); - Pipeline(const Pipeline &); - Pipeline(unsigned task_id); - Pipeline(const QSqlQuery &query, const OTDBtree &SAS_tree); - Pipeline(unsigned id, const OTDBtree &SAS_tree); - - ~Pipeline(); - - friend QDataStream& operator<< (QDataStream &out, const Pipeline &task); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, Pipeline &task); // used for reading data from binary file - - Pipeline & operator=(const Pipeline &other) { - if (this != &other) { - Task::operator=(other); - itsPipelineType = other.itsPipelineType; - delete itsStorage; - itsStorage = new TaskStorage(this, other.storage()); - } - return *this; - } - - virtual void clone(const Task *other) { - if (this != other) { - const Pipeline *pOther = dynamic_cast<const Pipeline *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *pOther; - taskID = myTaskID; - } - } - } - - pipelineType pipelinetype(void) const {return itsPipelineType;} - bool isCalibrationPipeline(void) const {return itsPipelineType == PIPELINE_CALIBRATION;} - bool isImagingPipeline(void) const {return itsPipelineType == PIPELINE_IMAGING;} - bool isPulsarPipeline(void) const {return itsPipelineType == PIPELINE_PULSAR;} - bool isLongBaselinePipeline(void) const {return itsPipelineType == PIPELINE_LONGBASELINE;} - - // calculate the output data sizes for pipeline - const std::map<dataProductTypes, TaskStorage::outputDataProduct> &generateFileList(void) {return itsStorage->generateFileList();} - - virtual const std::vector<storageResult> &getStorageCheckResult(void) const { return itsStorage->getStorageCheckResult(); } - inline bool hasStorage(void) const {return true;} - TaskStorage *storage(void) {return itsStorage;} - const TaskStorage *storage(void) const {return itsStorage;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - - void calculateDataFiles(void); - -private: - virtual void calculateDataSize(void) {} - - -protected: - TaskStorage *itsStorage; - pipelineType itsPipelineType; -}; - -#endif // PIPELINE_H diff --git a/SAS/Scheduler/src/publishdialog.cpp b/SAS/Scheduler/src/publishdialog.cpp deleted file mode 100755 index 7c29e3936fe466ba4dc0f3006a997405200e9522..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/publishdialog.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * publishdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Dec 8, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/publishdialog.cpp $ - * - */ - -#include "publishdialog.h" -#include "Controller.h" -#include "schedulersettings.h" -#include <QMessageBox> - -PublishDialog::PublishDialog(QWidget *parent) - : QDialog(parent), select(true) -{ - ui.setupUi(this); - connect(ui.pushButton_select, SIGNAL(clicked()), this, SLOT(toggleSelection())); -} - -PublishDialog::~PublishDialog() -{ - -} - -void PublishDialog::show(void) { - ui.listWidget_Weeks->setFocus(); - this->showNormal(); -} - -void PublishDialog::toggleSelection(void) { - if (select) { - ui.listWidget_Weeks->selectAll(); - ui.pushButton_select->setText("Select none"); - select = false; - } - else { - ui.listWidget_Weeks->clearSelection(); - ui.pushButton_select->setText("Select all"); - select = true; - } - ui.listWidget_Weeks->setFocus(); -} - -void PublishDialog::accept(void) { - itsPublishWeeks.clear(); - AstroDate monday; - for (int idx = 0; idx != ui.listWidget_Weeks->count(); ++idx) { - if (ui.listWidget_Weeks->item(idx)->isSelected()) { - monday = ui.listWidget_Weeks->item(idx)->data(200).toInt(); - itsPublishWeeks.push_back(std::pair<unsigned, AstroDate>(monday.getWeek(), monday)); - } - } - if (!itsPublishWeeks.empty()) { - this->hide(); - emit goPublish(itsPublishWeeks); - } -} - -void PublishDialog::initPublishDialog(void) { - ui.listWidget_Weeks->clear(); - const scheduleWeekVector &weeks = Controller::theSchedulerSettings.getScheduleWeeks(); - QString weekStr; - - for (scheduleWeekVector::const_iterator it = weeks.begin(); it != weeks.end(); ++it) { - weekStr=""; - weekStr = QString(int2String(it->first).c_str()) + QString(", starting on Monday ") + QString(it->second.toString().c_str()); - QListWidgetItem * item = new QListWidgetItem(weekStr); - item->setData(200, it->second.toJulian()); // store the date of Monday as an int (julian day) in the listwidget item for later comparison - ui.listWidget_Weeks->addItem(item); - } -} diff --git a/SAS/Scheduler/src/publishdialog.h b/SAS/Scheduler/src/publishdialog.h deleted file mode 100755 index be94450b8f8895032b5e2708c20980b496ab32e7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/publishdialog.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * publishdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Dec 8, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/publishdialog.h $ - * - */ - -#ifndef PUBLISHDIALOG_H -#define PUBLISHDIALOG_H - -#include <QDialog> -#include <QFileInfo> -#include "ui_publishdialog.h" -#include "schedulersettings.h" - -class PublishDialog : public QDialog -{ - Q_OBJECT - -public: - PublishDialog(QWidget *parent = 0); - ~PublishDialog(); - - // put the correct week numbers and dates in the publish week selection dialog - void initPublishDialog(void); - void show(void); - -private: - void accept(void); - -signals: - void goPublish(const scheduleWeekVector &); - -private slots: - void toggleSelection(void); - -private: - Ui::PublishDialogClass ui; - scheduleWeekVector itsPublishWeeks; - bool select; -}; - -#endif // PUBLISHDIALOG_H diff --git a/SAS/Scheduler/src/publishdialog.ui b/SAS/Scheduler/src/publishdialog.ui deleted file mode 100755 index 8c6cb4dcdbfce5900fe127afbcea177d97d635e7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/publishdialog.ui +++ /dev/null @@ -1,89 +0,0 @@ -<ui version="4.0" > - <class>PublishDialogClass</class> - <widget class="QDialog" name="PublishDialogClass" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>285</width> - <height>224</height> - </rect> - </property> - <property name="windowTitle" > - <string>Publish schedule</string> - </property> - <layout class="QGridLayout" name="gridLayout" > - <item row="0" column="0" colspan="3" > - <widget class="QLabel" name="label" > - <property name="text" > - <string>Please select the weeks to publish</string> - </property> - </widget> - </item> - <item row="1" column="0" colspan="3" > - <widget class="QListWidget" name="listWidget_Weeks" > - <property name="selectionMode" > - <enum>QAbstractItemView::MultiSelection</enum> - </property> - </widget> - </item> - <item row="2" column="0" > - <widget class="QPushButton" name="pushButton_select" > - <property name="text" > - <string>Select all</string> - </property> - </widget> - </item> - <item row="2" column="1" > - <widget class="QPushButton" name="pushButton_Cancel" > - <property name="text" > - <string>Cancel</string> - </property> - </widget> - </item> - <item row="2" column="2" > - <widget class="QPushButton" name="pushButton_Ok" > - <property name="text" > - <string>Ok</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11" /> - <resources/> - <connections> - <connection> - <sender>pushButton_Cancel</sender> - <signal>clicked()</signal> - <receiver>PublishDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel" > - <x>158</x> - <y>200</y> - </hint> - <hint type="destinationlabel" > - <x>100</x> - <y>193</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButton_Ok</sender> - <signal>clicked()</signal> - <receiver>PublishDialogClass</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel" > - <x>266</x> - <y>197</y> - </hint> - <hint type="destinationlabel" > - <x>278</x> - <y>189</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/pulsarpipeline.cpp b/SAS/Scheduler/src/pulsarpipeline.cpp deleted file mode 100644 index 85a8c1e87a221bf0f1b3ce5df2e74deff6f45627..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/pulsarpipeline.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * pulsarpipeline.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/pulsarpipeline.cpp $ - * - */ - -#include "pulsarpipeline.h" - -PulsarPipeline::PulsarPipeline() - : Pipeline(), itsNoFold(false), itsNoPdmp(false), itsNoRFI(false), itsRawTo8bit(false), itsRrats(false), - itsSinglePulse(false), itsSkipDspsr(false), itsSkipDynamicSpectrum(false), itsSkipPrepfold(false), - itsDecodeNblocks(100), itsDecodeSigma(3), itsTsubint(-1), itsEightBitConvSigma(5.0), itsDynamicSpectrumAvg(0.5), itsRratsDmRange(5.0), - itsCoherentType(DATA_TYPE_UNDEFINED), itsIncoherentType(DATA_TYPE_UNDEFINED) -{ - itsPipelineType = PIPELINE_PULSAR; - itsSASTree.setProcessSubtype(PST_PULSAR_PIPELINE); -} - -PulsarPipeline::PulsarPipeline(unsigned task_id) - : Pipeline(task_id), itsNoFold(false), itsNoPdmp(false), itsNoRFI(false), itsRawTo8bit(false), itsRrats(false), - itsSinglePulse(false), itsSkipDspsr(false), itsSkipDynamicSpectrum(false), itsSkipPrepfold(false), - itsDecodeNblocks(100), itsDecodeSigma(3), itsTsubint(-1), itsEightBitConvSigma(5.0), itsDynamicSpectrumAvg(0.5), itsRratsDmRange(5.0), - itsCoherentType(DATA_TYPE_UNDEFINED), itsIncoherentType(DATA_TYPE_UNDEFINED) -{ - itsPipelineType = PIPELINE_PULSAR; - itsSASTree.setProcessSubtype(PST_PULSAR_PIPELINE); -} - -PulsarPipeline::PulsarPipeline(const QSqlQuery &query, const OTDBtree &SAS_tree) - : Pipeline(query, SAS_tree), itsNoFold(false), itsNoPdmp(false), itsNoRFI(false), itsRawTo8bit(false), itsRrats(false), - itsSinglePulse(false), itsSkipDspsr(false), itsSkipDynamicSpectrum(false), itsSkipPrepfold(false), - itsDecodeNblocks(100), itsDecodeSigma(3), itsTsubint(-1), itsEightBitConvSigma(5.0), itsDynamicSpectrumAvg(0.5), itsRratsDmRange(5.0), - itsCoherentType(DATA_TYPE_UNDEFINED), itsIncoherentType(DATA_TYPE_UNDEFINED) -{ - itsPipelineType = PIPELINE_PULSAR; -} - -PulsarPipeline::PulsarPipeline(unsigned id, const OTDBtree &SAS_tree) - : Pipeline(id, SAS_tree), itsNoFold(false), itsNoPdmp(false), itsNoRFI(false), itsRawTo8bit(false), itsRrats(false), - itsSinglePulse(false), itsSkipDspsr(false), itsSkipDynamicSpectrum(false), itsSkipPrepfold(false), - itsDecodeNblocks(100), itsDecodeSigma(3), itsTsubint(-1), itsEightBitConvSigma(5.0), itsDynamicSpectrumAvg(0.5), itsRratsDmRange(5.0), - itsCoherentType(DATA_TYPE_UNDEFINED), itsIncoherentType(DATA_TYPE_UNDEFINED) -{ - itsPipelineType = PIPELINE_PULSAR; -} - -QDataStream& operator<< (QDataStream &out, const PulsarPipeline &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const Pipeline &>(task); - - out << task.itsNoFold << task.itsNoPdmp << task.itsNoRFI << task.itsRawTo8bit - << task.itsRrats << task.itsSinglePulse << task.itsSkipDspsr << task.itsSkipDynamicSpectrum << task.itsSkipPrepfold - << task.itsTwoBf2fitsExtra << task.itsDigifilExtra << task.itsDspsrExtra << task.itsPrepDataExtra << task.itsPrepFoldExtra - << task.itsPrepSubbandExtra << task.itsPulsar << task.itsRfiFindExtra - << task.itsDecodeNblocks << task.itsDecodeSigma << task.itsTsubint - << task.itsEightBitConvSigma << task.itsDynamicSpectrumAvg << task.itsRratsDmRange - << (quint8) task.itsCoherentType << (quint8) task.itsIncoherentType; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, PulsarPipeline &task) { - if (in.status() == QDataStream::Ok) { - in >> static_cast<Pipeline &>(task); - - in >> task.itsNoFold >> task.itsNoPdmp >> task.itsNoRFI >> task.itsRawTo8bit - >> task.itsRrats >> task.itsSinglePulse >> task.itsSkipDspsr >> task.itsSkipDynamicSpectrum >> task.itsSkipPrepfold - >> task.itsTwoBf2fitsExtra >> task.itsDigifilExtra >> task.itsDspsrExtra >> task.itsPrepDataExtra >> task.itsPrepFoldExtra - >> task.itsPrepSubbandExtra >> task.itsPulsar >> task.itsRfiFindExtra - >> task.itsDecodeNblocks >> task.itsDecodeSigma >> task.itsTsubint - >> task.itsEightBitConvSigma >> task.itsDynamicSpectrumAvg >> task.itsRratsDmRange; - - quint8 type; - in >> type; - task.itsCoherentType = (dataTypes) type; - in >> type; - task.itsIncoherentType = (dataTypes) type; - - task.calculateDataFiles(); - } - return in; -} - - -void PulsarPipeline::calculateDataSize(void) { - itsStorage->itsTotalDataSizekBytes = 0.0; - itsStorage->itsTotalBandWidth = 0.0; - - // TODO: pulsar integration: set the correct number of ouptut files and file size estimate for the pulsar pipeline - if (itsStorage->itsEnabledOutputData.pulsar) { - unsigned totalNrOutputFiles(0); - // the number of pulsar outputfiles is equal to the sum of coherent and incoherent input files - dataFileMap::const_iterator dit(itsStorage->itsInputDataFiles.find(DP_COHERENT_STOKES)); // the number of pulsar outputfiles created for now set equal to the number of input coherent - if (dit != itsStorage->itsInputDataFiles.end()) { - // itsRTCPsettings.coherentType for the pulsar pipeline is set to the predecessor it's coherent data type in Controller::setInputFilesForPipeline - if (itsCoherentType == DATA_TYPE_XXYY) { // for complex voltages the 'polarizations' XXYY are tarred into one output file - totalNrOutputFiles += dit->second.second / 4; - } - else { - totalNrOutputFiles += dit->second.second; - } - } - dit = itsStorage->itsInputDataFiles.find(DP_INCOHERENT_STOKES); - if (dit != itsStorage->itsInputDataFiles.end()) { - totalNrOutputFiles += dit->second.second; - } - - itsStorage->itsOutputDataFiles[DP_PULSAR] = std::pair<double, unsigned>(1000.0, totalNrOutputFiles); - } - - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator it = itsStorage->itsOutputDataFiles.begin(); it != itsStorage->itsOutputDataFiles.end(); ++it) { - itsStorage->itsTotalDataSizekBytes += it->second.first * it->second.second; - } - - itsStorage->itsTotalBandWidth = (itsStorage->itsTotalDataSizekBytes * 8) / itsDuration.totalSeconds(); // kbit/sec -} - -bool PulsarPipeline::diff(const Task *other, task_diff &dif) const { - bool pipelineDif(Pipeline::diff(other, dif)); - - const PulsarPipeline *otherPipe = dynamic_cast<const PulsarPipeline *>(other); - if (otherPipe) { - // TODO: Why not assign/test the tertairy test case emediately? - // copy paste codesmell - dif.pulsar_pipeline_settings |= itsNoRFI != otherPipe->noRFI() ? true : false; // == dif.pulsar_pipeline_settings |= (itsNoRFI != otherPipe->noRFI()) // The () is not even needed - dif.pulsar_pipeline_settings |= itsSkipDspsr != otherPipe->skipDspsr() ? true : false; - dif.pulsar_pipeline_settings |= itsNoPdmp != otherPipe->noPdmp() ? true : false; - dif.pulsar_pipeline_settings |= itsRawTo8bit != otherPipe->rawTo8Bit() ? true : false; - dif.pulsar_pipeline_settings |= itsRrats != otherPipe->rrats() ? true : false; - dif.pulsar_pipeline_settings |= itsSinglePulse != otherPipe->singlePulse() ? true : false; - dif.pulsar_pipeline_settings |= itsSkipDynamicSpectrum != otherPipe->skipDynamicSpectrum() ? true : false; - dif.pulsar_pipeline_settings |= itsSkipPrepfold != otherPipe->skipPrepfold() ? true : false; - dif.pulsar_pipeline_settings |= itsTwoBf2fitsExtra != otherPipe->twoBf2fitsExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsDigifilExtra != otherPipe->digifilExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsDspsrExtra != otherPipe->dspsrExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsPrepDataExtra != otherPipe->prepDataExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsPrepFoldExtra != otherPipe->prepFoldExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsPrepSubbandExtra != otherPipe->prepSubbandExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsPulsar != otherPipe->pulsarName() ? true : false; - dif.pulsar_pipeline_settings |= itsRfiFindExtra != otherPipe->rfiFindExtra() ? true : false; - dif.pulsar_pipeline_settings |= itsDecodeNblocks != otherPipe->decodeNblocks() ? true : false; - dif.pulsar_pipeline_settings |= itsDecodeSigma != otherPipe->decodeSigma() ? true : false; - dif.pulsar_pipeline_settings |= itsTsubint != otherPipe->tsubInt() ? true : false; - dif.pulsar_pipeline_settings |= itsEightBitConvSigma != otherPipe->eightBitConversionSigma() ? true : false; - dif.pulsar_pipeline_settings |= itsDynamicSpectrumAvg != otherPipe->dynamicSpectrumAvg() ? true : false; - dif.pulsar_pipeline_settings |= itsRratsDmRange != otherPipe->rratsDmRange() ? true : false; - - return (pipelineDif || dif.pulsar_pipeline_settings); - } - else return pipelineDif; -} - -QString PulsarPipeline::diffString(const task_diff &dif) const { - QString difstr(Pipeline::diffString(dif)); - if (!difstr.isEmpty()) difstr += ","; - - if (dif.pulsar_pipeline_settings) difstr += QString(SAS_item_names[TP_PULSAR_PIPELINE_SETTINGS]); - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} diff --git a/SAS/Scheduler/src/pulsarpipeline.h b/SAS/Scheduler/src/pulsarpipeline.h deleted file mode 100644 index be3d6b089ba8752bb24024b112c3ebbc7593919d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/pulsarpipeline.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * pulsarpipeline.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/pulsarpipeline.h $ - * - */ - -#ifndef PULSARPIPELINE_H -#define PULSARPIPELINE_H - -#include <QString> -#include "pipeline.h" - -class PulsarPipeline : public Pipeline -{ - friend class TaskStorage; - -public: - PulsarPipeline(); - PulsarPipeline(unsigned task_id); - PulsarPipeline(const QSqlQuery &query, const OTDBtree &SAS_tree); - PulsarPipeline(unsigned id, const OTDBtree &SAS_tree); - - friend QDataStream& operator<< (QDataStream &out, const PulsarPipeline &task); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, PulsarPipeline &task); // used for reading data from binary file - - virtual void clone(const Task *other) { - if (this != other) { - const PulsarPipeline *pOther = dynamic_cast<const PulsarPipeline *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *pOther; - taskID = myTaskID; - } - } - } - - // getters - inline bool noRFI(void) const {return itsNoRFI;} - inline bool skipDspsr(void) const {return itsSkipDspsr;} - inline bool noFold(void) const {return itsNoFold;} - inline bool noPdmp(void) const {return itsNoPdmp;} - inline bool rawTo8Bit(void) const {return itsRawTo8bit;} - inline bool singlePulse(void) const {return itsSinglePulse;} - inline bool rrats(void) const {return itsRrats;} - inline bool skipDynamicSpectrum(void) const {return itsSkipDynamicSpectrum;} - inline bool skipPrepfold(void) const {return itsSkipPrepfold;} - inline const QString & twoBf2fitsExtra(void) const {return itsTwoBf2fitsExtra;} - inline const QString & digifilExtra(void) const {return itsDigifilExtra;} - inline const QString & dspsrExtra(void) const {return itsDspsrExtra;} - inline const QString & prepDataExtra(void) const {return itsPrepDataExtra;} - inline const QString & prepFoldExtra(void) const {return itsPrepFoldExtra;} - inline const QString & prepSubbandExtra(void) const {return itsPrepSubbandExtra;} - inline const QString & pulsarName(void) const {return itsPulsar;} - inline const QString & rfiFindExtra(void) const {return itsRfiFindExtra;} - inline int decodeNblocks(void) const {return itsDecodeNblocks;} - inline int decodeSigma(void) const {return itsDecodeSigma;} - inline int tsubInt(void) const {return itsTsubint;} - inline const double & eightBitConversionSigma(void) const {return itsEightBitConvSigma;} - inline const double & dynamicSpectrumAvg(void) const {return itsDynamicSpectrumAvg;} - inline const double & rratsDmRange(void) const {return itsRratsDmRange;} - dataTypes coherentType(void) const {return itsCoherentType;} - dataTypes incoherentType(void) const {return itsIncoherentType;} - - // setters - inline void setNoRFI(bool bVal) {itsNoRFI = bVal;} - inline void setSkipDspsr(bool bVal) {itsSkipDspsr = bVal;} - inline void setNoFold(bool bVal) {itsNoFold = bVal;} - inline void setNoPdmp(bool bVal) {itsNoPdmp = bVal;} - inline void setRawTo8Bit(bool bVal) {itsRawTo8bit = bVal;} - inline void setSinglePulse(bool bVal) {itsSinglePulse = bVal;} - inline void setRRATS(bool bVal) {itsRrats = bVal;} - inline void setSkipDynamicSpectrum(bool bVal) {itsSkipDynamicSpectrum = bVal;} - inline void setSkipPrepfold(bool bVal) {itsSkipPrepfold = bVal;} - inline void setTwoBf2fitsExtra(const QString & text) {itsTwoBf2fitsExtra = text;} - inline void setDigifilExtra(const QString &text) {itsDigifilExtra = text;} - inline void setDspsrExtra(const QString &text) {itsDspsrExtra = text;} - inline void setPrepDataExtra(const QString &text) {itsPrepDataExtra = text;} - inline void setPrepFoldExtra(const QString &text) {itsPrepFoldExtra = text;} - inline void setPrepSubbandExtra(const QString &text) {itsPrepSubbandExtra = text;} - inline void setPulsarName(const QString &text) {itsPulsar = text;} - inline void setRFIfindExtra(const QString &text) {itsRfiFindExtra = text;} - inline void setDecodeNblocks(int value) {itsDecodeNblocks = value;} - inline void setDecodeSigma(int value) {itsDecodeSigma = value;} - inline void setTsubInt(int value) {itsTsubint = value;} - inline void setEightBitConversionSigma(const double &value) {itsEightBitConvSigma = value;} - inline void setDynamicSpectrumAvg(const double &value) {itsDynamicSpectrumAvg = value;} - inline void setRratsDmRange(const double &value) {itsRratsDmRange = value;} - inline void setCoherentType(dataTypes type) {itsCoherentType = type;} - inline void setIncoherentType(dataTypes type) {itsIncoherentType = type;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - - virtual void calculateDataSize(void); - -private: - bool itsNoFold, itsNoPdmp, itsNoRFI, itsRawTo8bit, itsRrats, itsSinglePulse, itsSkipDspsr, itsSkipDynamicSpectrum, itsSkipPrepfold; - QString itsTwoBf2fitsExtra, itsDigifilExtra, itsDspsrExtra, itsPrepDataExtra, itsPrepFoldExtra, itsPrepSubbandExtra, itsPulsar, itsRfiFindExtra; - int itsDecodeNblocks, itsDecodeSigma, itsTsubint; - double itsEightBitConvSigma, itsDynamicSpectrumAvg, itsRratsDmRange; - dataTypes itsCoherentType, itsIncoherentType; -}; - -#endif // PULSARPIPELINE_H diff --git a/SAS/Scheduler/src/qcustomplot.cpp b/SAS/Scheduler/src/qcustomplot.cpp deleted file mode 100644 index ad267b64033f9dd804cbed384aded68d20e6496e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/qcustomplot.cpp +++ /dev/null @@ -1,21370 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 07.04.14 ** -** Version: 1.2.1 ** -****************************************************************************/ - -#include "qcustomplot.h" - - - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPainter -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPainter - \brief QPainter subclass used internally - - This QPainter subclass is used to provide some extended functionality e.g. for tweaking position - consistency between antialiased and non-antialiased painting. Further it provides workarounds - for QPainter quirks. - - \warning This class intentionally hides non-virtual functions of QPainter, e.g. setPen, save and - restore. So while it is possible to pass a QCPPainter instance to a function that expects a - QPainter pointer, some of the workarounds and tweaks will be unavailable to the function (because - it will call the base class implementations of the functions actually hidden by QCPPainter). -*/ - -/*! - Creates a new QCPPainter instance and sets default values -*/ -QCPPainter::QCPPainter() : - QPainter(), - mModes(pmDefault), - mIsAntialiasing(false) -{ - // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and - // a call to begin() will follow -} - -/*! - Creates a new QCPPainter instance on the specified paint \a device and sets default values. Just - like the analogous QPainter constructor, begins painting on \a device immediately. - - Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. -*/ -QCPPainter::QCPPainter(QPaintDevice *device) : - QPainter(device), - mModes(pmDefault), - mIsAntialiasing(false) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (isActive()) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif -} - -QCPPainter::~QCPPainter() -{ -} - -/*! - Sets the pen of the painter and applies certain fixes to it, depending on the mode of this - QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QPen &pen) -{ - QPainter::setPen(pen); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by color) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(const QColor &color) -{ - QPainter::setPen(color); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Sets the pen (by style) of the painter and applies certain fixes to it, depending on the mode of - this QCPPainter. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::setPen(Qt::PenStyle penStyle) -{ - QPainter::setPen(penStyle); - if (mModes.testFlag(pmNonCosmetic)) - makeNonCosmetic(); -} - -/*! \overload - - Works around a Qt bug introduced with Qt 4.8 which makes drawing QLineF unpredictable when - antialiasing is disabled. Thus when antialiasing is disabled, it rounds the \a line to - integer coordinates and then passes it to the original drawLine. - - \note this function hides the non-virtual base class implementation. -*/ -void QCPPainter::drawLine(const QLineF &line) -{ - if (mIsAntialiasing || mModes.testFlag(pmVectorized)) - QPainter::drawLine(line); - else - QPainter::drawLine(line.toLine()); -} - -/*! - Sets whether painting uses antialiasing or not. Use this method instead of using setRenderHint - with QPainter::Antialiasing directly, as it allows QCPPainter to regain pixel exactness between - antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for - AA/Non-AA painting). -*/ -void QCPPainter::setAntialiasing(bool enabled) -{ - setRenderHint(QPainter::Antialiasing, enabled); - if (mIsAntialiasing != enabled) - { - mIsAntialiasing = enabled; - if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs - { - if (mIsAntialiasing) - translate(0.5, 0.5); - else - translate(-0.5, -0.5); - } - } -} - -/*! - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setModes(QCPPainter::PainterModes modes) -{ - mModes = modes; -} - -/*! - Sets the QPainter::NonCosmeticDefaultPen in Qt versions before Qt5 after beginning painting on \a - device. This is necessary to get cosmetic pen consistency across Qt versions, because since Qt5, - all pens are non-cosmetic by default, and in Qt4 this render hint must be set to get that - behaviour. - - The Constructor \ref QCPPainter(QPaintDevice *device) which directly starts painting also sets - the render hint as appropriate. - - \note this function hides the non-virtual base class implementation. -*/ -bool QCPPainter::begin(QPaintDevice *device) -{ - bool result = QPainter::begin(device); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (result) - setRenderHint(QPainter::NonCosmeticDefaultPen); -#endif - return result; -} - -/*! \overload - - Sets the mode of the painter. This controls whether the painter shall adjust its - fixes/workarounds optimized for certain output devices. -*/ -void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) -{ - if (!enabled && mModes.testFlag(mode)) - mModes &= ~mode; - else if (enabled && !mModes.testFlag(mode)) - mModes |= mode; -} - -/*! - Saves the painter (see QPainter::save). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see restore -*/ -void QCPPainter::save() -{ - mAntialiasingStack.push(mIsAntialiasing); - QPainter::save(); -} - -/*! - Restores the painter (see QPainter::restore). Since QCPPainter adds some new internal state to - QPainter, the save/restore functions are reimplemented to also save/restore those members. - - \note this function hides the non-virtual base class implementation. - - \see save -*/ -void QCPPainter::restore() -{ - if (!mAntialiasingStack.isEmpty()) - mIsAntialiasing = mAntialiasingStack.pop(); - else - qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; - QPainter::restore(); -} - -/*! - Changes the pen width to 1 if it currently is 0. This function is called in the \ref setPen - overrides when the \ref pmNonCosmetic mode is set. -*/ -void QCPPainter::makeNonCosmetic() -{ - if (qFuzzyIsNull(pen().widthF())) - { - QPen p = pen(); - p.setWidth(1); - QPainter::setPen(p); - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPScatterStyle -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPScatterStyle - \brief Represents the visual appearance of scatter points - - This class holds information about shape, color and size of scatter points. In plottables like - QCPGraph it is used to store how scatter points shall be drawn. For example, \ref - QCPGraph::setScatterStyle takes a QCPScatterStyle instance. - - A scatter style consists of a shape (\ref setShape), a line color (\ref setPen) and possibly a - fill (\ref setBrush), if the shape provides a fillable area. Further, the size of the shape can - be controlled with \ref setSize. - - \section QCPScatterStyle-defining Specifying a scatter style - - You can set all these configurations either by calling the respective functions on an instance: - \code - QCPScatterStyle myScatter; - myScatter.setShape(QCPScatterStyle::ssCircle); - myScatter.setPen(Qt::blue); - myScatter.setBrush(Qt::white); - myScatter.setSize(5); - customPlot->graph(0)->setScatterStyle(myScatter); - \endcode - - Or you can use one of the various constructors that take different parameter combinations, making - it easy to specify a scatter style in a single call, like so: - \code - customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::blue, Qt::white, 5)); - \endcode - - \section QCPScatterStyle-undefinedpen Leaving the color/pen up to the plottable - - There are two constructors which leave the pen undefined: \ref QCPScatterStyle() and \ref - QCPScatterStyle(ScatterShape shape, double size). If those constructors are used, a call to \ref - isPenDefined will return false. It leads to scatter points that inherit the pen from the - plottable that uses the scatter style. Thus, if such a scatter style is passed to QCPGraph, the line - color of the graph (\ref QCPGraph::setPen) will be used by the scatter points. This makes - it very convenient to set up typical scatter settings: - - \code - customPlot->graph(0)->setScatterStyle(QCPScatterStyle::ssPlus); - \endcode - - Notice that it wasn't even necessary to explicitly call a QCPScatterStyle constructor. This works - because QCPScatterStyle provides a constructor that can transform a \ref ScatterShape directly - into a QCPScatterStyle instance (that's the \ref QCPScatterStyle(ScatterShape shape, double size) - constructor with a default for \a size). In those cases, C++ allows directly supplying a \ref - ScatterShape, where actually a QCPScatterStyle is expected. - - \section QCPScatterStyle-custompath-and-pixmap Custom shapes and pixmaps - - QCPScatterStyle supports drawing custom shapes and arbitrary pixmaps as scatter points. - - For custom shapes, you can provide a QPainterPath with the desired shape to the \ref - setCustomPath function or call the constructor that takes a painter path. The scatter shape will - automatically be set to \ref ssCustom. - - For pixmaps, you call \ref setPixmap with the desired QPixmap. Alternatively you can use the - constructor that takes a QPixmap. The scatter shape will automatically be set to \ref ssPixmap. - Note that \ref setSize does not influence the appearance of the pixmap. -*/ - -/* start documentation of inline functions */ - -/*! \fn bool QCPScatterStyle::isNone() const - - Returns whether the scatter shape is \ref ssNone. - - \see setShape -*/ - -/*! \fn bool QCPScatterStyle::isPenDefined() const - - Returns whether a pen has been defined for this scatter style. - - The pen is undefined if a constructor is called that does not carry \a pen as parameter. Those are - \ref QCPScatterStyle() and \ref QCPScatterStyle(ScatterShape shape, double size). If the pen is - left undefined, the scatter color will be inherited from the plottable that uses this scatter - style. - - \see setPen -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPScatterStyle instance with size set to 6. No shape, pen or brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle() : - mSize(6), - mShape(ssNone), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape and size to \a size. No pen or - brush is defined. - - Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited - from the plottable that uses this scatter style. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : - mSize(size), - mShape(shape), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - and size to \a size. No brush is defined, i.e. the scatter point will not be filled. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(Qt::NoBrush), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, - the brush color to \a fill (with a solid pattern), and size to \a size. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(QBrush(fill)), - mPenDefined(true) -{ -} - -/*! - Creates a new QCPScatterStyle instance with shape set to \a shape, the pen set to \a pen, the - brush to \a brush, and size to \a size. - - \warning In some cases it might be tempting to directly use a pen style like <tt>Qt::NoPen</tt> as \a pen - and a color like <tt>Qt::blue</tt> as \a brush. Notice however, that the corresponding call\n - <tt>QCPScatterStyle(QCPScatterShape::ssCircle, Qt::NoPen, Qt::blue, 5)</tt>\n - doesn't necessarily lead C++ to use this constructor in some cases, but might mistake - <tt>Qt::NoPen</tt> for a QColor and use the - \ref QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) - constructor instead (which will lead to an unexpected look of the scatter points). To prevent - this, be more explicit with the parameter types. For example, use <tt>QBrush(Qt::blue)</tt> - instead of just <tt>Qt::blue</tt>, to clearly point out to the compiler that this constructor is - wanted. -*/ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(shape), - mPen(pen), - mBrush(brush), - mPenDefined(pen.style() != Qt::NoPen) -{ -} - -/*! - Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape - is set to \ref ssPixmap. -*/ -QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : - mSize(5), - mShape(ssPixmap), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPixmap(pixmap), - mPenDefined(false) -{ -} - -/*! - Creates a new QCPScatterStyle instance with a custom shape that is defined via \a customPath. The - scatter shape is set to \ref ssCustom. - - The custom shape line will be drawn with \a pen and filled with \a brush. The size has a slightly - different meaning than for built-in scatter points: The custom path will be drawn scaled by a - factor of \a size/6.0. Since the default \a size is 6, the custom path will appear at a its - natural size by default. To double the size of the path for example, set \a size to 12. -*/ -QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(ssCustom), - mPen(pen), - mBrush(brush), - mCustomPath(customPath), - mPenDefined(false) -{ -} - -/*! - Sets the size (pixel diameter) of the drawn scatter points to \a size. - - \see setShape -*/ -void QCPScatterStyle::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the shape to \a shape. - - Note that the calls \ref setPixmap and \ref setCustomPath automatically set the shape to \ref - ssPixmap and \ref ssCustom, respectively. - - \see setSize -*/ -void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) -{ - mShape = shape; -} - -/*! - Sets the pen that will be used to draw scatter points to \a pen. - - If the pen was previously undefined (see \ref isPenDefined), the pen is considered defined after - a call to this function, even if \a pen is <tt>Qt::NoPen</tt>. - - \see setBrush -*/ -void QCPScatterStyle::setPen(const QPen &pen) -{ - mPenDefined = true; - mPen = pen; -} - -/*! - Sets the brush that will be used to fill scatter points to \a brush. Note that not all scatter - shapes have fillable areas. For example, \ref ssPlus does not while \ref ssCircle does. - - \see setPen -*/ -void QCPScatterStyle::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the pixmap that will be drawn as scatter point to \a pixmap. - - Note that \ref setSize does not influence the appearance of the pixmap. - - The scatter shape is automatically set to \ref ssPixmap. -*/ -void QCPScatterStyle::setPixmap(const QPixmap &pixmap) -{ - setShape(ssPixmap); - mPixmap = pixmap; -} - -/*! - Sets the custom shape that will be drawn as scatter point to \a customPath. - - The scatter shape is automatically set to \ref ssCustom. -*/ -void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) -{ - setShape(ssCustom); - mCustomPath = customPath; -} - -/*! - Applies the pen and the brush of this scatter style to \a painter. If this scatter style has an - undefined pen (\ref isPenDefined), sets the pen of \a painter to \a defaultPen instead. - - This function is used by plottables (or any class that wants to draw scatters) just before a - number of scatters with this style shall be drawn with the \a painter. - - \see drawShape -*/ -void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const -{ - painter->setPen(mPenDefined ? mPen : defaultPen); - painter->setBrush(mBrush); -} - -/*! - Draws the scatter shape with \a painter at position \a pos. - - This function does not modify the pen or the brush on the painter, as \ref applyTo is meant to be - called before scatter points are drawn with \ref drawShape. - - \see applyTo -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, QPointF pos) const -{ - drawShape(painter, pos.x(), pos.y()); -} - -/*! \overload - Draws the scatter shape with \a painter at position \a x and \a y. -*/ -void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const -{ - double w = mSize/2.0; - switch (mShape) - { - case ssNone: break; - case ssDot: - { - painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); - break; - } - case ssCross: - { - painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); - painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); - break; - } - case ssPlus: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCircle: - { - painter->drawEllipse(QPointF(x , y), w, w); - break; - } - case ssDisc: - { - QBrush b = painter->brush(); - painter->setBrush(painter->pen().color()); - painter->drawEllipse(QPointF(x , y), w, w); - painter->setBrush(b); - break; - } - case ssSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssDiamond: - { - painter->drawLine(QLineF(x-w, y, x, y-w)); - painter->drawLine(QLineF( x, y-w, x+w, y)); - painter->drawLine(QLineF(x+w, y, x, y+w)); - painter->drawLine(QLineF( x, y+w, x-w, y)); - break; - } - case ssStar: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); - break; - } - case ssTriangle: - { - painter->drawLine(QLineF(x-w, y+0.755*w, x+w, y+0.755*w)); - painter->drawLine(QLineF(x+w, y+0.755*w, x, y-0.977*w)); - painter->drawLine(QLineF( x, y-0.977*w, x-w, y+0.755*w)); - break; - } - case ssTriangleInverted: - { - painter->drawLine(QLineF(x-w, y-0.755*w, x+w, y-0.755*w)); - painter->drawLine(QLineF(x+w, y-0.755*w, x, y+0.977*w)); - painter->drawLine(QLineF( x, y+0.977*w, x-w, y-0.755*w)); - break; - } - case ssCrossSquare: - { - painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); - painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssPlusSquare: - { - painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssCrossCircle: - { - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); - painter->drawEllipse(QPointF(x, y), w, w); - break; - } - case ssPlusCircle: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawEllipse(QPointF(x, y), w, w); - break; - } - case ssPeace: - { - painter->drawLine(QLineF(x, y-w, x, y+w)); - painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); - painter->drawEllipse(QPointF(x, y), w, w); - break; - } - case ssPixmap: - { - painter->drawPixmap(x-mPixmap.width()*0.5, y-mPixmap.height()*0.5, mPixmap); - break; - } - case ssCustom: - { - QTransform oldTransform = painter->transform(); - painter->translate(x, y); - painter->scale(mSize/6.0, mSize/6.0); - painter->drawPath(mCustomPath); - painter->setTransform(oldTransform); - break; - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayer - \brief A layer that may contain objects, to control the rendering order - - The Layering system of QCustomPlot is the mechanism to control the rendering order of the - elements inside the plot. - - It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of - one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, - QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers - bottom to top and successively draws the layerables of the layers. - - A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base - class from which almost all visible objects derive, like axes, grids, graphs, items, etc. - - Initially, QCustomPlot has five layers: "background", "grid", "main", "axes" and "legend" (in - that order). The top two layers "axes" and "legend" contain the default axes and legend, so they - will be drawn on top. In the middle, there is the "main" layer. It is initially empty and set as - the current layer (see QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. - are created on this layer by default. Then comes the "grid" layer which contains the QCPGrid - instances (which belong tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background - shall be drawn behind everything else, thus the default QCPAxisRect instance is placed on the - "background" layer. Of course, the layer affiliation of the individual objects can be changed as - required (\ref QCPLayerable::setLayer). - - Controlling the ordering of objects is easy: Create a new layer in the position you want it to - be, e.g. above "main", with QCustomPlot::addLayer. Then set the current layer with - QCustomPlot::setCurrentLayer to that new layer and finally create the objects normally. They will - be placed on the new layer automatically, due to the current layer setting. Alternatively you - could have also ignored the current layer setting and just moved the objects with - QCPLayerable::setLayer to the desired layer after creating them. - - It is also possible to move whole layers. For example, If you want the grid to be shown in front - of all plottables/items on the "main" layer, just move it above "main" with - QCustomPlot::moveLayer. - - The rendering order within one layer is simply by order of creation or insertion. The item - created last (or added last to the layer), is drawn on top of all other objects on that layer. - - When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below - the deleted layer, see QCustomPlot::removeLayer. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList<QCPLayerable*> QCPLayer::children() const - - Returns a list of all layerables on this layer. The order corresponds to the rendering order: - layerables with higher indices are drawn above layerables with lower indices. -*/ - -/*! \fn int QCPLayer::index() const - - Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be - accessed via \ref QCustomPlot::layer. - - Layers with higher indices will be drawn above layers with lower indices. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPLayer instance. - - Normally you shouldn't directly instantiate layers, use \ref QCustomPlot::addLayer instead. - - \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. - This check is only performed by \ref QCustomPlot::addLayer. -*/ -QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : - QObject(parentPlot), - mParentPlot(parentPlot), - mName(layerName), - mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function - mVisible(true) -{ - // Note: no need to make sure layerName is unique, because layer - // management is done with QCustomPlot functions. -} - -QCPLayer::~QCPLayer() -{ - // If child layerables are still on this layer, detach them, so they don't try to reach back to this - // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted - // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to - // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) - - while (!mChildren.isEmpty()) - mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() - - if (mParentPlot->currentLayer() == this) - qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; -} - -/*! - Sets whether this layer is visible or not. If \a visible is set to false, all layerables on this - layer will be invisible. - - This function doesn't change the visibility property of the layerables (\ref - QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the - visibility of the parent layer into account. -*/ -void QCPLayer::setVisible(bool visible) -{ - mVisible = visible; -} - -/*! \internal - - Adds the \a layerable to the list of this layer. If \a prepend is set to true, the layerable will - be prepended to the list, i.e. be drawn beneath the other layerables already in the list. - - This function does not change the \a mLayer member of \a layerable to this layer. (Use - QCPLayerable::setLayer to change the layer of an object, not this function.) - - \see removeChild -*/ -void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) -{ - if (!mChildren.contains(layerable)) - { - if (prepend) - mChildren.prepend(layerable); - else - mChildren.append(layerable); - } else - qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast<quintptr>(layerable); -} - -/*! \internal - - Removes the \a layerable from the list of this layer. - - This function does not change the \a mLayer member of \a layerable. (Use QCPLayerable::setLayer - to change the layer of an object, not this function.) - - \see addChild -*/ -void QCPLayer::removeChild(QCPLayerable *layerable) -{ - if (!mChildren.removeOne(layerable)) - qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast<quintptr>(layerable); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayerable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayerable - \brief Base class for all drawable objects - - This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid - etc. - - Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking - the layers accordingly. - - For details about the layering mechanism, see the QCPLayer documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayerable *QCPLayerable::parentLayerable() const - - Returns the parent layerable of this layerable. The parent layerable is used to provide - visibility hierarchies in conjunction with the method \ref realVisibility. This way, layerables - only get drawn if their parent layerables are visible, too. - - Note that a parent layerable is not necessarily also the QObject parent for memory management. - Further, a layerable doesn't always have a parent layerable, so this function may return 0. - - A parent layerable is set implicitly with when placed inside layout elements and doesn't need to be - set manually by the user. -*/ - -/* end documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn virtual void QCPLayerable::applyDefaultAntialiasingHint(QCPPainter *painter) const = 0 - \internal - - This function applies the default antialiasing setting to the specified \a painter, using the - function \ref applyAntialiasingHint. It is the antialiasing state the painter is put in, when - \ref draw is called on the layerable. If the layerable has multiple entities whose antialiasing - setting may be specified individually, this function should set the antialiasing state of the - most prominent entity. In this case however, the \ref draw function usually calls the specialized - versions of this function before drawing each entity, effectively overriding the setting of the - default antialiasing hint. - - <b>First example:</b> QCPGraph has multiple entities that have an antialiasing setting: The graph - line, fills, scatters and error bars. Those can be configured via QCPGraph::setAntialiased, - QCPGraph::setAntialiasedFill, QCPGraph::setAntialiasedScatters etc. Consequently, there isn't - only the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's - antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and - QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw - calls the respective specialized applyAntialiasingHint function. - - <b>Second example:</b> QCPItemLine consists only of a line so there is only one antialiasing - setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by - all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the - respective layerable subclass.) Consequently it only has the normal - QCPItemLine::applyDefaultAntialiasingHint. The \ref QCPItemLine::draw function doesn't need to - care about setting any antialiasing states, because the default antialiasing hint is already set - on the painter when the \ref draw function is called, and that's the state it wants to draw the - line with. -*/ - -/*! \fn virtual void QCPLayerable::draw(QCPPainter *painter) const = 0 - \internal - - This function draws the layerable with the specified \a painter. It is only called by - QCustomPlot, if the layerable is visible (\ref setVisible). - - Before this function is called, the painter's antialiasing state is set via \ref - applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was - set to \ref clipRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPLayerable::layerChanged(QCPLayer *newLayer); - - This signal is emitted when the layer of this layerable changes, i.e. this layerable is moved to - a different layer. - - \see setLayer -*/ - -/* end documentation of signals */ - -/*! - Creates a new QCPLayerable instance. - - Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the - derived classes. - - If \a plot is provided, it automatically places itself on the layer named \a targetLayer. If \a - targetLayer is an empty string, it places itself on the current layer of the plot (see \ref - QCustomPlot::setCurrentLayer). - - It is possible to provide 0 as \a plot. In that case, you should assign a parent plot at a later - time with \ref initializeParentPlot. - - The layerable's parent layerable is set to \a parentLayerable, if provided. Direct layerable parents - are mainly used to control visibility in a hierarchy of layerables. This means a layerable is - only drawn, if all its ancestor layerables are also visible. Note that \a parentLayerable does - not become the QObject-parent (for memory management) of this layerable, \a plot does. -*/ -QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : - QObject(plot), - mVisible(true), - mParentPlot(plot), - mParentLayerable(parentLayerable), - mLayer(0), - mAntialiased(true) -{ - if (mParentPlot) - { - if (targetLayer.isEmpty()) - setLayer(mParentPlot->currentLayer()); - else if (!setLayer(targetLayer)) - qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; - } -} - -QCPLayerable::~QCPLayerable() -{ - if (mLayer) - { - mLayer->removeChild(this); - mLayer = 0; - } -} - -/*! - Sets the visibility of this layerable object. If an object is not visible, it will not be drawn - on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not - possible. -*/ -void QCPLayerable::setVisible(bool on) -{ - mVisible = on; -} - -/*! - Sets the \a layer of this layerable object. The object will be placed on top of the other objects - already on \a layer. - - Returns true on success, i.e. if \a layer is a valid layer. -*/ -bool QCPLayerable::setLayer(QCPLayer *layer) -{ - return moveToLayer(layer, false); -} - -/*! \overload - Sets the layer of this layerable object by name - - Returns true on success, i.e. if \a layerName is a valid layer name. -*/ -bool QCPLayerable::setLayer(const QString &layerName) -{ - if (!mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (QCPLayer *layer = mParentPlot->layer(layerName)) - { - return setLayer(layer); - } else - { - qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; - return false; - } -} - -/*! - Sets whether this object will be drawn antialiased or not. - - Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPLayerable::setAntialiased(bool enabled) -{ - mAntialiased = enabled; -} - -/*! - Returns whether this layerable is visible, taking the visibility of the layerable parent and the - visibility of the layer this layerable is on into account. This is the method that is consulted - to decide whether a layerable shall be drawn or not. - - If this layerable has a direct layerable parent (usually set via hierarchies implemented in - subclasses, like in the case of QCPLayoutElement), this function returns true only if this - layerable has its visibility set to true and the parent layerable's \ref realVisibility returns - true. - - If this layerable doesn't have a direct layerable parent, returns the state of this layerable's - visibility. -*/ -bool QCPLayerable::realVisibility() const -{ - return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); -} - -/*! - This function is used to decide whether a click hits a layerable object or not. - - \a pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the - shortest pixel distance of this point to the object. If the object is either invisible or the - distance couldn't be determined, -1.0 is returned. Further, if \a onlySelectable is true and the - object is not selectable, -1.0 is returned, too. - - If the item is represented not by single lines but by an area like QCPItemRect or QCPItemText, a - click inside the area returns a constant value greater zero (typically the selectionTolerance of - the parent QCustomPlot multiplied by 0.99). If the click lies outside the area, this function - returns -1.0. - - Providing a constant value for area objects allows selecting line objects even when they are - obscured by such area objects, by clicking close to the lines (i.e. closer than - 0.99*selectionTolerance). - - The actual setting of the selection state is not done by this function. This is handled by the - parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified - via the selectEvent/deselectEvent methods. - - \a details is an optional output parameter. Every layerable subclass may place any information - in \a details. This information will be passed to \ref selectEvent when the parent QCustomPlot - decides on the basis of this selectTest call, that the object was successfully selected. The - subsequent call to \ref selectEvent will carry the \a details. This is useful for multi-part - objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked - is only done once in \ref selectTest. The result (i.e. the actually clicked part) can then be - placed in \a details. So in the subsequent \ref selectEvent, the decision which part was - selected doesn't have to be done a second time for a single selection operation. - - You may pass 0 as \a details to indicate that you are not interested in those selection details. - - \see selectEvent, deselectEvent, QCustomPlot::setInteractions -*/ -double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(pos) - Q_UNUSED(onlySelectable) - Q_UNUSED(details) - return -1.0; -} - -/*! \internal - - Sets the parent plot of this layerable. Use this function once to set the parent plot if you have - passed 0 in the constructor. It can not be used to move a layerable from one QCustomPlot to - another one. - - Note that, unlike when passing a non-null parent plot in the constructor, this function does not - make \a parentPlot the QObject-parent of this layerable. If you want this, call - QObject::setParent(\a parentPlot) in addition to this function. - - Further, you will probably want to set a layer (\ref setLayer) after calling this function, to - make the layerable appear on the QCustomPlot. - - The parent plot change will be propagated to subclasses via a call to \ref parentPlotInitialized - so they can react accordingly (e.g. also initialize the parent plot of child layerables, like - QCPLayout does). -*/ -void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) -{ - if (mParentPlot) - { - qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; - return; - } - - if (!parentPlot) - qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; - - mParentPlot = parentPlot; - parentPlotInitialized(mParentPlot); -} - -/*! \internal - - Sets the parent layerable of this layerable to \a parentLayerable. Note that \a parentLayerable does not - become the QObject-parent (for memory management) of this layerable. - - The parent layerable has influence on the return value of the \ref realVisibility method. Only - layerables with a fully visible parent tree will return true for \ref realVisibility, and thus be - drawn. - - \see realVisibility -*/ -void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) -{ - mParentLayerable = parentLayerable; -} - -/*! \internal - - Moves this layerable object to \a layer. If \a prepend is true, this object will be prepended to - the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is - false, the object will be appended. - - Returns true on success, i.e. if \a layer is a valid layer. -*/ -bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) -{ - if (layer && !mParentPlot) - { - qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; - return false; - } - if (layer && layer->parentPlot() != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; - return false; - } - - QCPLayer *oldLayer = mLayer; - if (mLayer) - mLayer->removeChild(this); - mLayer = layer; - if (mLayer) - mLayer->addChild(this, prepend); - if (mLayer != oldLayer) - emit layerChanged(mLayer); - return true; -} - -/*! \internal - - Sets the QCPainter::setAntialiasing state on the provided \a painter, depending on the \a - localAntialiased value as well as the overrides \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is - controlled via \a overrideElement. -*/ -void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const -{ - if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(false); - else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(true); - else - painter->setAntialiasing(localAntialiased); -} - -/*! \internal - - This function is called by \ref initializeParentPlot, to allow subclasses to react on the setting - of a parent plot. This is the case when 0 was passed as parent plot in the constructor, and the - parent plot is set at a later time. - - For example, QCPLayoutElement/QCPLayout hierarchies may be created independently of any - QCustomPlot at first. When they are then added to a layout inside the QCustomPlot, the top level - element of the hierarchy gets its parent plot initialized with \ref initializeParentPlot. To - propagate the parent plot to all the children of the hierarchy, the top level element then uses - this function to pass the parent plot on to its child elements. - - The default implementation does nothing. - - \see initializeParentPlot -*/ -void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_UNUSED(parentPlot) -} - -/*! \internal - - Returns the selection category this layerable shall belong to. The selection category is used in - conjunction with \ref QCustomPlot::setInteractions to control which objects are selectable and - which aren't. - - Subclasses that don't fit any of the normal \ref QCP::Interaction values can use \ref - QCP::iSelectOther. This is what the default implementation returns. - - \see QCustomPlot::setInteractions -*/ -QCP::Interaction QCPLayerable::selectionCategory() const -{ - return QCP::iSelectOther; -} - -/*! \internal - - Returns the clipping rectangle of this layerable object. By default, this is the viewport of the - parent QCustomPlot. Specific subclasses may reimplement this function to provide different - clipping rects. - - The returned clipping rect is set on the painter before the draw function of the respective - object is called. -*/ -QRect QCPLayerable::clipRect() const -{ - if (mParentPlot) - return mParentPlot->viewport(); - else - return QRect(); -} - -/*! \internal - - This event is called when the layerable shall be selected, as a consequence of a click by the - user. Subclasses should react to it by setting their selection state appropriately. The default - implementation does nothing. - - \a event is the mouse event that caused the selection. \a additive indicates, whether the user - was holding the multi-select-modifier while performing the selection (see \ref - QCustomPlot::setMultiSelectModifier). if \a additive is true, the selection state must be toggled - (i.e. become selected when unselected and unselected when selected). - - Every selectEvent is preceded by a call to \ref selectTest, which has returned positively (i.e. - returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). - The \a details data you output from \ref selectTest is fed back via \a details here. You may - use it to transport any kind of information from the selectTest to the possibly subsequent - selectEvent. Usually \a details is used to transfer which part was clicked, if it is a layerable - that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need - to do the calculation again to find out which part was actually clicked. - - \a selectionStateChanged is an output parameter. If the pointer is non-null, this function must - set the value either to true or false, depending on whether the selection state of this layerable - was actually changed. For layerables that only are selectable as a whole and not in parts, this - is simple: if \a additive is true, \a selectionStateChanged must also be set to true, because the - selection toggles. If \a additive is false, \a selectionStateChanged is only set to true, if the - layerable was previously unselected and now is switched to the selected state. - - \see selectTest, deselectEvent -*/ -void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(additive) - Q_UNUSED(details) - Q_UNUSED(selectionStateChanged) -} - -/*! \internal - - This event is called when the layerable shall be deselected, either as consequence of a user - interaction or a call to \ref QCustomPlot::deselectAll. Subclasses should react to it by - unsetting their selection appropriately. - - just as in \ref selectEvent, the output parameter \a selectionStateChanged (if non-null), must - return true or false when the selection state of this layerable has changed or not changed, - respectively. - - \see selectTest, selectEvent -*/ -void QCPLayerable::deselectEvent(bool *selectionStateChanged) -{ - Q_UNUSED(selectionStateChanged) -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPRange -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPRange - \brief Represents the range an axis is encompassing. - - contains a \a lower and \a upper double value and provides convenience input, output and - modification functions. - - \see QCPAxis::setRange -*/ - -/*! - Minimum range size (\a upper - \a lower) the range changing functions will accept. Smaller - intervals would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a minimum magnitude of roughly 1e-308. - \see validRange, maxRange -*/ -const double QCPRange::minRange = 1e-280; - -/*! - Maximum values (negative and positive) the range will accept in range-changing functions. - Larger absolute values would cause errors due to the 11-bit exponent of double precision numbers, - corresponding to a maximum magnitude of roughly 1e308. - Since the number of planck-volumes in the entire visible universe is only ~1e183, this should - be enough. - \see validRange, minRange -*/ -const double QCPRange::maxRange = 1e250; - -/*! - Constructs a range with \a lower and \a upper set to zero. -*/ -QCPRange::QCPRange() : - lower(0), - upper(0) -{ -} - -/*! \overload - Constructs a range with the specified \a lower and \a upper values. -*/ -QCPRange::QCPRange(double lower, double upper) : - lower(lower), - upper(upper) -{ - normalize(); -} - -/*! - Returns the size of the range, i.e. \a upper-\a lower -*/ -double QCPRange::size() const -{ - return upper-lower; -} - -/*! - Returns the center of the range, i.e. (\a upper+\a lower)*0.5 -*/ -double QCPRange::center() const -{ - return (upper+lower)*0.5; -} - -/*! - Makes sure \a lower is numerically smaller than \a upper. If this is not the case, the values - are swapped. -*/ -void QCPRange::normalize() -{ - if (lower > upper) - qSwap(lower, upper); -} - -/*! - Expands this range such that \a otherRange is contained in the new range. It is assumed that both - this range and \a otherRange are normalized (see \ref normalize). - - If \a otherRange is already inside the current range, this function does nothing. - - \see expanded -*/ -void QCPRange::expand(const QCPRange &otherRange) -{ - if (lower > otherRange.lower) - lower = otherRange.lower; - if (upper < otherRange.upper) - upper = otherRange.upper; -} - - -/*! - Returns an expanded range that contains this and \a otherRange. It is assumed that both this - range and \a otherRange are normalized (see \ref normalize). - - \see expand -*/ -QCPRange QCPRange::expanded(const QCPRange &otherRange) const -{ - QCPRange result = *this; - result.expand(otherRange); - return result; -} - -/*! - Returns a sanitized version of the range. Sanitized means for logarithmic scales, that - the range won't span the positive and negative sign domain, i.e. contain zero. Further - \a lower will always be numerically smaller (or equal) to \a upper. - - If the original range does span positive and negative sign domains or contains zero, - the returned range will try to approximate the original range as good as possible. - If the positive interval of the original range is wider than the negative interval, the - returned range will only contain the positive interval, with lower bound set to \a rangeFac or - \a rangeFac *\a upper, whichever is closer to zero. Same procedure is used if the negative interval - is wider than the positive interval, this time by changing the \a upper bound. -*/ -QCPRange QCPRange::sanitizedForLogScale() const -{ - double rangeFac = 1e-3; - QCPRange sanitizedRange(lower, upper); - sanitizedRange.normalize(); - // can't have range spanning negative and positive values in log plot, so change range to fix it - //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) - if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) - { - // case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) - else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) - { - // case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) - { - // find out whether negative or positive interval is wider to decide which sign domain will be chosen - if (-sanitizedRange.lower > sanitizedRange.upper) - { - // negative is wider, do same as in case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) - sanitizedRange.upper = -rangeFac; - else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else - { - // positive is wider, do same as in case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) - sanitizedRange.lower = rangeFac; - else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } - } - // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper<lower - return sanitizedRange; -} - -/*! - Returns a sanitized version of the range. Sanitized means for linear scales, that - \a lower will always be numerically smaller (or equal) to \a upper. -*/ -QCPRange QCPRange::sanitizedForLinScale() const -{ - QCPRange sanitizedRange(lower, upper); - sanitizedRange.normalize(); - return sanitizedRange; -} - -/*! - Returns true when \a value lies within or exactly on the borders of the range. -*/ -bool QCPRange::contains(double value) const -{ - return value >= lower && value <= upper; -} - -/*! - Checks, whether the specified range is within valid bounds, which are defined - as QCPRange::maxRange and QCPRange::minRange. - A valid range means: - \li range bounds within -maxRange and maxRange - \li range size above minRange - \li range size below maxRange -*/ -bool QCPRange::validRange(double lower, double upper) -{ - /* - return (lower > -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - (lower < -minRange || lower > minRange) && - (upper < -minRange || upper > minRange)); - */ - return (lower > -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - qAbs(lower-upper) < maxRange); -} - -/*! - \overload - Checks, whether the specified range is within valid bounds, which are defined - as QCPRange::maxRange and QCPRange::minRange. - A valid range means: - \li range bounds within -maxRange and maxRange - \li range size above minRange - \li range size below maxRange -*/ -bool QCPRange::validRange(const QCPRange &range) -{ - /* - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange && - (range.lower < -minRange || range.lower > minRange) && - (range.upper < -minRange || range.upper > minRange)); - */ - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange); -} - - -/*! \page thelayoutsystem The Layout System - - The layout system is responsible for positioning and scaling layout elements such as axis rects, - legends and plot titles in a QCustomPlot. - - \section layoutsystem-classesandmechanisms Classes and mechanisms - - The layout system is based on the abstract base class \ref QCPLayoutElement. All objects that - take part in the layout system derive from this class, either directly or indirectly. - - Since QCPLayoutElement itself derives from \ref QCPLayerable, a layout element may draw its own - content. However, it is perfectly possible for a layout element to only serve as a structuring - and/or positioning element, not drawing anything on its own. - - \subsection layoutsystem-rects Rects of a layout element - - A layout element is a rectangular object described by two rects: the inner rect (\ref - QCPLayoutElement::rect) and the outer rect (\ref QCPLayoutElement::setOuterRect). The inner rect - is calculated automatically by applying the margin (\ref QCPLayoutElement::setMargins) inward - from the outer rect. The inner rect is meant for main content while the margin area may either be - left blank or serve for displaying peripheral graphics. For example, \ref QCPAxisRect positions - the four main axes at the sides of the inner rect, so graphs end up inside it and the axis labels - and tick labels are in the margin area. - - \subsection layoutsystem-margins Margins - - Each layout element may provide a mechanism to automatically determine its margins. Internally, - this is realized with the \ref QCPLayoutElement::calculateAutoMargin function which takes a \ref - QCP::MarginSide and returns an integer value which represents the ideal margin for the specified - side. The automatic margin will be used on the sides specified in \ref - QCPLayoutElement::setAutoMargins. By default, it is set to \ref QCP::msAll meaning automatic - margin calculation is enabled for all four sides. In this case, a minimum margin may be set with - \ref QCPLayoutElement::setMinimumMargins, to prevent the automatic margin mechanism from setting - margins smaller than desired for a specific situation. If automatic margin calculation is unset - for a specific side, the margin of that side can be controlled directy via \ref - QCPLayoutElement::setMargins. - - If multiple layout ements are arranged next to or beneath each other, it may be desirable to - align their inner rects on certain sides. Since they all might have different automatic margins, - this usually isn't the case. The class \ref QCPMarginGroup and \ref - QCPLayoutElement::setMarginGroup fix this by allowing to synchronize multiple margins. See the - documentation there for details. - - \subsection layoutsystem-layout Layouts - - As mentioned, a QCPLayoutElement may have an arbitrary number of child layout elements and in - princple can have the only purpose to manage/arrange those child elements. This is what the - subclass \ref QCPLayout specializes on. It is a QCPLayoutElement itself but has no visual - representation. It defines an interface to add, remove and manage child layout elements. - QCPLayout isn't a usable layout though, it's an abstract base class that concrete layouts derive - from, like \ref QCPLayoutGrid which arranges its child elements in a grid and \ref QCPLayoutInset - which allows placing child elements freely inside its rect. - - Since a QCPLayout is a layout element itself, it may be placed inside other layouts. This way, - complex hierarchies may be created, offering very flexible arrangements. - - \image html LayoutsystemSketch.png - - Above is a sketch of the default \ref QCPLayoutGrid accessible via \ref QCustomPlot::plotLayout. - It shows how two child layout elements are placed inside the grid layout next to each other in - cells (0, 0) and (0, 1). - - \subsection layoutsystem-plotlayout The top level plot layout - - Every QCustomPlot has one top level layout of type \ref QCPLayoutGrid. It is accessible via \ref - QCustomPlot::plotLayout and contains (directly or indirectly via other sub-layouts) all layout - elements in the QCustomPlot. By default, this top level grid layout contains a single cell which - holds the main axis rect. - - \subsection layoutsystem-examples Examples - - <b>Adding a plot title</b> is a typical and simple case to demonstrate basic workings of the layout system. - \code - // first we create and prepare a plot title layout element: - QCPPlotTitle *title = new QCPPlotTitle(customPlot); - title->setText("Plot Title Example"); - title->setFont(QFont("sans", 12, QFont::Bold)); - // then we add it to the main plot layout: - customPlot->plotLayout()->insertRow(0); // insert an empty row above the axis rect - customPlot->plotLayout()->addElement(0, 0, title); // place the title in the empty cell we've just created - \endcode - \image html layoutsystem-addingplottitle.png - - <b>Arranging multiple axis rects</b> actually is the central purpose of the layout system. - \code - customPlot->plotLayout()->clear(); // let's start from scratch and remove the default axis rect - // add the first axis rect in second row (row index 1): - QCPAxisRect *topAxisRect = new QCPAxisRect(customPlot); - customPlot->plotLayout()->addElement(1, 0, topAxisRect); - // create a sub layout that we'll place in first row: - QCPLayoutGrid *subLayout = new QCPLayoutGrid; - customPlot->plotLayout()->addElement(0, 0, subLayout); - // add two axis rects in the sub layout next to each other: - QCPAxisRect *leftAxisRect = new QCPAxisRect(customPlot); - QCPAxisRect *rightAxisRect = new QCPAxisRect(customPlot); - subLayout->addElement(0, 0, leftAxisRect); - subLayout->addElement(0, 1, rightAxisRect); - subLayout->setColumnStretchFactor(0, 3); // left axis rect shall have 60% of width - subLayout->setColumnStretchFactor(1, 2); // right one only 40% (3:2 = 60:40) - // since we've created the axis rects and axes from scratch, we need to place them on - // according layers, if we don't want the grid to be drawn above the axes etc. - // place the axis on "axes" layer and grids on the "grid" layer, which is below "axes": - QList<QCPAxis*> allAxes; - allAxes << topAxisRect->axes() << leftAxisRect->axes() << rightAxisRect->axes(); - foreach (QCPAxis *axis, allAxes) - { - axis->setLayer("axes"); - axis->grid()->setLayer("grid"); - } - \endcode - \image html layoutsystem-multipleaxisrects.png - -*/ - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPMarginGroup -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPMarginGroup - \brief A margin group allows synchronization of margin sides if working with multiple layout elements. - - QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that - they will all have the same size, based on the largest required margin in the group. - - \n - \image html QCPMarginGroup.png "Demonstration of QCPMarginGroup" - \n - - In certain situations it is desirable that margins at specific sides are synchronized across - layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will - provide a cleaner look to the user if the left and right margins of the two axis rects are of the - same size. The left axis of the top axis rect will then be at the same horizontal position as the - left axis of the lower axis rect, making them appear aligned. The same applies for the right - axes. This is what QCPMarginGroup makes possible. - - To add/remove a specific side of a layout element to/from a margin group, use the \ref - QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call - \ref clear, or just delete the margin group. - - \section QCPMarginGroup-example Example - - First create a margin group: - \code - QCPMarginGroup *group = new QCPMarginGroup(customPlot); - \endcode - Then set this group on the layout element sides: - \code - customPlot->axisRect(0)->setMarginGroup(QCP::msLeft|QCP::msRight, group); - customPlot->axisRect(1)->setMarginGroup(QCP::msLeft|QCP::msRight, group); - \endcode - Here, we've used the first two axis rects of the plot and synchronized their left margins with - each other and their right margins with each other. -*/ - -/* start documentation of inline functions */ - -/*! \fn QList<QCPLayoutElement*> QCPMarginGroup::elements(QCP::MarginSide side) const - - Returns a list of all layout elements that have their margin \a side associated with this margin - group. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPMarginGroup instance in \a parentPlot. -*/ -QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot) -{ - mChildren.insert(QCP::msLeft, QList<QCPLayoutElement*>()); - mChildren.insert(QCP::msRight, QList<QCPLayoutElement*>()); - mChildren.insert(QCP::msTop, QList<QCPLayoutElement*>()); - mChildren.insert(QCP::msBottom, QList<QCPLayoutElement*>()); -} - -QCPMarginGroup::~QCPMarginGroup() -{ - clear(); -} - -/*! - Returns whether this margin group is empty. If this function returns true, no layout elements use - this margin group to synchronize margin sides. -*/ -bool QCPMarginGroup::isEmpty() const -{ - QHashIterator<QCP::MarginSide, QList<QCPLayoutElement*> > it(mChildren); - while (it.hasNext()) - { - it.next(); - if (!it.value().isEmpty()) - return false; - } - return true; -} - -/*! - Clears this margin group. The synchronization of the margin sides that use this margin group is - lifted and they will use their individual margin sizes again. -*/ -void QCPMarginGroup::clear() -{ - // make all children remove themselves from this margin group: - QHashIterator<QCP::MarginSide, QList<QCPLayoutElement*> > it(mChildren); - while (it.hasNext()) - { - it.next(); - const QList<QCPLayoutElement*> elements = it.value(); - for (int i=elements.size()-1; i>=0; --i) - elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild - } -} - -/*! \internal - - Returns the synchronized common margin for \a side. This is the margin value that will be used by - the layout element on the respective side, if it is part of this margin group. - - The common margin is calculated by requesting the automatic margin (\ref - QCPLayoutElement::calculateAutoMargin) of each element associated with \a side in this margin - group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into - account, too.) -*/ -int QCPMarginGroup::commonMargin(QCP::MarginSide side) const -{ - // query all automatic margins of the layout elements in this margin group side and find maximum: - int result = 0; - const QList<QCPLayoutElement*> elements = mChildren.value(side); - for (int i=0; i<elements.size(); ++i) - { - if (!elements.at(i)->autoMargins().testFlag(side)) - continue; - int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); - if (m > result) - result = m; - } - return result; -} - -/*! \internal - - Adds \a element to the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].contains(element)) - mChildren[side].append(element); - else - qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast<quintptr>(element); -} - -/*! \internal - - Removes \a element from the internal list of child elements, for the margin \a side. - - This function does not modify the margin group property of \a element. -*/ -void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) -{ - if (!mChildren[side].removeOne(element)) - qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast<quintptr>(element); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutElement -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutElement - \brief The abstract base class for all objects that form \ref thelayoutsystem "the layout system". - - This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses. - - A Layout element is a rectangular object which can be placed in layouts. It has an outer rect - (QCPLayoutElement::outerRect) and an inner rect (\ref QCPLayoutElement::rect). The difference - between outer and inner rect is called its margin. The margin can either be set to automatic or - manual (\ref setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be - set explicitly with \ref setMargins and will stay fixed at that value. If it's set to automatic, - the layout element subclass will control the value itself (via \ref calculateAutoMargin). - - Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level - layout is reachable via \ref QCustomPlot::plotLayout, and is a \ref QCPLayoutGrid. Since \ref - QCPLayout itself derives from \ref QCPLayoutElement, layouts can be nested. - - Thus in QCustomPlot one can divide layout elements into two categories: The ones that are - invisible by themselves, because they don't draw anything. Their only purpose is to manage the - position and size of other layout elements. This category of layout elements usually use - QCPLayout as base class. Then there is the category of layout elements which actually draw - something. For example, QCPAxisRect, QCPLegend and QCPPlotTitle are of this category. This does - not necessarily mean that the latter category can't have child layout elements. QCPLegend for - instance, actually derives from QCPLayoutGrid and the individual legend items are child layout - elements in the grid layout. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayout *QCPLayoutElement::layout() const - - Returns the parent layout of this layout element. -*/ - -/*! \fn QRect QCPLayoutElement::rect() const - - Returns the inner rect of this layout element. The inner rect is the outer rect (\ref - setOuterRect) shrinked by the margins (\ref setMargins, \ref setAutoMargins). - - In some cases, the area between outer and inner rect is left blank. In other cases the margin - area is used to display peripheral graphics while the main content is in the inner rect. This is - where automatic margin calculation becomes interesting because it allows the layout element to - adapt the margins to the peripheral graphics it wants to draw. For example, \ref QCPAxisRect - draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if - \ref setAutoMargins is enabled) according to the space required by the labels of the axes. -*/ - -/*! \fn virtual void QCPLayoutElement::mousePressEvent(QMouseEvent *event) - - This event is called, if the mouse was pressed while being inside the outer rect of this layout - element. -*/ - -/*! \fn virtual void QCPLayoutElement::mouseMoveEvent(QMouseEvent *event) - - This event is called, if the mouse is moved inside the outer rect of this layout element. -*/ - -/*! \fn virtual void QCPLayoutElement::mouseReleaseEvent(QMouseEvent *event) - - This event is called, if the mouse was previously pressed inside the outer rect of this layout - element and is now released. -*/ - -/*! \fn virtual void QCPLayoutElement::mouseDoubleClickEvent(QMouseEvent *event) - - This event is called, if the mouse is double-clicked inside the outer rect of this layout - element. -*/ - -/*! \fn virtual void QCPLayoutElement::wheelEvent(QWheelEvent *event) - - This event is called, if the mouse wheel is scrolled while the cursor is inside the rect of this - layout element. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutElement and sets default values. -*/ -QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) - mParentLayout(0), - mMinimumSize(), - mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), - mRect(0, 0, 0, 0), - mOuterRect(0, 0, 0, 0), - mMargins(0, 0, 0, 0), - mMinimumMargins(0, 0, 0, 0), - mAutoMargins(QCP::msAll) -{ -} - -QCPLayoutElement::~QCPLayoutElement() -{ - setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any - // unregister at layout: - if (qobject_cast<QCPLayout*>(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor - mParentLayout->take(this); -} - -/*! - Sets the outer rect of this layout element. If the layout element is inside a layout, the layout - sets the position and size of this layout element using this function. - - Calling this function externally has no effect, since the layout will overwrite any changes to - the outer rect upon the next replot. - - The layout element will adapt its inner \ref rect by applying the margins inward to the outer rect. - - \see rect -*/ -void QCPLayoutElement::setOuterRect(const QRect &rect) -{ - if (mOuterRect != rect) - { - mOuterRect = rect; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - Sets the margins of this layout element. If \ref setAutoMargins is disabled for some or all - sides, this function is used to manually set the margin on those sides. Sides that are still set - to be handled automatically are ignored and may have any value in \a margins. - - The margin is the distance between the outer rect (controlled by the parent layout via \ref - setOuterRect) and the inner \ref rect (which usually contains the main content of this layout - element). - - \see setAutoMargins -*/ -void QCPLayoutElement::setMargins(const QMargins &margins) -{ - if (mMargins != margins) - { - mMargins = margins; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); - } -} - -/*! - If \ref setAutoMargins is enabled on some or all margins, this function is used to provide - minimum values for those margins. - - The minimum values are not enforced on margin sides that were set to be under manual control via - \ref setAutoMargins. - - \see setAutoMargins -*/ -void QCPLayoutElement::setMinimumMargins(const QMargins &margins) -{ - if (mMinimumMargins != margins) - { - mMinimumMargins = margins; - } -} - -/*! - Sets on which sides the margin shall be calculated automatically. If a side is calculated - automatically, a minimum margin value may be provided with \ref setMinimumMargins. If a side is - set to be controlled manually, the value may be specified with \ref setMargins. - - Margin sides that are under automatic control may participate in a \ref QCPMarginGroup (see \ref - setMarginGroup), to synchronize (align) it with other layout elements in the plot. - - \see setMinimumMargins, setMargins -*/ -void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) -{ - mAutoMargins = sides; -} - -/*! - Sets the minimum size for the inner \ref rect of this layout element. A parent layout tries to - respect the \a size here by changing row/column sizes in the layout accordingly. - - If the parent layout size is not sufficient to satisfy all minimum size constraints of its child - layout elements, the layout may set a size that is actually smaller than \a size. QCustomPlot - propagates the layout's size constraints to the outside by setting its own minimum QWidget size - accordingly, so violations of \a size should be exceptions. -*/ -void QCPLayoutElement::setMinimumSize(const QSize &size) -{ - if (mMinimumSize != size) - { - mMinimumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the minimum size for the inner \ref rect of this layout element. -*/ -void QCPLayoutElement::setMinimumSize(int width, int height) -{ - setMinimumSize(QSize(width, height)); -} - -/*! - Sets the maximum size for the inner \ref rect of this layout element. A parent layout tries to - respect the \a size here by changing row/column sizes in the layout accordingly. -*/ -void QCPLayoutElement::setMaximumSize(const QSize &size) -{ - if (mMaximumSize != size) - { - mMaximumSize = size; - if (mParentLayout) - mParentLayout->sizeConstraintsChanged(); - } -} - -/*! \overload - - Sets the maximum size for the inner \ref rect of this layout element. -*/ -void QCPLayoutElement::setMaximumSize(int width, int height) -{ - setMaximumSize(QSize(width, height)); -} - -/*! - Sets the margin \a group of the specified margin \a sides. - - Margin groups allow synchronizing specified margins across layout elements, see the documentation - of \ref QCPMarginGroup. - - To unset the margin group of \a sides, set \a group to 0. - - Note that margin groups only work for margin sides that are set to automatic (\ref - setAutoMargins). -*/ -void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) -{ - QVector<QCP::MarginSide> sideVector; - if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); - if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); - if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); - if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); - - for (int i=0; i<sideVector.size(); ++i) - { - QCP::MarginSide side = sideVector.at(i); - if (marginGroup(side) != group) - { - QCPMarginGroup *oldGroup = marginGroup(side); - if (oldGroup) // unregister at old group - oldGroup->removeChild(side, this); - - if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there - { - mMarginGroups.remove(side); - } else // setting to a new group - { - mMarginGroups[side] = group; - group->addChild(side, this); - } - } - } -} - -/*! - Updates the layout element and sub-elements. This function is automatically called before every - replot by the parent layout element. It is called multiple times, once for every \ref - UpdatePhase. The phases are run through in the order of the enum values. For details about what - happens at the different phases, see the documentation of \ref UpdatePhase. - - Layout elements that have child elements should call the \ref update method of their child - elements, and pass the current \a phase unchanged. - - The default implementation executes the automatic margin mechanism in the \ref upMargins phase. - Subclasses should make sure to call the base class implementation. -*/ -void QCPLayoutElement::update(UpdatePhase phase) -{ - if (phase == upMargins) - { - if (mAutoMargins != QCP::msNone) - { - // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: - QMargins newMargins = mMargins; - foreach (QCP::MarginSide side, QList<QCP::MarginSide>() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom) - { - if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically - { - if (mMarginGroups.contains(side)) - QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group - else - QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly - // apply minimum margin restrictions: - if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) - QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); - } - } - setMargins(newMargins); - } - } -} - -/*! - Returns the minimum size this layout element (the inner \ref rect) may be compressed to. - - if a minimum size (\ref setMinimumSize) was not set manually, parent layouts consult this - function to determine the minimum allowed size of this layout element. (A manual minimum size is - considered set if it is non-zero.) -*/ -QSize QCPLayoutElement::minimumSizeHint() const -{ - return mMinimumSize; -} - -/*! - Returns the maximum size this layout element (the inner \ref rect) may be expanded to. - - if a maximum size (\ref setMaximumSize) was not set manually, parent layouts consult this - function to determine the maximum allowed size of this layout element. (A manual maximum size is - considered set if it is smaller than Qt's QWIDGETSIZE_MAX.) -*/ -QSize QCPLayoutElement::maximumSizeHint() const -{ - return mMaximumSize; -} - -/*! - Returns a list of all child elements in this layout element. If \a recursive is true, all - sub-child elements are included in the list, too. - - \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have - empty cells which yield 0 at the respective index.) -*/ -QList<QCPLayoutElement*> QCPLayoutElement::elements(bool recursive) const -{ - Q_UNUSED(recursive) - return QList<QCPLayoutElement*>(); -} - -/*! - Layout elements are sensitive to events inside their outer rect. If \a pos is within the outer - rect, this method returns a value corresponding to 0.99 times the parent plot's selection - tolerance. However, layout elements are not selectable by default. So if \a onlySelectable is - true, -1.0 is returned. - - See \ref QCPLayerable::selectTest for a general explanation of this virtual method. - - QCPLayoutElement subclasses may reimplement this method to provide more specific selection test - behaviour. -*/ -double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - - if (onlySelectable) - return -1; - - if (QRectF(mOuterRect).contains(pos)) - { - if (mParentPlot) - return mParentPlot->selectionTolerance()*0.99; - else - { - qDebug() << Q_FUNC_INFO << "parent plot not defined"; - return -1; - } - } else - return -1; -} - -/*! \internal - - propagates the parent plot initialization to all child elements, by calling \ref - QCPLayerable::initializeParentPlot on them. -*/ -void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) -{ - foreach (QCPLayoutElement* el, elements(false)) - { - if (!el->parentPlot()) - el->initializeParentPlot(parentPlot); - } -} - -/*! \internal - - Returns the margin size for this \a side. It is used if automatic margins is enabled for this \a - side (see \ref setAutoMargins). If a minimum margin was set with \ref setMinimumMargins, the - returned value will not be smaller than the specified minimum margin. - - The default implementation just returns the respective manual margin (\ref setMargins) or the - minimum margin, whichever is larger. -*/ -int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) -{ - return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayout -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayout - \brief The abstract base class for layouts - - This is an abstract base class for layout elements whose main purpose is to define the position - and size of other child layout elements. In most cases, layouts don't draw anything themselves - (but there are exceptions to this, e.g. QCPLegend). - - QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts. - - QCPLayout introduces a common interface for accessing and manipulating the child elements. Those - functions are most notably \ref elementCount, \ref elementAt, \ref takeAt, \ref take, \ref - simplify, \ref removeAt, \ref remove and \ref clear. Individual subclasses may add more functions - to this interface which are more specialized to the form of the layout. For example, \ref - QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid - more conveniently. - - Since this is an abstract base class, you can't instantiate it directly. Rather use one of its - subclasses like QCPLayoutGrid or QCPLayoutInset. - - For a general introduction to the layout system, see the dedicated documentation page \ref - thelayoutsystem "The Layout System". -*/ - -/* start documentation of pure virtual functions */ - -/*! \fn virtual int QCPLayout::elementCount() const = 0 - - Returns the number of elements/cells in the layout. - - \see elements, elementAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::elementAt(int index) const = 0 - - Returns the element in the cell with the given \a index. If \a index is invalid, returns 0. - - Note that even if \a index is valid, the respective cell may be empty in some layouts (e.g. - QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check - whether a cell is empty or not. - - \see elements, elementCount, takeAt -*/ - -/*! \fn virtual QCPLayoutElement* QCPLayout::takeAt(int index) = 0 - - Removes the element with the given \a index from the layout and returns it. - - If the \a index is invalid or the cell with that index is empty, returns 0. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see elementAt, take -*/ - -/*! \fn virtual bool QCPLayout::take(QCPLayoutElement* element) = 0 - - Removes the specified \a element from the layout and returns true on success. - - If the \a element isn't in this layout, returns false. - - Note that some layouts don't remove the respective cell right away but leave an empty cell after - successful removal of the layout element. To collapse empty cells, use \ref simplify. - - \see takeAt -*/ - -/* end documentation of pure virtual functions */ - -/*! - Creates an instance of QCPLayout and sets default values. Note that since QCPLayout - is an abstract base class, it can't be instantiated directly. -*/ -QCPLayout::QCPLayout() -{ -} - -/*! - First calls the QCPLayoutElement::update base class implementation to update the margins on this - layout. - - Then calls \ref updateLayout which subclasses reimplement to reposition and resize their cells. - - Finally, \ref update is called on all child elements. -*/ -void QCPLayout::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - // set child element rects according to layout: - if (phase == upLayout) - updateLayout(); - - // propagate update call to child elements: - const int elCount = elementCount(); - for (int i=0; i<elCount; ++i) - { - if (QCPLayoutElement *el = elementAt(i)) - el->update(phase); - } -} - -/* inherits documentation from base class */ -QList<QCPLayoutElement*> QCPLayout::elements(bool recursive) const -{ - const int c = elementCount(); - QList<QCPLayoutElement*> result; -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(c); -#endif - for (int i=0; i<c; ++i) - result.append(elementAt(i)); - if (recursive) - { - for (int i=0; i<c; ++i) - { - if (result.at(i)) - result << result.at(i)->elements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the - default implementation does nothing. - - Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit - simplification while QCPLayoutGrid does. -*/ -void QCPLayout::simplify() -{ -} - -/*! - Removes and deletes the element at the provided \a index. Returns true on success. If \a index is - invalid or points to an empty cell, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the returned element. - - \see remove, takeAt -*/ -bool QCPLayout::removeAt(int index) -{ - if (QCPLayoutElement *el = takeAt(index)) - { - delete el; - return true; - } else - return false; -} - -/*! - Removes and deletes the provided \a element. Returns true on success. If \a element is not in the - layout, returns false. - - This function internally uses \ref takeAt to remove the element from the layout and then deletes - the element. - - \see removeAt, take -*/ -bool QCPLayout::remove(QCPLayoutElement *element) -{ - if (take(element)) - { - delete element; - return true; - } else - return false; -} - -/*! - Removes and deletes all layout elements in this layout. - - \see remove, removeAt -*/ -void QCPLayout::clear() -{ - for (int i=elementCount()-1; i>=0; --i) - { - if (elementAt(i)) - removeAt(i); - } - simplify(); -} - -/*! - Subclasses call this method to report changed (minimum/maximum) size constraints. - - If the parent of this layout is again a QCPLayout, forwards the call to the parent's \ref - sizeConstraintsChanged. If the parent is a QWidget (i.e. is the \ref QCustomPlot::plotLayout of - QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, - it may update itself and resize cells accordingly. -*/ -void QCPLayout::sizeConstraintsChanged() const -{ - if (QWidget *w = qobject_cast<QWidget*>(parent())) - w->updateGeometry(); - else if (QCPLayout *l = qobject_cast<QCPLayout*>(parent())) - l->sizeConstraintsChanged(); -} - -/*! \internal - - Subclasses reimplement this method to update the position and sizes of the child elements/cells - via calling their \ref QCPLayoutElement::setOuterRect. The default implementation does nothing. - - The geometry used as a reference is the inner \ref rect of this layout. Child elements should stay - within that rect. - - \ref getSectionSizes may help with the reimplementation of this function. - - \see update -*/ -void QCPLayout::updateLayout() -{ -} - - -/*! \internal - - Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the - \ref QCPLayerable::parentLayerable and the QObject parent to this layout. - - Further, if \a el didn't previously have a parent plot, calls \ref - QCPLayerable::initializeParentPlot on \a el to set the paret plot. - - This method is used by subclass specific methods that add elements to the layout. Note that this - method only changes properties in \a el. The removal from the old layout and the insertion into - the new layout must be done additionally. -*/ -void QCPLayout::adoptElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = this; - el->setParentLayerable(this); - el->setParent(this); - if (!el->parentPlot()) - el->initializeParentPlot(mParentPlot); - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - Disassociates \a el from this layout. This is done by setting the \ref QCPLayoutElement::layout - and the \ref QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent - QCustomPlot. - - This method is used by subclass specific methods that remove elements from the layout (e.g. \ref - take or \ref takeAt). Note that this method only changes properties in \a el. The removal from - the old layout must be done additionally. -*/ -void QCPLayout::releaseElement(QCPLayoutElement *el) -{ - if (el) - { - el->mParentLayout = 0; - el->setParentLayerable(0); - el->setParent(mParentPlot); - // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot - } else - qDebug() << Q_FUNC_INFO << "Null element passed"; -} - -/*! \internal - - This is a helper function for the implementation of \ref updateLayout in subclasses. - - It calculates the sizes of one-dimensional sections with provided constraints on maximum section - sizes, minimum section sizes, relative stretch factors and the final total size of all sections. - - The QVector entries refer to the sections. Thus all QVectors must have the same size. - - \a maxSizes gives the maximum allowed size of each section. If there shall be no maximum size - imposed, set all vector values to Qt's QWIDGETSIZE_MAX. - - \a minSizes gives the minimum allowed size of each section. If there shall be no minimum size - imposed, set all vector values to zero. If the \a minSizes entries add up to a value greater than - \a totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, - not exceeding the allowed total size is taken to be more important than not going below minimum - section sizes.) - - \a stretchFactors give the relative proportions of the sections to each other. If all sections - shall be scaled equally, set all values equal. If the first section shall be double the size of - each individual other section, set the first number of \a stretchFactors to double the value of - the other individual values (e.g. {2, 1, 1, 1}). - - \a totalSize is the value that the final section sizes will add up to. Due to rounding, the - actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, - you could distribute the remaining difference on the sections. - - The return value is a QVector containing the section sizes. -*/ -QVector<int> QCPLayout::getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const -{ - if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) - { - qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; - return QVector<int>(); - } - if (stretchFactors.isEmpty()) - return QVector<int>(); - int sectionCount = stretchFactors.size(); - QVector<double> sectionSizes(sectionCount); - // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): - int minSizeSum = 0; - for (int i=0; i<sectionCount; ++i) - minSizeSum += minSizes.at(i); - if (totalSize < minSizeSum) - { - // new stretch factors are minimum sizes and minimum sizes are set to zero: - for (int i=0; i<sectionCount; ++i) - { - stretchFactors[i] = minSizes.at(i); - minSizes[i] = 0; - } - } - - QList<int> minimumLockedSections; - QList<int> unfinishedSections; - for (int i=0; i<sectionCount; ++i) - unfinishedSections.append(i); - double freeSize = totalSize; - - int outerIterations = 0; - while (!unfinishedSections.isEmpty() && outerIterations < sectionCount*2) // the iteration check ist just a failsafe in case something really strange happens - { - ++outerIterations; - int innerIterations = 0; - while (!unfinishedSections.isEmpty() && innerIterations < sectionCount*2) // the iteration check ist just a failsafe in case something really strange happens - { - ++innerIterations; - // find section that hits its maximum next: - int nextId = -1; - double nextMax = 1e12; - for (int i=0; i<unfinishedSections.size(); ++i) - { - int secId = unfinishedSections.at(i); - double hitsMaxAt = (maxSizes.at(secId)-sectionSizes.at(secId))/stretchFactors.at(secId); - if (hitsMaxAt < nextMax) - { - nextMax = hitsMaxAt; - nextId = secId; - } - } - // check if that maximum is actually within the bounds of the total size (i.e. can we stretch all remaining sections so far that the found section - // actually hits its maximum, without exceeding the total size when we add up all sections) - double stretchFactorSum = 0; - for (int i=0; i<unfinishedSections.size(); ++i) - stretchFactorSum += stretchFactors.at(unfinishedSections.at(i)); - double nextMaxLimit = freeSize/stretchFactorSum; - if (nextMax < nextMaxLimit) // next maximum is actually hit, move forward to that point and fix the size of that section - { - for (int i=0; i<unfinishedSections.size(); ++i) - { - sectionSizes[unfinishedSections.at(i)] += nextMax*stretchFactors.at(unfinishedSections.at(i)); // increment all sections - freeSize -= nextMax*stretchFactors.at(unfinishedSections.at(i)); - } - unfinishedSections.removeOne(nextId); // exclude the section that is now at maximum from further changes - } else // next maximum isn't hit, just distribute rest of free space on remaining sections - { - for (int i=0; i<unfinishedSections.size(); ++i) - sectionSizes[unfinishedSections.at(i)] += nextMaxLimit*stretchFactors.at(unfinishedSections.at(i)); // increment all sections - unfinishedSections.clear(); - } - } - if (innerIterations == sectionCount*2) - qDebug() << Q_FUNC_INFO << "Exceeded maximum expected inner iteration count, layouting aborted. Input was:" << maxSizes << minSizes << stretchFactors << totalSize; - - // now check whether the resulting section sizes violate minimum restrictions: - bool foundMinimumViolation = false; - for (int i=0; i<sectionSizes.size(); ++i) - { - if (minimumLockedSections.contains(i)) - continue; - if (sectionSizes.at(i) < minSizes.at(i)) // section violates minimum - { - sectionSizes[i] = minSizes.at(i); // set it to minimum - foundMinimumViolation = true; // make sure we repeat the whole optimization process - minimumLockedSections.append(i); - } - } - if (foundMinimumViolation) - { - freeSize = totalSize; - for (int i=0; i<sectionCount; ++i) - { - if (!minimumLockedSections.contains(i)) // only put sections that haven't hit their minimum back into the pool - unfinishedSections.append(i); - else - freeSize -= sectionSizes.at(i); // remove size of minimum locked sections from available space in next round - } - // reset all section sizes to zero that are in unfinished sections (all others have been set to their minimum): - for (int i=0; i<unfinishedSections.size(); ++i) - sectionSizes[unfinishedSections.at(i)] = 0; - } - } - if (outerIterations == sectionCount*2) - qDebug() << Q_FUNC_INFO << "Exceeded maximum expected outer iteration count, layouting aborted. Input was:" << maxSizes << minSizes << stretchFactors << totalSize; - - QVector<int> result(sectionCount); - for (int i=0; i<sectionCount; ++i) - result[i] = qRound(sectionSizes.at(i)); - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLayoutGrid - \brief A layout that arranges child elements in a grid - - Elements are laid out in a grid with configurable stretch factors (\ref setColumnStretchFactor, - \ref setRowStretchFactor) and spacing (\ref setColumnSpacing, \ref setRowSpacing). - - Elements can be added to cells via \ref addElement. The grid is expanded if the specified row or - column doesn't exist yet. Whether a cell contains a valid layout element can be checked with \ref - hasElement, that element can be retrieved with \ref element. If rows and columns that only have - empty cells shall be removed, call \ref simplify. Removal of elements is either done by just - adding the element to a different layout or by using the QCPLayout interface \ref take or \ref - remove. - - Row and column insertion can be performed with \ref insertRow and \ref insertColumn. -*/ - -/*! - Creates an instance of QCPLayoutGrid and sets default values. -*/ -QCPLayoutGrid::QCPLayoutGrid() : - mColumnSpacing(5), - mRowSpacing(5) -{ -} - -QCPLayoutGrid::~QCPLayoutGrid() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the element in the cell in \a row and \a column. - - Returns 0 if either the row/column is invalid or if the cell is empty. In those cases, a qDebug - message is printed. To check whether a cell exists and isn't empty, use \ref hasElement. - - \see addElement, hasElement -*/ -QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const -{ - if (row >= 0 && row < mElements.size()) - { - if (column >= 0 && column < mElements.first().size()) - { - if (QCPLayoutElement *result = mElements.at(row).at(column)) - return result; - else - qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; - } else - qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; - return 0; -} - -/*! - Returns the number of rows in the layout. - - \see columnCount -*/ -int QCPLayoutGrid::rowCount() const -{ - return mElements.size(); -} - -/*! - Returns the number of columns in the layout. - - \see rowCount -*/ -int QCPLayoutGrid::columnCount() const -{ - if (mElements.size() > 0) - return mElements.first().size(); - else - return 0; -} - -/*! - Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it - is first removed from there. If \a row or \a column don't exist yet, the layout is expanded - accordingly. - - Returns true if the element was added successfully, i.e. if the cell at \a row and \a column - didn't already have an element. - - \see element, hasElement, take, remove -*/ -bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) -{ - if (element) - { - if (!hasElement(row, column)) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - expandTo(row+1, column+1); - mElements[row][column] = element; - adoptElement(element); - return true; - } else - qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; - } else - qDebug() << Q_FUNC_INFO << "Can't add null element to row/column:" << row << column; - return false; -} - -/*! - Returns whether the cell at \a row and \a column exists and contains a valid element, i.e. isn't - empty. - - \see element -*/ -bool QCPLayoutGrid::hasElement(int row, int column) -{ - if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) - return mElements.at(row).at(column); - else - return false; -} - -/*! - Sets the stretch \a factor of \a column. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights (\ref QCPLayoutElement::setMinimumSize, \ref - QCPLayoutElement::setMaximumSize), regardless of the stretch factor. - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactors, setRowStretchFactor -*/ -void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) -{ - if (column >= 0 && column < columnCount()) - { - if (factor > 0) - mColumnStretchFactors[column] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid column:" << column; -} - -/*! - Sets the stretch \a factors of all columns. \a factors must have the size \ref columnCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights (\ref QCPLayoutElement::setMinimumSize, \ref - QCPLayoutElement::setMaximumSize), regardless of the stretch factor. - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactor, setRowStretchFactors -*/ -void QCPLayoutGrid::setColumnStretchFactors(const QList<double> &factors) -{ - if (factors.size() == mColumnStretchFactors.size()) - { - mColumnStretchFactors = factors; - for (int i=0; i<mColumnStretchFactors.size(); ++i) - { - if (mColumnStretchFactors.at(i) <= 0) - { - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << mColumnStretchFactors.at(i); - mColumnStretchFactors[i] = 1; - } - } - } else - qDebug() << Q_FUNC_INFO << "Column count not equal to passed stretch factor count:" << factors; -} - -/*! - Sets the stretch \a factor of \a row. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights (\ref QCPLayoutElement::setMinimumSize, \ref - QCPLayoutElement::setMaximumSize), regardless of the stretch factor. - - The default stretch factor of newly created rows/columns is 1. - - \see setColumnStretchFactors, setRowStretchFactor -*/ -void QCPLayoutGrid::setRowStretchFactor(int row, double factor) -{ - if (row >= 0 && row < rowCount()) - { - if (factor > 0) - mRowStretchFactors[row] = factor; - else - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else - qDebug() << Q_FUNC_INFO << "Invalid row:" << row; -} - -/*! - Sets the stretch \a factors of all rows. \a factors must have the size \ref rowCount. - - Stretch factors control the relative sizes of rows and columns. Cells will not be resized beyond - their minimum and maximum widths/heights (\ref QCPLayoutElement::setMinimumSize, \ref - QCPLayoutElement::setMaximumSize), regardless of the stretch factor. - - The default stretch factor of newly created rows/columns is 1. - - \see setRowStretchFactor, setColumnStretchFactors -*/ -void QCPLayoutGrid::setRowStretchFactors(const QList<double> &factors) -{ - if (factors.size() == mRowStretchFactors.size()) - { - mRowStretchFactors = factors; - for (int i=0; i<mRowStretchFactors.size(); ++i) - { - if (mRowStretchFactors.at(i) <= 0) - { - qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << mRowStretchFactors.at(i); - mRowStretchFactors[i] = 1; - } - } - } else - qDebug() << Q_FUNC_INFO << "Row count not equal to passed stretch factor count:" << factors; -} - -/*! - Sets the gap that is left blank between columns to \a pixels. - - \see setRowSpacing -*/ -void QCPLayoutGrid::setColumnSpacing(int pixels) -{ - mColumnSpacing = pixels; -} - -/*! - Sets the gap that is left blank between rows to \a pixels. - - \see setColumnSpacing -*/ -void QCPLayoutGrid::setRowSpacing(int pixels) -{ - mRowSpacing = pixels; -} - -/*! - Expands the layout to have \a newRowCount rows and \a newColumnCount columns. So the last valid - row index will be \a newRowCount-1, the last valid column index will be \a newColumnCount-1. - - If the current column/row count is already larger or equal to \a newColumnCount/\a newRowCount, - this function does nothing in that dimension. - - Newly created cells are empty, new rows and columns have the stretch factor 1. - - Note that upon a call to \ref addElement, the layout is expanded automatically to contain the - specified row and column, using this function. - - \see simplify -*/ -void QCPLayoutGrid::expandTo(int newRowCount, int newColumnCount) -{ - // add rows as necessary: - while (rowCount() < newRowCount) - { - mElements.append(QList<QCPLayoutElement*>()); - mRowStretchFactors.append(1); - } - // go through rows and expand columns as necessary: - int newColCount = qMax(columnCount(), newColumnCount); - for (int i=0; i<rowCount(); ++i) - { - while (mElements.at(i).size() < newColCount) - mElements[i].append(0); - } - while (mColumnStretchFactors.size() < newColCount) - mColumnStretchFactors.append(1); -} - -/*! - Inserts a new row with empty cells at the row index \a newIndex. Valid values for \a newIndex - range from 0 (inserts a row at the top) to \a rowCount (appends a row at the bottom). - - \see insertColumn -*/ -void QCPLayoutGrid::insertRow(int newIndex) -{ - if (mElements.isEmpty() || mElements.first().isEmpty()) // if grid is completely empty, add first cell - { - expandTo(1, 1); - return; - } - - if (newIndex < 0) - newIndex = 0; - if (newIndex > rowCount()) - newIndex = rowCount(); - - mRowStretchFactors.insert(newIndex, 1); - QList<QCPLayoutElement*> newRow; - for (int col=0; col<columnCount(); ++col) - newRow.append((QCPLayoutElement*)0); - mElements.insert(newIndex, newRow); -} - -/*! - Inserts a new column with empty cells at the column index \a newIndex. Valid values for \a - newIndex range from 0 (inserts a row at the left) to \a rowCount (appends a row at the right). - - \see insertRow -*/ -void QCPLayoutGrid::insertColumn(int newIndex) -{ - if (mElements.isEmpty() || mElements.first().isEmpty()) // if grid is completely empty, add first cell - { - expandTo(1, 1); - return; - } - - if (newIndex < 0) - newIndex = 0; - if (newIndex > columnCount()) - newIndex = columnCount(); - - mColumnStretchFactors.insert(newIndex, 1); - for (int row=0; row<rowCount(); ++row) - mElements[row].insert(newIndex, (QCPLayoutElement*)0); -} - -/* inherits documentation from base class */ -void QCPLayoutGrid::updateLayout() -{ - QVector<int> minColWidths, minRowHeights, maxColWidths, maxRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - int totalRowSpacing = (rowCount()-1) * mRowSpacing; - int totalColSpacing = (columnCount()-1) * mColumnSpacing; - QVector<int> colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); - QVector<int> rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); - - // go through cells and set rects accordingly: - int yOffset = mRect.top(); - for (int row=0; row<rowCount(); ++row) - { - if (row > 0) - yOffset += rowHeights.at(row-1)+mRowSpacing; - int xOffset = mRect.left(); - for (int col=0; col<columnCount(); ++col) - { - if (col > 0) - xOffset += colWidths.at(col-1)+mColumnSpacing; - if (mElements.at(row).at(col)) - mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); - } - } -} - -/* inherits documentation from base class */ -int QCPLayoutGrid::elementCount() const -{ - return rowCount()*columnCount(); -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const -{ - if (index >= 0 && index < elementCount()) - return mElements.at(index / columnCount()).at(index % columnCount()); - else - return 0; -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutGrid::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - mElements[index / columnCount()][index % columnCount()] = 0; - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutGrid::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; i<elementCount(); ++i) - { - if (elementAt(i) == element) - { - takeAt(i); - return true; - } - } - qDebug() << Q_FUNC_INFO << "Element not in this layout, couldn't take"; - } else - qDebug() << Q_FUNC_INFO << "Can't take null element"; - return false; -} - -/* inherits documentation from base class */ -QList<QCPLayoutElement*> QCPLayoutGrid::elements(bool recursive) const -{ - QList<QCPLayoutElement*> result; - int colC = columnCount(); - int rowC = rowCount(); -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(colC*rowC); -#endif - for (int row=0; row<rowC; ++row) - { - for (int col=0; col<colC; ++col) - { - result.append(mElements.at(row).at(col)); - } - } - if (recursive) - { - int c = result.size(); - for (int i=0; i<c; ++i) - { - if (result.at(i)) - result << result.at(i)->elements(recursive); - } - } - return result; -} - -/*! - Simplifies the layout by collapsing rows and columns which only contain empty cells. -*/ -void QCPLayoutGrid::simplify() -{ - // remove rows with only empty cells: - for (int row=rowCount()-1; row>=0; --row) - { - bool hasElements = false; - for (int col=0; col<columnCount(); ++col) - { - if (mElements.at(row).at(col)) - { - hasElements = true; - break; - } - } - if (!hasElements) - { - mRowStretchFactors.removeAt(row); - mElements.removeAt(row); - if (mElements.isEmpty()) // removed last element, also remove stretch factor (wouldn't happen below because also columnCount changed to 0 now) - mColumnStretchFactors.clear(); - } - } - - // remove columns with only empty cells: - for (int col=columnCount()-1; col>=0; --col) - { - bool hasElements = false; - for (int row=0; row<rowCount(); ++row) - { - if (mElements.at(row).at(col)) - { - hasElements = true; - break; - } - } - if (!hasElements) - { - mColumnStretchFactors.removeAt(col); - for (int row=0; row<rowCount(); ++row) - mElements[row].removeAt(col); - } - } -} - -/* inherits documentation from base class */ -QSize QCPLayoutGrid::minimumSizeHint() const -{ - QVector<int> minColWidths, minRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - QSize result(0, 0); - for (int i=0; i<minColWidths.size(); ++i) - result.rwidth() += minColWidths.at(i); - for (int i=0; i<minRowHeights.size(); ++i) - result.rheight() += minRowHeights.at(i); - result.rwidth() += qMax(0, columnCount()-1) * mColumnSpacing + mMargins.left() + mMargins.right(); - result.rheight() += qMax(0, rowCount()-1) * mRowSpacing + mMargins.top() + mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -QSize QCPLayoutGrid::maximumSizeHint() const -{ - QVector<int> maxColWidths, maxRowHeights; - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - QSize result(0, 0); - for (int i=0; i<maxColWidths.size(); ++i) - result.setWidth(qMin(result.width()+maxColWidths.at(i), QWIDGETSIZE_MAX)); - for (int i=0; i<maxRowHeights.size(); ++i) - result.setHeight(qMin(result.height()+maxRowHeights.at(i), QWIDGETSIZE_MAX)); - result.rwidth() += qMax(0, columnCount()-1) * mColumnSpacing + mMargins.left() + mMargins.right(); - result.rheight() += qMax(0, rowCount()-1) * mRowSpacing + mMargins.top() + mMargins.bottom(); - return result; -} - -/*! \internal - - Places the minimum column widths and row heights into \a minColWidths and \a minRowHeights - respectively. - - The minimum height of a row is the largest minimum height of any element in that row. The minimum - width of a column is the largest minimum width of any element in that column. - - This is a helper function for \ref updateLayout. - - \see getMaximumRowColSizes -*/ -void QCPLayoutGrid::getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const -{ - *minColWidths = QVector<int>(columnCount(), 0); - *minRowHeights = QVector<int>(rowCount(), 0); - for (int row=0; row<rowCount(); ++row) - { - for (int col=0; col<columnCount(); ++col) - { - if (mElements.at(row).at(col)) - { - QSize minHint = mElements.at(row).at(col)->minimumSizeHint(); - QSize min = mElements.at(row).at(col)->minimumSize(); - QSize final(min.width() > 0 ? min.width() : minHint.width(), min.height() > 0 ? min.height() : minHint.height()); - if (minColWidths->at(col) < final.width()) - (*minColWidths)[col] = final.width(); - if (minRowHeights->at(row) < final.height()) - (*minRowHeights)[row] = final.height(); - } - } - } -} - -/*! \internal - - Places the maximum column widths and row heights into \a maxColWidths and \a maxRowHeights - respectively. - - The maximum height of a row is the smallest maximum height of any element in that row. The - maximum width of a column is the smallest maximum width of any element in that column. - - This is a helper function for \ref updateLayout. - - \see getMinimumRowColSizes -*/ -void QCPLayoutGrid::getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const -{ - *maxColWidths = QVector<int>(columnCount(), QWIDGETSIZE_MAX); - *maxRowHeights = QVector<int>(rowCount(), QWIDGETSIZE_MAX); - for (int row=0; row<rowCount(); ++row) - { - for (int col=0; col<columnCount(); ++col) - { - if (mElements.at(row).at(col)) - { - QSize maxHint = mElements.at(row).at(col)->maximumSizeHint(); - QSize max = mElements.at(row).at(col)->maximumSize(); - QSize final(max.width() < QWIDGETSIZE_MAX ? max.width() : maxHint.width(), max.height() < QWIDGETSIZE_MAX ? max.height() : maxHint.height()); - if (maxColWidths->at(col) > final.width()) - (*maxColWidths)[col] = final.width(); - if (maxRowHeights->at(row) > final.height()) - (*maxRowHeights)[row] = final.height(); - } - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLayoutInset -//////////////////////////////////////////////////////////////////////////////////////////////////// -/*! \class QCPLayoutInset - \brief A layout that places child elements aligned to the border or arbitrarily positioned - - Elements are placed either aligned to the border or at arbitrary position in the area of the - layout. Which placement applies is controlled with the \ref InsetPlacement (\ref - setInsetPlacement). - - Elements are added via \ref addElement(QCPLayoutElement *element, Qt::Alignment alignment) or - addElement(QCPLayoutElement *element, const QRectF &rect). If the first method is used, the inset - placement will default to \ref ipBorderAligned and the element will be aligned according to the - \a alignment parameter. The second method defaults to \ref ipFree and allows placing elements at - arbitrary position and size, defined by \a rect. - - The alignment or rect can be set via \ref setInsetAlignment or \ref setInsetRect, respectively. - - This is the layout that every QCPAxisRect has as \ref QCPAxisRect::insetLayout. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual void QCPLayoutInset::simplify() - - The QCPInsetLayout does not need simplification since it can never have empty cells due to its - linear index structure. This method does nothing. -*/ - -/* end documentation of inline functions */ - -/*! - Creates an instance of QCPLayoutInset and sets default values. -*/ -QCPLayoutInset::QCPLayoutInset() -{ -} - -QCPLayoutInset::~QCPLayoutInset() -{ - // clear all child layout elements. This is important because only the specific layouts know how - // to handle removing elements (clear calls virtual removeAt method to do that). - clear(); -} - -/*! - Returns the placement type of the element with the specified \a index. -*/ -QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const -{ - if (elementAt(index)) - return mInsetPlacement.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return ipFree; - } -} - -/*! - Returns the alignment of the element with the specified \a index. The alignment only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. -*/ -Qt::Alignment QCPLayoutInset::insetAlignment(int index) const -{ - if (elementAt(index)) - return mInsetAlignment.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return 0; - } -} - -/*! - Returns the rect of the element with the specified \a index. The rect only has a - meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. -*/ -QRectF QCPLayoutInset::insetRect(int index) const -{ - if (elementAt(index)) - return mInsetRect.at(index); - else - { - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; - return QRectF(); - } -} - -/*! - Sets the inset placement type of the element with the specified \a index to \a placement. - - \see InsetPlacement -*/ -void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) -{ - if (elementAt(index)) - mInsetPlacement[index] = placement; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned, this function - is used to set the alignment of the element with the specified \a index to \a alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. -*/ -void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) -{ - if (elementAt(index)) - mInsetAlignment[index] = alignment; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/*! - If the inset placement (\ref setInsetPlacement) is \ref ipFree, this function is used to set the - position and size of the element with the specified \a index to \a rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - Note that the minimum and maximum sizes of the embedded element (\ref - QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. -*/ -void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) -{ - if (elementAt(index)) - mInsetRect[index] = rect; - else - qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; -} - -/* inherits documentation from base class */ -void QCPLayoutInset::updateLayout() -{ - for (int i=0; i<mElements.size(); ++i) - { - QRect insetRect; - QSize finalMinSize, finalMaxSize; - QSize minSizeHint = mElements.at(i)->minimumSizeHint(); - QSize maxSizeHint = mElements.at(i)->maximumSizeHint(); - finalMinSize.setWidth(mElements.at(i)->minimumSize().width() > 0 ? mElements.at(i)->minimumSize().width() : minSizeHint.width()); - finalMinSize.setHeight(mElements.at(i)->minimumSize().height() > 0 ? mElements.at(i)->minimumSize().height() : minSizeHint.height()); - finalMaxSize.setWidth(mElements.at(i)->maximumSize().width() < QWIDGETSIZE_MAX ? mElements.at(i)->maximumSize().width() : maxSizeHint.width()); - finalMaxSize.setHeight(mElements.at(i)->maximumSize().height() < QWIDGETSIZE_MAX ? mElements.at(i)->maximumSize().height() : maxSizeHint.height()); - if (mInsetPlacement.at(i) == ipFree) - { - insetRect = QRect(rect().x()+rect().width()*mInsetRect.at(i).x(), - rect().y()+rect().height()*mInsetRect.at(i).y(), - rect().width()*mInsetRect.at(i).width(), - rect().height()*mInsetRect.at(i).height()); - if (insetRect.size().width() < finalMinSize.width()) - insetRect.setWidth(finalMinSize.width()); - if (insetRect.size().height() < finalMinSize.height()) - insetRect.setHeight(finalMinSize.height()); - if (insetRect.size().width() > finalMaxSize.width()) - insetRect.setWidth(finalMaxSize.width()); - if (insetRect.size().height() > finalMaxSize.height()) - insetRect.setHeight(finalMaxSize.height()); - } else if (mInsetPlacement.at(i) == ipBorderAligned) - { - insetRect.setSize(finalMinSize); - Qt::Alignment al = mInsetAlignment.at(i); - if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); - else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); - else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter - if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); - else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); - else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter - } - mElements.at(i)->setOuterRect(insetRect); - } -} - -/* inherits documentation from base class */ -int QCPLayoutInset::elementCount() const -{ - return mElements.size(); -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::elementAt(int index) const -{ - if (index >= 0 && index < mElements.size()) - return mElements.at(index); - else - return 0; -} - -/* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::takeAt(int index) -{ - if (QCPLayoutElement *el = elementAt(index)) - { - releaseElement(el); - mElements.removeAt(index); - mInsetPlacement.removeAt(index); - mInsetAlignment.removeAt(index); - mInsetRect.removeAt(index); - return el; - } else - { - qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; - return 0; - } -} - -/* inherits documentation from base class */ -bool QCPLayoutInset::take(QCPLayoutElement *element) -{ - if (element) - { - for (int i=0; i<elementCount(); ++i) - { - if (elementAt(i) == element) - { - takeAt(i); - return true; - } - } - qDebug() << Q_FUNC_INFO << "Element not in this layout, couldn't take"; - } else - qDebug() << Q_FUNC_INFO << "Can't take null element"; - return false; -} - -/*! - The inset layout is sensitive to events only at areas where its (visible) child elements are - sensitive. If the selectTest method of any of the child elements returns a positive number for \a - pos, this method returns a value corresponding to 0.99 times the parent plot's selection - tolerance. The inset layout is not selectable itself by default. So if \a onlySelectable is true, - -1.0 is returned. - - See \ref QCPLayerable::selectTest for a general explanation of this virtual method. -*/ -double QCPLayoutInset::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable) - return -1; - - for (int i=0; i<mElements.size(); ++i) - { - // inset layout shall only return positive selectTest, if actually an inset object is at pos - // else it would block the entire underlying QCPAxisRect with its surface. - if (mElements.at(i)->realVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/*! - Adds the specified \a element to the layout as an inset aligned at the border (\ref - setInsetAlignment is initialized with \ref ipBorderAligned). The alignment is set to \a - alignment. - - \a alignment is an or combination of the following alignment flags: Qt::AlignLeft, - Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other - alignment flags will be ignored. - - \see addElement(QCPLayoutElement *element, const QRectF &rect) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipBorderAligned); - mInsetAlignment.append(alignment); - mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} - -/*! - Adds the specified \a element to the layout as an inset with free positioning/sizing (\ref - setInsetAlignment is initialized with \ref ipFree). The position and size is set to \a - rect. - - \a rect is given in fractions of the whole inset layout rect. So an inset with rect (0, 0, 1, 1) - will span the entire layout. An inset with rect (0.6, 0.1, 0.35, 0.35) will be in the top right - corner of the layout, with 35% width and height of the parent layout. - - \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) -*/ -void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) -{ - if (element) - { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipFree); - mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); - mInsetRect.append(rect); - adoptElement(element); - } else - qDebug() << Q_FUNC_INFO << "Can't add null element"; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLineEnding -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLineEnding - \brief Handles the different ending decorations for line-like items - - \image html QCPLineEnding.png "The various ending styles currently supported" - - For every ending a line-like item has, an instance of this class exists. For example, QCPItemLine - has two endings which can be set with QCPItemLine::setHead and QCPItemLine::setTail. - - The styles themselves are defined via the enum QCPLineEnding::EndingStyle. Most decorations can - be modified regarding width and length, see \ref setWidth and \ref setLength. The direction of - the ending decoration (e.g. direction an arrow is pointing) is controlled by the line-like item. - For example, when both endings of a QCPItemLine are set to be arrows, they will point to opposite - directions, e.g. "outward". This can be changed by \ref setInverted, which would make the - respective arrow point inward. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify a - QCPLineEnding::EndingStyle where actually a QCPLineEnding is expected, e.g. \code - myItemLine->setHead(QCPLineEnding::esSpikeArrow) \endcode -*/ - -/*! - Creates a QCPLineEnding instance with default values (style \ref esNone). -*/ -QCPLineEnding::QCPLineEnding() : - mStyle(esNone), - mWidth(8), - mLength(10), - mInverted(false) -{ -} - -/*! - Creates a QCPLineEnding instance with the specified values. -*/ -QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : - mStyle(style), - mWidth(width), - mLength(length), - mInverted(inverted) -{ -} - -/*! - Sets the style of the ending decoration. -*/ -void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) -{ - mStyle = style; -} - -/*! - Sets the width of the ending decoration, if the style supports it. On arrows, for example, the - width defines the size perpendicular to the arrow's pointing direction. - - \see setLength -*/ -void QCPLineEnding::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the length of the ending decoration, if the style supports it. On arrows, for example, the - length defines the size in pointing direction. - - \see setWidth -*/ -void QCPLineEnding::setLength(double length) -{ - mLength = length; -} - -/*! - Sets whether the ending decoration shall be inverted. For example, an arrow decoration will point - inward when \a inverted is set to true. - - Note that also the \a width direction is inverted. For symmetrical ending styles like arrows or - discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are - affected by it, which can be used to control to which side the half bar points to. -*/ -void QCPLineEnding::setInverted(bool inverted) -{ - mInverted = inverted; -} - -/*! \internal - - Returns the maximum pixel radius the ending decoration might cover, starting from the position - the decoration is drawn at (typically a line ending/\ref QCPItemPosition of an item). - - This is relevant for clipping. Only omit painting of the decoration when the position where the - decoration is supposed to be drawn is farther away from the clipping rect than the returned - distance. -*/ -double QCPLineEnding::boundingDistance() const -{ - switch (mStyle) - { - case esNone: - return 0; - - case esFlatArrow: - case esSpikeArrow: - case esLineArrow: - case esSkewedBar: - return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length - - case esDisc: - case esSquare: - case esDiamond: - case esBar: - case esHalfBar: - return mWidth*1.42; // items that only have a width -> width*sqrt(2) - - } - return 0; -} - -/*! - Starting from the origin of this line ending (which is style specific), returns the length - covered by the line ending symbol, in backward direction. - - For example, the \ref esSpikeArrow has a shorter real length than a \ref esFlatArrow, even if - both have the same \ref setLength value, because the spike arrow has an inward curved back, which - reduces the length along its center axis (the drawing origin for arrows is at the tip). - - This function is used for precise, style specific placement of line endings, for example in - QCPAxes. -*/ -double QCPLineEnding::realLength() const -{ - switch (mStyle) - { - case esNone: - case esLineArrow: - case esSkewedBar: - case esBar: - case esHalfBar: - return 0; - - case esFlatArrow: - return mLength; - - case esDisc: - case esSquare: - case esDiamond: - return mWidth*0.5; - - case esSpikeArrow: - return mLength*0.8; - } - return 0; -} - -/*! \internal - - Draws the line ending with the specified \a painter at the position \a pos. The direction of the - line ending is controlled with \a dir. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const -{ - if (mStyle == esNone) - return; - - QVector2D lengthVec(dir.normalized()); - if (lengthVec.isNull()) - lengthVec = QVector2D(1, 0); - QVector2D widthVec(-lengthVec.y(), lengthVec.x()); - lengthVec *= (float)(mLength*(mInverted ? -1 : 1)); - widthVec *= (float)(mWidth*0.5*(mInverted ? -1 : 1)); - - QPen penBackup = painter->pen(); - QBrush brushBackup = painter->brush(); - QPen miterPen = penBackup; - miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey - QBrush brush(painter->pen().color(), Qt::SolidPattern); - switch (mStyle) - { - case esNone: break; - case esFlatArrow: - { - QPointF points[3] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 3); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esSpikeArrow: - { - QPointF points[4] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec*0.8f).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esLineArrow: - { - QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), - pos.toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->drawPolyline(points, 3); - painter->setPen(penBackup); - break; - } - case esDisc: - { - painter->setBrush(brush); - painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); - painter->setBrush(brushBackup); - break; - } - case esSquare: - { - QVector2D widthVecPerp(-widthVec.y(), widthVec.x()); - QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), - (pos-widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esDiamond: - { - QVector2D widthVecPerp(-widthVec.y(), widthVec.x()); - QPointF points[4] = {(pos-widthVecPerp).toPointF(), - (pos-widthVec).toPointF(), - (pos+widthVecPerp).toPointF(), - (pos+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esBar: - { - painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); - break; - } - case esHalfBar: - { - painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); - break; - } - case esSkewedBar: - { - if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) - { - // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line - painter->drawLine((pos+widthVec+lengthVec*0.2f*(mInverted?-1:1)).toPointF(), - (pos-widthVec-lengthVec*0.2f*(mInverted?-1:1)).toPointF()); - } else - { - // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly - painter->drawLine((pos+widthVec+lengthVec*0.2f*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), - (pos-widthVec-lengthVec*0.2f*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); - } - break; - } - } -} - -/*! \internal - \overload - - Draws the line ending. The direction is controlled with the \a angle parameter in radians. -*/ -void QCPLineEnding::draw(QCPPainter *painter, const QVector2D &pos, double angle) const -{ - draw(painter, pos, QVector2D(qCos(angle), qSin(angle))); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGrid -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGrid - \brief Responsible for drawing the grid of a QCPAxis. - - This class is tightly bound to QCPAxis. Every axis owns a grid instance and uses it to draw the - grid lines, sub grid lines and zero-line. You can interact with the grid of an axis via \ref - QCPAxis::grid. Normally, you don't need to create an instance of QCPGrid yourself. - - The axis and grid drawing was split into two classes to allow them to be placed on different - layers (both QCPAxis and QCPGrid inherit from QCPLayerable). Thus it is possible to have the grid - in the background and the axes in the foreground, and any plottables/items in between. This - described situation is the default setup, see the QCPLayer documentation. -*/ - -/*! - Creates a QCPGrid instance and sets default values. - - You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. -*/ -QCPGrid::QCPGrid(QCPAxis *parentAxis) : - QCPLayerable(parentAxis->parentPlot(), "", parentAxis), - mParentAxis(parentAxis) -{ - // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called - setParent(parentAxis); - setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); - setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); - setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); - setSubGridVisible(false); - setAntialiased(false); - setAntialiasedSubGrid(false); - setAntialiasedZeroLine(false); -} - -/*! - Sets whether grid lines at sub tick marks are drawn. - - \see setSubGridPen -*/ -void QCPGrid::setSubGridVisible(bool visible) -{ - mSubGridVisible = visible; -} - -/*! - Sets whether sub grid lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedSubGrid(bool enabled) -{ - mAntialiasedSubGrid = enabled; -} - -/*! - Sets whether zero lines are drawn antialiased. -*/ -void QCPGrid::setAntialiasedZeroLine(bool enabled) -{ - mAntialiasedZeroLine = enabled; -} - -/*! - Sets the pen with which (major) grid lines are drawn. -*/ -void QCPGrid::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen with which sub grid lines are drawn. -*/ -void QCPGrid::setSubGridPen(const QPen &pen) -{ - mSubGridPen = pen; -} - -/*! - Sets the pen with which zero lines are drawn. - - Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid - lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. -*/ -void QCPGrid::setZeroLinePen(const QPen &pen) -{ - mZeroLinePen = pen; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing the major grid lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); -} - -/*! \internal - - Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning - over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). -*/ -void QCPGrid::draw(QCPPainter *painter) -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - if (mSubGridVisible) - drawSubGridLines(painter); - drawGridLines(painter); -} - -/*! \internal - - Draws the main grid lines and possibly a zero line with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - int lowTick = mParentAxis->mLowestVisibleTick; - int highTick = mParentAxis->mHighestVisibleTick; - double t; // helper variable, result of coordinate-to-pixel transforms - if (mParentAxis->orientation() == Qt::Horizontal) - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero - for (int i=lowTick; i <= highTick; ++i) - { - if (qAbs(mParentAxis->mTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=lowTick; i <= highTick; ++i) - { - if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - // draw zeroline: - int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) - { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero - for (int i=lowTick; i <= highTick; ++i) - { - if (qAbs(mParentAxis->mTickVector.at(i)) < epsilon) - { - zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - break; - } - } - } - // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=lowTick; i <= highTick; ++i) - { - if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - -/*! \internal - - Draws the sub grid lines with the specified painter. - - This is a helper function called by \ref draw. -*/ -void QCPGrid::drawSubGridLines(QCPPainter *painter) const -{ - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); - double t; // helper variable, result of coordinate-to-pixel transforms - painter->setPen(mSubGridPen); - if (mParentAxis->orientation() == Qt::Horizontal) - { - for (int i=0; i<mParentAxis->mSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); - } - } else - { - for (int i=0; i<mParentAxis->mSubTickVector.size(); ++i) - { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxis -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxis - \brief Manages a single axis inside a QCustomPlot. - - Usually doesn't need to be instantiated externally. Access %QCustomPlot's default four axes via - QCustomPlot::xAxis (bottom), QCustomPlot::yAxis (left), QCustomPlot::xAxis2 (top) and - QCustomPlot::yAxis2 (right). - - Axes are always part of an axis rect, see QCPAxisRect. - \image html AxisNamesOverview.png - <center>Naming convention of axis parts</center> - \n - - \image html AxisRectSpacingOverview.png - <center>Overview of the spacings and paddings that define the geometry of an axis. The dashed gray line - on the left represents the QCustomPlot widget border.</center> - -*/ - -/* start of documentation of inline functions */ - -/*! \fn Qt::Orientation QCPAxis::orientation() const - - Returns the orientation of this axis. The axis orientation (horizontal or vertical) is deduced - from the axis type (left, top, right or bottom). - - \see orientation(AxisType type) -*/ - -/*! \fn QCPGrid *QCPAxis::grid() const - - Returns the \ref QCPGrid instance belonging to this axis. Access it to set details about the way the - grid is displayed. -*/ - -/*! \fn static Qt::Orientation QCPAxis::orientation(AxisType type) - - Returns the orientation of the specified axis type - - \see orientation() -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAxis::ticksRequest() - - This signal is emitted when \ref setAutoTicks is false and the axis is about to generate tick - labels for a replot. - - Modifying the tick positions can be done with \ref setTickVector. If you also want to control the - tick labels, set \ref setAutoTickLabels to false and also provide the labels with \ref - setTickVectorLabels. - - If you only want static ticks you probably don't need this signal, since you can just set the - tick vector (and possibly tick label vector) once. However, if you want to provide ticks (and - maybe labels) dynamically, e.g. depending on the current axis range, connect a slot to this - signal and set the vector/vectors there. -*/ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange) - - This signal is emitted when the range of this axis has changed. You can connect it to the \ref - setRange slot of another axis to communicate the new range to the other axis, in order for it to - be synchronized. -*/ - -/*! \fn void QCPAxis::rangeChanged(const QCPRange &newRange, const QCPRange &oldRange) - \overload - - Additionally to the new range, this signal also provides the previous range held by the axis as - \a oldRange. -*/ - -/*! \fn void QCPAxis::scaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the scale type changes, by calls to \ref setScaleType -*/ - -/*! \fn void QCPAxis::selectionChanged(QCPAxis::SelectableParts selection) - - This signal is emitted when the selection state of this axis has changed, either by user interaction - or by a direct call to \ref setSelectedParts. -*/ - -/*! \fn void QCPAxis::selectableChanged(const QCPAxis::SelectableParts &parts); - - This signal is emitted when the selectability changes, by calls to \ref setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs an Axis instance of Type \a type for the axis rect \a parent. - You shouldn't instantiate axes directly, rather use \ref QCPAxisRect::addAxis. -*/ -QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : - QCPLayerable(parent->parentPlot(), "", parent), - // axis base: - mAxisType(type), - mAxisRect(parent), - mPadding(5), - mOrientation(orientation(type)), - mSelectableParts(spAxis | spTickLabels | spAxisLabel), - mSelectedParts(spNone), - mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedBasePen(QPen(Qt::blue, 2)), - // axis label: - mLabel(""), - mLabelFont(mParentPlot->font()), - mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), - mLabelColor(Qt::black), - mSelectedLabelColor(Qt::blue), - // tick labels: - mTickLabels(true), - mAutoTickLabels(true), - mTickLabelType(ltNumber), - mTickLabelFont(mParentPlot->font()), - mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), - mTickLabelColor(Qt::black), - mSelectedTickLabelColor(Qt::blue), - mDateTimeFormat("hh:mm:ss\ndd.MM.yy"), - mDateTimeSpec(Qt::LocalTime), - mNumberPrecision(6), - mNumberFormatChar('g'), - mNumberBeautifulPowers(true), - // ticks and subticks: - mTicks(true), - mTickStep(1), - mSubTickCount(4), - mAutoTickCount(6), - mAutoTicks(true), - mAutoTickStep(true), - mAutoSubTicks(true), - mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedTickPen(QPen(Qt::blue, 2)), - mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedSubTickPen(QPen(Qt::blue, 2)), - // scale and range: - mRange(0, 5), - mRangeReversed(false), - mScaleType(stLinear), - mScaleLogBase(10), - mScaleLogBaseLogInv(1.0/qLn(mScaleLogBase)), - // internal members: - mGrid(new QCPGrid(this)), - mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), - mLowestVisibleTick(0), - mHighestVisibleTick(-1), - mCachedMarginValid(false), - mCachedMargin(0) -{ - mGrid->setVisible(false); - setAntialiased(false); - setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again - - if (type == atTop) - { - setTickLabelPadding(3); - setLabelPadding(6); - } else if (type == atRight) - { - setTickLabelPadding(7); - setLabelPadding(12); - } else if (type == atBottom) - { - setTickLabelPadding(3); - setLabelPadding(3); - } else if (type == atLeft) - { - setTickLabelPadding(5); - setLabelPadding(10); - } -} - -QCPAxis::~QCPAxis() -{ - delete mAxisPainter; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLabelPadding() const -{ - return mAxisPainter->tickLabelPadding; -} - -/* No documentation as it is a property getter */ -double QCPAxis::tickLabelRotation() const -{ - return mAxisPainter->tickLabelRotation; -} - -/* No documentation as it is a property getter */ -QString QCPAxis::numberFormat() const -{ - QString result; - result.append(mNumberFormatChar); - if (mNumberBeautifulPowers) - { - result.append("b"); - if (mAxisPainter->numberMultiplyCross) - result.append("c"); - } - return result; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthIn() const -{ - return mAxisPainter->tickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::tickLengthOut() const -{ - return mAxisPainter->tickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthIn() const -{ - return mAxisPainter->subTickLengthIn; -} - -/* No documentation as it is a property getter */ -int QCPAxis::subTickLengthOut() const -{ - return mAxisPainter->subTickLengthOut; -} - -/* No documentation as it is a property getter */ -int QCPAxis::labelPadding() const -{ - return mAxisPainter->labelPadding; -} - -/* No documentation as it is a property getter */ -int QCPAxis::offset() const -{ - return mAxisPainter->offset; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::lowerEnding() const -{ - return mAxisPainter->lowerEnding; -} - -/* No documentation as it is a property getter */ -QCPLineEnding QCPAxis::upperEnding() const -{ - return mAxisPainter->upperEnding; -} - -/*! - Sets whether the axis uses a linear scale or a logarithmic scale. If \a type is set to \ref - stLogarithmic, the logarithm base can be set with \ref setScaleLogBase. In logarithmic axis - scaling, major tick marks appear at all powers of the logarithm base. Properties like tick step - (\ref setTickStep) don't apply in logarithmic scaling. If you wish a decimal base but less major - ticks, consider choosing a logarithm base of 100, 1000 or even higher. - - If \a type is \ref stLogarithmic and the number format (\ref setNumberFormat) uses the 'b' option - (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10 - [superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]" - part). To only display the decimal power, set the number precision to zero with - \ref setNumberPrecision. -*/ -void QCPAxis::setScaleType(QCPAxis::ScaleType type) -{ - if (mScaleType != type) - { - mScaleType = type; - if (mScaleType == stLogarithmic) - setRange(mRange.sanitizedForLogScale()); - mCachedMarginValid = false; - emit scaleTypeChanged(mScaleType); - } -} - -/*! - If \ref setScaleType is set to \ref stLogarithmic, \a base will be the logarithm base of the - scaling. In logarithmic axis scaling, major tick marks appear at all powers of \a base. - - Properties like tick step (\ref setTickStep) don't apply in logarithmic scaling. If you wish a decimal base but - less major ticks, consider choosing \a base 100, 1000 or even higher. -*/ -void QCPAxis::setScaleLogBase(double base) -{ - if (base > 1) - { - mScaleLogBase = base; - mScaleLogBaseLogInv = 1.0/qLn(mScaleLogBase); // buffer for faster baseLog() calculation - mCachedMarginValid = false; - } else - qDebug() << Q_FUNC_INFO << "Invalid logarithmic scale base (must be greater 1):" << base; -} - -/*! - Sets the range of the axis. - - This slot may be connected with the \ref rangeChanged signal of another axis so this axis - is always synchronized with the other axis range, when it changes. - - To invert the direction of an axis, use \ref setRangeReversed. -*/ -void QCPAxis::setRange(const QCPRange &range) -{ - if (range.lower == mRange.lower && range.upper == mRange.upper) - return; - - if (!QCPRange::validRange(range)) return; - QCPRange oldRange = mRange; - if (mScaleType == stLogarithmic) - { - mRange = range.sanitizedForLogScale(); - } else - { - mRange = range.sanitizedForLinScale(); - } - mCachedMarginValid = false; - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains iSelectAxes.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPAxis::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - emit selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective axis parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font. - - The entire selection mechanism for axes is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectAxes. You only need to call this function when you - wish to change the selection state manually. - - This function can change the selection state of a part, independent of the \ref setSelectableParts setting. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, - setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor -*/ -void QCPAxis::setSelectedParts(const SelectableParts &selected) -{ - if (mSelectedParts != selected) - { - mSelectedParts = selected; - emit selectionChanged(mSelectedParts); - } -} - -/*! - \overload - - Sets the lower and upper bound of the axis range. - - To invert the direction of an axis, use \ref setRangeReversed. - - There is also a slot to set a range, see \ref setRange(const QCPRange &range). -*/ -void QCPAxis::setRange(double lower, double upper) -{ - if (lower == mRange.lower && upper == mRange.upper) - return; - - if (!QCPRange::validRange(lower, upper)) return; - QCPRange oldRange = mRange; - mRange.lower = lower; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - mCachedMarginValid = false; - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - \overload - - Sets the range of the axis. - - The \a position coordinate indicates together with the \a alignment parameter, where the new - range will be positioned. \a size defines the size of the new axis range. \a alignment may be - Qt::AlignLeft, Qt::AlignRight or Qt::AlignCenter. This will cause the left border, right border, - or center of the range to be aligned with \a position. Any other values of \a alignment will - default to Qt::AlignCenter. -*/ -void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) -{ - if (alignment == Qt::AlignLeft) - setRange(position, position+size); - else if (alignment == Qt::AlignRight) - setRange(position-size, position); - else // alignment == Qt::AlignCenter - setRange(position-size/2.0, position+size/2.0); -} - -/*! - Sets the lower bound of the axis range. The upper bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeLower(double lower) -{ - if (mRange.lower == lower) - return; - - QCPRange oldRange = mRange; - mRange.lower = lower; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - mCachedMarginValid = false; - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Sets the upper bound of the axis range. The lower bound is not changed. - \see setRange -*/ -void QCPAxis::setRangeUpper(double upper) -{ - if (mRange.upper == upper) - return; - - QCPRange oldRange = mRange; - mRange.upper = upper; - if (mScaleType == stLogarithmic) - { - mRange = mRange.sanitizedForLogScale(); - } else - { - mRange = mRange.sanitizedForLinScale(); - } - mCachedMarginValid = false; - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Sets whether the axis range (direction) is displayed reversed. Normally, the values on horizontal - axes increase left to right, on vertical axes bottom to top. When \a reversed is set to true, the - direction of increasing values is inverted. - - Note that the range and data interface stays the same for reversed axes, e.g. the \a lower part - of the \ref setRange interface will still reference the mathematically smaller number than the \a - upper part. -*/ -void QCPAxis::setRangeReversed(bool reversed) -{ - if (mRangeReversed != reversed) - { - mRangeReversed = reversed; - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick positions should be calculated automatically (either from an automatically - generated tick step or a tick step provided manually via \ref setTickStep, see \ref setAutoTickStep). - - If \a on is set to false, you must provide the tick positions manually via \ref setTickVector. - For these manual ticks you may let QCPAxis generate the appropriate labels automatically by - leaving \ref setAutoTickLabels set to true. If you also wish to control the displayed labels - manually, set \ref setAutoTickLabels to false and provide the label strings with \ref - setTickVectorLabels. - - If you need dynamically calculated tick vectors (and possibly tick label vectors), set the - vectors in a slot connected to the \ref ticksRequest signal. - - \see setAutoTickLabels, setAutoSubTicks, setAutoTickCount, setAutoTickStep -*/ -void QCPAxis::setAutoTicks(bool on) -{ - if (mAutoTicks != on) - { - mAutoTicks = on; - mCachedMarginValid = false; - } -} - -/*! - When \ref setAutoTickStep is true, \a approximateCount determines how many ticks should be - generated in the visible range, approximately. - - It's not guaranteed that this number of ticks is met exactly, but approximately within a - tolerance of about two. - - Only values greater than zero are accepted as \a approximateCount. - - \see setAutoTickStep, setAutoTicks, setAutoSubTicks -*/ -void QCPAxis::setAutoTickCount(int approximateCount) -{ - if (mAutoTickCount != approximateCount) - { - if (approximateCount > 0) - { - mAutoTickCount = approximateCount; - mCachedMarginValid = false; - } else - qDebug() << Q_FUNC_INFO << "approximateCount must be greater than zero:" << approximateCount; - } -} - -/*! - Sets whether the tick labels are generated automatically. Depending on the tick label type (\ref - ltNumber or \ref ltDateTime), the labels will either show the coordinate as floating point - number (\ref setNumberFormat), or a date/time formatted according to \ref setDateTimeFormat. - - If \a on is set to false, you should provide the tick labels via \ref setTickVectorLabels. This - is usually used in a combination with \ref setAutoTicks set to false for complete control over - tick positions and labels, e.g. when the ticks should be at multiples of pi and show "2pi", "3pi" - etc. as tick labels. - - If you need dynamically calculated tick vectors (and possibly tick label vectors), set the - vectors in a slot connected to the \ref ticksRequest signal. - - \see setAutoTicks -*/ -void QCPAxis::setAutoTickLabels(bool on) -{ - if (mAutoTickLabels != on) - { - mAutoTickLabels = on; - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick step, i.e. the interval between two (major) ticks, is calculated - automatically. If \a on is set to true, the axis finds a tick step that is reasonable for human - readable plots. - - The number of ticks the algorithm aims for within the visible range can be specified with \ref - setAutoTickCount. - - If \a on is set to false, you may set the tick step manually with \ref setTickStep. - - \see setAutoTicks, setAutoSubTicks, setAutoTickCount -*/ -void QCPAxis::setAutoTickStep(bool on) -{ - if (mAutoTickStep != on) - { - mAutoTickStep = on; - mCachedMarginValid = false; - } -} - -/*! - Sets whether the number of sub ticks in one tick interval is determined automatically. This - works, as long as the tick step mantissa is a multiple of 0.5. When \ref setAutoTickStep is - enabled, this is always the case. - - When \a on is set to false, you may set the sub tick count with \ref setSubTickCount manually. - - \see setAutoTickCount, setAutoTicks, setAutoTickStep -*/ -void QCPAxis::setAutoSubTicks(bool on) -{ - if (mAutoSubTicks != on) - { - mAutoSubTicks = on; - mCachedMarginValid = false; - } -} - -/*! - Sets whether tick marks are displayed. - - Note that setting \a show to false does not imply that tick labels are invisible, too. To achieve - that, see \ref setTickLabels. -*/ -void QCPAxis::setTicks(bool show) -{ - if (mTicks != show) - { - mTicks = show; - mCachedMarginValid = false; - } -} - -/*! - Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. -*/ -void QCPAxis::setTickLabels(bool show) -{ - if (mTickLabels != show) - { - mTickLabels = show; - mCachedMarginValid = false; - } -} - -/*! - Sets the distance between the axis base line (including any outward ticks) and the tick labels. - \see setLabelPadding, setPadding -*/ -void QCPAxis::setTickLabelPadding(int padding) -{ - if (mAxisPainter->tickLabelPadding != padding) - { - mAxisPainter->tickLabelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets whether the tick labels display numbers or dates/times. - - If \a type is set to \ref ltNumber, the format specifications of \ref setNumberFormat apply. - - If \a type is set to \ref ltDateTime, the format specifications of \ref setDateTimeFormat apply. - - In QCustomPlot, date/time coordinates are <tt>double</tt> numbers representing the seconds since - 1970-01-01T00:00:00 UTC. This format can be retrieved from QDateTime objects with the - QDateTime::toTime_t() function. Since this only gives a resolution of one second, there is also - the QDateTime::toMSecsSinceEpoch() function which returns the timespan described above in - milliseconds. Divide its return value by 1000.0 to get a value with the format needed for - date/time plotting, with a resolution of one millisecond. - - Using the toMSecsSinceEpoch function allows dates that go back to 2nd January 4713 B.C. - (represented by a negative number), unlike the toTime_t function, which works with unsigned - integers and thus only goes back to 1st January 1970. So both for range and accuracy, use of - toMSecsSinceEpoch()/1000.0 should be preferred as key coordinate for date/time axes. - - \see setTickLabels -*/ -void QCPAxis::setTickLabelType(LabelType type) -{ - if (mTickLabelType != type) - { - mTickLabelType = type; - mCachedMarginValid = false; - } -} - -/*! - Sets the font of the tick labels. - - \see setTickLabels, setTickLabelColor -*/ -void QCPAxis::setTickLabelFont(const QFont &font) -{ - if (font != mTickLabelFont) - { - mTickLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the tick labels. - - \see setTickLabels, setTickLabelFont -*/ -void QCPAxis::setTickLabelColor(const QColor &color) -{ - if (color != mTickLabelColor) - { - mTickLabelColor = color; - mCachedMarginValid = false; - } -} - -/*! - Sets the rotation of the tick labels. If \a degrees is zero, the labels are drawn normally. Else, - the tick labels are drawn rotated by \a degrees clockwise. The specified angle is bound to values - from -90 to 90 degrees. - - If \a degrees is exactly -90, 0 or 90, the tick labels are centered on the tick coordinate. For - other angles, the label is drawn with an offset such that it seems to point toward or away from - the tick mark. -*/ -void QCPAxis::setTickLabelRotation(double degrees) -{ - if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) - { - mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); - mCachedMarginValid = false; - } -} - -/*! - Sets the format in which dates and times are displayed as tick labels, if \ref setTickLabelType is \ref ltDateTime. - for details about the \a format string, see the documentation of QDateTime::toString(). - - Newlines can be inserted with "\n". - - \see setDateTimeSpec -*/ -void QCPAxis::setDateTimeFormat(const QString &format) -{ - if (mDateTimeFormat != format) - { - mDateTimeFormat = format; - mCachedMarginValid = false; - } -} - -/*! - Sets the time spec that is used for the date time values when \ref setTickLabelType is \ref - ltDateTime. - - The default value of QDateTime objects (and also QCustomPlot) is <tt>Qt::LocalTime</tt>. However, - if the date time values passed to QCustomPlot are given in the UTC spec, set \a - timeSpec to <tt>Qt::UTC</tt> to get the correct axis labels. - - \see setDateTimeFormat -*/ -void QCPAxis::setDateTimeSpec(const Qt::TimeSpec &timeSpec) -{ - mDateTimeSpec = timeSpec; -} - -/*! - Sets the number format for the numbers drawn as tick labels (if tick label type is \ref - ltNumber). This \a formatCode is an extended version of the format code used e.g. by - QString::number() and QLocale::toString(). For reference about that, see the "Argument Formats" - section in the detailed description of the QString class. \a formatCode is a string of one, two - or three characters. The first character is identical to the normal format code used by Qt. In - short, this means: 'e'/'E' scientific format, 'f' fixed format, 'g'/'G' scientific or fixed, - whichever is shorter. - - The second and third characters are optional and specific to QCustomPlot:\n - If the first char was 'e' or 'g', numbers are/might be displayed in the scientific format, e.g. - "5.5e9", which is ugly in a plot. So when the second char of \a formatCode is set to 'b' (for - "beautiful"), those exponential numbers are formatted in a more natural way, i.e. "5.5 - [multiplication sign] 10 [superscript] 9". By default, the multiplication sign is a centered dot. - If instead a cross should be shown (as is usual in the USA), the third char of \a formatCode can - be set to 'c'. The inserted multiplication signs are the UTF-8 characters 215 (0xD7) for the - cross and 183 (0xB7) for the dot. - - If the scale type (\ref setScaleType) is \ref stLogarithmic and the \a formatCode uses the 'b' - option (beautifully typeset decimal powers), the display usually is "1 [multiplication sign] 10 - [superscript] n", which looks unnatural for logarithmic scaling (the "1 [multiplication sign]" - part). To only display the decimal power, set the number precision to zero with \ref - setNumberPrecision. - - Examples for \a formatCode: - \li \c g normal format code behaviour. If number is small, fixed format is used, if number is large, - normal scientific format is used - \li \c gb If number is small, fixed format is used, if number is large, scientific format is used with - beautifully typeset decimal powers and a dot as multiplication sign - \li \c ebc All numbers are in scientific format with beautifully typeset decimal power and a cross as - multiplication sign - \li \c fb illegal format code, since fixed format doesn't support (or need) beautifully typeset decimal - powers. Format code will be reduced to 'f'. - \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format - code will not be changed. -*/ -void QCPAxis::setNumberFormat(const QString &formatCode) -{ - if (formatCode.isEmpty()) - { - qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; - return; - } - mCachedMarginValid = false; - - // interpret first char as number format char: - QString allowedFormatChars = "eEfgG"; - if (allowedFormatChars.contains(formatCode.at(0))) - { - mNumberFormatChar = formatCode.at(0).toLatin1(); - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; - return; - } - if (formatCode.length() < 2) - { - mNumberBeautifulPowers = false; - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret second char as indicator for beautiful decimal powers: - if (formatCode.at(1) == 'b' && (mNumberFormatChar == 'e' || mNumberFormatChar == 'g')) - { - mNumberBeautifulPowers = true; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - return; - } - if (formatCode.length() < 3) - { - mAxisPainter->numberMultiplyCross = false; - return; - } - - // interpret third char as indicator for dot or cross multiplication symbol: - if (formatCode.at(2) == 'c') - { - mAxisPainter->numberMultiplyCross = true; - } else if (formatCode.at(2) == 'd') - { - mAxisPainter->numberMultiplyCross = false; - } else - { - qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; - return; - } -} - -/*! - Sets the precision of the tick label numbers. See QLocale::toString(double i, char f, int prec) - for details. The effect of precisions are most notably for number Formats starting with 'e', see - \ref setNumberFormat - - If the scale type (\ref setScaleType) is \ref stLogarithmic and the number format (\ref - setNumberFormat) uses the 'b' format code (beautifully typeset decimal powers), the display - usually is "1 [multiplication sign] 10 [superscript] n", which looks unnatural for logarithmic - scaling (the redundant "1 [multiplication sign]" part). To only display the decimal power "10 - [superscript] n", set \a precision to zero. -*/ -void QCPAxis::setNumberPrecision(int precision) -{ - if (mNumberPrecision != precision) - { - mNumberPrecision = precision; - mCachedMarginValid = false; - } -} - -/*! - If \ref setAutoTickStep is set to false, use this function to set the tick step manually. - The tick step is the interval between (major) ticks, in plot coordinates. - \see setSubTickCount -*/ -void QCPAxis::setTickStep(double step) -{ - if (mTickStep != step) - { - mTickStep = step; - mCachedMarginValid = false; - } -} - -/*! - If you want full control over what ticks (and possibly labels) the axes show, this function is - used to set the coordinates at which ticks will appear.\ref setAutoTicks must be disabled, else - the provided tick vector will be overwritten with automatically generated tick coordinates upon - replot. The labels of the ticks can be generated automatically when \ref setAutoTickLabels is - left enabled. If it is disabled, you can set the labels manually with \ref setTickVectorLabels. - - \a vec is a vector containing the positions of the ticks, in plot coordinates. - - \warning \a vec must be sorted in ascending order, no additional checks are made to ensure this. - - \see setTickVectorLabels -*/ -void QCPAxis::setTickVector(const QVector<double> &vec) -{ - // don't check whether mTickVector != vec here, because it takes longer than we would save - mTickVector = vec; - mCachedMarginValid = false; -} - -/*! - If you want full control over what ticks and labels the axes show, this function is used to set a - number of QStrings that will be displayed at the tick positions which you need to provide with - \ref setTickVector. These two vectors should have the same size. (Note that you need to disable - \ref setAutoTicks and \ref setAutoTickLabels first.) - - \a vec is a vector containing the labels of the ticks. The entries correspond to the respective - indices in the tick vector, passed via \ref setTickVector. - - \see setTickVector -*/ -void QCPAxis::setTickVectorLabels(const QVector<QString> &vec) -{ - // don't check whether mTickVectorLabels != vec here, because it takes longer than we would save - mTickVectorLabels = vec; - mCachedMarginValid = false; -} - -/*! - Sets the length of the ticks in pixels. \a inside is the length the ticks will reach inside the - plot and \a outside is the length they will reach outside the plot. If \a outside is greater than - zero, the tick labels and axis label will increase their distance to the axis accordingly, so - they won't collide with the ticks. - - \see setSubTickLength, setTickLengthIn, setTickLengthOut -*/ -void QCPAxis::setTickLength(int inside, int outside) -{ - setTickLengthIn(inside); - setTickLengthOut(outside); -} - -/*! - Sets the length of the inward ticks in pixels. \a inside is the length the ticks will reach - inside the plot. - - \see setTickLengthOut, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthIn(int inside) -{ - if (mAxisPainter->tickLengthIn != inside) - { - mAxisPainter->tickLengthIn = inside; - } -} - -/*! - Sets the length of the outward ticks in pixels. \a outside is the length the ticks will reach - outside the plot. If \a outside is greater than zero, the tick labels and axis label will - increase their distance to the axis accordingly, so they won't collide with the ticks. - - \see setTickLengthIn, setTickLength, setSubTickLength -*/ -void QCPAxis::setTickLengthOut(int outside) -{ - if (mAxisPainter->tickLengthOut != outside) - { - mAxisPainter->tickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets the number of sub ticks in one (major) tick step. A sub tick count of three for example, - divides the tick intervals in four sub intervals. - - By default, the number of sub ticks is chosen automatically in a reasonable manner as long as the - mantissa of the tick step is a multiple of 0.5. When \ref setAutoTickStep is enabled, this is - always the case. - - If you want to disable automatic sub tick count and use this function to set the count manually, - see \ref setAutoSubTicks. -*/ -void QCPAxis::setSubTickCount(int count) -{ - mSubTickCount = count; -} - -/*! - Sets the length of the subticks in pixels. \a inside is the length the subticks will reach inside - the plot and \a outside is the length they will reach outside the plot. If \a outside is greater - than zero, the tick labels and axis label will increase their distance to the axis accordingly, - so they won't collide with the ticks. - - \see setTickLength, setSubTickLengthIn, setSubTickLengthOut -*/ -void QCPAxis::setSubTickLength(int inside, int outside) -{ - setSubTickLengthIn(inside); - setSubTickLengthOut(outside); -} - -/*! - Sets the length of the inward subticks in pixels. \a inside is the length the subticks will reach inside - the plot. - - \see setSubTickLengthOut, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthIn(int inside) -{ - if (mAxisPainter->subTickLengthIn != inside) - { - mAxisPainter->subTickLengthIn = inside; - } -} - -/*! - Sets the length of the outward subticks in pixels. \a outside is the length the subticks will reach - outside the plot. If \a outside is greater than zero, the tick labels will increase their - distance to the axis accordingly, so they won't collide with the ticks. - - \see setSubTickLengthIn, setSubTickLength, setTickLength -*/ -void QCPAxis::setSubTickLengthOut(int outside) -{ - if (mAxisPainter->subTickLengthOut != outside) - { - mAxisPainter->subTickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin - } -} - -/*! - Sets the pen, the axis base line is drawn with. - - \see setTickPen, setSubTickPen -*/ -void QCPAxis::setBasePen(const QPen &pen) -{ - mBasePen = pen; -} - -/*! - Sets the pen, tick marks will be drawn with. - - \see setTickLength, setBasePen -*/ -void QCPAxis::setTickPen(const QPen &pen) -{ - mTickPen = pen; -} - -/*! - Sets the pen, subtick marks will be drawn with. - - \see setSubTickCount, setSubTickLength, setBasePen -*/ -void QCPAxis::setSubTickPen(const QPen &pen) -{ - mSubTickPen = pen; -} - -/*! - Sets the font of the axis label. - - \see setLabelColor -*/ -void QCPAxis::setLabelFont(const QFont &font) -{ - if (mLabelFont != font) - { - mLabelFont = font; - mCachedMarginValid = false; - } -} - -/*! - Sets the color of the axis label. - - \see setLabelFont -*/ -void QCPAxis::setLabelColor(const QColor &color) -{ - mLabelColor = color; -} - -/*! - Sets the text of the axis label that will be shown below/above or next to the axis, depending on - its orientation. To disable axis labels, pass an empty string as \a str. -*/ -void QCPAxis::setLabel(const QString &str) -{ - if (mLabel != str) - { - mLabel = str; - mCachedMarginValid = false; - } -} - -/*! - Sets the distance between the tick labels and the axis label. - - \see setTickLabelPadding, setPadding -*/ -void QCPAxis::setLabelPadding(int padding) -{ - if (mAxisPainter->labelPadding != padding) - { - mAxisPainter->labelPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the padding of the axis. - - When \ref QCPAxisRect::setAutoMargins is enabled, the padding is the additional outer most space, - that is left blank. - - The axis padding has no meaning if \ref QCPAxisRect::setAutoMargins is disabled. - - \see setLabelPadding, setTickLabelPadding -*/ -void QCPAxis::setPadding(int padding) -{ - if (mPadding != padding) - { - mPadding = padding; - mCachedMarginValid = false; - } -} - -/*! - Sets the offset the axis has to its axis rect side. - - If an axis rect side has multiple axes and automatic margin calculation is enabled for that side, - only the offset of the inner most axis has meaning (even if it is set to be invisible). The - offset of the other, outer axes is controlled automatically, to place them at appropriate - positions. -*/ -void QCPAxis::setOffset(int offset) -{ - mAxisPainter->offset = offset; -} - -/*! - Sets the font that is used for tick labels when they are selected. - - \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelFont(const QFont &font) -{ - if (font != mSelectedTickLabelFont) - { - mSelectedTickLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts - } -} - -/*! - Sets the font that is used for the axis label when it is selected. - - \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelFont(const QFont &font) -{ - mSelectedLabelFont = font; - // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts -} - -/*! - Sets the color that is used for tick labels when they are selected. - - \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickLabelColor(const QColor &color) -{ - if (color != mSelectedTickLabelColor) - { - mSelectedTickLabelColor = color; - } -} - -/*! - Sets the color that is used for the axis label when it is selected. - - \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedLabelColor(const QColor &color) -{ - mSelectedLabelColor = color; -} - -/*! - Sets the pen that is used to draw the axis base line when selected. - - \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedBasePen(const QPen &pen) -{ - mSelectedBasePen = pen; -} - -/*! - Sets the pen that is used to draw the (major) ticks when selected. - - \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedTickPen(const QPen &pen) -{ - mSelectedTickPen = pen; -} - -/*! - Sets the pen that is used to draw the subticks when selected. - - \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAxis::setSelectedSubTickPen(const QPen &pen) -{ - mSelectedSubTickPen = pen; -} - -/*! - Sets the style for the lower axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the left ending, for vertical axes the bottom ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setUpperEnding -*/ -void QCPAxis::setLowerEnding(const QCPLineEnding &ending) -{ - mAxisPainter->lowerEnding = ending; -} - -/*! - Sets the style for the upper axis ending. See the documentation of QCPLineEnding for available - styles. - - For horizontal axes, this method refers to the right ending, for vertical axes the top ending. - Note that this meaning does not change when the axis range is reversed with \ref - setRangeReversed. - - \see setLowerEnding -*/ -void QCPAxis::setUpperEnding(const QCPLineEnding &ending) -{ - mAxisPainter->upperEnding = ending; -} - -/*! - If the scale type (\ref setScaleType) is \ref stLinear, \a diff is added to the lower and upper - bounds of the range. The range is simply moved by \a diff. - - If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This - corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). -*/ -void QCPAxis::moveRange(double diff) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - mRange.lower += diff; - mRange.upper += diff; - } else // mScaleType == stLogarithmic - { - mRange.lower *= diff; - mRange.upper *= diff; - } - mCachedMarginValid = false; - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis by \a factor around the coordinate \a center. For example, if \a - factor is 2.0, \a center is 1.0, then the axis range will double its size, and the point at - coordinate 1.0 won't have changed its position in the QCustomPlot widget (i.e. coordinates - around 1.0 will have moved symmetrically closer to 1.0). -*/ -void QCPAxis::scaleRange(double factor, double center) -{ - QCPRange oldRange = mRange; - if (mScaleType == stLinear) - { - QCPRange newRange; - newRange.lower = (mRange.lower-center)*factor + center; - newRange.upper = (mRange.upper-center)*factor + center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLinScale(); - } else // mScaleType == stLogarithmic - { - if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range - { - QCPRange newRange; - newRange.lower = pow(mRange.lower/center, factor)*center; - newRange.upper = pow(mRange.upper/center, factor)*center; - if (QCPRange::validRange(newRange)) - mRange = newRange.sanitizedForLogScale(); - } else - qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; - } - mCachedMarginValid = false; - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); -} - -/*! - Scales the range of this axis to have a certain scale \a ratio to \a otherAxis. The scaling will - be done around the center of the current axis range. - - For example, if \a ratio is 1, this axis is the \a yAxis and \a otherAxis is \a xAxis, graphs - plotted with those axes will appear in a 1:1 aspect ratio, independent of the aspect ratio the - axis rect has. - - This is an operation that changes the range of this axis once, it doesn't fix the scale ratio - indefinitely. Note that calling this function in the constructor of the QCustomPlot's parent - won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent - will follow. -*/ -void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) -{ - int otherPixelSize, ownPixelSize; - - if (otherAxis->orientation() == Qt::Horizontal) - otherPixelSize = otherAxis->axisRect()->width(); - else - otherPixelSize = otherAxis->axisRect()->height(); - - if (orientation() == Qt::Horizontal) - ownPixelSize = axisRect()->width(); - else - ownPixelSize = axisRect()->height(); - - double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; - setRange(range().center(), newRangeSize, Qt::AlignCenter); -} - -/*! - Changes the axis range such that all plottables associated with this axis are fully visible in - that dimension. - - \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes -*/ -void QCPAxis::rescale(bool onlyVisiblePlottables) -{ - QList<QCPAbstractPlottable*> p = plottables(); - QCPRange newRange; - bool haveRange = false; - for (int i=0; i<p.size(); ++i) - { - if (!p.at(i)->realVisibility() && onlyVisiblePlottables) - continue; - QCPRange plottableRange; - bool currentFoundRange; - QCPAbstractPlottable::SignDomain signDomain = QCPAbstractPlottable::sdBoth; - if (mScaleType == stLogarithmic) - signDomain = (mRange.upper < 0 ? QCPAbstractPlottable::sdNegative : QCPAbstractPlottable::sdPositive); - if (p.at(i)->keyAxis() == this) - plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); - else - plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); - if (currentFoundRange) - { - if (!haveRange) - newRange = plottableRange; - else - newRange.expand(plottableRange); - haveRange = true; - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mScaleType == stLinear) - { - newRange.lower = center-mRange.size()/2.0; - newRange.upper = center+mRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mRange.upper/mRange.lower); - newRange.upper = center*qSqrt(mRange.upper/mRange.lower); - } - } - setRange(newRange); - } -} - -/*! - Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. -*/ -double QCPAxis::pixelToCoord(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; - else - return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return pow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; - else - return pow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; - else - return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return pow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; - else - return pow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; - } - } -} - -/*! - Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. -*/ -double QCPAxis::coordToPixel(double value) const -{ - if (orientation() == Qt::Horizontal) - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - else - return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - } else // mScaleType == stLogarithmic - { - if (value >= 0 && mRange.upper < 0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; - else if (value <= 0 && mRange.upper > 0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; - else - { - if (!mRangeReversed) - return baseLog(value/mRange.lower)/baseLog(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - else - return baseLog(mRange.upper/value)/baseLog(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); - } - } - } else // orientation() == Qt::Vertical - { - if (mScaleType == stLinear) - { - if (!mRangeReversed) - return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); - else - return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); - } else // mScaleType == stLogarithmic - { - if (value >= 0 && mRange.upper < 0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; - else if (value <= 0 && mRange.upper > 0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; - else - { - if (!mRangeReversed) - return mAxisRect->bottom()-baseLog(value/mRange.lower)/baseLog(mRange.upper/mRange.lower)*mAxisRect->height(); - else - return mAxisRect->bottom()-baseLog(mRange.upper/value)/baseLog(mRange.upper/mRange.lower)*mAxisRect->height(); - } - } - } -} - -/*! - Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function - is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this - function does not change the current selection state of the axis. - - If the axis is not visible (\ref setVisible), this function always returns \ref spNone. - - \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions -*/ -QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const -{ - if (!mVisible) - return spNone; - - if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) - return spAxis; - else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) - return spTickLabels; - else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) - return spAxisLabel; - else - return spNone; -} - -/* inherits documentation from base class */ -double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - SelectablePart part = getPartAt(pos); - if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) - return -1; - - if (details) - details->setValue(part); - return mParentPlot->selectionTolerance()*0.99; -} - -/*! - Returns a list of all the plottables that have this axis as key or value axis. - - If you are only interested in plottables of type QCPGraph, see \ref graphs. - - \see graphs, items -*/ -QList<QCPAbstractPlottable*> QCPAxis::plottables() const -{ - QList<QCPAbstractPlottable*> result; - if (!mParentPlot) return result; - - for (int i=0; i<mParentPlot->mPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that have this axis as key or value axis. - - \see plottables, items -*/ -QList<QCPGraph*> QCPAxis::graphs() const -{ - QList<QCPGraph*> result; - if (!mParentPlot) return result; - - for (int i=0; i<mParentPlot->mGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis. An item is considered - associated with an axis if at least one of its positions uses the axis as key or value axis. - - \see plottables, graphs -*/ -QList<QCPAbstractItem*> QCPAxis::items() const -{ - QList<QCPAbstractItem*> result; - if (!mParentPlot) return result; - - for (int itemId=0; itemId<mParentPlot->mItems.size(); ++itemId) - { - QList<QCPItemPosition*> positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posId<positions.size(); ++posId) - { - if (positions.at(posId)->keyAxis() == this || positions.at(posId)->valueAxis() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to - QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) -*/ -QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return atLeft; - case QCP::msRight: return atRight; - case QCP::msTop: return atTop; - case QCP::msBottom: return atBottom; - default: break; - } - qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; - return atLeft; -} - -/*! - Returns the axis type that describes the opposite axis of an axis with the specified \a type. -*/ -QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) -{ - switch (type) - { - case atLeft: return atRight; break; - case atRight: return atLeft; break; - case atBottom: return atTop; break; - case atTop: return atBottom; break; - default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; - } -} - -/*! \internal - - This function is called to prepare the tick vector, sub tick vector and tick label vector. If - \ref setAutoTicks is set to true, appropriate tick values are determined automatically via \ref - generateAutoTicks. If it's set to false, the signal ticksRequest is emitted, which can be used to - provide external tick positions. Then the sub tick vectors and tick label vectors are created. -*/ -void QCPAxis::setupTickVectors() -{ - if (!mParentPlot) return; - if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; - - // fill tick vectors, either by auto generating or by notifying user to fill the vectors himself - if (mAutoTicks) - { - generateAutoTicks(); - } else - { - emit ticksRequest(); - } - - visibleTickBounds(mLowestVisibleTick, mHighestVisibleTick); - if (mTickVector.isEmpty()) - { - mSubTickVector.clear(); - return; - } - - // generate subticks between ticks: - mSubTickVector.resize((mTickVector.size()-1)*mSubTickCount); - if (mSubTickCount > 0) - { - double subTickStep = 0; - double subTickPosition = 0; - int subTickIndex = 0; - bool done = false; - int lowTick = mLowestVisibleTick > 0 ? mLowestVisibleTick-1 : mLowestVisibleTick; - int highTick = mHighestVisibleTick < mTickVector.size()-1 ? mHighestVisibleTick+1 : mHighestVisibleTick; - for (int i=lowTick+1; i<=highTick; ++i) - { - subTickStep = (mTickVector.at(i)-mTickVector.at(i-1))/(double)(mSubTickCount+1); - for (int k=1; k<=mSubTickCount; ++k) - { - subTickPosition = mTickVector.at(i-1) + k*subTickStep; - if (subTickPosition < mRange.lower) - continue; - if (subTickPosition > mRange.upper) - { - done = true; - break; - } - mSubTickVector[subTickIndex] = subTickPosition; - subTickIndex++; - } - if (done) break; - } - mSubTickVector.resize(subTickIndex); - } - - // generate tick labels according to tick positions: - if (mAutoTickLabels) - { - int vecsize = mTickVector.size(); - mTickVectorLabels.resize(vecsize); - if (mTickLabelType == ltNumber) - { - for (int i=mLowestVisibleTick; i<=mHighestVisibleTick; ++i) - mTickVectorLabels[i] = mParentPlot->locale().toString(mTickVector.at(i), mNumberFormatChar, mNumberPrecision); - } else if (mTickLabelType == ltDateTime) - { - for (int i=mLowestVisibleTick; i<=mHighestVisibleTick; ++i) - { -#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) // use fromMSecsSinceEpoch function if available, to gain sub-second accuracy on tick labels (e.g. for format "hh:mm:ss:zzz") - mTickVectorLabels[i] = mParentPlot->locale().toString(QDateTime::fromTime_t(mTickVector.at(i)).toTimeSpec(mDateTimeSpec), mDateTimeFormat); -#else - mTickVectorLabels[i] = mParentPlot->locale().toString(QDateTime::fromMSecsSinceEpoch(mTickVector.at(i)*1000).toTimeSpec(mDateTimeSpec), mDateTimeFormat); -#endif - } - } - } else // mAutoTickLabels == false - { - if (mAutoTicks) // ticks generated automatically, but not ticklabels, so emit ticksRequest here for labels - { - emit ticksRequest(); - } - // make sure provided tick label vector has correct (minimal) length: - if (mTickVectorLabels.size() < mTickVector.size()) - mTickVectorLabels.resize(mTickVector.size()); - } -} - -/*! \internal - - If \ref setAutoTicks is set to true, this function is called by \ref setupTickVectors to - generate reasonable tick positions (and subtick count). The algorithm tries to create - approximately <tt>mAutoTickCount</tt> ticks (set via \ref setAutoTickCount). - - If the scale is logarithmic, \ref setAutoTickCount is ignored, and one tick is generated at every - power of the current logarithm base, set via \ref setScaleLogBase. -*/ -void QCPAxis::generateAutoTicks() -{ - if (mScaleType == stLinear) - { - if (mAutoTickStep) - { - // Generate tick positions according to linear scaling: - mTickStep = mRange.size()/(double)(mAutoTickCount+1e-10); // mAutoTickCount ticks on average, the small addition is to prevent jitter on exact integers - double magnitudeFactor = qPow(10.0, qFloor(qLn(mTickStep)/qLn(10.0))); // get magnitude factor e.g. 0.01, 1, 10, 1000 etc. - double tickStepMantissa = mTickStep/magnitudeFactor; - if (tickStepMantissa < 5) - { - // round digit after decimal point to 0.5 - mTickStep = (int)(tickStepMantissa*2)/2.0*magnitudeFactor; - } else - { - // round to first digit in multiples of 2 - mTickStep = (int)(tickStepMantissa/2.0)*2.0*magnitudeFactor; - } - } - if (mAutoSubTicks) - mSubTickCount = calculateAutoSubTickCount(mTickStep); - // Generate tick positions according to mTickStep: - qint64 firstStep = floor(mRange.lower/mTickStep); - qint64 lastStep = ceil(mRange.upper/mTickStep); - int tickcount = lastStep-firstStep+1; - if (tickcount < 0) tickcount = 0; - mTickVector.resize(tickcount); - for (int i=0; i<tickcount; ++i) - mTickVector[i] = (firstStep+i)*mTickStep; - } else // mScaleType == stLogarithmic - { - // Generate tick positions according to logbase scaling: - if (mRange.lower > 0 && mRange.upper > 0) // positive range - { - double lowerMag = basePow((int)floor(baseLog(mRange.lower))); - double currentMag = lowerMag; - mTickVector.clear(); - mTickVector.append(currentMag); - while (currentMag < mRange.upper && currentMag > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentMag *= mScaleLogBase; - mTickVector.append(currentMag); - } - } else if (mRange.lower < 0 && mRange.upper < 0) // negative range - { - double lowerMag = -basePow((int)ceil(baseLog(-mRange.lower))); - double currentMag = lowerMag; - mTickVector.clear(); - mTickVector.append(currentMag); - while (currentMag < mRange.upper && currentMag < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case - { - currentMag /= mScaleLogBase; - mTickVector.append(currentMag); - } - } else // invalid range for logarithmic scale, because lower and upper have different sign - { - mTickVector.clear(); - qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << mRange.lower << "-" << mRange.upper; - } - } -} - -/*! \internal - - Called by generateAutoTicks when \ref setAutoSubTicks is set to true. Depending on the \a - tickStep between two major ticks on the axis, a different number of sub ticks is appropriate. For - Example taking 4 sub ticks for a \a tickStep of 1 makes more sense than taking 5 sub ticks, - because this corresponds to a sub tick step of 0.2, instead of the less intuitive 0.16667. Note - that a subtick count of 4 means dividing the major tick step into 5 sections. - - This is implemented by a hand made lookup for integer tick steps as well as fractional tick steps - with a fractional part of (approximately) 0.5. If a tick step is different (i.e. has no - fractional part close to 0.5), the currently set sub tick count (\ref setSubTickCount) is - returned. -*/ -int QCPAxis::calculateAutoSubTickCount(double tickStep) const -{ - int result = mSubTickCount; // default to current setting, if no proper value can be found - - // get mantissa of tickstep: - double magnitudeFactor = qPow(10.0, qFloor(qLn(tickStep)/qLn(10.0))); // get magnitude factor e.g. 0.01, 1, 10, 1000 etc. - double tickStepMantissa = tickStep/magnitudeFactor; - - // separate integer and fractional part of mantissa: - double epsilon = 0.01; - double intPartf; - int intPart; - double fracPart = modf(tickStepMantissa, &intPartf); - intPart = intPartf; - - // handle cases with (almost) integer mantissa: - if (fracPart < epsilon || 1.0-fracPart < epsilon) - { - if (1.0-fracPart < epsilon) - ++intPart; - switch (intPart) - { - case 1: result = 4; break; // 1.0 -> 0.2 substep - case 2: result = 3; break; // 2.0 -> 0.5 substep - case 3: result = 2; break; // 3.0 -> 1.0 substep - case 4: result = 3; break; // 4.0 -> 1.0 substep - case 5: result = 4; break; // 5.0 -> 1.0 substep - case 6: result = 2; break; // 6.0 -> 2.0 substep - case 7: result = 6; break; // 7.0 -> 1.0 substep - case 8: result = 3; break; // 8.0 -> 2.0 substep - case 9: result = 2; break; // 9.0 -> 3.0 substep - } - } else - { - // handle cases with significantly fractional mantissa: - if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa - { - switch (intPart) - { - case 1: result = 2; break; // 1.5 -> 0.5 substep - case 2: result = 4; break; // 2.5 -> 0.5 substep - case 3: result = 4; break; // 3.5 -> 0.7 substep - case 4: result = 2; break; // 4.5 -> 1.5 substep - case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with autoTickStep from here on) - case 6: result = 4; break; // 6.5 -> 1.3 substep - case 7: result = 2; break; // 7.5 -> 2.5 substep - case 8: result = 4; break; // 8.5 -> 1.7 substep - case 9: result = 4; break; // 9.5 -> 1.9 substep - } - } - // if mantissa fraction isnt 0.0 or 0.5, don't bother finding good sub tick marks, leave default - } - - return result; -} - -/* inherits documentation from base class */ -void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - SelectablePart part = details.value<SelectablePart>(); - if (mSelectableParts.testFlag(part)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^part : part); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAxis::deselectEvent(bool *selectionStateChanged) -{ - SelectableParts selBefore = mSelectedParts; - setSelectedParts(mSelectedParts & ~mSelectableParts); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing axis lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); -} - -/*! \internal - - Draws the axis with the specified \a painter, using the internal QCPAxisPainterPrivate instance. - -*/ -void QCPAxis::draw(QCPPainter *painter) -{ - const int lowTick = mLowestVisibleTick; - const int highTick = mHighestVisibleTick; - QVector<double> subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector<double> tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector<QString> tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(highTick-lowTick+1); - tickLabels.reserve(highTick-lowTick+1); - subTickPositions.reserve(mSubTickVector.size()); - - if (mTicks) - { - for (int i=lowTick; i<=highTick; ++i) - { - tickPositions.append(coordToPixel(mTickVector.at(i))); - if (mTickLabels) - tickLabels.append(mTickVectorLabels.at(i)); - } - - if (mSubTickCount > 0) - { - const int subTickCount = mSubTickVector.size(); - for (int i=0; i<subTickCount; ++i) // no need to check bounds because subticks are always only created inside current mRange - subTickPositions.append(coordToPixel(mSubTickVector.at(i))); - } - } - // transfer all properties of this axis to QCPAxisPainterPrivate which it needs to draw the axis. - // Note that some axis painter properties are already set by direct feed-through with QCPAxis setters - mAxisPainter->type = mAxisType; - mAxisPainter->basePen = getBasePen(); - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->labelColor = getLabelColor(); - mAxisPainter->label = mLabel; - mAxisPainter->substituteExponent = mAutoTickLabels && mNumberBeautifulPowers && mTickLabelType == ltNumber; - mAxisPainter->tickPen = getTickPen(); - mAxisPainter->subTickPen = getSubTickPen(); - mAxisPainter->tickLabelFont = getTickLabelFont(); - mAxisPainter->tickLabelColor = getTickLabelColor(); - mAxisPainter->alignmentRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->abbreviateDecimalPowers = mScaleType == stLogarithmic; - mAxisPainter->reversedEndings = mRangeReversed; - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw(painter); -} - -/*! \internal - - Returns via \a lowIndex and \a highIndex, which ticks in the current tick vector are visible in - the current range. The return values are indices of the tick vector, not the positions of the - ticks themselves. - - The actual use of this function is when an external tick vector is provided, since it might - exceed far beyond the currently displayed range, and would cause unnecessary calculations e.g. of - subticks. - - If all ticks are outside the axis range, an inverted range is returned, i.e. highIndex will be - smaller than lowIndex. There is one case, where this function returns indices that are not really - visible in the current axis range: When the tick spacing is larger than the axis range size and - one tick is below the axis range and the next tick is already above the axis range. Because in - such cases it is usually desirable to know the tick pair, to draw proper subticks. -*/ -void QCPAxis::visibleTickBounds(int &lowIndex, int &highIndex) const -{ - bool lowFound = false; - bool highFound = false; - lowIndex = 0; - highIndex = -1; - - for (int i=0; i < mTickVector.size(); ++i) - { - if (mTickVector.at(i) >= mRange.lower) - { - lowFound = true; - lowIndex = i; - break; - } - } - for (int i=mTickVector.size()-1; i >= 0; --i) - { - if (mTickVector.at(i) <= mRange.upper) - { - highFound = true; - highIndex = i; - break; - } - } - - if (!lowFound && highFound) - lowIndex = highIndex+1; - else if (lowFound && !highFound) - highIndex = lowIndex-1; -} - -/*! \internal - - A log function with the base mScaleLogBase, used mostly for coordinate transforms in logarithmic - scales with arbitrary log base. Uses the buffered mScaleLogBaseLogInv for faster calculation. - This is set to <tt>1.0/qLn(mScaleLogBase)</tt> in \ref setScaleLogBase. - - \see basePow, setScaleLogBase, setScaleType -*/ -double QCPAxis::baseLog(double value) const -{ - return qLn(value)*mScaleLogBaseLogInv; -} - -/*! \internal - - A power function with the base mScaleLogBase, used mostly for coordinate transforms in - logarithmic scales with arbitrary log base. - - \see baseLog, setScaleLogBase, setScaleType -*/ -double QCPAxis::basePow(double value) const -{ - return qPow(mScaleLogBase, value); -} - -/*! \internal - - Returns the pen that is used to draw the axis base line. Depending on the selection state, this - is either mSelectedBasePen or mBasePen. -*/ -QPen QCPAxis::getBasePen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; -} - -/*! \internal - - Returns the pen that is used to draw the (major) ticks. Depending on the selection state, this - is either mSelectedTickPen or mTickPen. -*/ -QPen QCPAxis::getTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; -} - -/*! \internal - - Returns the pen that is used to draw the subticks. Depending on the selection state, this - is either mSelectedSubTickPen or mSubTickPen. -*/ -QPen QCPAxis::getSubTickPen() const -{ - return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; -} - -/*! \internal - - Returns the font that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelFont or mTickLabelFont. -*/ -QFont QCPAxis::getTickLabelFont() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; -} - -/*! \internal - - Returns the font that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelFont or mLabelFont. -*/ -QFont QCPAxis::getLabelFont() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; -} - -/*! \internal - - Returns the color that is used to draw the tick labels. Depending on the selection state, this - is either mSelectedTickLabelColor or mTickLabelColor. -*/ -QColor QCPAxis::getTickLabelColor() const -{ - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; -} - -/*! \internal - - Returns the color that is used to draw the axis label. Depending on the selection state, this - is either mSelectedLabelColor or mLabelColor. -*/ -QColor QCPAxis::getLabelColor() const -{ - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; -} - -/*! \internal - - Returns the appropriate outward margin for this axis. It is needed if \ref - QCPAxisRect::setAutoMargins is set to true on the parent axis rect. An axis with axis type \ref - atLeft will return an appropriate left margin, \ref atBottom will return an appropriate bottom - margin and so forth. For the calculation, this function goes through similar steps as \ref draw, - so changing one function likely requires the modification of the other one as well. - - The margin consists of the outward tick length, tick label padding, tick label size, label - padding, label size, and padding. - - The margin is cached internally, so repeated calls while leaving the axis range, fonts, etc. - unchanged are very fast. -*/ -int QCPAxis::calculateMargin() -{ - if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis - return 0; - - if (mCachedMarginValid) - return mCachedMargin; - - // run through similar steps as QCPAxis::draw, and caluclate margin needed to fit axis and its labels - int margin = 0; - - int lowTick, highTick; - visibleTickBounds(lowTick, highTick); - QVector<double> tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector<QString> tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(highTick-lowTick+1); - tickLabels.reserve(highTick-lowTick+1); - if (mTicks) - { - for (int i=lowTick; i<=highTick; ++i) - { - tickPositions.append(coordToPixel(mTickVector.at(i))); - if (mTickLabels) - tickLabels.append(mTickVectorLabels.at(i)); - } - } - // transfer all properties of this axis to QCPAxisPainterPrivate which it needs to calculate the size. - // Note that some axis painter properties are already set by direct feed-through with QCPAxis setters - mAxisPainter->type = mAxisType; - mAxisPainter->labelFont = getLabelFont(); - mAxisPainter->label = mLabel; - mAxisPainter->tickLabelFont = mTickLabelFont; - mAxisPainter->alignmentRect = mAxisRect->rect(); - mAxisPainter->viewportRect = mParentPlot->viewport(); - mAxisPainter->tickPositions = tickPositions; - mAxisPainter->tickLabels = tickLabels; - margin += mAxisPainter->size(); - margin += mPadding; - - mCachedMargin = margin; - mCachedMarginValid = true; - return margin; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAxis::selectionCategory() const -{ - return QCP::iSelectAxes; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisPainterPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisPainterPrivate - - \internal - \brief (Private) - - This is a private class and not part of the public QCustomPlot interface. - - It is used by QCPAxis to do the low-level drawing of axis backbone, tick marks, tick labels and - axis label. It also buffers the labels to reduce replot times. The parameters are configured by - directly accessing the public member variables. -*/ - -/*! - Constructs a QCPAxisPainterPrivate instance. Make sure to not create a new instance on every - redraw, to utilize the caching mechanisms. -*/ -QCPAxisPainterPrivate::QCPAxisPainterPrivate(QCustomPlot *parentPlot) : - type(QCPAxis::atLeft), - basePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - lowerEnding(QCPLineEnding::esNone), - upperEnding(QCPLineEnding::esNone), - labelPadding(0), - tickLabelPadding(0), - tickLabelRotation(0), - substituteExponent(true), - numberMultiplyCross(false), - tickLengthIn(5), - tickLengthOut(0), - subTickLengthIn(2), - subTickLengthOut(0), - tickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - subTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - offset(0), - abbreviateDecimalPowers(false), - reversedEndings(false), - mParentPlot(parentPlot), - mLabelCache(16) // cache at most 16 (tick) labels -{ -} - -QCPAxisPainterPrivate::~QCPAxisPainterPrivate() -{ -} - -/*! \internal - - Draws the axis with the specified \a painter. - - The selection boxes (mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox) are set - here, too. -*/ -void QCPAxisPainterPrivate::draw(QCPPainter *painter) -{ - QByteArray newHash = generateLabelParameterHash(); - if (newHash != mLabelParameterHash) - { - mLabelCache.clear(); - mLabelParameterHash = newHash; - } - - QPoint origin; - switch (type) - { - case QCPAxis::atLeft: origin = alignmentRect.bottomLeft() +QPoint(-offset, 0); break; - case QCPAxis::atRight: origin = alignmentRect.bottomRight()+QPoint(+offset, 0); break; - case QCPAxis::atTop: origin = alignmentRect.topLeft() +QPoint(0, -offset); break; - case QCPAxis::atBottom: origin = alignmentRect.bottomLeft() +QPoint(0, +offset); break; - } - - double xCor = 0, yCor = 0; // paint system correction, for pixel exact matches (affects baselines and ticks of top/right axes) - switch (type) - { - case QCPAxis::atTop: yCor = -1; break; - case QCPAxis::atRight: xCor = 1; break; - default: break; - } - - int margin = 0; - // draw baseline: - QLineF baseLine; - painter->setPen(basePen); - if (QCPAxis::orientation(type) == Qt::Horizontal) - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(alignmentRect.width()+xCor, yCor)); - else - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -alignmentRect.height()+yCor)); - if (reversedEndings) - baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later - painter->drawLine(baseLine); - - // draw ticks: - if (!tickPositions.isEmpty()) - { - painter->setPen(tickPen); - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; i<tickPositions.size(); ++i) - painter->drawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; i<tickPositions.size(); ++i) - painter->drawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); - } - } - - // draw subticks: - if (!subTickPositions.isEmpty()) - { - painter->setPen(subTickPen); - // direction of ticks ("inward" is right for left axis and left for right axis) - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - for (int i=0; i<subTickPositions.size(); ++i) - painter->drawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); - } else - { - for (int i=0; i<subTickPositions.size(); ++i) - painter->drawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); - } - } - margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // draw axis base endings: - bool antialiasingBackup = painter->antialiasing(); - painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't - painter->setBrush(QBrush(basePen.color())); - QVector2D baseLineVector(baseLine.dx(), baseLine.dy()); - if (lowerEnding.style() != QCPLineEnding::esNone) - lowerEnding.draw(painter, QVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); - if (upperEnding.style() != QCPLineEnding::esNone) - upperEnding.draw(painter, QVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); - painter->setAntialiasing(antialiasingBackup); - - // tick labels: - QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label - if (!tickLabels.isEmpty()) - { - margin += tickLabelPadding; - painter->setFont(tickLabelFont); - painter->setPen(QPen(tickLabelColor)); - const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); - for (int i=0; i<maxLabelIndex; ++i) - placeTickLabel(painter, tickPositions.at(i), margin, tickLabels.at(i), &tickLabelsSize); - if (QCPAxis::orientation(type) == Qt::Horizontal) - margin += tickLabelsSize.height(); - else - margin += tickLabelsSize.width(); - } - - // axis label: - QRect labelBounds; - if (!label.isEmpty()) - { - margin += labelPadding; - painter->setFont(labelFont); - painter->setPen(QPen(labelColor)); - labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); - if (type == QCPAxis::atLeft) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); - painter->rotate(-90); - painter->drawText(0, 0, alignmentRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atRight) - { - QTransform oldTransform = painter->transform(); - painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-alignmentRect.height()); - painter->rotate(90); - painter->drawText(0, 0, alignmentRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); - } - else if (type == QCPAxis::atTop) - painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), alignmentRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - else if (type == QCPAxis::atBottom) - painter->drawText(origin.x(), origin.y()+margin, alignmentRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - } - - // set selection boxes: - int selectionTolerance = 0; - if (mParentPlot) - selectionTolerance = mParentPlot->selectionTolerance(); - else - qDebug() << Q_FUNC_INFO << "mParentPlot is null"; - int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); - int selAxisInSize = selectionTolerance; - int selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - int selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; - int selLabelSize = labelBounds.height(); - int selLabelOffset = selTickLabelOffset+selTickLabelSize+labelPadding; - if (type == QCPAxis::atLeft) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, alignmentRect.top(), origin.x()+selAxisInSize, alignmentRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, alignmentRect.top(), origin.x()-selTickLabelOffset, alignmentRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, alignmentRect.top(), origin.x()-selLabelOffset, alignmentRect.bottom()); - } else if (type == QCPAxis::atRight) - { - mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, alignmentRect.top(), origin.x()+selAxisOutSize, alignmentRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, alignmentRect.top(), origin.x()+selTickLabelOffset, alignmentRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, alignmentRect.top(), origin.x()+selLabelOffset, alignmentRect.bottom()); - } else if (type == QCPAxis::atTop) - { - mAxisSelectionBox.setCoords(alignmentRect.left(), origin.y()-selAxisOutSize, alignmentRect.right(), origin.y()+selAxisInSize); - mTickLabelsSelectionBox.setCoords(alignmentRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, alignmentRect.right(), origin.y()-selTickLabelOffset); - mLabelSelectionBox.setCoords(alignmentRect.left(), origin.y()-selLabelOffset-selLabelSize, alignmentRect.right(), origin.y()-selLabelOffset); - } else if (type == QCPAxis::atBottom) - { - mAxisSelectionBox.setCoords(alignmentRect.left(), origin.y()-selAxisInSize, alignmentRect.right(), origin.y()+selAxisOutSize); - mTickLabelsSelectionBox.setCoords(alignmentRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, alignmentRect.right(), origin.y()+selTickLabelOffset); - mLabelSelectionBox.setCoords(alignmentRect.left(), origin.y()+selLabelOffset+selLabelSize, alignmentRect.right(), origin.y()+selLabelOffset); - } - // draw hitboxes for debug purposes: - //painter->setBrush(Qt::NoBrush); - //painter->drawRects(QVector<QRect>() << mAxisSelectionBox << mTickLabelsSelectionBox << mLabelSelectionBox); -} - -/*! \internal - - Returns the size ("margin" in QCPAxisRect context, so measured perpendicular to the axis backbone - direction) needed to fit the axis. -*/ -int QCPAxisPainterPrivate::size() const -{ - int result = 0; - - // get length of tick marks pointing outwards: - if (!tickPositions.isEmpty()) - result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - - // calculate size of tick labels: - QSize tickLabelsSize(0, 0); - if (!tickLabels.isEmpty()) - { - for (int i=0; i<tickLabels.size(); ++i) - getMaxTickLabelSize(tickLabelFont, tickLabels.at(i), &tickLabelsSize); - result += QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width(); - result += tickLabelPadding; - } - - // calculate size of axis label (only height needed, because left/right labels are rotated by 90 degrees): - if (!label.isEmpty()) - { - QFontMetrics fontMetrics(labelFont); - QRect bounds; - bounds = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter | Qt::AlignVCenter, label); - result += bounds.height() + labelPadding; - } - - return result; -} - -/*! \internal - - Clears the internal label cache. Upon the next \ref draw, all labels will be created new. This - method is called automatically in \ref draw, if any parameters have changed that invalidate the - cached labels, such as font, color, etc. -*/ -void QCPAxisPainterPrivate::clearCache() -{ - mLabelCache.clear(); -} - -/*! \internal - - Returns a hash that allows uniquely identifying whether the label parameters have changed such - that the cached labels must be refreshed (\ref clearCache). It is used in \ref draw. If the - return value of this method hasn't changed since the last redraw, the respective label parameters - haven't changed and cached labels may be used. -*/ -QByteArray QCPAxisPainterPrivate::generateLabelParameterHash() const -{ - QByteArray result; - result.append(QByteArray::number(tickLabelRotation)); - result.append(QByteArray::number((int)substituteExponent)); - result.append(QByteArray::number((int)numberMultiplyCross)); - result.append(tickLabelColor.name()+QByteArray::number(tickLabelColor.alpha(), 16)); - result.append(tickLabelFont.toString()); - return result; -} - -/*! \internal - - Draws a single tick label with the provided \a painter, utilizing the internal label cache to - significantly speed up drawing of labels that were drawn in previous calls. The tick label is - always bound to an axis, the distance to the axis is controllable via \a distanceToAxis in - pixels. The pixel position in the axis direction is passed in the \a position parameter. Hence - for the bottom axis, \a position would indicate the horizontal pixel position (not coordinate), - at which the label should be drawn. - - In order to later draw the axis label in a place that doesn't overlap with the tick labels, the - largest tick label size is needed. This is acquired by passing a \a tickLabelsSize to the \ref - drawTickLabel calls during the process of drawing all tick labels of one axis. In every call, \a - tickLabelsSize is expanded, if the drawn label exceeds the value \a tickLabelsSize currently - holds. - - The label is drawn with the font and pen that are currently set on the \a painter. To draw - superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref - getTickLabelData). -*/ -void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) -{ - // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if (text.isEmpty()) return; - QSize finalSize; - QPointF labelAnchor; - switch (type) - { - case QCPAxis::atLeft: labelAnchor = QPointF(alignmentRect.left()-distanceToAxis-offset, position); break; - case QCPAxis::atRight: labelAnchor = QPointF(alignmentRect.right()+distanceToAxis+offset, position); break; - case QCPAxis::atTop: labelAnchor = QPointF(position, alignmentRect.top()-distanceToAxis-offset); break; - case QCPAxis::atBottom: labelAnchor = QPointF(position, alignmentRect.bottom()+distanceToAxis+offset); break; - } - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled - { - if (!mLabelCache.contains(text)) // no cached label exists, create it - { - CachedLabel *newCachedLabel = new CachedLabel; - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF drawOffset = getTickLabelDrawOffset(labelData); - newCachedLabel->offset = drawOffset+labelData.rotatedTotalBounds.topLeft(); - newCachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); - newCachedLabel->pixmap.fill(Qt::transparent); - QCPPainter cachePainter(&newCachedLabel->pixmap); - cachePainter.setPen(painter->pen()); - drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); - mLabelCache.insert(text, newCachedLabel, 1); - } - // draw cached label: - const CachedLabel *cachedLabel = mLabelCache.object(text); - // if label would be partly clipped by widget border on sides, don't draw it: - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - if (labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width() > viewportRect.right() || - labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left()) - return; - } else - { - if (labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height() >viewportRect.bottom() || - labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top()) - return; - } - painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); - finalSize = cachedLabel->pixmap.size(); - } else // label caching disabled, draw text directly on surface: - { - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); - // if label would be partly clipped by widget border on sides, don't draw it: - if (QCPAxis::orientation(type) == Qt::Horizontal) - { - if (finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || - finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left()) - return; - } else - { - if (finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || - finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top()) - return; - } - drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); - finalSize = labelData.rotatedTotalBounds.size(); - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Draws the tick label specified in \a labelData with \a painter at the pixel positions \a x and \a - y. This function is used by \ref placeTickLabel to create new tick labels for the cache, or to - directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when - QCP::phCacheLabels plotting hint is not set. -*/ -void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const -{ - // backup painter settings that we're about to change: - QTransform oldTransform = painter->transform(); - QFont oldFont = painter->font(); - - // transform painter to position/rotation: - painter->translate(x, y); - if (!qFuzzyIsNull(tickLabelRotation)) - painter->rotate(tickLabelRotation); - - // draw text: - if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); - painter->setFont(labelData.expFont); - painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); - } else - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); - } - - // reset painter settings to what it was before: - painter->setTransform(oldTransform); - painter->setFont(oldFont); -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Transforms the passed \a text and \a font to a tickLabelData structure that can then be further - processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and - exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. -*/ -QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const -{ - TickLabelData result; - - // determine whether beautiful decimal powers should be used - bool useBeautifulPowers = false; - int ePos = -1; - if (substituteExponent) - { - ePos = text.indexOf('e'); - if (ePos > -1) - useBeautifulPowers = true; - } - - // calculate text bounding rects and do string preparation for beautiful decimal powers: - result.baseFont = font; - if (result.baseFont.pointSizeF() > 0) // On some rare systems, this sometimes is initialized with -1 (Qt bug?), so we check here before possibly setting a negative value in the next line - result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding - if (useBeautifulPowers) - { - // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: - result.basePart = text.left(ePos); - // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: - if (abbreviateDecimalPowers && result.basePart == "1") - result.basePart = "10"; - else - result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + "10"; - result.expPart = text.mid(ePos+1); - // clip "+" and leading zeros off expPart: - while (result.expPart.length() > 2 && result.expPart.at(1) == '0') // length > 2 so we leave one zero when numberFormatChar is 'e' - result.expPart.remove(1, 1); - if (!result.expPart.isEmpty() && result.expPart.at(0) == '+') - result.expPart.remove(0, 1); - // prepare smaller font for exponent: - result.expFont = font; - result.expFont.setPointSize(result.expFont.pointSize()*0.75); - // calculate bounding rects of base part, exponent part and total one: - result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); - result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); - result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA - } else // useBeautifulPowers == false - { - result.basePart = text; - result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); - } - result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler - - // calculate possibly different bounding rect after rotation: - result.rotatedTotalBounds = result.totalBounds; - if (!qFuzzyIsNull(tickLabelRotation)) - { - QTransform transform; - transform.rotate(tickLabelRotation); - result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); - } - - return result; -} - -/*! \internal - - This is a \ref placeTickLabel helper function. - - Calculates the offset at which the top left corner of the specified tick label shall be drawn. - The offset is relative to a point right next to the tick the label belongs to. - - This function is thus responsible for e.g. centering tick labels under ticks and positioning them - appropriately when they are rotated. -*/ -QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const -{ - /* - calculate label offset from base point at tick (non-trivial, for best visual appearance): short - explanation for bottom axis: The anchor, i.e. the point in the label that is placed - horizontally under the corresponding tick is always on the label side that is closer to the - axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height - is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text - will be centered under the tick (i.e. displaced horizontally by half its height). At the same - time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick - labels. - */ - bool doRotation = !qFuzzyIsNull(tickLabelRotation); - bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. - double radians = tickLabelRotation/180.0*M_PI; - int x=0, y=0; - if (type == QCPAxis::atLeft) - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); - y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = -labelData.totalBounds.width(); - y = -labelData.totalBounds.height()/2.0; - } - } else if (type == QCPAxis::atRight) - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = 0; - y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; - } - } else - { - x = 0; - y = -labelData.totalBounds.height()/2.0; - } - } else if (type == QCPAxis::atTop) - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; - y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); - } else - { - x = -qSin(-radians)*labelData.totalBounds.height()/2.0; - y = -qCos(-radians)*labelData.totalBounds.height(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = -labelData.totalBounds.height(); - } - } else if (type == QCPAxis::atBottom) - { - if (doRotation) - { - if (tickLabelRotation > 0) - { - x = +qSin(radians)*labelData.totalBounds.height()/2.0; - y = 0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; - y = +qSin(-radians)*labelData.totalBounds.width(); - } - } else - { - x = -labelData.totalBounds.width()/2.0; - y = 0; - } - } - - return QPointF(x, y); -} - -/*! \internal - - Simulates the steps done by \ref placeTickLabel by calculating bounding boxes of the text label - to be drawn, depending on number format etc. Since only the largest tick label is wanted for the - margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a - smaller width/height. -*/ -void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const -{ - // note: this function must return the same tick label sizes as the placeTickLabel function. - QSize finalSize; - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label - { - const CachedLabel *cachedLabel = mLabelCache.object(text); - finalSize = cachedLabel->pixmap.size(); - } else // label caching disabled or no label with this text cached: - { - TickLabelData labelData = getTickLabelData(font, text); - finalSize = labelData.rotatedTotalBounds.size(); - } - - // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractPlottable -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractPlottable - \brief The abstract base class for all data representing objects in a plot. - - It defines a very basic interface like name, pen, brush, visibility etc. Since this class is - abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to - create new ways of displaying data (see "Creating own plottables" below). - - All further specifics are in the subclasses, for example: - \li A normal graph with possibly a line, scatter points and error bars is displayed by \ref QCPGraph - (typically created with \ref QCustomPlot::addGraph). - \li A parametric curve can be displayed with \ref QCPCurve. - \li A stackable bar chart can be achieved with \ref QCPBars. - \li A box of a statistical box plot is created with \ref QCPStatisticalBox. - - \section plottables-subclassing Creating own plottables - - To create an own plottable, you implement a subclass of QCPAbstractPlottable. These are the pure - virtual functions, you must implement: - \li \ref clearData - \li \ref selectTest - \li \ref draw - \li \ref drawLegendIcon - \li \ref getKeyRange - \li \ref getValueRange - - See the documentation of those functions for what they need to do. - - For drawing your plot, you can use the \ref coordsToPixels functions to translate a point in plot - coordinates to pixel coordinates. This function is quite convenient, because it takes the - orientation of the key and value axes into account for you (x and y are swapped when the key axis - is vertical and the value axis horizontal). If you are worried about performance (i.e. you need - to translate many points in a loop like QCPGraph), you can directly use \ref - QCPAxis::coordToPixel. However, you must then take care about the orientation of the axis - yourself. - - Here are some important members you inherit from QCPAbstractPlottable: - <table> - <tr> - <td>QCustomPlot *\b mParentPlot</td> - <td>A pointer to the parent QCustomPlot instance. The parent plot is inferred from the axes that are passed in the constructor.</td> - </tr><tr> - <td>QString \b mName</td> - <td>The name of the plottable.</td> - </tr><tr> - <td>QPen \b mPen</td> - <td>The generic pen of the plottable. You should use this pen for the most prominent data representing lines in the plottable (e.g QCPGraph uses this pen for its graph lines and scatters)</td> - </tr><tr> - <td>QPen \b mSelectedPen</td> - <td>The generic pen that should be used when the plottable is selected (hint: \ref mainPen gives you the right pen, depending on selection state).</td> - </tr><tr> - <td>QBrush \b mBrush</td> - <td>The generic brush of the plottable. You should use this brush for the most prominent fillable structures in the plottable (e.g. QCPGraph uses this brush to control filling under the graph)</td> - </tr><tr> - <td>QBrush \b mSelectedBrush</td> - <td>The generic brush that should be used when the plottable is selected (hint: \ref mainBrush gives you the right brush, depending on selection state).</td> - </tr><tr> - <td>QPointer<QCPAxis>\b mKeyAxis, \b mValueAxis</td> - <td>The key and value axes this plottable is attached to. Call their QCPAxis::coordToPixel functions to translate coordinates to pixels in either the key or value dimension. - Make sure to check whether the pointer is null before using it. If one of the axes is null, don't draw the plottable.</td> - </tr><tr> - <td>bool \b mSelected</td> - <td>indicates whether the plottable is selected or not.</td> - </tr> - </table> -*/ - -/* start of documentation of pure virtual functions */ - -/*! \fn void QCPAbstractPlottable::clearData() = 0 - Clears all data in the plottable. -*/ - -/*! \fn void QCPAbstractPlottable::drawLegendIcon(QCPPainter *painter, const QRect &rect) const = 0 - \internal - - called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation - of this plottable inside \a rect, next to the plottable name. -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getKeyRange(bool &foundRange, SignDomain inSignDomain) const = 0 - \internal - - called by rescaleAxes functions to get the full data key bounds. For logarithmic plots, one can - set \a inSignDomain to either \ref sdNegative or \ref sdPositive in order to restrict the - returned range to that sign domain. E.g. when only negative range is wanted, set \a inSignDomain - to \ref sdNegative and all positive points will be ignored for range calculation. For no - restriction, just set \a inSignDomain to \ref sdBoth (default). \a foundRange is an output - parameter that indicates whether a range could be found or not. If this is false, you shouldn't - use the returned range (e.g. no points in data). - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero, which wouldn't count as a valid range. - - \see rescaleAxes, getValueRange -*/ - -/*! \fn QCPRange QCPAbstractPlottable::getValueRange(bool &foundRange, SignDomain inSignDomain) const = 0 - \internal - - called by rescaleAxes functions to get the full data value bounds. For logarithmic plots, one can - set \a inSignDomain to either \ref sdNegative or \ref sdPositive in order to restrict the - returned range to that sign domain. E.g. when only negative range is wanted, set \a inSignDomain - to \ref sdNegative and all positive points will be ignored for range calculation. For no - restriction, just set \a inSignDomain to \ref sdBoth (default). \a foundRange is an output - parameter that indicates whether a range could be found or not. If this is false, you shouldn't - use the returned range (e.g. no points in data). - - Note that \a foundRange is not the same as \ref QCPRange::validRange, since the range returned by - this function may have size zero, which wouldn't count as a valid range. - - \see rescaleAxes, getKeyRange -*/ - -/* end of documentation of pure virtual functions */ -/* start of documentation of signals */ - -/*! \fn void QCPAbstractPlottable::selectionChanged(bool selected) - - This signal is emitted when the selection state of this plottable has changed, either by user - interaction or by a direct call to \ref setSelected. -*/ - -/*! \fn void QCPAbstractPlottable::selectableChanged(bool selectable); - - This signal is emitted when the selectability of this plottable has changed. - - \see setSelectable -*/ - -/* end of documentation of signals */ - -/*! - Constructs an abstract plottable which uses \a keyAxis as its key axis ("x") and \a valueAxis as - its value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance - and have perpendicular orientations. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - Since QCPAbstractPlottable is an abstract class that defines the basic interface to plottables, - it can't be directly instantiated. - - You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. -*/ -QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPLayerable(keyAxis->parentPlot(), "", keyAxis->axisRect()), - mName(""), - mAntialiasedFill(true), - mAntialiasedScatters(true), - mAntialiasedErrorBars(false), - mPen(Qt::black), - mSelectedPen(Qt::black), - mBrush(Qt::NoBrush), - mSelectedBrush(Qt::NoBrush), - mKeyAxis(keyAxis), - mValueAxis(valueAxis), - mSelectable(true), - mSelected(false) -{ - if (keyAxis->parentPlot() != valueAxis->parentPlot()) - qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; - if (keyAxis->orientation() == valueAxis->orientation()) - qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; -} - -/*! - The name is the textual representation of this plottable as it is displayed in the legend - (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. -*/ -void QCPAbstractPlottable::setName(const QString &name) -{ - mName = name; -} - -/*! - Sets whether fills of this plottable is drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedFill(bool enabled) -{ - mAntialiasedFill = enabled; -} - -/*! - Sets whether the scatter symbols of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) -{ - mAntialiasedScatters = enabled; -} - -/*! - Sets whether the error bars of this plottable are drawn antialiased or not. - - Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. -*/ -void QCPAbstractPlottable::setAntialiasedErrorBars(bool enabled) -{ - mAntialiasedErrorBars = enabled; -} - - -/*! - The pen is used to draw basic lines that make up the plottable representation in the - plot. - - For example, the \ref QCPGraph subclass draws its graph lines and scatter points - with this pen. - - \see setBrush -*/ -void QCPAbstractPlottable::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - When the plottable is selected, this pen is used to draw basic lines instead of the normal - pen set via \ref setPen. - - \see setSelected, setSelectable, setSelectedBrush, selectTest -*/ -void QCPAbstractPlottable::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - The brush is used to draw basic fills of the plottable representation in the - plot. The Fill can be a color, gradient or texture, see the usage of QBrush. - - For example, the \ref QCPGraph subclass draws the fill under the graph with this brush, when - it's not set to Qt::NoBrush. - - \see setPen -*/ -void QCPAbstractPlottable::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - When the plottable is selected, this brush is used to draw fills instead of the normal - brush set via \ref setBrush. - - \see setSelected, setSelectable, setSelectedPen, selectTest -*/ -void QCPAbstractPlottable::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - The key axis of a plottable can be set to any axis of a QCustomPlot, as long as it is orthogonal - to the plottable's value axis. This function performs no checks to make sure this is the case. - The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and the - y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setValueAxis -*/ -void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) -{ - mKeyAxis = axis; -} - -/*! - The value axis of a plottable can be set to any axis of a QCustomPlot, as long as it is - orthogonal to the plottable's key axis. This function performs no checks to make sure this is the - case. The typical mathematical choice is to use the x-axis (QCustomPlot::xAxis) as key axis and - the y-axis (QCustomPlot::yAxis) as value axis. - - Normally, the key and value axes are set in the constructor of the plottable (or \ref - QCustomPlot::addGraph when working with QCPGraphs through the dedicated graph interface). - - \see setKeyAxis -*/ -void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) -{ - mValueAxis = axis; -} - -/*! - Sets whether the user can (de-)select this plottable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains iSelectPlottables.) - - However, even when \a selectable was set to false, it is possible to set the selection manually, - by calling \ref setSelected directly. - - \see setSelected -*/ -void QCPAbstractPlottable::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets whether this plottable is selected or not. When selected, it uses a different pen and brush - to draw its lines and fills, see \ref setSelectedPen and \ref setSelectedBrush. - - The entire selection mechanism for plottables is handled automatically when \ref - QCustomPlot::setInteractions contains iSelectPlottables. You only need to call this function when - you wish to change the selection state manually. - - This function can change the selection state even when \ref setSelectable was set to false. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractPlottable::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/*! - Rescales the key and value axes associated with this plottable to contain all displayed data, so - the whole plottable is visible. If the scaling of an axis is logarithmic, rescaleAxes will make - sure not to rescale to an illegal range i.e. a range containing different signs and/or zero. - Instead it will stay in the current sign domain and ignore all parts of the plottable that lie - outside of that domain. - - \a onlyEnlarge makes sure the ranges are only expanded, never reduced. So it's possible to show - multiple plottables in their entirety by multiple calls to rescaleAxes where the first call has - \a onlyEnlarge set to false (the default), and all subsequent set to true. - - \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale -*/ -void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const -{ - rescaleKeyAxis(onlyEnlarge); - rescaleValueAxis(onlyEnlarge); -} - -/*! - Rescales the key axis of the plottable so the whole plottable is visible. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - SignDomain signDomain = sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? sdNegative : sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(keyAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (keyAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-keyAxis->range().size()/2.0; - newRange.upper = center+keyAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); - newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); - } - } - keyAxis->setRange(newRange); - } -} - -/*! - Rescales the value axis of the plottable so the whole plottable is visible. - - Returns true if the axis was actually scaled. This might not be the case if this plottable has an - invalid range, e.g. because it has no data points. - - See \ref rescaleAxes for detailed behaviour. -*/ -void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge) const -{ - QCPAxis *valueAxis = mValueAxis.data(); - if (!valueAxis) { qDebug() << Q_FUNC_INFO << "invalid value axis"; return; } - - SignDomain signDomain = sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? sdNegative : sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain); - if (foundRange) - { - if (onlyEnlarge) - newRange.expand(valueAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - newRange.lower = center-valueAxis->range().size()/2.0; - newRange.upper = center+valueAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic - { - newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); - newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); - } - } - valueAxis->setRange(newRange); - } -} - -/*! - Adds this plottable to the legend of the parent QCustomPlot (QCustomPlot::legend). - - Normally, a QCPPlottableLegendItem is created and inserted into the legend. If the plottable - needs a more specialized representation in the legend, this function will take this into account - and instead create the specialized subclass of QCPAbstractLegendItem. - - Returns true on success, i.e. when the legend exists and a legend item associated with this plottable isn't already in - the legend. - - \see removeFromLegend, QCPLegend::addItem -*/ -bool QCPAbstractPlottable::addToLegend() -{ - if (!mParentPlot || !mParentPlot->legend) - return false; - - if (!mParentPlot->legend->hasItemWithPlottable(this)) - { - mParentPlot->legend->addItem(new QCPPlottableLegendItem(mParentPlot->legend, this)); - return true; - } else - return false; -} - -/*! - Removes the plottable from the legend of the parent QCustomPlot. This means the - QCPAbstractLegendItem (usually a QCPPlottableLegendItem) that is associated with this plottable - is removed. - - Returns true on success, i.e. if the legend exists and a legend item associated with this - plottable was found and removed. - - \see addToLegend, QCPLegend::removeItem -*/ -bool QCPAbstractPlottable::removeFromLegend() const -{ - if (!mParentPlot->legend) - return false; - - if (QCPPlottableLegendItem *lip = mParentPlot->legend->itemWithPlottable(this)) - return mParentPlot->legend->removeItem(lip); - else - return false; -} - -/* inherits documentation from base class */ -QRect QCPAbstractPlottable::clipRect() const -{ - if (mKeyAxis && mValueAxis) - return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); - else - return QRect(); -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractPlottable::selectionCategory() const -{ - return QCP::iSelectPlottables; -} - -/*! \internal - - Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a key and \a value are transformed to the coodinates in pixels and are written to \a x and \a y. - - \see pixelsToCoords, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - x = keyAxis->coordToPixel(key); - y = valueAxis->coordToPixel(value); - } else - { - y = keyAxis->coordToPixel(key); - x = valueAxis->coordToPixel(value); - } -} - -/*! \internal - \overload - - Returns the input as pixel coordinates in a QPointF. -*/ -const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); - else - return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); -} - -/*! \internal - - Convenience function for transforming a x/y pixel pair on the QCustomPlot surface to plot coordinates, - taking the orientations of the axes associated with this plottable into account (e.g. whether key - represents x or y). - - \a x and \a y are transformed to the plot coodinates and are written to \a key and \a value. - - \see coordsToPixels, QCPAxis::coordToPixel -*/ -void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) - { - key = keyAxis->pixelToCoord(x); - value = valueAxis->pixelToCoord(y); - } else - { - key = keyAxis->pixelToCoord(y); - value = valueAxis->pixelToCoord(x); - } -} - -/*! \internal - \overload - - Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. -*/ -void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const -{ - pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); -} - -/*! \internal - - Returns the pen that should be used for drawing lines of the plottable. Returns mPen when the - graph is not selected and mSelectedPen when it is. -*/ -QPen QCPAbstractPlottable::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the plottable. Returns mBrush when the - graph is not selected and mSelectedBrush when it is. -*/ -QBrush QCPAbstractPlottable::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint, applyErrorBarsAntialiasingHint -*/ -void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable fills. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint, applyErrorBarsAntialiasingHint -*/ -void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable scatter points. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint, applyErrorBarsAntialiasingHint -*/ -void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing plottable error bars. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint, applyDefaultAntialiasingHint -*/ -void QCPAbstractPlottable::applyErrorBarsAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiasedErrorBars, QCP::aeErrorBars); -} - -/*! \internal - - Finds the shortest squared distance of \a point to the line segment defined by \a start and \a - end. - - This function may be used to help with the implementation of the \ref selectTest function for - specific plottables. - - \note This function is identical to QCPAbstractItem::distSqrToLine -*/ -double QCPAbstractPlottable::distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const -{ - QVector2D a(start); - QVector2D b(end); - QVector2D p(point); - QVector2D v(b-a); - - double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) - { - double mu = QVector2D::dotProduct(p-a, v)/vLengthSqr; - if (mu < 0) - return (a-p).lengthSquared(); - else if (mu > 1) - return (b-p).lengthSquared(); - else - return ((a + mu*v)-p).lengthSquared(); - } else - return (a-p).lengthSquared(); -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemAnchor -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemAnchor - \brief An anchor of an item to which positions can be attached to. - - An item (QCPAbstractItem) may have one or more anchors. Unlike QCPItemPosition, an anchor doesn't - control anything on its item, but provides a way to tie other items via their positions to the - anchor. - - For example, a QCPItemRect is defined by its positions \a topLeft and \a bottomRight. - Additionally it has various anchors like \a top, \a topRight or \a bottomLeft etc. So you can - attach the \a start (which is a QCPItemPosition) of a QCPItemLine to one of the anchors by - calling QCPItemPosition::setParentAnchor on \a start, passing the wanted anchor of the - QCPItemRect. This way the start of the line will now always follow the respective anchor location - on the rect item. - - Note that QCPItemPosition derives from QCPItemAnchor, so every position can also serve as an - anchor to other positions. - - To learn how to provide anchors in your own item subclasses, see the subclassing section of the - QCPAbstractItem documentation. -*/ - -/* start documentation of inline functions */ - -/*! \fn virtual QCPItemPosition *QCPItemAnchor::toQCPItemPosition() - - Returns 0 if this instance is merely a QCPItemAnchor, and a valid pointer of type QCPItemPosition* if - it actually is a QCPItemPosition (which is a subclass of QCPItemAnchor). - - This safe downcast functionality could also be achieved with a dynamic_cast. However, QCustomPlot avoids - dynamic_cast to work with projects that don't have RTTI support enabled (e.g. -fno-rtti flag with - gcc compiler). -*/ - -/* end documentation of inline functions */ - -/*! - Creates a new QCPItemAnchor. You shouldn't create QCPItemAnchor instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId) : - mName(name), - mParentPlot(parentPlot), - mParentItem(parentItem), - mAnchorId(anchorId) -{ -} - -QCPItemAnchor::~QCPItemAnchor() -{ - // unregister as parent at children: - QList<QCPItemPosition*> currentChildren(mChildren.toList()); - for (int i=0; i<currentChildren.size(); ++i) - currentChildren.at(i)->setParentAnchor(0); // this acts back on this anchor and child removes itself from mChildren -} - -/*! - Returns the final absolute pixel position of the QCPItemAnchor on the QCustomPlot surface. - - The pixel information is internally retrieved via QCPAbstractItem::anchorPixelPosition of the - parent item, QCPItemAnchor is just an intermediary. -*/ -QPointF QCPItemAnchor::pixelPoint() const -{ - if (mParentItem) - { - if (mAnchorId > -1) - { - return mParentItem->anchorPixelPoint(mAnchorId); - } else - { - qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; - return QPointF(); - } - } else - { - qDebug() << Q_FUNC_INFO << "no parent item set"; - return QPointF(); - } -} - -/*! \internal - - Adds \a pos to the child list of this anchor. This is necessary to notify the children prior to - destruction of the anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::addChild(QCPItemPosition *pos) -{ - if (!mChildren.contains(pos)) - mChildren.insert(pos); - else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast<quintptr>(pos); -} - -/*! \internal - - Removes \a pos from the child list of this anchor. - - Note that this function does not change the parent setting in \a pos. -*/ -void QCPItemAnchor::removeChild(QCPItemPosition *pos) -{ - if (!mChildren.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast<quintptr>(pos); -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPosition -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPosition - \brief Manages the position of an item. - - Every item has at least one public QCPItemPosition member pointer which provides ways to position the - item on the QCustomPlot surface. Some items have multiple positions, for example QCPItemRect has two: - \a topLeft and \a bottomRight. - - QCPItemPosition has a type (\ref PositionType) that can be set with \ref setType. This type defines - how coordinates passed to \ref setCoords are to be interpreted, e.g. as absolute pixel coordinates, as - plot coordinates of certain axes, etc. - - Further, QCPItemPosition may have a parent QCPItemAnchor, see \ref setParentAnchor. (Note that every - QCPItemPosition inherits from QCPItemAnchor and thus can itself be used as parent anchor for other - positions.) This way you can tie multiple items together. If the QCPItemPosition has a parent, the - coordinates set with \ref setCoords are considered to be absolute values in the reference frame of the - parent anchor, where (0, 0) means directly ontop of the parent anchor. For example, You could attach - the \a start position of a QCPItemLine to the \a bottom anchor of a QCPItemText to make the starting - point of the line always be centered under the text label, no matter where the text is moved to, or is - itself tied to. - - To set the apparent pixel position on the QCustomPlot surface directly, use \ref setPixelPoint. This - works no matter what type this QCPItemPosition is or what parent-child situation it is in, as \ref - setPixelPoint transforms the coordinates appropriately, to make the position appear at the specified - pixel values. -*/ - -/*! - Creates a new QCPItemPosition. You shouldn't create QCPItemPosition instances directly, even if - you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as - explained in the subclassing section of the QCPAbstractItem documentation. -*/ -QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name) : - QCPItemAnchor(parentPlot, parentItem, name), - mPositionType(ptAbsolute), - mKey(0), - mValue(0), - mParentAnchor(0) -{ -} - -QCPItemPosition::~QCPItemPosition() -{ - // unregister as parent at children: - // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then - // the setParentAnchor(0) call the correct QCPItemPosition::pixelPoint function instead of QCPItemAnchor::pixelPoint - QList<QCPItemPosition*> currentChildren(mChildren.toList()); - for (int i=0; i<currentChildren.size(); ++i) - currentChildren.at(i)->setParentAnchor(0); // this acts back on this anchor and child removes itself from mChildren - // unregister as child in parent: - if (mParentAnchor) - mParentAnchor->removeChild(this); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPItemPosition::axisRect() const -{ - return mAxisRect.data(); -} - -/*! - Sets the type of the position. The type defines how the coordinates passed to \ref setCoords - should be handled and how the QCPItemPosition should behave in the plot. - - The possible values for \a type can be separated in two main categories: - - \li The position is regarded as a point in plot coordinates. This corresponds to \ref ptPlotCoords - and requires two axes that define the plot coordinate system. They can be specified with \ref setAxes. - By default, the QCustomPlot's x- and yAxis are used. - - \li The position is fixed on the QCustomPlot surface, i.e. independent of axis ranges. This - corresponds to all other types, i.e. \ref ptAbsolute, \ref ptViewportRatio and \ref - ptAxisRectRatio. They differ only in the way the absolute position is described, see the - documentation of \ref PositionType for details. For \ref ptAxisRectRatio, note that you can specify - the axis rect with \ref setAxisRect. By default this is set to the main axis rect. - - Note that the position type \ref ptPlotCoords is only available (and sensible) when the position - has no parent anchor (\ref setParentAnchor). - - If the type is changed, the apparent pixel position on the plot is preserved. This means - the coordinates as retrieved with coords() and set with \ref setCoords may change in the process. -*/ -void QCPItemPosition::setType(QCPItemPosition::PositionType type) -{ - if (mPositionType != type) - { - // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect - // were deleted), don't try to recover the pixelPoint() because it would output a qDebug warning. - bool recoverPixelPosition = true; - if ((mPositionType == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) - recoverPixelPosition = false; - if ((mPositionType == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) - recoverPixelPosition = false; - - QPointF pixelP; - if (recoverPixelPosition) - pixelP = pixelPoint(); - - mPositionType = type; - - if (recoverPixelPosition) - setPixelPoint(pixelP); - } -} - -/*! - Sets the parent of this QCPItemPosition to \a parentAnchor. This means the position will now - follow any position changes of the anchor. The local coordinate system of positions with a parent - anchor always is absolute with (0, 0) being exactly on top of the parent anchor. (Hence the type - shouldn't be \ref ptPlotCoords for positions with parent anchors.) - - if \a keepPixelPosition is true, the current pixel position of the QCPItemPosition is preserved - during reparenting. If it's set to false, the coordinates are set to (0, 0), i.e. the position - will be exactly on top of the parent anchor. - - To remove this QCPItemPosition from any parent anchor, set \a parentAnchor to 0. - - If the QCPItemPosition previously had no parent and the type is \ref ptPlotCoords, the type is - set to \ref ptAbsolute, to keep the position in a valid state. -*/ -bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) -{ - // make sure self is not assigned as parent: - if (parentAnchor == this) - { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast<quintptr>(parentAnchor); - return false; - } - // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) - { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) - { - // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) - { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast<quintptr>(parentAnchor); - return false; - } - currentParent = currentParentPos->mParentAnchor; - } else - { - // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the - // same, to prevent a position being child of an anchor which itself depends on the position, - // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) - { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast<quintptr>(parentAnchor); - return false; - } - break; - } - } - - // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchor && mPositionType == ptPlotCoords) - setType(ptAbsolute); - - // save pixel position: - QPointF pixelP; - if (keepPixelPosition) - pixelP = pixelPoint(); - // unregister at current parent anchor: - if (mParentAnchor) - mParentAnchor->removeChild(this); - // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChild(this); - mParentAnchor = parentAnchor; - // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPoint(pixelP); - else - setCoords(0, 0); - return true; -} - -/*! - Sets the coordinates of this QCPItemPosition. What the coordinates mean, is defined by the type - (\ref setType). - - For example, if the type is \ref ptAbsolute, \a key and \a value mean the x and y pixel position - on the QCustomPlot surface. In that case the origin (0, 0) is in the top left corner of the - QCustomPlot viewport. If the type is \ref ptPlotCoords, \a key and \a value mean a point in the - plot coordinate system defined by the axes set by \ref setAxes. By default those are the - QCustomPlot's xAxis and yAxis. See the documentation of \ref setType for other available - coordinate types and their meaning. - - \see setPixelPoint -*/ -void QCPItemPosition::setCoords(double key, double value) -{ - mKey = key; - mValue = value; -} - -/*! \overload - - Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the - meaning of \a value of the \ref setCoords(double key, double value) method. -*/ -void QCPItemPosition::setCoords(const QPointF &pos) -{ - setCoords(pos.x(), pos.y()); -} - -/*! - Returns the final absolute pixel position of the QCPItemPosition on the QCustomPlot surface. It - includes all effects of type (\ref setType) and possible parent anchors (\ref setParentAnchor). - - \see setPixelPoint -*/ -QPointF QCPItemPosition::pixelPoint() const -{ - switch (mPositionType) - { - case ptAbsolute: - { - if (mParentAnchor) - return QPointF(mKey, mValue) + mParentAnchor->pixelPoint(); - else - return QPointF(mKey, mValue); - } - - case ptViewportRatio: - { - if (mParentAnchor) - { - return QPointF(mKey*mParentPlot->viewport().width(), - mValue*mParentPlot->viewport().height()) + mParentAnchor->pixelPoint(); - } else - { - return QPointF(mKey*mParentPlot->viewport().width(), - mValue*mParentPlot->viewport().height()) + mParentPlot->viewport().topLeft(); - } - } - - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchor) - { - return QPointF(mKey*mAxisRect.data()->width(), - mValue*mAxisRect.data()->height()) + mParentAnchor->pixelPoint(); - } else - { - return QPointF(mKey*mAxisRect.data()->width(), - mValue*mAxisRect.data()->height()) + mAxisRect.data()->topLeft(); - } - } else - { - qDebug() << Q_FUNC_INFO << "No axis rect defined"; - return QPointF(mKey, mValue); - } - } - - case ptPlotCoords: - { - double x, y; - if (mKeyAxis && mValueAxis) - { - // both key and value axis are given, translate key/value to x/y coordinates: - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - { - x = mKeyAxis.data()->coordToPixel(mKey); - y = mValueAxis.data()->coordToPixel(mValue); - } else - { - y = mKeyAxis.data()->coordToPixel(mKey); - x = mValueAxis.data()->coordToPixel(mValue); - } - } else if (mKeyAxis) - { - // only key axis is given, depending on orientation only transform x or y to key coordinate, other stays pixel: - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - { - x = mKeyAxis.data()->coordToPixel(mKey); - y = mValue; - } else - { - y = mKeyAxis.data()->coordToPixel(mKey); - x = mValue; - } - } else if (mValueAxis) - { - // only value axis is given, depending on orientation only transform x or y to value coordinate, other stays pixel: - if (mValueAxis.data()->orientation() == Qt::Horizontal) - { - x = mValueAxis.data()->coordToPixel(mValue); - y = mKey; - } else - { - y = mValueAxis.data()->coordToPixel(mValue); - x = mKey; - } - } else - { - // no axis given, basically the same as if mPositionType were ptAbsolute - qDebug() << Q_FUNC_INFO << "No axes defined"; - x = mKey; - y = mValue; - } - return QPointF(x, y); - } - } - return QPointF(); -} - -/*! - When \ref setType is \ref ptPlotCoords, this function may be used to specify the axes the - coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and - yAxis of the QCustomPlot. -*/ -void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - mKeyAxis = keyAxis; - mValueAxis = valueAxis; -} - -/*! - When \ref setType is \ref ptAxisRectRatio, this function may be used to specify the axis rect the - coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of - the QCustomPlot. -*/ -void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) -{ - mAxisRect = axisRect; -} - -/*! - Sets the apparent pixel position. This works no matter what type (\ref setType) this - QCPItemPosition is or what parent-child situation it is in, as coordinates are transformed - appropriately, to make the position finally appear at the specified pixel values. - - Only if the type is \ref ptAbsolute and no parent anchor is set, this function's effect is - identical to that of \ref setCoords. - - \see pixelPoint, setCoords -*/ -void QCPItemPosition::setPixelPoint(const QPointF &pixelPoint) -{ - switch (mPositionType) - { - case ptAbsolute: - { - if (mParentAnchor) - setCoords(pixelPoint-mParentAnchor->pixelPoint()); - else - setCoords(pixelPoint); - break; - } - - case ptViewportRatio: - { - if (mParentAnchor) - { - QPointF p(pixelPoint-mParentAnchor->pixelPoint()); - p.rx() /= (double)mParentPlot->viewport().width(); - p.ry() /= (double)mParentPlot->viewport().height(); - setCoords(p); - } else - { - QPointF p(pixelPoint-mParentPlot->viewport().topLeft()); - p.rx() /= (double)mParentPlot->viewport().width(); - p.ry() /= (double)mParentPlot->viewport().height(); - setCoords(p); - } - break; - } - - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchor) - { - QPointF p(pixelPoint-mParentAnchor->pixelPoint()); - p.rx() /= (double)mAxisRect.data()->width(); - p.ry() /= (double)mAxisRect.data()->height(); - setCoords(p); - } else - { - QPointF p(pixelPoint-mAxisRect.data()->topLeft()); - p.rx() /= (double)mAxisRect.data()->width(); - p.ry() /= (double)mAxisRect.data()->height(); - setCoords(p); - } - } else - { - qDebug() << Q_FUNC_INFO << "No axis rect defined"; - setCoords(pixelPoint); - } - break; - } - - case ptPlotCoords: - { - double newKey, newValue; - if (mKeyAxis && mValueAxis) - { - // both key and value axis are given, translate point to key/value coordinates: - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - { - newKey = mKeyAxis.data()->pixelToCoord(pixelPoint.x()); - newValue = mValueAxis.data()->pixelToCoord(pixelPoint.y()); - } else - { - newKey = mKeyAxis.data()->pixelToCoord(pixelPoint.y()); - newValue = mValueAxis.data()->pixelToCoord(pixelPoint.x()); - } - } else if (mKeyAxis) - { - // only key axis is given, depending on orientation only transform x or y to key coordinate, other stays pixel: - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - { - newKey = mKeyAxis.data()->pixelToCoord(pixelPoint.x()); - newValue = pixelPoint.y(); - } else - { - newKey = mKeyAxis.data()->pixelToCoord(pixelPoint.y()); - newValue = pixelPoint.x(); - } - } else if (mValueAxis) - { - // only value axis is given, depending on orientation only transform x or y to value coordinate, other stays pixel: - if (mValueAxis.data()->orientation() == Qt::Horizontal) - { - newKey = pixelPoint.y(); - newValue = mValueAxis.data()->pixelToCoord(pixelPoint.x()); - } else - { - newKey = pixelPoint.x(); - newValue = mValueAxis.data()->pixelToCoord(pixelPoint.y()); - } - } else - { - // no axis given, basically the same as if mPositionType were ptAbsolute - qDebug() << Q_FUNC_INFO << "No axes defined"; - newKey = pixelPoint.x(); - newValue = pixelPoint.y(); - } - setCoords(newKey, newValue); - break; - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractItem - \brief The abstract base class for all items in a plot. - - In QCustomPlot, items are supplemental graphical elements that are neither plottables - (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus - plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each - specific item has at least one QCPItemPosition member which controls the positioning. Some items - are defined by more than one coordinate and thus have two or more QCPItemPosition members (For - example, QCPItemRect has \a topLeft and \a bottomRight). - - This abstract base class defines a very basic interface like visibility and clipping. Since this - class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass - yourself to create new items. - - The built-in items are: - <table> - <tr><td>QCPItemLine</td><td>A line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).</td></tr> - <tr><td>QCPItemStraightLine</td><td>A straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.</td></tr> - <tr><td>QCPItemCurve</td><td>A curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).</td></tr> - <tr><td>QCPItemRect</td><td>A rectangle</td></tr> - <tr><td>QCPItemEllipse</td><td>An ellipse</td></tr> - <tr><td>QCPItemPixmap</td><td>An arbitrary pixmap</td></tr> - <tr><td>QCPItemText</td><td>A text label</td></tr> - <tr><td>QCPItemBracket</td><td>A bracket which may be used to reference/highlight certain parts in the plot.</td></tr> - <tr><td>QCPItemTracer</td><td>An item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.</td></tr> - </table> - - Items are by default clipped to the main axis rect. To make an item visible outside that axis - rect, disable clipping via \ref setClipToAxisRect. - - \section items-using Using items - - First you instantiate the item you want to use and add it to the plot: - \code - QCPItemLine *line = new QCPItemLine(customPlot); - customPlot->addItem(line); - \endcode - by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just - set the plot coordinates where the line should start/end: - \code - line->start->setCoords(-0.1, 0.8); - line->end->setCoords(1.1, 0.2); - \endcode - If we don't want the line to be positioned in plot coordinates but a different coordinate system, - e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this: - \code - line->start->setType(QCPItemPosition::ptAbsolute); - line->end->setType(QCPItemPosition::ptAbsolute); - \endcode - Then we can set the coordinates, this time in pixels: - \code - line->start->setCoords(100, 200); - line->end->setCoords(450, 320); - \endcode - - \section items-subclassing Creating own items - - To create an own item, you implement a subclass of QCPAbstractItem. These are the pure - virtual functions, you must implement: - \li \ref selectTest - \li \ref draw - - See the documentation of those functions for what they need to do. - - \subsection items-positioning Allowing the item to be positioned - - As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall - have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add - a public member of type QCPItemPosition like so: - - \code QCPItemPosition * const myPosition;\endcode - - the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition - instance it points to, can be modified, of course). - The initialization of this pointer is made easy with the \ref createPosition function. Just assign - the return value of this function to each QCPItemPosition in the constructor of your item. \ref createPosition - takes a string which is the name of the position, typically this is identical to the variable name. - For example, the constructor of QCPItemExample could look like this: - - \code - QCPItemExample::QCPItemExample(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - myPosition(createPosition("myPosition")) - { - // other constructor code - } - \endcode - - \subsection items-drawing The draw function - - To give your item a visual representation, reimplement the \ref draw function and use the passed - QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the - position member(s) via \ref QCPItemPosition::pixelPoint. - - To optimize performance you should calculate a bounding rect first (don't forget to take the pen - width into account), check whether it intersects the \ref clipRect, and only draw the item at all - if this is the case. - - \subsection items-selection The selectTest function - - Your implementation of the \ref selectTest function may use the helpers \ref distSqrToLine and - \ref rectSelectTest. With these, the implementation of the selection test becomes significantly - simpler for most items. See the documentation of \ref selectTest for what the function parameters - mean and what the function should return. - - \subsection anchors Providing anchors - - Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public - member, e.g. - - \code QCPItemAnchor * const bottom;\endcode - - and create it in the constructor with the \ref createAnchor function, assigning it a name and an - anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). - Since anchors can be placed anywhere, relative to the item's position(s), your item needs to - provide the position of every anchor with the reimplementation of the \ref anchorPixelPoint(int - anchorId) function. - - In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel - position when anything attached to the anchor needs to know the coordinates. -*/ - -/* start of documentation of inline functions */ - -/*! \fn QList<QCPItemPosition*> QCPAbstractItem::positions() const - - Returns all positions of the item in a list. - - \see anchors, position -*/ - -/*! \fn QList<QCPItemAnchor*> QCPAbstractItem::anchors() const - - Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always - also an anchor, the list will also contain the positions of this item. - - \see positions, anchor -*/ - -/* end of documentation of inline functions */ -/* start documentation of pure virtual functions */ - -/*! \fn void QCPAbstractItem::draw(QCPPainter *painter) = 0 - \internal - - Draws this item with the provided \a painter. - - The cliprect of the provided painter is set to the rect returned by \ref clipRect before this - function is called. The clipRect depends on the clipping settings defined by \ref - setClipToAxisRect and \ref setClipAxisRect. -*/ - -/* end documentation of pure virtual functions */ -/* start documentation of signals */ - -/*! \fn void QCPAbstractItem::selectionChanged(bool selected) - This signal is emitted when the selection state of this item has changed, either by user interaction - or by a direct call to \ref setSelected. -*/ - -/* end documentation of signals */ - -/*! - Base class constructor which initializes base class members. -*/ -QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), - mClipToAxisRect(false), - mSelectable(true), - mSelected(false) -{ - QList<QCPAxisRect*> rects = parentPlot->axisRects(); - if (rects.size() > 0) - { - setClipToAxisRect(true); - setClipAxisRect(rects.first()); - } -} - -QCPAbstractItem::~QCPAbstractItem() -{ - // don't delete mPositions because every position is also an anchor and thus in mAnchors - qDeleteAll(mAnchors); -} - -/* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPAbstractItem::clipAxisRect() const -{ - return mClipAxisRect.data(); -} - -/*! - Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the - entire QCustomPlot. The axis rect can be set with \ref setClipAxisRect. - - \see setClipAxisRect -*/ -void QCPAbstractItem::setClipToAxisRect(bool clip) -{ - mClipToAxisRect = clip; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets the clip axis rect. It defines the rect that will be used to clip the item when \ref - setClipToAxisRect is set to true. - - \see setClipToAxisRect -*/ -void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) -{ - mClipAxisRect = rect; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); -} - -/*! - Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.) - - However, even when \a selectable was set to false, it is possible to set the selection manually, - by calling \ref setSelected. - - \see QCustomPlot::setInteractions, setSelected -*/ -void QCPAbstractItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets whether this item is selected or not. When selected, it might use a different visual - appearance (e.g. pen and brush), this depends on the specific item though. - - The entire selection mechanism for items is handled automatically when \ref - QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this - function when you wish to change the selection state manually. - - This function can change the selection state even when \ref setSelectable was set to false. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - \see setSelectable, selectTest -*/ -void QCPAbstractItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/*! - Returns the QCPItemPosition with the specified \a name. If this item doesn't have a position by - that name, returns 0. - - This function provides an alternative way to access item positions. Normally, you access - positions direcly by their member pointers (which typically have the same variable name as \a - name). - - \see positions, anchor -*/ -QCPItemPosition *QCPAbstractItem::position(const QString &name) const -{ - for (int i=0; i<mPositions.size(); ++i) - { - if (mPositions.at(i)->name() == name) - return mPositions.at(i); - } - qDebug() << Q_FUNC_INFO << "position with name not found:" << name; - return 0; -} - -/*! - Returns the QCPItemAnchor with the specified \a name. If this item doesn't have an anchor by - that name, returns 0. - - This function provides an alternative way to access item anchors. Normally, you access - anchors direcly by their member pointers (which typically have the same variable name as \a - name). - - \see anchors, position -*/ -QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const -{ - for (int i=0; i<mAnchors.size(); ++i) - { - if (mAnchors.at(i)->name() == name) - return mAnchors.at(i); - } - qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; - return 0; -} - -/*! - Returns whether this item has an anchor with the specified \a name. - - Note that you can check for positions with this function, too. This is because every position is - also an anchor (QCPItemPosition inherits from QCPItemAnchor). - - \see anchor, position -*/ -bool QCPAbstractItem::hasAnchor(const QString &name) const -{ - for (int i=0; i<mAnchors.size(); ++i) - { - if (mAnchors.at(i)->name() == name) - return true; - } - return false; -} - -/*! \internal - - Returns the rect the visual representation of this item is clipped to. This depends on the - current setting of \ref setClipToAxisRect as well as the axis rect set with \ref setClipAxisRect. - - If the item is not clipped to an axis rect, the \ref QCustomPlot::viewport rect is returned. - - \see draw -*/ -QRect QCPAbstractItem::clipRect() const -{ - if (mClipToAxisRect && mClipAxisRect) - return mClipAxisRect.data()->rect(); - else - return mParentPlot->viewport(); -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing item lines. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); -} - -/*! \internal - - Finds the shortest squared distance of \a point to the line segment defined by \a start and \a - end. - - This function may be used to help with the implementation of the \ref selectTest function for - specific items. - - \note This function is identical to QCPAbstractPlottable::distSqrToLine - - \see rectSelectTest -*/ -double QCPAbstractItem::distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const -{ - QVector2D a(start); - QVector2D b(end); - QVector2D p(point); - QVector2D v(b-a); - - double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) - { - double mu = QVector2D::dotProduct(p-a, v)/vLengthSqr; - if (mu < 0) - return (a-p).lengthSquared(); - else if (mu > 1) - return (b-p).lengthSquared(); - else - return ((a + mu*v)-p).lengthSquared(); - } else - return (a-p).lengthSquared(); -} - -/*! \internal - - A convenience function which returns the selectTest value for a specified \a rect and a specified - click position \a pos. \a filledRect defines whether a click inside the rect should also be - considered a hit or whether only the rect border is sensitive to hits. - - This function may be used to help with the implementation of the \ref selectTest function for - specific items. - - For example, if your item consists of four rects, call this function four times, once for each - rect, in your \ref selectTest reimplementation. Finally, return the minimum of all four returned - values which were greater or equal to zero. (Because this function may return -1.0 when \a pos - doesn't hit \a rect at all). If all calls returned -1.0, return -1.0, too, because your item - wasn't hit. - - \see distSqrToLine -*/ -double QCPAbstractItem::rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const -{ - double result = -1; - - // distance to border: - QList<QLineF> lines; - lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) - << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); - double minDistSqr = std::numeric_limits<double>::max(); - for (int i=0; i<lines.size(); ++i) - { - double distSqr = distSqrToLine(lines.at(i).p1(), lines.at(i).p2(), pos); - if (distSqr < minDistSqr) - minDistSqr = distSqr; - } - result = qSqrt(minDistSqr); - - // filled rect, allow click inside to count as hit: - if (filledRect && result > mParentPlot->selectionTolerance()*0.99) - { - if (rect.contains(pos)) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/*! \internal - - Returns the pixel position of the anchor with Id \a anchorId. This function must be reimplemented in - item subclasses if they want to provide anchors (QCPItemAnchor). - - For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor - ids and returns the respective pixel points of the specified anchor. - - \see createAnchor -*/ -QPointF QCPAbstractItem::anchorPixelPoint(int anchorId) const -{ - qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the position - member (This is needed to provide the name-based \ref position access to positions). - - Don't delete positions created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each position member. Don't create QCPItemPositions with \b new yourself, because they - won't be registered with the item properly. - - \see createAnchor -*/ -QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); - mPositions.append(newPosition); - mAnchors.append(newPosition); // every position is also an anchor - newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); - newPosition->setType(QCPItemPosition::ptPlotCoords); - if (mParentPlot->axisRect()) - newPosition->setAxisRect(mParentPlot->axisRect()); - newPosition->setCoords(0, 0); - return newPosition; -} - -/*! \internal - - Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified - \a name must be a unique string that is usually identical to the variable name of the anchor - member (This is needed to provide the name based \ref anchor access to anchors). - - The \a anchorId must be a number identifying the created anchor. It is recommended to create an - enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor - to identify itself when it calls QCPAbstractItem::anchorPixelPoint. That function then returns - the correct pixel coordinates for the passed anchor id. - - Don't delete anchors created by this function manually, as the item will take care of it. - - Use this function in the constructor (initialization list) of the specific item subclass to - create each anchor member. Don't create QCPItemAnchors with \b new yourself, because then they - won't be registered with the item properly. - - \see createPosition -*/ -QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) -{ - if (hasAnchor(name)) - qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); - mAnchors.append(newAnchor); - return newAnchor; -} - -/* inherits documentation from base class */ -void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractItem::selectionCategory() const -{ - return QCP::iSelectItems; -} - - -/*! \file */ - - - -/*! \mainpage %QCustomPlot 1.2.1 Documentation - - \image html qcp-doc-logo.png - - Below is a brief overview of and guide to the classes and their relations. If you are new to - QCustomPlot and just want to start using it, it's recommended to look at the tutorials and - examples at - - http://www.qcustomplot.com/ - - This documentation is especially helpful as a reference, when you're familiar with the basic - concept of how to use %QCustomPlot and you wish to learn more about specific functionality. - See the \ref classoverview "class overview" for diagrams explaining the relationships between - the most important classes of the QCustomPlot library. - - The central widget which displays the plottables and axes on its surface is QCustomPlot. Every - QCustomPlot contains four axes by default. They can be accessed via the members \ref - QCustomPlot::xAxis "xAxis", \ref QCustomPlot::yAxis "yAxis", \ref QCustomPlot::xAxis2 "xAxis2" - and \ref QCustomPlot::yAxis2 "yAxis2", and are of type QCPAxis. QCustomPlot supports an arbitrary - number of axes and axis rects, see the documentation of QCPAxisRect for details. - - \section mainpage-plottables Plottables - - \a Plottables are classes that display any kind of data inside the QCustomPlot. They all derive - from QCPAbstractPlottable. For example, the QCPGraph class is a plottable that displays a graph - inside the plot with different line styles, scatter styles, filling etc. - - Since plotting graphs is such a dominant use case, QCustomPlot has a special interface for working - with QCPGraph plottables, that makes it very easy to handle them:\n - You create a new graph with QCustomPlot::addGraph and access them with QCustomPlot::graph. - - For all other plottables, you need to use the normal plottable interface:\n - First, you create an instance of the plottable you want, e.g. - \code - QCPCurve *newCurve = new QCPCurve(customPlot->xAxis, customPlot->yAxis);\endcode - add it to the customPlot: - \code - customPlot->addPlottable(newCurve);\endcode - and then modify the properties of the newly created plottable via the <tt>newCurve</tt> pointer. - - Plottables (including graphs) can be retrieved via QCustomPlot::plottable. Since the return type - of that function is the abstract base class of all plottables, QCPAbstractPlottable, you will - probably want to qobject_cast the returned pointer to the respective plottable subclass. (As - usual, if the cast returns zero, the plottable wasn't of that specific subclass.) - - All further interfacing with plottables (e.g how to set data) is specific to the plottable type. - See the documentations of the subclasses: QCPGraph, QCPCurve, QCPBars, QCPStatisticalBox, - QCPColorMap. - - \section mainpage-axes Controlling the Axes - - As mentioned, QCustomPlot has four axes by default: \a xAxis (bottom), \a yAxis (left), \a xAxis2 - (top), \a yAxis2 (right). - - Their range is handled by the simple QCPRange class. You can set the range with the - QCPAxis::setRange function. By default, the axes represent a linear scale. To set a logarithmic - scale, set \ref QCPAxis::setScaleType to \ref QCPAxis::stLogarithmic. The logarithm base can be set freely - with \ref QCPAxis::setScaleLogBase. - - By default, an axis automatically creates and labels ticks in a sensible manner. See the - following functions for tick manipulation:\n QCPAxis::setTicks, QCPAxis::setAutoTicks, - QCPAxis::setAutoTickCount, QCPAxis::setAutoTickStep, QCPAxis::setTickLabels, - QCPAxis::setTickLabelType, QCPAxis::setTickLabelRotation, QCPAxis::setTickStep, - QCPAxis::setTickLength,... - - Each axis can be given an axis label (e.g. "Voltage (mV)") with QCPAxis::setLabel. - - The distance of an axis backbone to the respective viewport border is called its margin. - Normally, the margins are calculated automatically. To change this, set - \ref QCPAxisRect::setAutoMargins to exclude the respective margin sides, set the margins manually with - \ref QCPAxisRect::setMargins. The main axis rect can be reached with \ref QCustomPlot::axisRect(). - - \section mainpage-legend Plot Legend - - Every QCustomPlot has one QCPLegend (as \ref QCustomPlot::legend) by default. A legend is a small - layout element inside the plot which lists the plottables with an icon of the plottable - line/symbol and a name (QCPAbstractPlottable::setName). Plottables can be added and removed from - the main legend via \ref QCPAbstractPlottable::addToLegend and \ref - QCPAbstractPlottable::removeFromLegend. By default, adding a plottable to QCustomPlot - automatically adds it to the legend, too. This behaviour can be modified with the - QCustomPlot::setAutoAddPlottableToLegend property. - - The QCPLegend provides an interface to access, add and remove legend items directly, too. See - QCPLegend::item, QCPLegend::itemWithPlottable, QCPLegend::addItem, QCPLegend::removeItem for - example. - - Multiple legends are supported via the \link thelayoutsystem layout system\endlink (as a - QCPLegend simply is a normal layout element). - - \section mainpage-userinteraction User Interactions - - QCustomPlot supports dragging axis ranges with the mouse (\ref - QCPAxisRect::setRangeDrag), zooming axis ranges with the mouse wheel (\ref - QCPAxisRect::setRangeZoom) and a complete selection mechanism. - - The availability of these interactions is controlled with \ref QCustomPlot::setInteractions. For - details about the interaction system, see the documentation there. - - Further, QCustomPlot always emits corresponding signals, when objects are clicked or - doubleClicked. See \ref QCustomPlot::plottableClick, \ref QCustomPlot::plottableDoubleClick - and \ref QCustomPlot::axisClick for example. - - \section mainpage-items Items - - Apart from plottables there is another category of plot objects that are important: Items. The - base class of all items is QCPAbstractItem. An item sets itself apart from plottables in that - it's not necessarily bound to any axes. This means it may also be positioned in absolute pixel - coordinates or placed at a relative position on an axis rect. Further, it usually doesn't - represent data directly, but acts as decoration, emphasis, description etc. - - Multiple items can be arranged in a parent-child-hierarchy allowing for dynamical behaviour. For - example, you could place the head of an arrow at a fixed plot coordinate, so it always points to - some important area in the plot. The tail of the arrow can be anchored to a text item which - always resides in the top center of the axis rect, independent of where the user drags the axis - ranges. This way the arrow stretches and turns so it always points from the label to the - specified plot coordinate, without any further code necessary. - - For a more detailed introduction, see the QCPAbstractItem documentation, and from there the - documentations of the individual built-in items, to find out how to use them. - - \section mainpage-layoutelements Layout elements and layouts - - QCustomPlot uses an internal layout system to provide dynamic sizing and positioning of objects like - the axis rect(s), legends and the plot title. They are all based on \ref QCPLayoutElement and are arranged by - placing them inside a \ref QCPLayout. - - Details on this topic are given on the dedicated page about \link thelayoutsystem the layout system\endlink. - - \section mainpage-performancetweaks Performance Tweaks - - Although QCustomPlot is quite fast, some features like translucent fills, antialiasing and thick - lines can cause a significant slow down. If you notice this in your application, here are some - thoughts on how to increase performance. By far the most time is spent in the drawing functions, - specifically the drawing of graphs. For maximum performance, consider the following (most - recommended/effective measures first): - - \li use Qt 4.8.0 and up. Performance has doubled or tripled with respect to Qt 4.7.4. However - QPainter was broken and drawing pixel precise things, e.g. scatters, isn't possible with Qt >= - 4.8.0. So it's a performance vs. plot quality tradeoff when switching to Qt 4.8. - \li To increase responsiveness during dragging, consider setting \ref QCustomPlot::setNoAntialiasingOnDrag to true. - \li On X11 (GNU/Linux), avoid the slow native drawing system, use raster by supplying - "-graphicssystem raster" as command line argument or calling QApplication::setGraphicsSystem("raster") - before creating the QApplication object. (Only available for Qt versions before 5.0) - \li On all operating systems, use OpenGL hardware acceleration by supplying "-graphicssystem - opengl" as command line argument or calling QApplication::setGraphicsSystem("opengl") (Only - available for Qt versions before 5.0). If OpenGL is available, this will slightly decrease the - quality of antialiasing, but extremely increase performance especially with alpha - (semi-transparent) fills, much antialiasing and a large QCustomPlot drawing surface. Note - however, that the maximum frame rate might be constrained by the vertical sync frequency of your - monitor (VSync can be disabled in the graphics card driver configuration). So for simple plots - (where the potential framerate is far above 60 frames per second), OpenGL acceleration might - achieve numerically lower frame rates than the other graphics systems, because they are not - capped at the VSync frequency. - \li Avoid any kind of alpha (transparency), especially in fills - \li Avoid lines with a pen width greater than one - \li Avoid any kind of antialiasing, especially in graph lines (see \ref QCustomPlot::setNotAntialiasedElements) - \li Avoid repeatedly setting the complete data set with \ref QCPGraph::setData. Use \ref QCPGraph::addData instead, if most - data points stay unchanged, e.g. in a running measurement. - \li Set the \a copy parameter of the setData functions to false, so only pointers get - transferred. (Relevant only if preparing data maps with a large number of points, i.e. over 10000) - - \section mainpage-flags Preprocessor Define Flags - - QCustomPlot understands some preprocessor defines that are useful for debugging and compilation: - <dl> - <dt>\c QCUSTOMPLOT_COMPILE_LIBRARY - <dd>Define this flag when you compile QCustomPlot as a shared library (.so/.dll) - <dt>\c QCUSTOMPLOT_USE_LIBRARY - <dd>Define this flag before including the header, when using QCustomPlot as a shared library - <dt>\c QCUSTOMPLOT_CHECK_DATA - <dd>If this flag is defined, the QCustomPlot plottables will perform data validity checks on every redraw. - This means they will give qDebug output when you plot \e inf or \e nan values, they will not - fix your data. - </dl> - -*/ - -/*! \page classoverview Class Overview - - The following diagrams may help to gain a deeper understanding of the relationships between classes that make up - the QCustomPlot library. The diagrams are not exhaustive, so only the classes deemed most relevant are shown. - - \section classoverview-relations Class Relationship Diagram - \image html RelationOverview.png "Overview of most important classes and their relations" - \section classoverview-inheritance Class Inheritance Tree - \image html InheritanceOverview.png "Inheritance tree of most important classes" - -*/ - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCustomPlot -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCustomPlot - - \brief The central class of the library. This is the QWidget which displays the plot and - interacts with the user. - - For tutorials on how to use QCustomPlot, see the website\n - http://www.qcustomplot.com/ -*/ - -/* start of documentation of inline functions */ - -/*! \fn QRect QCustomPlot::viewport() const - - Returns the viewport rect of this QCustomPlot instance. The viewport is the area the plot is - drawn in, all mechanisms, e.g. margin caluclation take the viewport to be the outer border of the - plot. The viewport normally is the rect() of the QCustomPlot widget, i.e. a rect with top left - (0, 0) and size of the QCustomPlot widget. - - Don't confuse the viewport with the axis rect (QCustomPlot::axisRect). An axis rect is typically - an area enclosed by four axes, where the graphs/plottables are drawn in. The viewport is larger - and contains also the axes themselves, their tick numbers, their labels, the plot title etc. - - Only when saving to a file (see \ref savePng, savePdf etc.) the viewport is temporarily modified - to allow saving plots with sizes independent of the current widget size. -*/ - -/*! \fn QCPLayoutGrid *QCustomPlot::plotLayout() const - - Returns the top level layout of this QCustomPlot instance. It is a \ref QCPLayoutGrid, initially containing just - one cell with the main QCPAxisRect inside. -*/ - -/* end of documentation of inline functions */ -/* start of documentation of signals */ - -/*! \fn void QCustomPlot::mouseDoubleClick(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse double click event. -*/ - -/*! \fn void QCustomPlot::mousePress(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse press event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. -*/ - -/*! \fn void QCustomPlot::mouseMove(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse move event. - - It is emitted before QCustomPlot handles any other mechanism like range dragging. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeDrag or \ref - QCPAxisRect::setRangeDragAxes. - - \warning It is discouraged to change the drag-axes with \ref QCPAxisRect::setRangeDragAxes here, - because the dragging starting point was saved the moment the mouse was pressed. Thus it only has - a meaning for the range drag axes that were set at that moment. If you want to change the drag - axes, consider doing this in the \ref mousePress signal instead. -*/ - -/*! \fn void QCustomPlot::mouseRelease(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse release event. - - It is emitted before QCustomPlot handles any other mechanisms like object selection. So a - slot connected to this signal can still influence the behaviour e.g. with \ref setInteractions or - \ref QCPAbstractPlottable::setSelectable. -*/ - -/*! \fn void QCustomPlot::mouseWheel(QMouseEvent *event) - - This signal is emitted when the QCustomPlot receives a mouse wheel event. - - It is emitted before QCustomPlot handles any other mechanisms like range zooming. So a slot - connected to this signal can still influence the behaviour e.g. with \ref QCPAxisRect::setRangeZoom, \ref - QCPAxisRect::setRangeZoomAxes or \ref QCPAxisRect::setRangeZoomFactor. -*/ - -/*! \fn void QCustomPlot::plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event) - - This signal is emitted when a plottable is clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. - - \see plottableDoubleClick -*/ - -/*! \fn void QCustomPlot::plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event) - - This signal is emitted when a plottable is double clicked. - - \a event is the mouse event that caused the click and \a plottable is the plottable that received - the click. - - \see plottableClick -*/ - -/*! \fn void QCustomPlot::itemClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemDoubleClick -*/ - -/*! \fn void QCustomPlot::itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event) - - This signal is emitted when an item is double clicked. - - \a event is the mouse event that caused the click and \a item is the item that received the - click. - - \see itemClick -*/ - -/*! \fn void QCustomPlot::axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisDoubleClick -*/ - -/*! \fn void QCustomPlot::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event) - - This signal is emitted when an axis is double clicked. - - \a event is the mouse event that caused the click, \a axis is the axis that received the click and - \a part indicates the part of the axis that was clicked. - - \see axisClick -*/ - -/*! \fn void QCustomPlot::legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendDoubleClick -*/ - -/*! \fn void QCustomPlot::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event) - - This signal is emitted when a legend (item) is double clicked. - - \a event is the mouse event that caused the click, \a legend is the legend that received the - click and \a item is the legend item that received the click. If only the legend and no item is - clicked, \a item is 0. This happens for a click inside the legend padding or the space between - two items. - - \see legendClick -*/ - -/*! \fn void QCustomPlot:: titleClick(QMouseEvent *event, QCPPlotTitle *title) - - This signal is emitted when a plot title is clicked. - - \a event is the mouse event that caused the click and \a title is the plot title that received - the click. - - \see titleDoubleClick -*/ - -/*! \fn void QCustomPlot::titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title) - - This signal is emitted when a plot title is double clicked. - - \a event is the mouse event that caused the click and \a title is the plot title that received - the click. - - \see titleClick -*/ - -/*! \fn void QCustomPlot::selectionChangedByUser() - - This signal is emitted after the user has changed the selection in the QCustomPlot, e.g. by - clicking. It is not emitted when the selection state of an object has changed programmatically by - a direct call to setSelected() on an object or by calling \ref deselectAll. - - In addition to this signal, selectable objects also provide individual signals, for example - QCPAxis::selectionChanged or QCPAbstractPlottable::selectionChanged. Note that those signals are - emitted even if the selection state is changed programmatically. - - See the documentation of \ref setInteractions for details about the selection mechanism. - - \see selectedPlottables, selectedGraphs, selectedItems, selectedAxes, selectedLegends -*/ - -/*! \fn void QCustomPlot::beforeReplot() - - This signal is emitted immediately before a replot takes place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, afterReplot -*/ - -/*! \fn void QCustomPlot::afterReplot() - - This signal is emitted immediately after a replot has taken place (caused by a call to the slot \ref - replot). - - It is safe to mutually connect the replot slot with this signal on two QCustomPlots to make them - replot synchronously, it won't cause an infinite recursion. - - \see replot, beforeReplot -*/ - -/* end of documentation of signals */ -/* start of documentation of public members */ - -/*! \var QCPAxis *QCustomPlot::xAxis - - A pointer to the primary x Axis (bottom) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis - - A pointer to the primary y Axis (left) of the main axis rect of the plot. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. -*/ - -/*! \var QCPAxis *QCustomPlot::xAxis2 - - A pointer to the secondary x Axis (top) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. -*/ - -/*! \var QCPAxis *QCustomPlot::yAxis2 - - A pointer to the secondary y Axis (right) of the main axis rect of the plot. Secondary axes are - invisible by default. Use QCPAxis::setVisible to change this (or use \ref - QCPAxisRect::setupFullAxesBox). - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple axis rects or multiple axes to one side, use the \ref - QCPAxisRect::axis interface to access the new axes. If one of the four default axes or the - default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointers become 0. -*/ - -/*! \var QCPLegend *QCustomPlot::legend - - A pointer to the default legend of the main axis rect. The legend is invisible by default. Use - QCPLegend::setVisible to change this. - - QCustomPlot offers convenient pointers to the axes (\ref xAxis, \ref yAxis, \ref xAxis2, \ref - yAxis2) and the \ref legend. They make it very easy working with plots that only have a single - axis rect and at most one axis at each axis rect side. If you use \link thelayoutsystem the - layout system\endlink to add multiple legends to the plot, use the layout system interface to - access the new legend. For example, legends can be placed inside an axis rect's \ref - QCPAxisRect::insetLayout "inset layout", and must then also be accessed via the inset layout. If - the default legend is removed due to manipulation of the layout system (e.g. by removing the main - axis rect), the corresponding pointer becomes 0. -*/ - -/* end of documentation of public members */ - -/*! - Constructs a QCustomPlot and sets reasonable default values. -*/ -QCustomPlot::QCustomPlot(QWidget *parent) : - QWidget(parent), - xAxis(0), - yAxis(0), - xAxis2(0), - yAxis2(0), - legend(0), - mPlotLayout(0), - mAutoAddPlottableToLegend(true), - mAntialiasedElements(QCP::aeNone), - mNotAntialiasedElements(QCP::aeNone), - mInteractions(0), - mSelectionTolerance(8), - mNoAntialiasingOnDrag(false), - mBackgroundBrush(Qt::white, Qt::SolidPattern), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mCurrentLayer(0), - mPlottingHints(QCP::phCacheLabels|QCP::phForceRepaint), - mMultiSelectModifier(Qt::ControlModifier), - mPaintBuffer(size()), - mMouseEventElement(0), - mReplotting(false) -{ - setAttribute(Qt::WA_NoMousePropagation); - setAttribute(Qt::WA_OpaquePaintEvent); - setMouseTracking(true); - QLocale currentLocale = locale(); - currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); - setLocale(currentLocale); - - // create initial layers: - mLayers.append(new QCPLayer(this, "background")); - mLayers.append(new QCPLayer(this, "grid")); - mLayers.append(new QCPLayer(this, "main")); - mLayers.append(new QCPLayer(this, "axes")); - mLayers.append(new QCPLayer(this, "legend")); - updateLayerIndices(); - setCurrentLayer("main"); - - // create initial layout, axis rect and legend: - mPlotLayout = new QCPLayoutGrid; - mPlotLayout->initializeParentPlot(this); - mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry - mPlotLayout->setLayer("main"); - QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); - mPlotLayout->addElement(0, 0, defaultAxisRect); - xAxis = defaultAxisRect->axis(QCPAxis::atBottom); - yAxis = defaultAxisRect->axis(QCPAxis::atLeft); - xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); - yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); - legend = new QCPLegend; - legend->setVisible(false); - defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); - defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); - - defaultAxisRect->setLayer("background"); - xAxis->setLayer("axes"); - yAxis->setLayer("axes"); - xAxis2->setLayer("axes"); - yAxis2->setLayer("axes"); - xAxis->grid()->setLayer("grid"); - yAxis->grid()->setLayer("grid"); - xAxis2->grid()->setLayer("grid"); - yAxis2->grid()->setLayer("grid"); - legend->setLayer("legend"); - - setViewport(rect()); // needs to be called after mPlotLayout has been created - - replot(); -} - -QCustomPlot::~QCustomPlot() -{ - clearPlottables(); - clearItems(); - - if (mPlotLayout) - { - delete mPlotLayout; - mPlotLayout = 0; - } - - mCurrentLayer = 0; - qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed - mLayers.clear(); -} - -/*! - Sets which elements are forcibly drawn antialiased as an \a or combination of QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a antialiasedElements contains \ref QCP::aePlottables, all plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a antialiasedElements is already set in \ref setNotAntialiasedElements, it is - removed from there. - - \see setNotAntialiasedElements -*/ -void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) -{ - mAntialiasedElements = antialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets whether the specified \a antialiasedElement is forcibly drawn antialiased. - - See \ref setAntialiasedElements for details. - - \see setNotAntialiasedElement -*/ -void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) -{ - if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements &= ~antialiasedElement; - else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) - mAntialiasedElements |= antialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mNotAntialiasedElements |= ~mAntialiasedElements; -} - -/*! - Sets which elements are forcibly drawn not antialiased as an \a or combination of - QCP::AntialiasedElement. - - This overrides the antialiasing settings for whole element groups, normally controlled with the - \a setAntialiasing function on the individual elements. If an element is neither specified in - \ref setAntialiasedElements nor in \ref setNotAntialiasedElements, the antialiasing setting on - each individual element instance is used. - - For example, if \a notAntialiasedElements contains \ref QCP::aePlottables, no plottables will be - drawn antialiased, no matter what the specific QCPAbstractPlottable::setAntialiased value was set - to. - - if an element in \a notAntialiasedElements is already set in \ref setAntialiasedElements, it is - removed from there. - - \see setAntialiasedElements -*/ -void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) -{ - mNotAntialiasedElements = notAntialiasedElements; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - Sets whether the specified \a notAntialiasedElement is forcibly drawn not antialiased. - - See \ref setNotAntialiasedElements for details. - - \see setAntialiasedElement -*/ -void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) -{ - if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements &= ~notAntialiasedElement; - else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) - mNotAntialiasedElements |= notAntialiasedElement; - - // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) - mAntialiasedElements |= ~mNotAntialiasedElements; -} - -/*! - If set to true, adding a plottable (e.g. a graph) to the QCustomPlot automatically also adds the - plottable to the legend (QCustomPlot::legend). - - \see addPlottable, addGraph, QCPLegend::addItem -*/ -void QCustomPlot::setAutoAddPlottableToLegend(bool on) -{ - mAutoAddPlottableToLegend = on; -} - -/*! - Sets the possible interactions of this QCustomPlot as an or-combination of \ref QCP::Interaction - enums. There are the following types of interactions: - - <b>Axis range manipulation</b> is controlled via \ref QCP::iRangeDrag and \ref QCP::iRangeZoom. When the - respective interaction is enabled, the user may drag axes ranges and zoom with the mouse wheel. - For details how to control which axes the user may drag/zoom and in what orientations, see \ref - QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeDragAxes, - \ref QCPAxisRect::setRangeZoomAxes. - - <b>Plottable selection</b> is controlled by \ref QCP::iSelectPlottables. If \ref QCP::iSelectPlottables is - set, the user may select plottables (graphs, curves, bars,...) by clicking on them or in their - vicinity (\ref setSelectionTolerance). Whether the user can actually select a plottable can - further be restricted with the \ref QCPAbstractPlottable::setSelectable function on the specific - plottable. To find out whether a specific plottable is selected, call - QCPAbstractPlottable::selected(). To retrieve a list of all currently selected plottables, call - \ref selectedPlottables. If you're only interested in QCPGraphs, you may use the convenience - function \ref selectedGraphs. - - <b>Item selection</b> is controlled by \ref QCP::iSelectItems. If \ref QCP::iSelectItems is set, the user - may select items (QCPItemLine, QCPItemText,...) by clicking on them or in their vicinity. To find - out whether a specific item is selected, call QCPAbstractItem::selected(). To retrieve a list of - all currently selected items, call \ref selectedItems. - - <b>Axis selection</b> is controlled with \ref QCP::iSelectAxes. If \ref QCP::iSelectAxes is set, the user - may select parts of the axes by clicking on them. What parts exactly (e.g. Axis base line, tick - labels, axis label) are selectable can be controlled via \ref QCPAxis::setSelectableParts for - each axis. To retrieve a list of all axes that currently contain selected parts, call \ref - selectedAxes. Which parts of an axis are selected, can be retrieved with QCPAxis::selectedParts(). - - <b>Legend selection</b> is controlled with \ref QCP::iSelectLegend. If this is set, the user may - select the legend itself or individual items by clicking on them. What parts exactly are - selectable can be controlled via \ref QCPLegend::setSelectableParts. To find out whether the - legend or any of its child items are selected, check the value of QCPLegend::selectedParts. To - find out which child items are selected, call \ref QCPLegend::selectedItems. - - <b>All other selectable elements</b> The selection of all other selectable objects (e.g. - QCPPlotTitle, or your own layerable subclasses) is controlled with \ref QCP::iSelectOther. If set, the - user may select those objects by clicking on them. To find out which are currently selected, you - need to check their selected state explicitly. - - If the selection state has changed by user interaction, the \ref selectionChangedByUser signal is - emitted. Each selectable object additionally emits an individual selectionChanged signal whenever - their selection state has changed, i.e. not only by user interaction. - - To allow multiple objects to be selected by holding the selection modifier (\ref - setMultiSelectModifier), set the flag \ref QCP::iMultiSelect. - - \note In addition to the selection mechanism presented here, QCustomPlot always emits - corresponding signals, when an object is clicked or double clicked. see \ref plottableClick and - \ref plottableDoubleClick for example. - - \see setInteraction, setSelectionTolerance -*/ -void QCustomPlot::setInteractions(const QCP::Interactions &interactions) -{ - mInteractions = interactions; -} - -/*! - Sets the single \a interaction of this QCustomPlot to \a enabled. - - For details about the interaction system, see \ref setInteractions. - - \see setInteractions -*/ -void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) -{ - if (!enabled && mInteractions.testFlag(interaction)) - mInteractions &= ~interaction; - else if (enabled && !mInteractions.testFlag(interaction)) - mInteractions |= interaction; -} - -/*! - Sets the tolerance that is used to decide whether a click selects an object (e.g. a plottable) or - not. - - If the user clicks in the vicinity of the line of e.g. a QCPGraph, it's only regarded as a - potential selection when the minimum distance between the click position and the graph line is - smaller than \a pixels. Objects that are defined by an area (e.g. QCPBars) only react to clicks - directly inside the area and ignore this selection tolerance. In other words, it only has meaning - for parts of objects that are too thin to exactly hit with a click and thus need such a - tolerance. - - \see setInteractions, QCPLayerable::selectTest -*/ -void QCustomPlot::setSelectionTolerance(int pixels) -{ - mSelectionTolerance = pixels; -} - -/*! - Sets whether antialiasing is disabled for this QCustomPlot while the user is dragging axes - ranges. If many objects, especially plottables, are drawn antialiased, this greatly improves - performance during dragging. Thus it creates a more responsive user experience. As soon as the - user stops dragging, the last replot is done with normal antialiasing, to restore high image - quality. - - \see setAntialiasedElements, setNotAntialiasedElements -*/ -void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) -{ - mNoAntialiasingOnDrag = enabled; -} - -/*! - Sets the plotting hints for this QCustomPlot instance as an \a or combination of QCP::PlottingHint. - - \see setPlottingHint -*/ -void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) -{ - mPlottingHints = hints; -} - -/*! - Sets the specified plotting \a hint to \a enabled. - - \see setPlottingHints -*/ -void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) -{ - QCP::PlottingHints newHints = mPlottingHints; - if (!enabled) - newHints &= ~hint; - else - newHints |= hint; - - if (newHints != mPlottingHints) - setPlottingHints(newHints); -} - -/*! - Sets the keyboard modifier that will be recognized as multi-select-modifier. - - If \ref QCP::iMultiSelect is specified in \ref setInteractions, the user may select multiple objects - by clicking on them one after the other while holding down \a modifier. - - By default the multi-select-modifier is set to Qt::ControlModifier. - - \see setInteractions -*/ -void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) -{ - mMultiSelectModifier = modifier; -} - -/*! - Sets the viewport of this QCustomPlot. The Viewport is the area that the top level layout - (QCustomPlot::plotLayout()) uses as its rect. Normally, the viewport is the entire widget rect. - - This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref - savePdf, etc. by temporarily changing the viewport size. -*/ -void QCustomPlot::setViewport(const QRect &rect) -{ - mViewport = rect; - if (mPlotLayout) - mPlotLayout->setOuterRect(mViewport); -} - -/*! - Sets \a pm as the viewport background pixmap (see \ref setViewport). The pixmap is always drawn - below all other objects in the plot. - - For cases where the provided pixmap doesn't have the same size as the viewport, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (whether and how the aspect ratio is - preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - If a background brush was set with \ref setBackground(const QBrush &brush), the viewport will - first be filled with that brush, before drawing the background pixmap. This can be useful for - background pixmaps with translucent areas. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! - Sets the background brush of the viewport (see \ref setViewport). - - Before drawing everything else, the background is filled with \a brush. If a background pixmap - was set with \ref setBackground(const QPixmap &pm), this brush will be used to fill the viewport - before the background pixmap is drawn. This can be useful for background pixmaps with translucent - areas. - - Set \a brush to Qt::NoBrush or Qt::Transparent to leave background transparent. This can be - useful for exporting to image formats which support transparency, e.g. \ref savePng. - - \see setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the viewport, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the viewport background pixmap shall be scaled to fit the viewport. If \a scaled is - set to true, control whether and how the aspect ratio of the original pixmap is preserved with - \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the viewport dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCustomPlot::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the viewport background pixmap is enabled (\ref setBackgroundScaled), use this - function to define whether and how the aspect ratio of the original pixmap is preserved. - - \see setBackground, setBackgroundScaled -*/ -void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the plottable with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - plottable, see QCustomPlot::plottable() - - \see plottableCount, addPlottable -*/ -QCPAbstractPlottable *QCustomPlot::plottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - { - return mPlottables.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last plottable that was added with \ref addPlottable. If there are no plottables in - the plot, returns 0. - - \see plottableCount, addPlottable -*/ -QCPAbstractPlottable *QCustomPlot::plottable() -{ - if (!mPlottables.isEmpty()) - { - return mPlottables.last(); - } else - return 0; -} - -/*! - Adds the specified plottable to the plot and, if \ref setAutoAddPlottableToLegend is enabled, to - the legend (QCustomPlot::legend). QCustomPlot takes ownership of the plottable. - - Returns true on success, i.e. when \a plottable isn't already in the plot and the parent plot of - \a plottable is this QCustomPlot (the latter is controlled by what axes were passed in the - plottable's constructor). - - \see plottable, plottableCount, removePlottable, clearPlottables -*/ -bool QCustomPlot::addPlottable(QCPAbstractPlottable *plottable) -{ - if (mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast<quintptr>(plottable); - return false; - } - if (plottable->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast<quintptr>(plottable); - return false; - } - - mPlottables.append(plottable); - // possibly add plottable to legend: - if (mAutoAddPlottableToLegend) - plottable->addToLegend(); - // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast<QCPGraph*>(plottable)) - mGraphs.append(graph); - if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - plottable->setLayer(currentLayer()); - return true; -} - -/*! - Removes the specified plottable from the plot and, if necessary, from the legend (QCustomPlot::legend). - - Returns true on success. - - \see addPlottable, clearPlottables -*/ -bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) -{ - if (!mPlottables.contains(plottable)) - { - qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast<quintptr>(plottable); - return false; - } - - // remove plottable from legend: - plottable->removeFromLegend(); - // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast<QCPGraph*>(plottable)) - mGraphs.removeOne(graph); - // remove plottable: - delete plottable; - mPlottables.removeOne(plottable); - return true; -} - -/*! \overload - - Removes the plottable by its \a index. -*/ -bool QCustomPlot::removePlottable(int index) -{ - if (index >= 0 && index < mPlottables.size()) - return removePlottable(mPlottables[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all plottables from the plot (and the QCustomPlot::legend, if necessary). - - Returns the number of plottables removed. - - \see removePlottable -*/ -int QCustomPlot::clearPlottables() -{ - int c = mPlottables.size(); - for (int i=c-1; i >= 0; --i) - removePlottable(mPlottables[i]); - return c; -} - -/*! - Returns the number of currently existing plottables in the plot - - \see plottable, addPlottable -*/ -int QCustomPlot::plottableCount() const -{ - return mPlottables.size(); -} - -/*! - Returns a list of the selected plottables. If no plottables are currently selected, the list is empty. - - There is a convenience function if you're only interested in selected graphs, see \ref selectedGraphs. - - \see setInteractions, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelected -*/ -QList<QCPAbstractPlottable*> QCustomPlot::selectedPlottables() const -{ - QList<QCPAbstractPlottable*> result; - foreach (QCPAbstractPlottable *plottable, mPlottables) - { - if (plottable->selected()) - result.append(plottable); - } - return result; -} - -/*! - Returns the plottable at the pixel position \a pos. Plottables that only consist of single lines - (like graphs) have a tolerance band around them, see \ref setSelectionTolerance. If multiple - plottables come into consideration, the one closest to \a pos is returned. - - If \a onlySelectable is true, only plottables that are selectable - (QCPAbstractPlottable::setSelectable) are considered. - - If there is no plottable at \a pos, the return value is 0. - - \see itemAt, layoutElementAt -*/ -QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractPlottable *resultPlottable = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach (QCPAbstractPlottable *plottable, mPlottables) - { - if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable - continue; - if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes - { - double currentDistance = plottable->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultPlottable = plottable; - resultDistance = currentDistance; - } - } - } - - return resultPlottable; -} - -/*! - Returns whether this QCustomPlot instance contains the \a plottable. - - \see addPlottable -*/ -bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const -{ - return mPlottables.contains(plottable); -} - -/*! - Returns the graph with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last created - graph, see QCustomPlot::graph() - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph(int index) const -{ - if (index >= 0 && index < mGraphs.size()) - { - return mGraphs.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last graph, that was created with \ref addGraph. If there are no graphs in the plot, - returns 0. - - \see graphCount, addGraph -*/ -QCPGraph *QCustomPlot::graph() const -{ - if (!mGraphs.isEmpty()) - { - return mGraphs.last(); - } else - return 0; -} - -/*! - Creates a new graph inside the plot. If \a keyAxis and \a valueAxis are left unspecified (0), the - bottom (xAxis) is used as key and the left (yAxis) is used as value axis. If specified, \a - keyAxis and \a valueAxis must reside in this QCustomPlot. - - \a keyAxis will be used as key axis (typically "x") and \a valueAxis as value axis (typically - "y") for the graph. - - Returns a pointer to the newly created graph, or 0 if adding the graph failed. - - \see graph, graphCount, removeGraph, clearGraphs -*/ -QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) -{ - if (!keyAxis) keyAxis = xAxis; - if (!valueAxis) valueAxis = yAxis; - if (!keyAxis || !valueAxis) - { - qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; - return 0; - } - if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) - { - qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; - return 0; - } - - QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); - if (addPlottable(newGraph)) - { - newGraph->setName("Graph "+QString::number(mGraphs.size())); - return newGraph; - } else - { - delete newGraph; - return 0; - } -} - -/*! - Removes the specified \a graph from the plot and, if necessary, from the QCustomPlot::legend. If - any other graphs in the plot have a channel fill set towards the removed graph, the channel fill - property of those graphs is reset to zero (no channel fill). - - Returns true on success. - - \see clearGraphs -*/ -bool QCustomPlot::removeGraph(QCPGraph *graph) -{ - return removePlottable(graph); -} - -/*! \overload - - Removes the graph by its \a index. -*/ -bool QCustomPlot::removeGraph(int index) -{ - if (index >= 0 && index < mGraphs.size()) - return removeGraph(mGraphs[index]); - else - return false; -} - -/*! - Removes all graphs from the plot (and the QCustomPlot::legend, if necessary). - - Returns the number of graphs removed. - - \see removeGraph -*/ -int QCustomPlot::clearGraphs() -{ - int c = mGraphs.size(); - for (int i=c-1; i >= 0; --i) - removeGraph(mGraphs[i]); - return c; -} - -/*! - Returns the number of currently existing graphs in the plot - - \see graph, addGraph -*/ -int QCustomPlot::graphCount() const -{ - return mGraphs.size(); -} - -/*! - Returns a list of the selected graphs. If no graphs are currently selected, the list is empty. - - If you are not only interested in selected graphs but other plottables like QCPCurve, QCPBars, - etc., use \ref selectedPlottables. - - \see setInteractions, selectedPlottables, QCPAbstractPlottable::setSelectable, QCPAbstractPlottable::setSelected -*/ -QList<QCPGraph*> QCustomPlot::selectedGraphs() const -{ - QList<QCPGraph*> result; - foreach (QCPGraph *graph, mGraphs) - { - if (graph->selected()) - result.append(graph); - } - return result; -} - -/*! - Returns the item with \a index. If the index is invalid, returns 0. - - There is an overloaded version of this function with no parameter which returns the last added - item, see QCustomPlot::item() - - \see itemCount, addItem -*/ -QCPAbstractItem *QCustomPlot::item(int index) const -{ - if (index >= 0 && index < mItems.size()) - { - return mItems.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! \overload - - Returns the last item, that was added with \ref addItem. If there are no items in the plot, - returns 0. - - \see itemCount, addItem -*/ -QCPAbstractItem *QCustomPlot::item() const -{ - if (!mItems.isEmpty()) - { - return mItems.last(); - } else - return 0; -} - -/*! - Adds the specified item to the plot. QCustomPlot takes ownership of the item. - - Returns true on success, i.e. when \a item wasn't already in the plot and the parent plot of \a - item is this QCustomPlot. - - \see item, itemCount, removeItem, clearItems -*/ -bool QCustomPlot::addItem(QCPAbstractItem *item) -{ - if (!mItems.contains(item) && item->parentPlot() == this) - { - mItems.append(item); - return true; - } else - { - qDebug() << Q_FUNC_INFO << "item either already in list or not created with this QCustomPlot as parent:" << reinterpret_cast<quintptr>(item); - return false; - } -} - -/*! - Removes the specified item from the plot. - - Returns true on success. - - \see addItem, clearItems -*/ -bool QCustomPlot::removeItem(QCPAbstractItem *item) -{ - if (mItems.contains(item)) - { - delete item; - mItems.removeOne(item); - return true; - } else - { - qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast<quintptr>(item); - return false; - } -} - -/*! \overload - - Removes the item by its \a index. -*/ -bool QCustomPlot::removeItem(int index) -{ - if (index >= 0 && index < mItems.size()) - return removeItem(mItems[index]); - else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return false; - } -} - -/*! - Removes all items from the plot. - - Returns the number of items removed. - - \see removeItem -*/ -int QCustomPlot::clearItems() -{ - int c = mItems.size(); - for (int i=c-1; i >= 0; --i) - removeItem(mItems[i]); - return c; -} - -/*! - Returns the number of currently existing items in the plot - - \see item, addItem -*/ -int QCustomPlot::itemCount() const -{ - return mItems.size(); -} - -/*! - Returns a list of the selected items. If no items are currently selected, the list is empty. - - \see setInteractions, QCPAbstractItem::setSelectable, QCPAbstractItem::setSelected -*/ -QList<QCPAbstractItem*> QCustomPlot::selectedItems() const -{ - QList<QCPAbstractItem*> result; - foreach (QCPAbstractItem *item, mItems) - { - if (item->selected()) - result.append(item); - } - return result; -} - -/*! - Returns the item at the pixel position \a pos. Items that only consist of single lines (e.g. \ref - QCPItemLine or \ref QCPItemCurve) have a tolerance band around them, see \ref - setSelectionTolerance. If multiple items come into consideration, the one closest to \a pos is - returned. - - If \a onlySelectable is true, only items that are selectable (QCPAbstractItem::setSelectable) are - considered. - - If there is no item at \a pos, the return value is 0. - - \see plottableAt, layoutElementAt -*/ -QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const -{ - QCPAbstractItem *resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach (QCPAbstractItem *item, mItems) - { - if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable - continue; - if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it - { - double currentDistance = item->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) - { - resultItem = item; - resultDistance = currentDistance; - } - } - } - - return resultItem; -} - -/*! - Returns whether this QCustomPlot contains the \a item. - - \see addItem -*/ -bool QCustomPlot::hasItem(QCPAbstractItem *item) const -{ - return mItems.contains(item); -} - -/*! - Returns the layer with the specified \a name. If there is no layer with the specified name, 0 is - returned. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(const QString &name) const -{ - foreach (QCPLayer *layer, mLayers) - { - if (layer->name() == name) - return layer; - } - return 0; -} - -/*! \overload - - Returns the layer by \a index. If the index is invalid, 0 is returned. - - \see addLayer, moveLayer, removeLayer -*/ -QCPLayer *QCustomPlot::layer(int index) const -{ - if (index >= 0 && index < mLayers.size()) - { - return mLayers.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; - return 0; - } -} - -/*! - Returns the layer that is set as current layer (see \ref setCurrentLayer). -*/ -QCPLayer *QCustomPlot::currentLayer() const -{ - return mCurrentLayer; -} - -/*! - Sets the layer with the specified \a name to be the current layer. All layerables (\ref - QCPLayerable), e.g. plottables and items, are created on the current layer. - - Returns true on success, i.e. if there is a layer with the specified \a name in the QCustomPlot. - - Layer names are case-sensitive. - - \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer -*/ -bool QCustomPlot::setCurrentLayer(const QString &name) -{ - if (QCPLayer *newCurrentLayer = layer(name)) - { - return setCurrentLayer(newCurrentLayer); - } else - { - qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; - return false; - } -} - -/*! \overload - - Sets the provided \a layer to be the current layer. - - Returns true on success, i.e. when \a layer is a valid layer in the QCustomPlot. - - \see addLayer, moveLayer, removeLayer -*/ -bool QCustomPlot::setCurrentLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(layer); - return false; - } - - mCurrentLayer = layer; - return true; -} - -/*! - Returns the number of currently existing layers in the plot - - \see layer, addLayer -*/ -int QCustomPlot::layerCount() const -{ - return mLayers.size(); -} - -/*! - Adds a new layer to this QCustomPlot instance. The new layer will have the name \a name, which - must be unique. Depending on \a insertMode, it is positioned either below or above \a otherLayer. - - Returns true on success, i.e. if there is no other layer named \a name and \a otherLayer is a - valid layer inside this QCustomPlot. - - If \a otherLayer is 0, the highest layer in the QCustomPlot will be used. - - For an explanation of what layers are in QCustomPlot, see the documentation of \ref QCPLayer. - - \see layer, moveLayer, removeLayer -*/ -bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!otherLayer) - otherLayer = mLayers.last(); - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(otherLayer); - return false; - } - if (layer(name)) - { - qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; - return false; - } - - QCPLayer *newLayer = new QCPLayer(this, name); - mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); - updateLayerIndices(); - return true; -} - -/*! - Removes the specified \a layer and returns true on success. - - All layerables (e.g. plottables and items) on the removed layer will be moved to the layer below - \a layer. If \a layer is the bottom layer, the layerables are moved to the layer above. In both - cases, the total rendering order of all layerables in the QCustomPlot is preserved. - - If \a layer is the current layer (\ref setCurrentLayer), the layer below (or above, if bottom - layer) becomes the new current layer. - - It is not possible to remove the last layer of the plot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::removeLayer(QCPLayer *layer) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(layer); - return false; - } - if (mLayers.size() < 2) - { - qDebug() << Q_FUNC_INFO << "can't remove last layer"; - return false; - } - - // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) - int removedIndex = layer->index(); - bool isFirstLayer = removedIndex==0; - QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); - QList<QCPLayerable*> children = layer->children(); - if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) - { - for (int i=children.size()-1; i>=0; --i) - children.at(i)->moveToLayer(targetLayer, true); - } else // append normally - { - for (int i=0; i<children.size(); ++i) - children.at(i)->moveToLayer(targetLayer, false); - } - // if removed layer is current layer, change current layer to layer below/above: - if (layer == mCurrentLayer) - setCurrentLayer(targetLayer); - // remove layer: - delete layer; - mLayers.removeOne(layer); - updateLayerIndices(); - return true; -} - -/*! - Moves the specified \a layer either above or below \a otherLayer. Whether it's placed above or - below is controlled with \a insertMode. - - Returns true on success, i.e. when both \a layer and \a otherLayer are valid layers in the - QCustomPlot. - - \see layer, addLayer, moveLayer -*/ -bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) -{ - if (!mLayers.contains(layer)) - { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(layer); - return false; - } - if (!mLayers.contains(otherLayer)) - { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast<quintptr>(otherLayer); - return false; - } - - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); - updateLayerIndices(); - return true; -} - -/*! - Returns the number of axis rects in the plot. - - All axis rects can be accessed via QCustomPlot::axisRect(). - - Initially, only one axis rect exists in the plot. - - \see axisRect, axisRects -*/ -int QCustomPlot::axisRectCount() const -{ - return axisRects().size(); -} - -/*! - Returns the axis rect with \a index. - - Initially, only one axis rect (with index 0) exists in the plot. If multiple axis rects were - added, all of them may be accessed with this function in a linear fashion (even when they are - nested in a layout hierarchy or inside other axis rects via QCPAxisRect::insetLayout). - - \see axisRectCount, axisRects -*/ -QCPAxisRect *QCustomPlot::axisRect(int index) const -{ - const QList<QCPAxisRect*> rectList = axisRects(); - if (index >= 0 && index < rectList.size()) - { - return rectList.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; - return 0; - } -} - -/*! - Returns all axis rects in the plot. - - \see axisRectCount, axisRect -*/ -QList<QCPAxisRect*> QCustomPlot::axisRects() const -{ - QList<QCPAxisRect*> result; - QStack<QCPLayoutElement*> elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - foreach (QCPLayoutElement *element, elementStack.pop()->elements(false)) - { - if (element) - { - elementStack.push(element); - if (QCPAxisRect *ar = qobject_cast<QCPAxisRect*>(element)) - result.append(ar); - } - } - } - - return result; -} - -/*! - Returns the layout element at pixel position \a pos. If there is no element at that position, - returns 0. - - Only visible elements are used. If \ref QCPLayoutElement::setVisible on the element itself or on - any of its parent elements is set to false, it will not be considered. - - \see itemAt, plottableAt -*/ -QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const -{ - QCPLayoutElement *currentElement = mPlotLayout; - bool searchSubElements = true; - while (searchSubElements && currentElement) - { - searchSubElements = false; - foreach (QCPLayoutElement *subElement, currentElement->elements(false)) - { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) - { - currentElement = subElement; - searchSubElements = true; - break; - } - } - } - return currentElement; -} - -/*! - Returns the axes that currently have selected parts, i.e. whose selection state is not \ref - QCPAxis::spNone. - - \see selectedPlottables, selectedLegends, setInteractions, QCPAxis::setSelectedParts, - QCPAxis::setSelectableParts -*/ -QList<QCPAxis*> QCustomPlot::selectedAxes() const -{ - QList<QCPAxis*> result, allAxes; - foreach (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - foreach (QCPAxis *axis, allAxes) - { - if (axis->selectedParts() != QCPAxis::spNone) - result.append(axis); - } - - return result; -} - -/*! - Returns the legends that currently have selected parts, i.e. whose selection state is not \ref - QCPLegend::spNone. - - \see selectedPlottables, selectedAxes, setInteractions, QCPLegend::setSelectedParts, - QCPLegend::setSelectableParts, QCPLegend::selectedItems -*/ -QList<QCPLegend*> QCustomPlot::selectedLegends() const -{ - QList<QCPLegend*> result; - - QStack<QCPLayoutElement*> elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) - { - foreach (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) - { - if (subElement) - { - elementStack.push(subElement); - if (QCPLegend *leg = qobject_cast<QCPLegend*>(subElement)) - { - if (leg->selectedParts() != QCPLegend::spNone) - result.append(leg); - } - } - } - } - - return result; -} - -/*! - Deselects all layerables (plottables, items, axes, legends,...) of the QCustomPlot. - - Since calling this function is not a user interaction, this does not emit the \ref - selectionChangedByUser signal. The individual selectionChanged signals are emitted though, if the - objects were previously selected. - - \see setInteractions, selectedPlottables, selectedItems, selectedAxes, selectedLegends -*/ -void QCustomPlot::deselectAll() -{ - foreach (QCPLayer *layer, mLayers) - { - foreach (QCPLayerable *layerable, layer->children()) - layerable->deselectEvent(0); - } -} - -/*! - Causes a complete replot into the internal buffer. Finally, update() is called, to redraw the - buffer on the QCustomPlot widget surface. This is the method that must be called to make changes, - for example on the axis ranges or data points of graphs, visible. - - Under a few circumstances, QCustomPlot causes a replot by itself. Those are resize events of the - QCustomPlot widget and user interactions (object selection and range dragging/zooming). - - Before the replot happens, the signal \ref beforeReplot is emitted. After the replot, \ref - afterReplot is emitted. It is safe to mutually connect the replot slot with any of those two - signals on two QCustomPlots to make them replot synchronously, it won't cause an infinite - recursion. -*/ -void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) -{ - if (mReplotting) // incase signals loop back to replot slot - return; - mReplotting = true; - emit beforeReplot(); - - mPaintBuffer.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); - QCPPainter painter; - painter.begin(&mPaintBuffer); - if (painter.isActive()) - { - painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - painter.end(); - if ((refreshPriority == rpHint && mPlottingHints.testFlag(QCP::phForceRepaint)) || refreshPriority==rpImmediate) - repaint(); - else - update(); - } else // might happen if QCustomPlot has width or height zero - qDebug() << Q_FUNC_INFO << "Couldn't activate painter on buffer"; - - emit afterReplot(); - mReplotting = false; -} - -/*! - Rescales the axes such that all plottables (like graphs) in the plot are fully visible. - - if \a onlyVisiblePlottables is set to true, only the plottables that have their visibility set to true - (QCPLayerable::setVisible), will be used to rescale the axes. - - \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale -*/ -void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) -{ - QList<QCPAxis*> allAxes; - foreach (QCPAxisRect *rect, axisRects()) - allAxes << rect->axes(); - - foreach (QCPAxis *axis, allAxes) - axis->rescale(onlyVisiblePlottables); -} - -/*! - Saves a PDF with the vectorized plot to the file \a fileName. The axis ratio as well as the scale - of texts and lines will be derived from the specified \a width and \a height. This means, the - output will look like the normal on-screen output of a QCustomPlot widget with the corresponding - pixel width and height. If either \a width or \a height is zero, the exported image will have the - same dimensions as the QCustomPlot widget currently has. - - \a noCosmeticPen disables the use of cosmetic pens when drawing to the PDF file. Cosmetic pens - are pens with numerical width 0, which are always drawn as a one pixel wide line, no matter what - zoom factor is set in the PDF-Viewer. For more information about cosmetic pens, see the QPainter - and QPen documentation. - - The objects of the plot will appear in the current selection state. If you don't want any - selected objects to be painted in their selected look, deselect everything with \ref deselectAll - before calling this function. - - Returns true on success. - - \warning - \li If you plan on editing the exported PDF file with a vector graphics editor like - Inkscape, it is advised to set \a noCosmeticPen to true to avoid losing those cosmetic lines - (which might be quite many, because cosmetic pens are the default for e.g. axes and tick marks). - \li If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - \a pdfCreator and \a pdfTitle may be used to set the according metadata fields in the resulting - PDF file. - - \note On Android systems, this method does nothing and issues an according qDebug warning - message. This is also the case if for other reasons the define flag QT_NO_PRINTER is set. - - \see savePng, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePdf(const QString &fileName, bool noCosmeticPen, int width, int height, const QString &pdfCreator, const QString &pdfTitle) -{ - bool success = false; -#ifdef QT_NO_PRINTER - Q_UNUSED(fileName) - Q_UNUSED(noCosmeticPen) - Q_UNUSED(width) - Q_UNUSED(height) - qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; -#else - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setFullPage(true); - printer.setColorMode(QPrinter::Color); - printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); - printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); - QCPPainter printpainter; - if (printpainter.begin(&printer)) - { - printpainter.setMode(QCPPainter::pmVectorized); - printpainter.setMode(QCPPainter::pmNoCaching); - printpainter.setMode(QCPPainter::pmNonCosmetic, noCosmeticPen); - printpainter.setWindow(mViewport); - if (mBackgroundBrush.style() != Qt::NoBrush && - mBackgroundBrush.color() != Qt::white && - mBackgroundBrush.color() != Qt::transparent && - mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent - printpainter.fillRect(viewport(), mBackgroundBrush); - draw(&printpainter); - printpainter.end(); - success = true; - } - setViewport(oldViewport); -#endif // QT_NO_PRINTER - return success; -} - -/*! - Saves a PNG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels. If either \a width or \a height is zero, the exported image will have - the same dimensions as the QCustomPlot widget currently has. Line widths and texts etc. are not - scaled up when larger widths/heights are used. If you want that effect, use the \a scale parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements via - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - If you want the PNG to have a transparent background, call \ref setBackground(const QBrush - &brush) with no brush (Qt::NoBrush) or a transparent color (Qt::transparent), before saving. - - PNG compression can be controlled with the \a quality parameter which must be between 0 and 100 or - -1 to use the default setting. - - Returns true on success. If this function fails, most likely the PNG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - \see savePdf, saveBmp, saveJpg, saveRastered -*/ -bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality) -{ - return saveRastered(fileName, width, height, scale, "PNG", quality); -} - -/*! - Saves a JPG image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels. If either \a width or \a height is zero, the exported image will have - the same dimensions as the QCustomPlot widget currently has. Line widths and texts etc. are not - scaled up when larger widths/heights are used. If you want that effect, use the \a scale parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements via - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - JPG compression can be controlled with the \a quality parameter which must be between 0 and 100 or - -1 to use the default setting. - - Returns true on success. If this function fails, most likely the JPG format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - \see savePdf, savePng, saveBmp, saveRastered -*/ -bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality) -{ - return saveRastered(fileName, width, height, scale, "JPG", quality); -} - -/*! - Saves a BMP image file to \a fileName on disc. The output plot will have the dimensions \a width - and \a height in pixels. If either \a width or \a height is zero, the exported image will have - the same dimensions as the QCustomPlot widget currently has. Line widths and texts etc. are not - scaled up when larger widths/heights are used. If you want that effect, use the \a scale parameter. - - For example, if you set both \a width and \a height to 100 and \a scale to 2, you will end up with an - image file of size 200*200 in which all graphical elements are scaled up by factor 2 (line widths, - texts, etc.). This scaling is not done by stretching a 100*100 image, the result will have full - 200*200 pixel resolution. - - If you use a high scaling factor, it is recommended to enable antialiasing for all elements via - temporarily setting \ref QCustomPlot::setAntialiasedElements to \ref QCP::aeAll as this allows - QCustomPlot to place objects with sub-pixel accuracy. - - \warning If calling this function inside the constructor of the parent of the QCustomPlot widget - (i.e. the MainWindow constructor, if QCustomPlot is inside the MainWindow), always provide - explicit non-zero widths and heights. If you leave \a width or \a height as 0 (default), this - function uses the current width and height of the QCustomPlot widget. However, in Qt, these - aren't defined yet inside the constructor, so you would get an image that has strange - widths/heights. - - The objects of the plot will appear in the current selection state. If you don't want any selected - objects to be painted in their selected look, deselect everything with \ref deselectAll before calling - this function. - - Returns true on success. If this function fails, most likely the BMP format isn't supported by - the system, see Qt docs about QImageWriter::supportedImageFormats(). - - \see savePdf, savePng, saveJpg, saveRastered -*/ -bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale) -{ - return saveRastered(fileName, width, height, scale, "BMP"); -} - -/*! \internal - - Returns a minimum size hint that corresponds to the minimum size of the top level layout - (\ref plotLayout). To prevent QCustomPlot from being collapsed to size/width zero, set a minimum - size (setMinimumSize) either on the whole QCustomPlot or on any layout elements inside the plot. - This is especially important, when placed in a QLayout where other components try to take in as - much space as possible (e.g. QMdiArea). -*/ -QSize QCustomPlot::minimumSizeHint() const -{ - return mPlotLayout->minimumSizeHint(); -} - -/*! \internal - - Returns a size hint that is the same as \ref minimumSizeHint. - -*/ -QSize QCustomPlot::sizeHint() const -{ - return mPlotLayout->minimumSizeHint(); -} - -/*! \internal - - Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but - draws the internal buffer on the widget surface. -*/ -void QCustomPlot::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - QPainter painter(this); - painter.drawPixmap(0, 0, mPaintBuffer); -} - -/*! \internal - - Event handler for a resize of the QCustomPlot widget. Causes the internal buffer to be resized to - the new size. The viewport (which becomes the outer rect of mPlotLayout) is resized - appropriately. Finally a \ref replot is performed. -*/ -void QCustomPlot::resizeEvent(QResizeEvent *event) -{ - // resize and repaint the buffer: - mPaintBuffer = QPixmap(event->size()); - setViewport(rect()); - replot(rpQueued); // queued update is important here, to prevent painting issues in some contexts -} - -/*! \internal - - Event handler for when a double click occurs. Emits the \ref mouseDoubleClick signal, then emits - the specialized signals when certain objecs are clicked (e.g. \ref plottableDoubleClick, \ref - axisDoubleClick, etc.). Finally determines the affected layout element and forwards the event to - it. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) -{ - emit mouseDoubleClick(event); - - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), false, &details); - - // emit specialized object double click signals: - if (QCPAbstractPlottable *ap = qobject_cast<QCPAbstractPlottable*>(clickedLayerable)) - emit plottableDoubleClick(ap, event); - else if (QCPAxis *ax = qobject_cast<QCPAxis*>(clickedLayerable)) - emit axisDoubleClick(ax, details.value<QCPAxis::SelectablePart>(), event); - else if (QCPAbstractItem *ai = qobject_cast<QCPAbstractItem*>(clickedLayerable)) - emit itemDoubleClick(ai, event); - else if (QCPLegend *lg = qobject_cast<QCPLegend*>(clickedLayerable)) - emit legendDoubleClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast<QCPAbstractLegendItem*>(clickedLayerable)) - emit legendDoubleClick(li->parentLegend(), li, event); - else if (QCPPlotTitle *pt = qobject_cast<QCPPlotTitle*>(clickedLayerable)) - emit titleDoubleClick(event, pt); - - // call double click event of affected layout element: - if (QCPLayoutElement *el = layoutElementAt(event->pos())) - el->mouseDoubleClickEvent(event); - - // call release event of affected layout element (as in mouseReleaseEvent, since the mouseDoubleClick replaces the second release event in double click case): - if (mMouseEventElement) - { - mMouseEventElement->mouseReleaseEvent(event); - mMouseEventElement = 0; - } - - //QWidget::mouseDoubleClickEvent(event); don't call base class implementation because it would just cause a mousePress/ReleaseEvent, which we don't want. -} - -/*! \internal - - Event handler for when a mouse button is pressed. Emits the mousePress signal. Then determines - the affected layout element and forwards the event to it. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCustomPlot::mousePressEvent(QMouseEvent *event) -{ - emit mousePress(event); - mMousePressPos = event->pos(); // need this to determine in releaseEvent whether it was a click (no position change between press and release) - - // call event of affected layout element: - mMouseEventElement = layoutElementAt(event->pos()); - if (mMouseEventElement) - mMouseEventElement->mousePressEvent(event); - - QWidget::mousePressEvent(event); -} - -/*! \internal - - Event handler for when the cursor is moved. Emits the \ref mouseMove signal. - - If a layout element has mouse capture focus (a mousePressEvent happened on top of the layout - element before), the mouseMoveEvent is forwarded to that element. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCustomPlot::mouseMoveEvent(QMouseEvent *event) -{ - emit mouseMove(event); - - // call event of affected layout element: - if (mMouseEventElement) - mMouseEventElement->mouseMoveEvent(event); - - QWidget::mouseMoveEvent(event); -} - -/*! \internal - - Event handler for when a mouse button is released. Emits the \ref mouseRelease signal. - - If the mouse was moved less than a certain threshold in any direction since the \ref - mousePressEvent, it is considered a click which causes the selection mechanism (if activated via - \ref setInteractions) to possibly change selection states accordingly. Further, specialized mouse - click signals are emitted (e.g. \ref plottableClick, \ref axisClick, etc.) - - If a layout element has mouse capture focus (a \ref mousePressEvent happened on top of the layout - element before), the \ref mouseReleaseEvent is forwarded to that element. - - \see mousePressEvent, mouseMoveEvent -*/ -void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) -{ - emit mouseRelease(event); - bool doReplot = false; - - if ((mMousePressPos-event->pos()).manhattanLength() < 5) // determine whether it was a click operation - { - if (event->button() == Qt::LeftButton) - { - // handle selection mechanism: - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); - bool selectionStateChanged = false; - bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); - // deselect all other layerables if not additive selection: - if (!additive) - { - foreach (QCPLayer *layer, mLayers) - { - foreach (QCPLayerable *layerable, layer->children()) - { - if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) - { - bool selChanged = false; - layerable->deselectEvent(&selChanged); - selectionStateChanged |= selChanged; - } - } - } - } - if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) - { - // a layerable was actually clicked, call its selectEvent: - bool selChanged = false; - clickedLayerable->selectEvent(event, additive, details, &selChanged); - selectionStateChanged |= selChanged; - } - doReplot = true; - if (selectionStateChanged) - emit selectionChangedByUser(); - } - - // emit specialized object click signals: - QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), false, &details); // for these signals, selectability is ignored, that's why we call this again with onlySelectable set to false - if (QCPAbstractPlottable *ap = qobject_cast<QCPAbstractPlottable*>(clickedLayerable)) - emit plottableClick(ap, event); - else if (QCPAxis *ax = qobject_cast<QCPAxis*>(clickedLayerable)) - emit axisClick(ax, details.value<QCPAxis::SelectablePart>(), event); - else if (QCPAbstractItem *ai = qobject_cast<QCPAbstractItem*>(clickedLayerable)) - emit itemClick(ai, event); - else if (QCPLegend *lg = qobject_cast<QCPLegend*>(clickedLayerable)) - emit legendClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast<QCPAbstractLegendItem*>(clickedLayerable)) - emit legendClick(li->parentLegend(), li, event); - else if (QCPPlotTitle *pt = qobject_cast<QCPPlotTitle*>(clickedLayerable)) - emit titleClick(event, pt); - } - - // call event of affected layout element: - if (mMouseEventElement) - { - mMouseEventElement->mouseReleaseEvent(event); - mMouseEventElement = 0; - } - - if (doReplot || noAntialiasingOnDrag()) - replot(); - - QWidget::mouseReleaseEvent(event); -} - -/*! \internal - - Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then - determines the affected layout element and forwards the event to it. - -*/ -void QCustomPlot::wheelEvent(QWheelEvent *event) -{ - emit mouseWheel(event); - - // call event of affected layout element: - if (QCPLayoutElement *el = layoutElementAt(event->pos())) - el->wheelEvent(event); - - QWidget::wheelEvent(event); -} - -/*! \internal - - This is the main draw function. It draws the entire plot, including background pixmap, with the - specified \a painter. Note that it does not fill the background with the background brush (as the - user may specify with \ref setBackground(const QBrush &brush)), this is up to the respective - functions calling this method (e.g. \ref replot, \ref toPixmap and \ref toPainter). -*/ -void QCustomPlot::draw(QCPPainter *painter) -{ - // run through layout phases: - mPlotLayout->update(QCPLayoutElement::upPreparation); - mPlotLayout->update(QCPLayoutElement::upMargins); - mPlotLayout->update(QCPLayoutElement::upLayout); - - // draw viewport background pixmap: - drawBackground(painter); - - // draw all layered objects (grid, axes, plottables, items, legend,...): - foreach (QCPLayer *layer, mLayers) - { - foreach (QCPLayerable *child, layer->children()) - { - if (child->realVisibility()) - { - painter->save(); - painter->setClipRect(child->clipRect().translated(0, -1)); - child->applyDefaultAntialiasingHint(painter); - child->draw(painter); - painter->restore(); - } - } - } - - /* Debug code to draw all layout element rects - foreach (QCPLayoutElement* el, findChildren<QCPLayoutElement*>()) - { - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(QColor(0, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->rect()); - painter->setPen(QPen(QColor(255, 0, 0, 100), 0, Qt::DashLine)); - painter->drawRect(el->outerRect()); - } - */ -} - -/*! \internal - - Draws the viewport background pixmap of the plot. - - If a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the viewport with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependent on the \ref setBackgroundScaledMode), or when a differend axis background pixmap was - set. - - Note that this function does not draw a fill with the background brush (\ref setBackground(const - QBrush &brush)) beneath the pixmap. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCustomPlot::drawBackground(QCPPainter *painter) -{ - // Note: background color is handled in individual replot/save functions - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mViewport.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); - } - } -} - - -/*! \internal - - This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot - so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. -*/ -void QCustomPlot::axisRemoved(QCPAxis *axis) -{ - if (xAxis == axis) - xAxis = 0; - if (xAxis2 == axis) - xAxis2 = 0; - if (yAxis == axis) - yAxis = 0; - if (yAxis2 == axis) - yAxis2 = 0; - - // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers -} - -/*! \internal - - This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so - it may clear its QCustomPlot::legend member accordingly. -*/ -void QCustomPlot::legendRemoved(QCPLegend *legend) -{ - if (this->legend == legend) - this->legend = 0; -} - -/*! \internal - - Assigns all layers their index (QCPLayer::mIndex) in the mLayers list. This method is thus called - after every operation that changes the layer indices, like layer removal, layer creation, layer - moving. -*/ -void QCustomPlot::updateLayerIndices() const -{ - for (int i=0; i<mLayers.size(); ++i) - mLayers.at(i)->mIndex = i; -} - -/*! \internal - - Returns the layerable at pixel position \a pos. If \a onlySelectable is set to true, only those - layerables that are selectable will be considered. (Layerable subclasses communicate their - selectability via the QCPLayerable::selectTest method, by returning -1.) - - \a selectionDetails is an output parameter that contains selection specifics of the affected - layerable. This is useful if the respective layerable shall be given a subsequent - QCPLayerable::selectEvent (like in \ref mouseReleaseEvent). \a selectionDetails usually contains - information about which part of the layerable was hit, in multi-part layerables (e.g. - QCPAxis::SelectablePart). -*/ -QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const -{ - for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) - { - const QList<QCPLayerable*> layerables = mLayers.at(layerIndex)->children(); - double minimumDistance = selectionTolerance()*1.1; - QCPLayerable *minimumDistanceLayerable = 0; - for (int i=layerables.size()-1; i>=0; --i) - { - if (!layerables.at(i)->realVisibility()) - continue; - QVariant details; - double dist = layerables.at(i)->selectTest(pos, onlySelectable, &details); - if (dist >= 0 && dist < minimumDistance) - { - minimumDistance = dist; - minimumDistanceLayerable = layerables.at(i); - if (selectionDetails) *selectionDetails = details; - } - } - if (minimumDistance < selectionTolerance()) - return minimumDistanceLayerable; - } - return 0; -} - -/*! - Saves the plot to a rastered image file \a fileName in the image format \a format. The plot is - sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and scale 2.0 lead - to a full resolution file with width 200.) If the \a format supports compression, \a quality may - be between 0 and 100 to control it. - - Returns true on success. If this function fails, most likely the given \a format isn't supported - by the system, see Qt docs about QImageWriter::supportedImageFormats(). - - \see saveBmp, saveJpg, savePng, savePdf -*/ -bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality) -{ - QPixmap buffer = toPixmap(width, height, scale); - if (!buffer.isNull()) - return buffer.save(fileName, format, quality); - else - return false; -} - -/*! - Renders the plot to a pixmap and returns it. - - The plot is sized to \a width and \a height in pixels and scaled with \a scale. (width 100 and - scale 2.0 lead to a full resolution pixmap with width 200.) - - \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf -*/ -QPixmap QCustomPlot::toPixmap(int width, int height, double scale) -{ - // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - int scaledWidth = qRound(scale*newWidth); - int scaledHeight = qRound(scale*newHeight); - - QPixmap result(scaledWidth, scaledHeight); - result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later - QCPPainter painter; - painter.begin(&result); - if (painter.isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter.setMode(QCPPainter::pmNoCaching); - if (!qFuzzyCompare(scale, 1.0)) - { - if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales - painter.setMode(QCPPainter::pmNonCosmetic); - painter.scale(scale, scale); - } - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - setViewport(oldViewport); - painter.end(); - } else // might happen if pixmap has width or height zero - { - qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; - return QPixmap(); - } - return result; -} - -/*! - Renders the plot using the passed \a painter. - - The plot is sized to \a width and \a height in pixels. If the \a painter's scale is not 1.0, the resulting plot will - appear scaled accordingly. - - \note If you are restricted to using a QPainter (instead of QCPPainter), create a temporary QPicture and open a QCPPainter - on it. Then call \ref toPainter with this QCPPainter. After ending the paint operation on the picture, draw it with - the QPainter. This will reproduce the painter actions the QCPPainter took, with a QPainter. - - \see toPixmap -*/ -void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) -{ - // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. - int newWidth, newHeight; - if (width == 0 || height == 0) - { - newWidth = this->width(); - newHeight = this->height(); - } else - { - newWidth = width; - newHeight = height; - } - - if (painter->isActive()) - { - QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter->setMode(QCPPainter::pmNoCaching); - // warning: the following is different in toPixmap, because a solid background color is applied there via QPixmap::fill - // here, we need to do this via QPainter::fillRect. - if (mBackgroundBrush.style() != Qt::NoBrush) - painter->fillRect(mViewport, mBackgroundBrush); - draw(painter); - setViewport(oldViewport); - } else - qDebug() << Q_FUNC_INFO << "Passed painter is not active"; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorGradient -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorGradient - \brief Defines a color gradient for use with e.g. \ref QCPColorMap - - This class describes a color gradient which can be used to encode data with color. For example, - QCPColorMap and QCPColorScale have a \ref QCPColorMap::setGradient "setGradient" method which - takes an instance of this class. Colors are set with \ref setColorStopAt(double position, const QColor &color) - with a \a position from 0 to 1. In between these defined color positions, the - color will be interpolated linearly either in RGB or HSV space, see \ref setColorInterpolation. - - Alternatively, load one of the preset color gradients shown in the image below, with \ref - loadPreset, or by directly specifying the preset in the constructor. - - \image html QCPColorGradient.png - - The fact that the \ref QCPColorGradient(GradientPreset preset) constructor allows directly - converting a \ref GradientPreset to a QCPColorGradient, you can also directly pass \ref - GradientPreset to all the \a setGradient methods, e.g.: - \code - colorMap->setGradient(QCPColorGradient::gpHot); - \endcode - - The total number of levels used in the gradient can be set with \ref setLevelCount. Whether the - color gradient shall be applied periodically (wrapping around) to data values that lie outside - the data range specified on the plottable instance can be controlled with \ref setPeriodic. -*/ - -/*! - Constructs a new QCPColorGradient initialized with the colors and color interpolation according - to \a preset. - - The color level count is initialized to 350. -*/ -QCPColorGradient::QCPColorGradient(GradientPreset preset) : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) -{ - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); - loadPreset(preset); -} - -/* undocumented operator */ -bool QCPColorGradient::operator==(const QCPColorGradient &other) const -{ - return ((other.mLevelCount == this->mLevelCount) && - (other.mColorInterpolation == this->mColorInterpolation) && - (other.mPeriodic == this->mPeriodic) && - (other.mColorStops == this->mColorStops)); -} - -/*! - Sets the number of discretization levels of the color gradient to \a n. The default is 350 which - is typically enough to create a smooth appearance. - - \image html QCPColorGradient-levelcount.png -*/ -void QCPColorGradient::setLevelCount(int n) -{ - if (n < 2) - { - qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; - n = 2; - } - if (n != mLevelCount) - { - mLevelCount = n; - mColorBufferInvalidated = true; - } -} - -/*! - Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the - colors are the values of the passed QMap \a colorStops. In between these color stops, the color - is interpolated according to \ref setColorInterpolation. - - A more convenient way to create a custom gradient may be to clear all color stops with \ref - clearColorStops and then adding them one by one with \ref setColorStopAt. - - \see clearColorStops -*/ -void QCPColorGradient::setColorStops(const QMap<double, QColor> &colorStops) -{ - mColorStops = colorStops; - mColorBufferInvalidated = true; -} - -/*! - Sets the \a color the gradient will have at the specified \a position (from 0 to 1). In between - these color stops, the color is interpolated according to \ref setColorInterpolation. - - \see setColorStops, clearColorStops -*/ -void QCPColorGradient::setColorStopAt(double position, const QColor &color) -{ - mColorStops.insert(position, color); - mColorBufferInvalidated = true; -} - -/*! - Sets whether the colors in between the configured color stops (see \ref setColorStopAt) shall be - interpolated linearly in RGB or in HSV color space. - - For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, - whereas in HSV space the intermediate color is yellow. -*/ -void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) -{ - if (interpolation != mColorInterpolation) - { - mColorInterpolation = interpolation; - mColorBufferInvalidated = true; - } -} - -/*! - Sets whether data points that are outside the configured data range (e.g. \ref - QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether - they all have the same color, corresponding to the respective gradient boundary color. - - \image html QCPColorGradient-periodic.png - - As shown in the image above, gradients that have the same start and end color are especially - suitable for a periodic gradient mapping, since they produce smooth color transitions throughout - the color map. A preset that has this property is \ref gpHues. - - In practice, using periodic color gradients makes sense when the data corresponds to a periodic - dimension, such as an angle or a phase. If this is not the case, the color encoding might become - ambiguous, because multiple different data values are shown as the same color. -*/ -void QCPColorGradient::setPeriodic(bool enabled) -{ - mPeriodic = enabled; -} - -/*! - This method is used to quickly convert a \a data array to colors. The colors will be output in - the array \a scanLine. Both \a data and \a scanLine must have the length \a n when passed to this - function. The data range that shall be used for mapping the data value to the gradient is passed - in \a range. \a logarithmic indicates whether the data values shall be mapped to colors - logarithmically. - - if \a data actually contains 2D-data linearized via <tt>[row*columnCount + column]</tt>, you can - set \a dataIndexFactor to <tt>columnCount</tt> to convert a column instead of a row of the data - array, in \a scanLine. \a scanLine will remain a regular (1D) array. This works because \a data - is addressed <tt>data[i*dataIndexFactor]</tt>. -*/ -void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) -{ - // If you change something here, make sure to also adapt ::color() - if (!data) - { - qDebug() << Q_FUNC_INFO << "null pointer given as data"; - return; - } - if (!scanLine) - { - qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; - return; - } - if (mColorBufferInvalidated) - updateColorBuffer(); - - if (!logarithmic) - { - const double posToIndexFactor = mLevelCount/range.size(); - if (mPeriodic) - { - for (int i=0; i<n; ++i) - { - int index = (int)((data[dataIndexFactor*i]-range.lower)*posToIndexFactor) % mLevelCount; - if (index < 0) - index += mLevelCount; - scanLine[i] = mColorBuffer.at(index); - } - } else - { - for (int i=0; i<n; ++i) - { - int index = (data[dataIndexFactor*i]-range.lower)*posToIndexFactor; - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } else // logarithmic == true - { - if (mPeriodic) - { - for (int i=0; i<n; ++i) - { - int index = (int)(qLn(data[dataIndexFactor*i]/range.lower)/qLn(range.upper/range.lower)*mLevelCount) % mLevelCount; - if (index < 0) - index += mLevelCount; - scanLine[i] = mColorBuffer.at(index); - } - } else - { - for (int i=0; i<n; ++i) - { - int index = qLn(data[dataIndexFactor*i]/range.lower)/qLn(range.upper/range.lower)*mLevelCount; - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); - } - } - } -} - -/*! \internal - - This method is used to colorize a single data value given in \a position, to colors. The data - range that shall be used for mapping the data value to the gradient is passed in \a range. \a - logarithmic indicates whether the data value shall be mapped to a color logarithmically. - - If an entire array of data values shall be converted, rather use \ref colorize, for better - performance. -*/ -QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) -{ - // If you change something here, make sure to also adapt ::colorize() - if (mColorBufferInvalidated) - updateColorBuffer(); - int index = 0; - if (!logarithmic) - index = (position-range.lower)*mLevelCount/range.size(); - else - index = qLn(position/range.lower)/qLn(range.upper/range.lower)*mLevelCount; - if (mPeriodic) - { - index = index % mLevelCount; - if (index < 0) - index += mLevelCount; - } else - { - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; - } - return mColorBuffer.at(index); -} - -/*! - Clears the current color stops and loads the specified \a preset. A preset consists of predefined - color stops and the corresponding color interpolation method. - - The available presets are: - \image html QCPColorGradient.png -*/ -void QCPColorGradient::loadPreset(GradientPreset preset) -{ - clearColorStops(); - switch (preset) - { - case gpGrayscale: - setColorInterpolation(ciRGB); - setColorStopAt(0, Qt::black); - setColorStopAt(1, Qt::white); - break; - case gpHot: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 0, 0)); - setColorStopAt(0.2, QColor(180, 10, 0)); - setColorStopAt(0.4, QColor(245, 50, 0)); - setColorStopAt(0.6, QColor(255, 150, 10)); - setColorStopAt(0.8, QColor(255, 255, 50)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpCold: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.2, QColor(0, 10, 180)); - setColorStopAt(0.4, QColor(0, 50, 245)); - setColorStopAt(0.6, QColor(10, 150, 255)); - setColorStopAt(0.8, QColor(50, 255, 255)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpNight: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(10, 20, 30)); - setColorStopAt(1, QColor(250, 255, 250)); - break; - case gpCandy: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(0, 0, 255)); - setColorStopAt(1, QColor(255, 250, 250)); - break; - case gpGeography: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(70, 170, 210)); - setColorStopAt(0.20, QColor(90, 160, 180)); - setColorStopAt(0.25, QColor(45, 130, 175)); - setColorStopAt(0.30, QColor(100, 140, 125)); - setColorStopAt(0.5, QColor(100, 140, 100)); - setColorStopAt(0.6, QColor(130, 145, 120)); - setColorStopAt(0.7, QColor(140, 130, 120)); - setColorStopAt(0.9, QColor(180, 190, 190)); - setColorStopAt(1, QColor(210, 210, 230)); - break; - case gpIon: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 10, 10)); - setColorStopAt(0.45, QColor(0, 0, 255)); - setColorStopAt(0.8, QColor(0, 255, 255)); - setColorStopAt(1, QColor(0, 255, 0)); - break; - case gpThermal: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.15, QColor(20, 0, 120)); - setColorStopAt(0.33, QColor(200, 30, 140)); - setColorStopAt(0.6, QColor(255, 100, 0)); - setColorStopAt(0.85, QColor(255, 255, 40)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpPolar: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 255, 255)); - setColorStopAt(0.18, QColor(10, 70, 255)); - setColorStopAt(0.28, QColor(10, 10, 190)); - setColorStopAt(0.5, QColor(0, 0, 0)); - setColorStopAt(0.72, QColor(190, 10, 10)); - setColorStopAt(0.82, QColor(255, 70, 10)); - setColorStopAt(1, QColor(255, 255, 50)); - break; - case gpSpectrum: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 0, 50)); - setColorStopAt(0.15, QColor(0, 0, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.6, QColor(255, 255, 0)); - setColorStopAt(0.75, QColor(255, 30, 0)); - setColorStopAt(1, QColor(50, 0, 0)); - break; - case gpJet: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 100)); - setColorStopAt(0.15, QColor(0, 50, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.65, QColor(255, 255, 0)); - setColorStopAt(0.85, QColor(255, 30, 0)); - setColorStopAt(1, QColor(100, 0, 0)); - break; - case gpHues: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(255, 0, 0)); - setColorStopAt(1.0/3.0, QColor(0, 0, 255)); - setColorStopAt(2.0/3.0, QColor(0, 255, 0)); - setColorStopAt(1, QColor(255, 0, 0)); - break; - } -} - -/*! - Clears all color stops. - - \see setColorStops, setColorStopAt -*/ -void QCPColorGradient::clearColorStops() -{ - mColorStops.clear(); - mColorBufferInvalidated = true; -} - -/*! - Returns an inverted gradient. The inverted gradient has all properties as this \ref - QCPColorGradient, but the order of the color stops is inverted. - - \see setColorStops, setColorStopAt -*/ -QCPColorGradient QCPColorGradient::inverted() const -{ - QCPColorGradient result(*this); - result.clearColorStops(); - for (QMap<double, QColor>::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - result.setColorStopAt(1.0-it.key(), it.value()); - return result; -} - -/*! \internal - - Updates the internal color buffer which will be used by \ref colorize and \ref color, to quickly - convert positions to colors. This is where the interpolation between color stops is calculated. -*/ -void QCPColorGradient::updateColorBuffer() -{ - if (mColorBuffer.size() != mLevelCount) - mColorBuffer.resize(mLevelCount); - if (mColorStops.size() > 1) - { - double indexToPosFactor = 1.0/(double)(mLevelCount-1); - for (int i=0; i<mLevelCount; ++i) - { - double position = i*indexToPosFactor; - QMap<double, QColor>::const_iterator it = mColorStops.lowerBound(position); - if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop - { - mColorBuffer[i] = (it-1).value().rgb(); - } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop - { - mColorBuffer[i] = it.value().rgb(); - } else // position is in between stops (or on an intermediate stop), interpolate color - { - QMap<double, QColor>::const_iterator high = it; - QMap<double, QColor>::const_iterator low = it-1; - double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 - switch (mColorInterpolation) - { - case ciRGB: - { - mColorBuffer[i] = qRgb((1-t)*low.value().red() + t*high.value().red(), - (1-t)*low.value().green() + t*high.value().green(), - (1-t)*low.value().blue() + t*high.value().blue()); - break; - } - case ciHSV: - { - QColor lowHsv = low.value().toHsv(); - QColor highHsv = high.value().toHsv(); - double hue = 0; - double hueDiff = highHsv.hueF()-lowHsv.hueF(); - if (hueDiff > 0.5) - hue = lowHsv.hueF() - t*(1.0-hueDiff); - else if (hueDiff < -0.5) - hue = lowHsv.hueF() + t*(1.0+hueDiff); - else - hue = lowHsv.hueF() + t*hueDiff; - if (hue < 0) hue += 1.0; - else if (hue >= 1.0) hue -= 1.0; - mColorBuffer[i] = QColor::fromHsvF(hue, (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - break; - } - } - } - } - } else if (mColorStops.size() == 1) - { - mColorBuffer.fill(mColorStops.constBegin().value().rgb()); - } else // mColorStops is empty, fill color buffer with black - { - mColorBuffer.fill(qRgb(0, 0, 0)); - } - mColorBufferInvalidated = false; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAxisRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAxisRect - \brief Holds multiple axes and arranges them in a rectangular shape. - - This class represents an axis rect, a rectangular area that is bounded on all sides with an - arbitrary number of axes. - - Initially QCustomPlot has one axis rect, accessible via QCustomPlot::axisRect(). However, the - layout system allows to have multiple axis rects, e.g. arranged in a grid layout - (QCustomPlot::plotLayout). - - By default, QCPAxisRect comes with four axes, at bottom, top, left and right. They can be - accessed via \ref axis by providing the respective axis type (\ref QCPAxis::AxisType) and index. - If you need all axes in the axis rect, use \ref axes. The top and right axes are set to be - invisible initially (QCPAxis::setVisible). To add more axes to a side, use \ref addAxis or \ref - addAxes. To remove an axis, use \ref removeAxis. - - The axis rect layerable itself only draws a background pixmap or color, if specified (\ref - setBackground). It is placed on the "background" layer initially (see \ref QCPLayer for an - explanation of the QCustomPlot layer system). The axes that are held by the axis rect can be - placed on other layers, independently of the axis rect. - - Every axis rect has a child layout of type \ref QCPLayoutInset. It is accessible via \ref - insetLayout and can be used to have other layout elements (or even other layouts with multiple - elements) hovering inside the axis rect. - - If an axis rect is clicked and dragged, it processes this by moving certain axis ranges. The - behaviour can be controlled with \ref setRangeDrag and \ref setRangeDragAxes. If the mouse wheel - is scrolled while the cursor is on the axis rect, certain axes are scaled. This is controllable - via \ref setRangeZoom, \ref setRangeZoomAxes and \ref setRangeZoomFactor. These interactions are - only enabled if \ref QCustomPlot::setInteractions contains \ref QCP::iRangeDrag and \ref - QCP::iRangeZoom. - - \image html AxisRectSpacingOverview.png - <center>Overview of the spacings and paddings that define the geometry of an axis. The dashed - line on the far left indicates the viewport/widget border.</center> -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPLayoutInset *QCPAxisRect::insetLayout() const - - Returns the inset layout of this axis rect. It can be used to place other layout elements (or - even layouts with multiple other elements) inside/on top of an axis rect. - - \see QCPLayoutInset -*/ - -/*! \fn int QCPAxisRect::left() const - - Returns the pixel position of the left border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::right() const - - Returns the pixel position of the right border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::top() const - - Returns the pixel position of the top border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::bottom() const - - Returns the pixel position of the bottom border of this axis rect. Margins are not taken into - account here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::width() const - - Returns the pixel width of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn int QCPAxisRect::height() const - - Returns the pixel height of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QSize QCPAxisRect::size() const - - Returns the pixel size of this axis rect. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topLeft() const - - Returns the top left corner of this axis rect in pixels. Margins are not taken into account here, - so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::topRight() const - - Returns the top right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomLeft() const - - Returns the bottom left corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::bottomRight() const - - Returns the bottom right corner of this axis rect in pixels. Margins are not taken into account - here, so the returned value is with respect to the inner \ref rect. -*/ - -/*! \fn QPoint QCPAxisRect::center() const - - Returns the center of this axis rect in pixels. Margins are not taken into account here, so the - returned value is with respect to the inner \ref rect. -*/ - -/* end documentation of inline functions */ - -/*! - Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four - sides, the top and right axes are set invisible initially. -*/ -QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : - QCPLayoutElement(parentPlot), - mBackgroundBrush(Qt::NoBrush), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mInsetLayout(new QCPLayoutInset), - mRangeDrag(Qt::Horizontal|Qt::Vertical), - mRangeZoom(Qt::Horizontal|Qt::Vertical), - mRangeZoomFactorHorz(0.85), - mRangeZoomFactorVert(0.85), - mDragging(false) -{ - mInsetLayout->initializeParentPlot(mParentPlot); - mInsetLayout->setParentLayerable(this); - mInsetLayout->setParent(this); - - setMinimumSize(50, 50); - setMinimumMargins(QMargins(15, 15, 15, 15)); - mAxes.insert(QCPAxis::atLeft, QList<QCPAxis*>()); - mAxes.insert(QCPAxis::atRight, QList<QCPAxis*>()); - mAxes.insert(QCPAxis::atTop, QList<QCPAxis*>()); - mAxes.insert(QCPAxis::atBottom, QList<QCPAxis*>()); - - if (setupDefaultAxes) - { - QCPAxis *xAxis = addAxis(QCPAxis::atBottom); - QCPAxis *yAxis = addAxis(QCPAxis::atLeft); - QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); - QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); - setRangeDragAxes(xAxis, yAxis); - setRangeZoomAxes(xAxis, yAxis); - xAxis2->setVisible(false); - yAxis2->setVisible(false); - xAxis->grid()->setVisible(true); - yAxis->grid()->setVisible(true); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - xAxis2->grid()->setZeroLinePen(Qt::NoPen); - yAxis2->grid()->setZeroLinePen(Qt::NoPen); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - } -} - -QCPAxisRect::~QCPAxisRect() -{ - delete mInsetLayout; - mInsetLayout = 0; - - QList<QCPAxis*> axesList = axes(); - for (int i=0; i<axesList.size(); ++i) - removeAxis(axesList.at(i)); -} - -/*! - Returns the number of axes on the axis rect side specified with \a type. - - \see axis -*/ -int QCPAxisRect::axisCount(QCPAxis::AxisType type) const -{ - return mAxes.value(type).size(); -} - -/*! - Returns the axis with the given \a index on the axis rect side specified with \a type. - - \see axisCount, axes -*/ -QCPAxis *QCPAxisRect::axis(QCPAxis::AxisType type, int index) const -{ - QList<QCPAxis*> ax(mAxes.value(type)); - if (index >= 0 && index < ax.size()) - { - return ax.at(index); - } else - { - qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; - return 0; - } -} - -/*! - Returns all axes on the axis rect sides specified with \a types. - - \a types may be a single \ref QCPAxis::AxisType or an <tt>or</tt>-combination, to get the axes of - multiple sides. - - \see axis -*/ -QList<QCPAxis*> QCPAxisRect::axes(QCPAxis::AxisTypes types) const -{ - QList<QCPAxis*> result; - if (types.testFlag(QCPAxis::atLeft)) - result << mAxes.value(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << mAxes.value(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << mAxes.value(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << mAxes.value(QCPAxis::atBottom); - return result; -} - -/*! \overload - - Returns all axes of this axis rect. -*/ -QList<QCPAxis*> QCPAxisRect::axes() const -{ - QList<QCPAxis*> result; - QHashIterator<QCPAxis::AxisType, QList<QCPAxis*> > it(mAxes); - while (it.hasNext()) - { - it.next(); - result << it.value(); - } - return result; -} - -/*! - Adds a new axis to the axis rect side specified with \a type, and returns it. - - If an axis rect side already contains one or more axes, the lower and upper endings of the new - axis (\ref QCPAxis::setLowerEnding, \ref QCPAxis::setUpperEnding) are initialized to \ref - QCPLineEnding::esHalfBar. - - \see addAxes, setupFullAxesBox -*/ -QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type) -{ - QCPAxis *newAxis = new QCPAxis(this, type); - if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset - { - bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); - newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); - newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); - } - mAxes[type].append(newAxis); - return newAxis; -} - -/*! - Adds a new axis with \ref addAxis to each axis rect side specified in \a types. This may be an - <tt>or</tt>-combination of QCPAxis::AxisType, so axes can be added to multiple sides at once. - - Returns a list of the added axes. - - \see addAxis, setupFullAxesBox -*/ -QList<QCPAxis*> QCPAxisRect::addAxes(QCPAxis::AxisTypes types) -{ - QList<QCPAxis*> result; - if (types.testFlag(QCPAxis::atLeft)) - result << addAxis(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << addAxis(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << addAxis(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << addAxis(QCPAxis::atBottom); - return result; -} - -/*! - Removes the specified \a axis from the axis rect and deletes it. - - Returns true on success, i.e. if \a axis was a valid axis in this axis rect. - - \see addAxis -*/ -bool QCPAxisRect::removeAxis(QCPAxis *axis) -{ - // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: - QHashIterator<QCPAxis::AxisType, QList<QCPAxis*> > it(mAxes); - while (it.hasNext()) - { - it.next(); - if (it.value().contains(axis)) - { - mAxes[it.key()].removeOne(axis); - if (qobject_cast<QCustomPlot*>(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) - parentPlot()->axisRemoved(axis); - delete axis; - return true; - } - } - qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast<quintptr>(axis); - return false; -} - -/*! - Convenience function to create an axis on each side that doesn't have any axes yet and set their - visibility to true. Further, the top/right axes are assigned the following properties of the - bottom/left axes: - - \li range (\ref QCPAxis::setRange) - \li range reversed (\ref QCPAxis::setRangeReversed) - \li scale type (\ref QCPAxis::setScaleType) - \li scale log base (\ref QCPAxis::setScaleLogBase) - \li ticks (\ref QCPAxis::setTicks) - \li auto (major) tick count (\ref QCPAxis::setAutoTickCount) - \li sub tick count (\ref QCPAxis::setSubTickCount) - \li auto sub ticks (\ref QCPAxis::setAutoSubTicks) - \li tick step (\ref QCPAxis::setTickStep) - \li auto tick step (\ref QCPAxis::setAutoTickStep) - \li number format (\ref QCPAxis::setNumberFormat) - \li number precision (\ref QCPAxis::setNumberPrecision) - \li tick label type (\ref QCPAxis::setTickLabelType) - \li date time format (\ref QCPAxis::setDateTimeFormat) - \li date time spec (\ref QCPAxis::setDateTimeSpec) - - Tick labels (\ref QCPAxis::setTickLabels) of the right and top axes are set to false. - - If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom - and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. -*/ -void QCPAxisRect::setupFullAxesBox(bool connectRanges) -{ - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - if (axisCount(QCPAxis::atBottom) == 0) - xAxis = addAxis(QCPAxis::atBottom); - else - xAxis = axis(QCPAxis::atBottom); - - if (axisCount(QCPAxis::atLeft) == 0) - yAxis = addAxis(QCPAxis::atLeft); - else - yAxis = axis(QCPAxis::atLeft); - - if (axisCount(QCPAxis::atTop) == 0) - xAxis2 = addAxis(QCPAxis::atTop); - else - xAxis2 = axis(QCPAxis::atTop); - - if (axisCount(QCPAxis::atRight) == 0) - yAxis2 = addAxis(QCPAxis::atRight); - else - yAxis2 = axis(QCPAxis::atRight); - - xAxis->setVisible(true); - yAxis->setVisible(true); - xAxis2->setVisible(true); - yAxis2->setVisible(true); - xAxis2->setTickLabels(false); - yAxis2->setTickLabels(false); - - xAxis2->setRange(xAxis->range()); - xAxis2->setRangeReversed(xAxis->rangeReversed()); - xAxis2->setScaleType(xAxis->scaleType()); - xAxis2->setScaleLogBase(xAxis->scaleLogBase()); - xAxis2->setTicks(xAxis->ticks()); - xAxis2->setAutoTickCount(xAxis->autoTickCount()); - xAxis2->setSubTickCount(xAxis->subTickCount()); - xAxis2->setAutoSubTicks(xAxis->autoSubTicks()); - xAxis2->setTickStep(xAxis->tickStep()); - xAxis2->setAutoTickStep(xAxis->autoTickStep()); - xAxis2->setNumberFormat(xAxis->numberFormat()); - xAxis2->setNumberPrecision(xAxis->numberPrecision()); - xAxis2->setTickLabelType(xAxis->tickLabelType()); - xAxis2->setDateTimeFormat(xAxis->dateTimeFormat()); - xAxis2->setDateTimeSpec(xAxis->dateTimeSpec()); - - yAxis2->setRange(yAxis->range()); - yAxis2->setRangeReversed(yAxis->rangeReversed()); - yAxis2->setScaleType(yAxis->scaleType()); - yAxis2->setScaleLogBase(yAxis->scaleLogBase()); - yAxis2->setTicks(yAxis->ticks()); - yAxis2->setAutoTickCount(yAxis->autoTickCount()); - yAxis2->setSubTickCount(yAxis->subTickCount()); - yAxis2->setAutoSubTicks(yAxis->autoSubTicks()); - yAxis2->setTickStep(yAxis->tickStep()); - yAxis2->setAutoTickStep(yAxis->autoTickStep()); - yAxis2->setNumberFormat(yAxis->numberFormat()); - yAxis2->setNumberPrecision(yAxis->numberPrecision()); - yAxis2->setTickLabelType(yAxis->tickLabelType()); - yAxis2->setDateTimeFormat(yAxis->dateTimeFormat()); - yAxis2->setDateTimeSpec(yAxis->dateTimeSpec()); - - if (connectRanges) - { - connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); - connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); - } -} - -/*! - Returns a list of all the plottables that are associated with this axis rect. - - A plottable is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see graphs, items -*/ -QList<QCPAbstractPlottable*> QCPAxisRect::plottables() const -{ - // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries - QList<QCPAbstractPlottable*> result; - for (int i=0; i<mParentPlot->mPlottables.size(); ++i) - { - if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this ||mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mPlottables.at(i)); - } - return result; -} - -/*! - Returns a list of all the graphs that are associated with this axis rect. - - A graph is considered associated with an axis rect if its key or value axis (or both) is in - this axis rect. - - \see plottables, items -*/ -QList<QCPGraph*> QCPAxisRect::graphs() const -{ - // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries - QList<QCPGraph*> result; - for (int i=0; i<mParentPlot->mGraphs.size(); ++i) - { - if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mGraphs.at(i)); - } - return result; -} - -/*! - Returns a list of all the items that are associated with this axis rect. - - An item is considered associated with an axis rect if any of its positions has key or value axis - set to an axis that is in this axis rect, or if any of its positions has \ref - QCPItemPosition::setAxisRect set to the axis rect, or if the clip axis rect (\ref - QCPAbstractItem::setClipAxisRect) is set to this axis rect. - - \see plottables, graphs -*/ -QList<QCPAbstractItem *> QCPAxisRect::items() const -{ - // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries - // and miss those items that have this axis rect as clipAxisRect. - QList<QCPAbstractItem*> result; - for (int itemId=0; itemId<mParentPlot->mItems.size(); ++itemId) - { - if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - continue; - } - QList<QCPItemPosition*> positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posId<positions.size(); ++posId) - { - if (positions.at(posId)->axisRect() == this || - positions.at(posId)->keyAxis()->axisRect() == this || - positions.at(posId)->valueAxis()->axisRect() == this) - { - result.append(mParentPlot->mItems.at(itemId)); - break; - } - } - } - return result; -} - -/*! - This method is called automatically upon replot and doesn't need to be called by users of - QCPAxisRect. - - Calls the base class implementation to update the margins (see \ref QCPLayoutElement::update), - and finally passes the \ref rect to the inset layout (\ref insetLayout) and calls its - QCPInsetLayout::update function. -*/ -void QCPAxisRect::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - - switch (phase) - { - case upPreparation: - { - QList<QCPAxis*> allAxes = axes(); - for (int i=0; i<allAxes.size(); ++i) - allAxes.at(i)->setupTickVectors(); - break; - } - case upLayout: - { - mInsetLayout->setOuterRect(rect()); - break; - } - default: break; - } - - // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): - mInsetLayout->update(phase); -} - -/* inherits documentation from base class */ -QList<QCPLayoutElement*> QCPAxisRect::elements(bool recursive) const -{ - QList<QCPLayoutElement*> result; - if (mInsetLayout) - { - result << mInsetLayout; - if (recursive) - result << mInsetLayout->elements(recursive); - } - return result; -} - -/* inherits documentation from base class */ -void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPAxisRect::draw(QCPPainter *painter) -{ - drawBackground(painter); -} - -/*! - Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the - axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect - backgrounds are usually drawn below everything else. - - For cases where the provided pixmap doesn't have the same size as the axis rect, scaling can be - enabled with \ref setBackgroundScaled and the scaling mode (i.e. whether and how the aspect ratio - is preserved) can be set with \ref setBackgroundScaledMode. To set all these options in one call, - consider using the overloaded version of this function. - - Below the pixmap, the axis rect may be optionally filled with a brush, if specified with \ref - setBackground(const QBrush &brush). - - \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) -*/ -void QCPAxisRect::setBackground(const QPixmap &pm) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); -} - -/*! \overload - - Sets \a brush as the background brush. The axis rect background will be filled with this brush. - Since axis rects place themselves on the "background" layer by default, the axis rect backgrounds - are usually drawn below everything else. - - The brush will be drawn before (under) any background pixmap, which may be specified with \ref - setBackground(const QPixmap &pm). - - To disable drawing of a background brush, set \a brush to Qt::NoBrush. - - \see setBackground(const QPixmap &pm) -*/ -void QCPAxisRect::setBackground(const QBrush &brush) -{ - mBackgroundBrush = brush; -} - -/*! \overload - - Allows setting the background pixmap of the axis rect, whether it shall be scaled and how it - shall be scaled in one call. - - \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) -{ - mBackgroundPixmap = pm; - mScaledBackgroundPixmap = QPixmap(); - mBackgroundScaled = scaled; - mBackgroundScaledMode = mode; -} - -/*! - Sets whether the axis background pixmap shall be scaled to fit the axis rect or not. If \a scaled - is set to true, you may control whether and how the aspect ratio of the original pixmap is - preserved with \ref setBackgroundScaledMode. - - Note that the scaled version of the original pixmap is buffered, so there is no performance - penalty on replots. (Except when the axis rect dimensions are changed continuously.) - - \see setBackground, setBackgroundScaledMode -*/ -void QCPAxisRect::setBackgroundScaled(bool scaled) -{ - mBackgroundScaled = scaled; -} - -/*! - If scaling of the axis background pixmap is enabled (\ref setBackgroundScaled), use this function to - define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. - \see setBackground, setBackgroundScaled -*/ -void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) -{ - mBackgroundScaledMode = mode; -} - -/*! - Returns the range drag axis of the \a orientation provided. - - \see setRangeDragAxes -*/ -QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) -{ - return (orientation == Qt::Horizontal ? mRangeDragHorzAxis.data() : mRangeDragVertAxis.data()); -} - -/*! - Returns the range zoom axis of the \a orientation provided. - - \see setRangeZoomAxes -*/ -QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) -{ - return (orientation == Qt::Horizontal ? mRangeZoomHorzAxis.data() : mRangeZoomVertAxis.data()); -} - -/*! - Returns the range zoom factor of the \a orientation provided. - - \see setRangeZoomFactor -*/ -double QCPAxisRect::rangeZoomFactor(Qt::Orientation orientation) -{ - return (orientation == Qt::Horizontal ? mRangeZoomFactorHorz : mRangeZoomFactorVert); -} - -/*! - Sets which axis orientation may be range dragged by the user with mouse interaction. - What orientation corresponds to which specific axis can be set with - \ref setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical). By - default, the horizontal axis is the bottom axis (xAxis) and the vertical axis - is the left axis (yAxis). - - To disable range dragging entirely, pass 0 as \a orientations or remove \ref QCP::iRangeDrag from \ref - QCustomPlot::setInteractions. To enable range dragging for both directions, pass <tt>Qt::Horizontal | - Qt::Vertical</tt> as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeDrag to enable the range dragging interaction. - - \see setRangeZoom, setRangeDragAxes, setNoAntialiasingOnDrag -*/ -void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) -{ - mRangeDrag = orientations; -} - -/*! - Sets which axis orientation may be zoomed by the user with the mouse wheel. What orientation - corresponds to which specific axis can be set with \ref setRangeZoomAxes(QCPAxis *horizontal, - QCPAxis *vertical). By default, the horizontal axis is the bottom axis (xAxis) and the vertical - axis is the left axis (yAxis). - - To disable range zooming entirely, pass 0 as \a orientations or remove \ref QCP::iRangeZoom from \ref - QCustomPlot::setInteractions. To enable range zooming for both directions, pass <tt>Qt::Horizontal | - Qt::Vertical</tt> as \a orientations. - - In addition to setting \a orientations to a non-zero value, make sure \ref QCustomPlot::setInteractions - contains \ref QCP::iRangeZoom to enable the range zooming interaction. - - \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag -*/ -void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) -{ - mRangeZoom = orientations; -} - -/*! - Sets the axes whose range will be dragged when \ref setRangeDrag enables mouse range dragging - on the QCustomPlot widget. - - \see setRangeZoomAxes -*/ -void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - mRangeDragHorzAxis = horizontal; - mRangeDragVertAxis = vertical; -} - -/*! - Sets the axes whose range will be zoomed when \ref setRangeZoom enables mouse wheel zooming on the - QCustomPlot widget. The two axes can be zoomed with different strengths, when different factors - are passed to \ref setRangeZoomFactor(double horizontalFactor, double verticalFactor). - - \see setRangeDragAxes -*/ -void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) -{ - mRangeZoomHorzAxis = horizontal; - mRangeZoomVertAxis = vertical; -} - -/*! - Sets how strong one rotation step of the mouse wheel zooms, when range zoom was activated with - \ref setRangeZoom. The two parameters \a horizontalFactor and \a verticalFactor provide a way to - let the horizontal axis zoom at different rates than the vertical axis. Which axis is horizontal - and which is vertical, can be set with \ref setRangeZoomAxes. - - When the zoom factor is greater than one, scrolling the mouse wheel backwards (towards the user) - will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the - same scrolling direction will zoom out. -*/ -void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) -{ - mRangeZoomFactorHorz = horizontalFactor; - mRangeZoomFactorVert = verticalFactor; -} - -/*! \overload - - Sets both the horizontal and vertical zoom \a factor. -*/ -void QCPAxisRect::setRangeZoomFactor(double factor) -{ - mRangeZoomFactorHorz = factor; - mRangeZoomFactorVert = factor; -} - -/*! \internal - - Draws the background of this axis rect. It may consist of a background fill (a QBrush) and a - pixmap. - - If a brush was given via \ref setBackground(const QBrush &brush), this function first draws an - according filling inside the axis rect with the provided \a painter. - - Then, if a pixmap was provided via \ref setBackground, this function buffers the scaled version - depending on \ref setBackgroundScaled and \ref setBackgroundScaledMode and then draws it inside - the axis rect with the provided \a painter. The scaled version is buffered in - mScaledBackgroundPixmap to prevent expensive rescaling at every redraw. It is only updated, when - the axis rect has changed in a way that requires a rescale of the background pixmap (this is - dependant on the \ref setBackgroundScaledMode), or when a differend axis backgroud pixmap was - set. - - \see setBackground, setBackgroundScaled, setBackgroundScaledMode -*/ -void QCPAxisRect::drawBackground(QCPPainter *painter) -{ - // draw background fill: - if (mBackgroundBrush != Qt::NoBrush) - painter->fillRect(mRect, mBackgroundBrush); - - // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) - { - if (mBackgroundScaled) - { - // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mRect.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mRect.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); - } else - { - painter->drawPixmap(mRect.topLeft(), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); - } - } -} - -/*! \internal - - This function makes sure multiple axes on the side specified with \a type don't collide, but are - distributed according to their respective space requirement (QCPAxis::calculateMargin). - - It does this by setting an appropriate offset (\ref QCPAxis::setOffset) on all axes except the - one with index zero. - - This function is called by \ref calculateAutoMargin. -*/ -void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) -{ - const QList<QCPAxis*> axesList = mAxes.value(type); - if (axesList.isEmpty()) - return; - - bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false - for (int i=1; i<axesList.size(); ++i) - { - int offset = axesList.at(i-1)->offset() + axesList.at(i-1)->calculateMargin(); - if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) - { - if (!isFirstVisible) - offset += axesList.at(i)->tickLengthIn(); - isFirstVisible = false; - } - axesList.at(i)->setOffset(offset); - } -} - -/* inherits documentation from base class */ -int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) -{ - if (!mAutoMargins.testFlag(side)) - qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; - - updateAxesOffset(QCPAxis::marginSideToAxisType(side)); - - // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call - const QList<QCPAxis*> axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); - if (axesList.size() > 0) - return axesList.last()->offset() + axesList.last()->calculateMargin(); - else - return 0; -} - -/*! \internal - - Event handler for when a mouse button is pressed on the axis rect. If the left mouse button is - pressed, the range dragging interaction is initialized (the actual range manipulation happens in - the \ref mouseMoveEvent). - - The mDragging flag is set to true and some anchor points are set that are needed to determine the - distance the mouse was dragged in the mouse move/release events later. - - \see mouseMoveEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mousePressEvent(QMouseEvent *event) -{ - mDragStart = event->pos(); // need this even when not LeftButton is pressed, to determine in releaseEvent whether it was a full click (no position change between press and release) - if (event->buttons() & Qt::LeftButton) - { - mDragging = true; - // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) - { - mAADragBackup = mParentPlot->antialiasedElements(); - mNotAADragBackup = mParentPlot->notAntialiasedElements(); - } - // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - if (mRangeDragHorzAxis) - mDragStartHorzRange = mRangeDragHorzAxis.data()->range(); - if (mRangeDragVertAxis) - mDragStartVertRange = mRangeDragVertAxis.data()->range(); - } - } -} - -/*! \internal - - Event handler for when the mouse is moved on the axis rect. If range dragging was activated in a - preceding \ref mousePressEvent, the range is moved accordingly. - - \see mousePressEvent, mouseReleaseEvent -*/ -void QCPAxisRect::mouseMoveEvent(QMouseEvent *event) -{ - // Mouse range dragging interaction: - if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) - { - if (mRangeDrag.testFlag(Qt::Horizontal)) - { - if (QCPAxis *rangeDragHorzAxis = mRangeDragHorzAxis.data()) - { - if (rangeDragHorzAxis->mScaleType == QCPAxis::stLinear) - { - double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) - rangeDragHorzAxis->pixelToCoord(event->pos().x()); - rangeDragHorzAxis->setRange(mDragStartHorzRange.lower+diff, mDragStartHorzRange.upper+diff); - } else if (rangeDragHorzAxis->mScaleType == QCPAxis::stLogarithmic) - { - double diff = rangeDragHorzAxis->pixelToCoord(mDragStart.x()) / rangeDragHorzAxis->pixelToCoord(event->pos().x()); - rangeDragHorzAxis->setRange(mDragStartHorzRange.lower*diff, mDragStartHorzRange.upper*diff); - } - } - } - if (mRangeDrag.testFlag(Qt::Vertical)) - { - if (QCPAxis *rangeDragVertAxis = mRangeDragVertAxis.data()) - { - if (rangeDragVertAxis->mScaleType == QCPAxis::stLinear) - { - double diff = rangeDragVertAxis->pixelToCoord(mDragStart.y()) - rangeDragVertAxis->pixelToCoord(event->pos().y()); - rangeDragVertAxis->setRange(mDragStartVertRange.lower+diff, mDragStartVertRange.upper+diff); - } else if (rangeDragVertAxis->mScaleType == QCPAxis::stLogarithmic) - { - double diff = rangeDragVertAxis->pixelToCoord(mDragStart.y()) / rangeDragVertAxis->pixelToCoord(event->pos().y()); - rangeDragVertAxis->setRange(mDragStartVertRange.lower*diff, mDragStartVertRange.upper*diff); - } - } - } - if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot - { - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(); - } - } -} - -/* inherits documentation from base class */ -void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event) -{ - Q_UNUSED(event) - mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) - { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); - } -} - -/*! \internal - - Event handler for mouse wheel events. If rangeZoom is Qt::Horizontal, Qt::Vertical or both, the - ranges of the axes defined as rangeZoomHorzAxis and rangeZoomVertAxis are scaled. The center of - the scaling operation is the current cursor position inside the axis rect. The scaling factor is - dependant on the mouse wheel delta (which direction the wheel was rotated) to provide a natural - zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor. - - Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse - wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be - multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as - exponent of the range zoom factor. This takes care of the wheel direction automatically, by - inverting the factor, when the wheel step is negative (f^-1 = 1/f). -*/ -void QCPAxisRect::wheelEvent(QWheelEvent *event) -{ - // Mouse range zooming interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) - { - if (mRangeZoom != 0) - { - double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if (mRangeZoom.testFlag(Qt::Horizontal)) - { - factor = pow(mRangeZoomFactorHorz, wheelSteps); - if (mRangeZoomHorzAxis.data()) - mRangeZoomHorzAxis.data()->scaleRange(factor, mRangeZoomHorzAxis.data()->pixelToCoord(event->pos().x())); - } - if (mRangeZoom.testFlag(Qt::Vertical)) - { - factor = pow(mRangeZoomFactorVert, wheelSteps); - if (mRangeZoomVertAxis.data()) - mRangeZoomVertAxis.data()->scaleRange(factor, mRangeZoomVertAxis.data()->pixelToCoord(event->pos().y())); - } - mParentPlot->replot(); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPAbstractLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPAbstractLegendItem - \brief The abstract base class for all entries in a QCPLegend. - - It defines a very basic interface for entries in a QCPLegend. For representing plottables in the - legend, the subclass \ref QCPPlottableLegendItem is more suitable. - - Only derive directly from this class when you need absolute freedom (e.g. a custom legend entry - that's not even associated with a plottable). - - You must implement the following pure virtual functions: - \li \ref draw (from QCPLayerable) - - You inherit the following members you may use: - <table> - <tr> - <td>QCPLegend *\b mParentLegend</td> - <td>A pointer to the parent QCPLegend.</td> - </tr><tr> - <td>QFont \b mFont</td> - <td>The generic font of the item. You should use this font for all or at least the most prominent text of the item.</td> - </tr> - </table> -*/ - -/* start of documentation of signals */ - -/*! \fn void QCPAbstractLegendItem::selectionChanged(bool selected) - - This signal is emitted when the selection state of this legend item has changed, either by user - interaction or by a direct call to \ref setSelected. -*/ - -/* end of documentation of signals */ - -/*! - Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not - cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. -*/ -QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : - QCPLayoutElement(parent->parentPlot()), - mParentLegend(parent), - mFont(parent->font()), - mTextColor(parent->textColor()), - mSelectedFont(parent->selectedFont()), - mSelectedTextColor(parent->selectedTextColor()), - mSelectable(true), - mSelected(false) -{ - setLayer("legend"); - setMargins(QMargins(8, 2, 8, 2)); -} - -/*! - Sets the default font of this specific legend item to \a font. - - \see setTextColor, QCPLegend::setFont -*/ -void QCPAbstractLegendItem::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the default text color of this specific legend item to \a color. - - \see setFont, QCPLegend::setTextColor -*/ -void QCPAbstractLegendItem::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - When this legend item is selected, \a font is used to draw generic text, instead of the normal - font set with \ref setFont. - - \see setFont, QCPLegend::setSelectedFont -*/ -void QCPAbstractLegendItem::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - When this legend item is selected, \a color is used to draw generic text, instead of the normal - color set with \ref setTextColor. - - \see setTextColor, QCPLegend::setSelectedTextColor -*/ -void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether this specific legend item is selectable. - - \see setSelectedParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets whether this specific legend item is selected. - - It is possible to set the selection state of this item by calling this function directly, even if - setSelectable is set to false. - - \see setSelectableParts, QCustomPlot::setInteractions -*/ -void QCPAbstractLegendItem::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (!mParentPlot) return -1; - if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) - return -1; - - if (mRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); -} - -/* inherits documentation from base class */ -QRect QCPAbstractLegendItem::clipRect() const -{ - return mOuterRect; -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlottableLegendItem -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlottableLegendItem - \brief A legend item representing a plottable with an icon and the plottable name. - - This is the standard legend item for plottables. It displays an icon of the plottable next to the - plottable name. The icon is drawn by the respective plottable itself (\ref - QCPAbstractPlottable::drawLegendIcon), and tries to give an intuitive symbol for the plottable. - For example, the QCPGraph draws a centered horizontal line and/or a single scatter point in the - middle. - - Legend items of this type are always associated with one plottable (retrievable via the - plottable() function and settable with the constructor). You may change the font of the plottable - name with \ref setFont. Icon padding and border pen is taken from the parent QCPLegend, see \ref - QCPLegend::setIconBorderPen and \ref QCPLegend::setIconTextPadding. - - The function \ref QCPAbstractPlottable::addToLegend/\ref QCPAbstractPlottable::removeFromLegend - creates/removes legend items of this type in the default implementation. However, these functions - may be reimplemented such that a different kind of legend item (e.g a direct subclass of - QCPAbstractLegendItem) is used for that plottable. - - Since QCPLegend is based on QCPLayoutGrid, a legend item itself is just a subclass of - QCPLayoutElement. While it could be added to a legend (or any other layout) via the normal layout - interface, QCPLegend has specialized functions for handling legend items conveniently, see the - documentation of \ref QCPLegend. -*/ - -/*! - Creates a new legend item associated with \a plottable. - - Once it's created, it can be added to the legend via \ref QCPLegend::addItem. - - A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref - QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. -*/ -QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : - QCPAbstractLegendItem(parent), - mPlottable(plottable) -{ -} - -/*! \internal - - Returns the pen that shall be used to draw the icon border, taking into account the selection - state of this item. -*/ -QPen QCPPlottableLegendItem::getIconBorderPen() const -{ - return mSelected ? mParentLegend->selectedIconBorderPen() : mParentLegend->iconBorderPen(); -} - -/*! \internal - - Returns the text color that shall be used to draw text, taking into account the selection state - of this item. -*/ -QColor QCPPlottableLegendItem::getTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} - -/*! \internal - - Returns the font that shall be used to draw text, taking into account the selection state of this - item. -*/ -QFont QCPPlottableLegendItem::getFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Draws the item with \a painter. The size and position of the drawn legend item is defined by the - parent layout (typically a \ref QCPLegend) and the \ref minimumSizeHint and \ref maximumSizeHint - of this legend item. -*/ -void QCPPlottableLegendItem::draw(QCPPainter *painter) -{ - if (!mPlottable) return; - painter->setFont(getFont()); - painter->setPen(QPen(getTextColor())); - QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - QRectF iconRect(mRect.topLeft(), iconSize); - int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops - painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); - // draw icon: - painter->save(); - painter->setClipRect(iconRect, Qt::IntersectClip); - mPlottable->drawLegendIcon(painter, iconRect); - painter->restore(); - // draw icon border: - if (getIconBorderPen().style() != Qt::NoPen) - { - painter->setPen(getIconBorderPen()); - painter->setBrush(Qt::NoBrush); - painter->drawRect(iconRect); - } -} - -/*! \internal - - Calculates and returns the size of this item. This includes the icon, the text and the padding in - between. -*/ -QSize QCPPlottableLegendItem::minimumSizeHint() const -{ - if (!mPlottable) return QSize(); - QSize result(0, 0); - QRect textRect; - QFontMetrics fontMetrics(getFont()); - QSize iconSize = mParentLegend->iconSize(); - textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width() + mMargins.left() + mMargins.right()); - result.setHeight(qMax(textRect.height(), iconSize.height()) + mMargins.top() + mMargins.bottom()); - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPLegend -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPLegend - \brief Manages a legend inside a QCustomPlot. - - A legend is a small box somewhere in the plot which lists plottables with their name and icon. - - Normally, the legend is populated by calling \ref QCPAbstractPlottable::addToLegend. The - respective legend item can be removed with \ref QCPAbstractPlottable::removeFromLegend. However, - QCPLegend also offers an interface to add and manipulate legend items directly: \ref item, \ref - itemWithPlottable, \ref itemCount, \ref addItem, \ref removeItem, etc. - - The QCPLegend derives from QCPLayoutGrid and as such can be placed in any position a - QCPLayoutElement may be positioned. The legend items are themselves QCPLayoutElements which are - placed in the grid layout of the legend. QCPLegend only adds an interface specialized for - handling child elements of type QCPAbstractLegendItem, as mentioned above. In principle, any - other layout elements may also be added to a legend via the normal \ref QCPLayoutGrid interface. - However, the QCPAbstractLegendItem-Interface will ignore those elements (e.g. \ref itemCount will - only return the number of items with QCPAbstractLegendItems type). - - By default, every QCustomPlot has one legend (QCustomPlot::legend) which is placed in the inset - layout of the main axis rect (\ref QCPAxisRect::insetLayout). To move the legend to another - position inside the axis rect, use the methods of the \ref QCPLayoutInset. To move the legend - outside of the axis rect, place it anywhere else with the QCPLayout/QCPLayoutElement interface. -*/ - -/* start of documentation of signals */ - -/*! \fn void QCPLegend::selectionChanged(QCPLegend::SelectableParts selection); - - This signal is emitted when the selection state of this legend has changed. - - \see setSelectedParts, setSelectableParts -*/ - -/* end of documentation of signals */ - -/*! - Constructs a new QCPLegend instance with \a parentPlot as the containing plot and default values. - - Note that by default, QCustomPlot already contains a legend ready to be used as - QCustomPlot::legend -*/ -QCPLegend::QCPLegend() -{ - setRowSpacing(0); - setColumnSpacing(10); - setMargins(QMargins(2, 3, 2, 2)); - setAntialiased(false); - setIconSize(32, 18); - - setIconTextPadding(7); - - setSelectableParts(spLegendBox | spItems); - setSelectedParts(spNone); - - setBorderPen(QPen(Qt::black)); - setSelectedBorderPen(QPen(Qt::blue, 2)); - setIconBorderPen(Qt::NoPen); - setSelectedIconBorderPen(QPen(Qt::blue, 2)); - setBrush(Qt::white); - setSelectedBrush(Qt::white); - setTextColor(Qt::black); - setSelectedTextColor(Qt::blue); -} - -QCPLegend::~QCPLegend() -{ - clearItems(); - if (mParentPlot) - mParentPlot->legendRemoved(this); -} - -/* no doc for getter, see setSelectedParts */ -QCPLegend::SelectableParts QCPLegend::selectedParts() const -{ - // check whether any legend elements selected, if yes, add spItems to return value - bool hasSelectedItems = false; - for (int i=0; i<itemCount(); ++i) - { - if (item(i) && item(i)->selected()) - { - hasSelectedItems = true; - break; - } - } - if (hasSelectedItems) - return mSelectedParts | spItems; - else - return mSelectedParts & ~spItems; -} - -/*! - Sets the pen, the border of the entire legend is drawn with. -*/ -void QCPLegend::setBorderPen(const QPen &pen) -{ - mBorderPen = pen; -} - -/*! - Sets the brush of the legend background. -*/ -void QCPLegend::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the default font of legend text. Legend items that draw text (e.g. the name of a graph) will - use this font by default. However, a different font can be specified on a per-item-basis by - accessing the specific legend item. - - This function will also set \a font on all already existing legend items. - - \see QCPAbstractLegendItem::setFont -*/ -void QCPLegend::setFont(const QFont &font) -{ - mFont = font; - for (int i=0; i<itemCount(); ++i) - { - if (item(i)) - item(i)->setFont(mFont); - } -} - -/*! - Sets the default color of legend text. Legend items that draw text (e.g. the name of a graph) - will use this color by default. However, a different colors can be specified on a per-item-basis - by accessing the specific legend item. - - This function will also set \a color on all already existing legend items. - - \see QCPAbstractLegendItem::setTextColor -*/ -void QCPLegend::setTextColor(const QColor &color) -{ - mTextColor = color; - for (int i=0; i<itemCount(); ++i) - { - if (item(i)) - item(i)->setTextColor(color); - } -} - -/*! - Sets the size of legend icons. Legend items that draw an icon (e.g. a visual - representation of the graph) will use this size by default. -*/ -void QCPLegend::setIconSize(const QSize &size) -{ - mIconSize = size; -} - -/*! \overload -*/ -void QCPLegend::setIconSize(int width, int height) -{ - mIconSize.setWidth(width); - mIconSize.setHeight(height); -} - -/*! - Sets the horizontal space in pixels between the legend icon and the text next to it. - Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the - name of the graph) will use this space by default. -*/ -void QCPLegend::setIconTextPadding(int padding) -{ - mIconTextPadding = padding; -} - -/*! - Sets the pen used to draw a border around each legend icon. Legend items that draw an - icon (e.g. a visual representation of the graph) will use this pen by default. - - If no border is wanted, set this to \a Qt::NoPen. -*/ -void QCPLegend::setIconBorderPen(const QPen &pen) -{ - mIconBorderPen = pen; -} - -/*! - Sets whether the user can (de-)select the parts in \a selectable by clicking on the QCustomPlot surface. - (When \ref QCustomPlot::setInteractions contains \ref QCP::iSelectLegend.) - - However, even when \a selectable is set to a value not allowing the selection of a specific part, - it is still possible to set the selection of this part manually, by calling \ref setSelectedParts - directly. - - \see SelectablePart, setSelectedParts -*/ -void QCPLegend::setSelectableParts(const SelectableParts &selectable) -{ - if (mSelectableParts != selectable) - { - mSelectableParts = selectable; - emit selectableChanged(mSelectableParts); - } -} - -/*! - Sets the selected state of the respective legend parts described by \ref SelectablePart. When a part - is selected, it uses a different pen/font and brush. If some legend items are selected and \a selected - doesn't contain \ref spItems, those items become deselected. - - The entire selection mechanism is handled automatically when \ref QCustomPlot::setInteractions - contains iSelectLegend. You only need to call this function when you wish to change the selection - state manually. - - This function can change the selection state of a part even when \ref setSelectableParts was set to a - value that actually excludes the part. - - emits the \ref selectionChanged signal when \a selected is different from the previous selection state. - - Note that it doesn't make sense to set the selected state \ref spItems here when it wasn't set - before, because there's no way to specify which exact items to newly select. Do this by calling - \ref QCPAbstractLegendItem::setSelected directly on the legend item you wish to select. - - \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, - setSelectedFont -*/ -void QCPLegend::setSelectedParts(const SelectableParts &selected) -{ - SelectableParts newSelected = selected; - mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed - - if (mSelectedParts != newSelected) - { - if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) - { - qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; - newSelected &= ~spItems; - } - if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection - { - for (int i=0; i<itemCount(); ++i) - { - if (item(i)) - item(i)->setSelected(false); - } - } - mSelectedParts = newSelected; - emit selectionChanged(mSelectedParts); - } -} - -/*! - When the legend box is selected, this pen is used to draw the border instead of the normal pen - set via \ref setBorderPen. - - \see setSelectedParts, setSelectableParts, setSelectedBrush -*/ -void QCPLegend::setSelectedBorderPen(const QPen &pen) -{ - mSelectedBorderPen = pen; -} - -/*! - Sets the pen legend items will use to draw their icon borders, when they are selected. - - \see setSelectedParts, setSelectableParts, setSelectedFont -*/ -void QCPLegend::setSelectedIconBorderPen(const QPen &pen) -{ - mSelectedIconBorderPen = pen; -} - -/*! - When the legend box is selected, this brush is used to draw the legend background instead of the normal brush - set via \ref setBrush. - - \see setSelectedParts, setSelectableParts, setSelectedBorderPen -*/ -void QCPLegend::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the default font that is used by legend items when they are selected. - - This function will also set \a font on all already existing legend items. - - \see setFont, QCPAbstractLegendItem::setSelectedFont -*/ -void QCPLegend::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; - for (int i=0; i<itemCount(); ++i) - { - if (item(i)) - item(i)->setSelectedFont(font); - } -} - -/*! - Sets the default text color that is used by legend items when they are selected. - - This function will also set \a color on all already existing legend items. - - \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor -*/ -void QCPLegend::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; - for (int i=0; i<itemCount(); ++i) - { - if (item(i)) - item(i)->setSelectedTextColor(color); - } -} - -/*! - Returns the item with index \a i. - - \see itemCount -*/ -QCPAbstractLegendItem *QCPLegend::item(int index) const -{ - return qobject_cast<QCPAbstractLegendItem*>(elementAt(index)); -} - -/*! - Returns the QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns 0. - - \see hasItemWithPlottable -*/ -QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - for (int i=0; i<itemCount(); ++i) - { - if (QCPPlottableLegendItem *pli = qobject_cast<QCPPlottableLegendItem*>(item(i))) - { - if (pli->plottable() == plottable) - return pli; - } - } - return 0; -} - -/*! - Returns the number of items currently in the legend. - \see item -*/ -int QCPLegend::itemCount() const -{ - return elementCount(); -} - -/*! - Returns whether the legend contains \a itm. -*/ -bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const -{ - for (int i=0; i<itemCount(); ++i) - { - if (item == this->item(i)) - return true; - } - return false; -} - -/*! - Returns whether the legend contains a QCPPlottableLegendItem which is associated with \a plottable (e.g. a \ref QCPGraph*). - If such an item isn't in the legend, returns false. - - \see itemWithPlottable -*/ -bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const -{ - return itemWithPlottable(plottable); -} - -/*! - Adds \a item to the legend, if it's not present already. - - Returns true on sucess, i.e. if the item wasn't in the list already and has been successfuly added. - - The legend takes ownership of the item. -*/ -bool QCPLegend::addItem(QCPAbstractLegendItem *item) -{ - if (!hasItem(item)) - { - return addElement(rowCount(), 0, item); - } else - return false; -} - -/*! - Removes the item with index \a index from the legend. - - Returns true, if successful. - - \see itemCount, clearItems -*/ -bool QCPLegend::removeItem(int index) -{ - if (QCPAbstractLegendItem *ali = item(index)) - { - bool success = remove(ali); - simplify(); - return success; - } else - return false; -} - -/*! \overload - - Removes \a item from the legend. - - Returns true, if successful. - - \see clearItems -*/ -bool QCPLegend::removeItem(QCPAbstractLegendItem *item) -{ - bool success = remove(item); - simplify(); - return success; -} - -/*! - Removes all items from the legend. -*/ -void QCPLegend::clearItems() -{ - for (int i=itemCount()-1; i>=0; --i) - removeItem(i); -} - -/*! - Returns the legend items that are currently selected. If no items are selected, - the list is empty. - - \see QCPAbstractLegendItem::setSelected, setSelectable -*/ -QList<QCPAbstractLegendItem *> QCPLegend::selectedItems() const -{ - QList<QCPAbstractLegendItem*> result; - for (int i=0; i<itemCount(); ++i) - { - if (QCPAbstractLegendItem *ali = item(i)) - { - if (ali->selected()) - result.append(ali); - } - } - return result; -} - -/*! \internal - - A convenience function to easily set the QPainter::Antialiased hint on the provided \a painter - before drawing main legend elements. - - This is the antialiasing state the painter passed to the \ref draw method is in by default. - - This function takes into account the local setting of the antialiasing flag as well as the - overrides set with \ref QCustomPlot::setAntialiasedElements and \ref - QCustomPlot::setNotAntialiasedElements. - - \see setAntialiased -*/ -void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); -} - -/*! \internal - - Returns the pen used to paint the border of the legend, taking into account the selection state - of the legend box. -*/ -QPen QCPLegend::getBorderPen() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; -} - -/*! \internal - - Returns the brush used to paint the background of the legend, taking into account the selection - state of the legend box. -*/ -QBrush QCPLegend::getBrush() const -{ - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; -} - -/*! \internal - - Draws the legend box with the provided \a painter. The individual legend items are layerables - themselves, thus are drawn independently. -*/ -void QCPLegend::draw(QCPPainter *painter) -{ - // draw background rect: - painter->setBrush(getBrush()); - painter->setPen(getBorderPen()); - painter->drawRect(mOuterRect); -} - -/* inherits documentation from base class */ -double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - if (!mParentPlot) return -1; - if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) - return -1; - - if (mOuterRect.contains(pos.toPoint())) - { - if (details) details->setValue(spLegendBox); - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/* inherits documentation from base class */ -void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - mSelectedParts = selectedParts(); // in case item selection has changed - if (details.value<SelectablePart>() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPLegend::deselectEvent(bool *selectionStateChanged) -{ - mSelectedParts = selectedParts(); // in case item selection has changed - if (mSelectableParts.testFlag(spLegendBox)) - { - SelectableParts selBefore = mSelectedParts; - setSelectedParts(selectedParts() & ~spLegendBox); - if (selectionStateChanged) - *selectionStateChanged = mSelectedParts != selBefore; - } -} - -/* inherits documentation from base class */ -QCP::Interaction QCPLegend::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -QCP::Interaction QCPAbstractLegendItem::selectionCategory() const -{ - return QCP::iSelectLegend; -} - -/* inherits documentation from base class */ -void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) -{ - Q_UNUSED(parentPlot) -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPPlotTitle -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPPlotTitle - \brief A layout element displaying a plot title text - - The text may be specified with \ref setText, theformatting can be controlled with \ref setFont - and \ref setTextColor. - - A plot title can be added as follows: - \code - customPlot->plotLayout()->insertRow(0); // inserts an empty row above the default axis rect - customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "Your Plot Title")); - \endcode - - Since a plot title is a common requirement, QCustomPlot offers specialized selection signals for - easy interaction with QCPPlotTitle. If a layout element of type QCPPlotTitle is clicked, the - signal \ref QCustomPlot::titleClick is emitted. A double click emits the \ref - QCustomPlot::titleDoubleClick signal. -*/ - -/* start documentation of signals */ - -/*! \fn void QCPPlotTitle::selectionChanged(bool selected) - - This signal is emitted when the selection state has changed to \a selected, either by user - interaction or by a direct call to \ref setSelected. - - \see setSelected, setSelectable -*/ - -/* end documentation of signals */ - -/*! - Creates a new QCPPlotTitle instance and sets default values. The initial text is empty (\ref setText). - - To set the title text in the constructor, rather use \ref QCPPlotTitle(QCustomPlot *parentPlot, const QString &text). -*/ -QCPPlotTitle::QCPPlotTitle(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mFont(QFont("sans serif", 13*1.5, QFont::Bold)), - mTextColor(Qt::black), - mSelectedFont(QFont("sans serif", 13*1.6, QFont::Bold)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - if (parentPlot) - { - setLayer(parentPlot->currentLayer()); - mFont = QFont(parentPlot->font().family(), parentPlot->font().pointSize()*1.5, QFont::Bold); - mSelectedFont = QFont(parentPlot->font().family(), parentPlot->font().pointSize()*1.6, QFont::Bold); - } - setMargins(QMargins(5, 5, 5, 0)); -} - -/*! \overload - - Creates a new QCPPlotTitle instance and sets default values. The initial text is set to \a text. -*/ -QCPPlotTitle::QCPPlotTitle(QCustomPlot *parentPlot, const QString &text) : - QCPLayoutElement(parentPlot), - mText(text), - mFont(QFont(parentPlot->font().family(), parentPlot->font().pointSize()*1.5, QFont::Bold)), - mTextColor(Qt::black), - mSelectedFont(QFont(parentPlot->font().family(), parentPlot->font().pointSize()*1.6, QFont::Bold)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) -{ - setLayer("axes"); - setMargins(QMargins(5, 5, 5, 0)); -} - -/*! - Sets the text that will be displayed to \a text. Multiple lines can be created by insertion of "\n". - - \see setFont, setTextColor -*/ -void QCPPlotTitle::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets the \a font of the title text. - - \see setTextColor, setSelectedFont -*/ -void QCPPlotTitle::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the \a color of the title text. - - \see setFont, setSelectedTextColor -*/ -void QCPPlotTitle::setTextColor(const QColor &color) -{ - mTextColor = color; -} - -/*! - Sets the \a font of the title text that will be used if the plot title is selected (\ref setSelected). - - \see setFont -*/ -void QCPPlotTitle::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the \a color of the title text that will be used if the plot title is selected (\ref setSelected). - - \see setTextColor -*/ -void QCPPlotTitle::setSelectedTextColor(const QColor &color) -{ - mSelectedTextColor = color; -} - -/*! - Sets whether the user may select this plot title to \a selectable. - - Note that even when \a selectable is set to <tt>false</tt>, the selection state may be changed - programmatically via \ref setSelected. -*/ -void QCPPlotTitle::setSelectable(bool selectable) -{ - if (mSelectable != selectable) - { - mSelectable = selectable; - emit selectableChanged(mSelectable); - } -} - -/*! - Sets the selection state of this plot title to \a selected. If the selection has changed, \ref - selectionChanged is emitted. - - Note that this function can change the selection state independently of the current \ref - setSelectable state. -*/ -void QCPPlotTitle::setSelected(bool selected) -{ - if (mSelected != selected) - { - mSelected = selected; - emit selectionChanged(mSelected); - } -} - -/* inherits documentation from base class */ -void QCPPlotTitle::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - applyAntialiasingHint(painter, mAntialiased, QCP::aeNone); -} - -/* inherits documentation from base class */ -void QCPPlotTitle::draw(QCPPainter *painter) -{ - painter->setFont(mainFont()); - painter->setPen(QPen(mainTextColor())); - painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); -} - -/* inherits documentation from base class */ -QSize QCPPlotTitle::minimumSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result = metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size(); - result.rwidth() += mMargins.left() + mMargins.right(); - result.rheight() += mMargins.top() + mMargins.bottom(); - return result; -} - -/* inherits documentation from base class */ -QSize QCPPlotTitle::maximumSizeHint() const -{ - QFontMetrics metrics(mFont); - QSize result = metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size(); - result.rheight() += mMargins.top() + mMargins.bottom(); - result.setWidth(QWIDGETSIZE_MAX); - return result; -} - -/* inherits documentation from base class */ -void QCPPlotTitle::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) -{ - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -void QCPPlotTitle::deselectEvent(bool *selectionStateChanged) -{ - if (mSelectable) - { - bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) - *selectionStateChanged = mSelected != selBefore; - } -} - -/* inherits documentation from base class */ -double QCPPlotTitle::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - if (mTextBoundingRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; - else - return -1; -} - -/*! \internal - - Returns the main font to be used. This is mSelectedFont if \ref setSelected is set to - <tt>true</tt>, else mFont is returned. -*/ -QFont QCPPlotTitle::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the main color to be used. This is mSelectedTextColor if \ref setSelected is set to - <tt>true</tt>, else mTextColor is returned. -*/ -QColor QCPPlotTitle::mainTextColor() const -{ - return mSelected ? mSelectedTextColor : mTextColor; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScale -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScale - \brief A color scale for use with color coding data such as QCPColorMap - - This layout element can be placed on the plot to correlate a color gradient with data values. It - is usually used in combination with one or multiple \ref QCPColorMap "QCPColorMaps". - - \image html QCPColorScale.png - - The color scale can be either horizontal or vertical, as shown in the image above. The - orientation and the side where the numbers appear is controlled with \ref setType. - - Use \ref QCPColorMap::setColorScale to connect a color map with a color scale. Once they are - connected, they share their gradient, data range and data scale type (\ref setGradient, \ref - setDataRange, \ref setDataScaleType). Multiple color maps may be associated with a single color - scale, to make them all synchronize these properties. - - To have finer control over the number display and axis behaviour, you can directly access the - \ref axis. See the documentation of QCPAxis for details about configuring axes. For example, if - you want to change the number of automatically generated ticks, call - \code - colorScale->axis()->setAutoTickCount(3); - \endcode - - Placing a color scale next to the main axis rect works like with any other layout element: - \code - QCPColorScale *colorScale = new QCPColorScale(customPlot); - customPlot->plotLayout()->addElement(0, 1, colorScale); - colorScale->setLabel("Some Label Text"); - \endcode - In this case we have placed it to the right of the default axis rect, so it wasn't necessary to - call \ref setType, since \ref QCPAxis::atRight is already the default. The text next to the color - scale can be set with \ref setLabel. - - For optimum appearance (like in the image above), it may be desirable to line up the axis rect and - the borders of the color scale. Use a \ref QCPMarginGroup to achieve this: - \code - QCPMarginGroup *group = new QCPMarginGroup(customPlot); - colorScale->setMarginGroup(QCP::msTop|QCP::msBottom, group); - customPlot->axisRect()->setMarginGroup(QCP::msTop|QCP::msBottom, group); - \endcode - - Color scales are initialized with a non-zero minimum top and bottom margin (\ref - setMinimumMargins), because vertical color scales are most common and the minimum top/bottom - margin makes sure it keeps some distance to the top/bottom widget border. So if you change to a - horizontal color scale by setting \ref setType to \ref QCPAxis::atBottom or \ref QCPAxis::atTop, you - might want to also change the minimum margins accordingly, e.g. \ref - setMinimumMargins(QMargins(6, 0, 6, 0)). -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPAxis *QCPColorScale::axis() const - - Returns the internal \ref QCPAxis instance of this color scale. You can access it to alter the - appearance and behaviour of the axis. \ref QCPColorScale duplicates some properties in its - interface for convenience. Those are \ref setDataRange (\ref QCPAxis::setRange), \ref - setDataScaleType (\ref QCPAxis::setScaleType), and the method \ref setLabel (\ref - QCPAxis::setLabel). As they each are connected, it does not matter whether you use the method on - the QCPColorScale or on its QCPAxis. - - If the type of the color scale is changed with \ref setType, the axis returned by this method - will change, too, to either the left, right, bottom or top axis, depending on which type was set. -*/ - -/* end documentation of signals */ -/* start documentation of signals */ - -/*! \fn void QCPColorScale::dataRangeChanged(QCPRange newRange); - - This signal is emitted when the data range changes. - - \see setDataRange -*/ - -/*! \fn void QCPColorScale::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the data scale type changes. - - \see setDataScaleType -*/ - -/*! \fn void QCPColorScale::gradientChanged(QCPColorGradient newGradient); - - This signal is emitted when the gradient changes. - - \see setGradient -*/ - -/* end documentation of signals */ - -/*! - Constructs a new QCPColorScale. -*/ -QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight - mDataScaleType(QCPAxis::stLinear), - mBarWidth(20), - mAxisRect(new QCPColorScaleAxisRectPrivate(this)) -{ - setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) - setType(QCPAxis::atRight); - setDataRange(QCPRange(0, 6)); -} - -QCPColorScale::~QCPColorScale() -{ - delete mAxisRect; -} - -/* undocumented getter */ -QString QCPColorScale::label() const -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return QString(); - } - - return mColorAxis.data()->label(); -} - -/* undocumented getter */ -bool QCPColorScale::rangeDrag() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/* undocumented getter */ -bool QCPColorScale::rangeZoom() const -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return false; - } - - return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); -} - -/*! - Sets at which side of the color scale the axis is placed, and thus also its orientation. - - Note that after setting \a type to a different value, the axis returned by \ref axis() will - be a different one. The new axis will adopt the following properties from the previous axis: The - range, scale type, log base and label. -*/ -void QCPColorScale::setType(QCPAxis::AxisType type) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - if (mType != type) - { - mType = type; - QCPRange rangeTransfer(0, 6); - double logBaseTransfer = 10; - QString labelTransfer; - // revert some settings on old axis: - if (mColorAxis) - { - rangeTransfer = mColorAxis.data()->range(); - labelTransfer = mColorAxis.data()->label(); - logBaseTransfer = mColorAxis.data()->scaleLogBase(); - mColorAxis.data()->setLabel(""); - disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - foreach (QCPAxis::AxisType atype, QList<QCPAxis::AxisType>() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop) - { - mAxisRect.data()->axis(atype)->setTicks(atype == mType); - mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); - } - // set new mColorAxis pointer: - mColorAxis = mAxisRect.data()->axis(mType); - // transfer settings to new axis: - mColorAxis.data()->setRange(rangeTransfer); // transfer range of old axis to new one (necessary if axis changes from vertical to horizontal or vice versa) - mColorAxis.data()->setLabel(labelTransfer); - mColorAxis.data()->setScaleLogBase(logBaseTransfer); // scaleType is synchronized among axes in realtime via signals (connected in QCPColorScale ctor), so we only need to take care of log base here - connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - mAxisRect.data()->setRangeDragAxes(QCPAxis::orientation(mType) == Qt::Horizontal ? mColorAxis.data() : 0, - QCPAxis::orientation(mType) == Qt::Vertical ? mColorAxis.data() : 0); - } -} - -/*! - Sets the range spanned by the color gradient and that is shown by the axis in the color scale. - - It is equivalent to calling QCPColorMap::setDataRange on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its range with \ref - QCPAxis::setRange. - - \see setDataScaleType, setGradient, rescaleDataRange -*/ -void QCPColorScale::setDataRange(const QCPRange &dataRange) -{ - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - mDataRange = dataRange; - if (mColorAxis) - mColorAxis.data()->setRange(mDataRange); - emit dataRangeChanged(mDataRange); - } -} - -/*! - Sets the scale type of the color scale, i.e. whether values are linearly associated with colors - or logarithmically. - - It is equivalent to calling QCPColorMap::setDataScaleType on any of the connected color maps. It is - also equivalent to directly accessing the \ref axis and setting its scale type with \ref - QCPAxis::setScaleType. - - \see setDataRange, setGradient -*/ -void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - if (mColorAxis) - mColorAxis.data()->setScaleType(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - emit dataScaleTypeChanged(mDataScaleType); - } -} - -/*! - Sets the color gradient that will be used to represent data values. - - It is equivalent to calling QCPColorMap::setGradient on any of the connected color maps. - - \see setDataRange, setDataScaleType -*/ -void QCPColorScale::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - if (mAxisRect) - mAxisRect.data()->mGradientImageInvalidated = true; - emit gradientChanged(mGradient); - } -} - -/*! - Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on - the internal \ref axis. -*/ -void QCPColorScale::setLabel(const QString &str) -{ - if (!mColorAxis) - { - qDebug() << Q_FUNC_INFO << "internal color axis undefined"; - return; - } - - mColorAxis.data()->setLabel(str); -} - -/*! - Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed - will have. -*/ -void QCPColorScale::setBarWidth(int width) -{ - mBarWidth = width; -} - -/*! - Sets whether the user can drag the data range (\ref setDataRange). - - Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeDrag(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeDrag(0); -} - -/*! - Sets whether the user can zoom the data range (\ref setDataRange) by scrolling the mouse wheel. - - Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref - QCustomPlot::setInteractions) to allow range dragging. -*/ -void QCPColorScale::setRangeZoom(bool enabled) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - if (enabled) - mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); - else - mAxisRect.data()->setRangeZoom(0); -} - -/*! - Returns a list of all the color maps associated with this color scale. -*/ -QList<QCPColorMap*> QCPColorScale::colorMaps() const -{ - QList<QCPColorMap*> result; - for (int i=0; i<mParentPlot->plottableCount(); ++i) - { - if (QCPColorMap *cm = qobject_cast<QCPColorMap*>(mParentPlot->plottable(i))) - if (cm->colorScale() == this) - result.append(cm); - } - return result; -} - -/*! - Changes the data range such that all color maps associated with this color scale are fully mapped - to the gradient in the data dimension. - - \see setDataRange -*/ -void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) -{ - QList<QCPColorMap*> maps = colorMaps(); - QCPRange newRange; - bool haveRange = false; - int sign = 0; // TODO: should change this to QCPAbstractPlottable::SignDomain later (currently is protected, maybe move to QCP namespace) - if (mDataScaleType == QCPAxis::stLogarithmic) - sign = (mDataRange.upper < 0 ? -1 : 1); - for (int i=0; i<maps.size(); ++i) - { - if (!maps.at(i)->realVisibility() && onlyVisibleMaps) - continue; - QCPRange mapRange; - if (maps.at(i)->colorScale() == this) - { - bool currentFoundRange = true; - mapRange = maps.at(i)->data()->dataBounds(); - if (sign == 1) - { - if (mapRange.lower <= 0 && mapRange.upper > 0) - mapRange.lower = mapRange.upper*1e-3; - else if (mapRange.lower <= 0 && mapRange.upper <= 0) - currentFoundRange = false; - } else if (sign == -1) - { - if (mapRange.upper >= 0 && mapRange.lower < 0) - mapRange.upper = mapRange.lower*1e-3; - else if (mapRange.upper >= 0 && mapRange.lower >= 0) - currentFoundRange = false; - } - if (currentFoundRange) - { - if (!haveRange) - newRange = mapRange; - else - newRange.expand(mapRange); - haveRange = true; - } - } - } - if (haveRange) - { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data - { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mDataScaleType == QCPAxis::stLinear) - { - newRange.lower = center-mDataRange.size()/2.0; - newRange.upper = center+mDataRange.size()/2.0; - } else // mScaleType == stLogarithmic - { - newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); - newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); - } - } - setDataRange(newRange); - } -} - -/* inherits documentation from base class */ -void QCPColorScale::update(UpdatePhase phase) -{ - QCPLayoutElement::update(phase); - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - - mAxisRect.data()->update(phase); - - switch (phase) - { - case upMargins: - { - if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) - { - setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()+margins().top()+margins().bottom()); - setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()+margins().top()+margins().bottom()); - } else - { - setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right()+margins().left()+margins().right(), QWIDGETSIZE_MAX); - setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right()+margins().left()+margins().right(), 0); - } - break; - } - case upLayout: - { - mAxisRect.data()->setOuterRect(rect()); - break; - } - default: break; - } -} - -/* inherits documentation from base class */ -void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const -{ - painter->setAntialiasing(false); -} - -/* inherits documentation from base class */ -void QCPColorScale::mousePressEvent(QMouseEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mousePressEvent(event); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseMoveEvent(QMouseEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseMoveEvent(event); -} - -/* inherits documentation from base class */ -void QCPColorScale::mouseReleaseEvent(QMouseEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->mouseReleaseEvent(event); -} - -/* inherits documentation from base class */ -void QCPColorScale::wheelEvent(QWheelEvent *event) -{ - if (!mAxisRect) - { - qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; - return; - } - mAxisRect.data()->wheelEvent(event); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorScaleAxisRectPrivate -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorScaleAxisRectPrivate - - \internal - \brief An axis rect subclass for use in a QCPColorScale - - This is a private class and not part of the public QCustomPlot interface. - - It provides the axis rect functionality for the QCPColorScale class. -*/ - - -/*! - Creates a new instance, as a child of \a parentColorScale. -*/ -QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : - QCPAxisRect(parentColorScale->parentPlot(), true), - mParentColorScale(parentColorScale), - mGradientImageInvalidated(true) -{ - setParentLayerable(parentColorScale); - setMinimumMargins(QMargins(0, 0, 0, 0)); - foreach (QCPAxis::AxisType type, QList<QCPAxis::AxisType>() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight) - { - axis(type)->setVisible(true); - axis(type)->grid()->setVisible(false); - axis(type)->setPadding(0); - connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); - connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); - } - - connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); - - // make layer transfers of color scale transfer to axis rect and axes - // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); - foreach (QCPAxis::AxisType type, QList<QCPAxis::AxisType>() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight) - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); -} - -/*! \internal - Updates the color gradient image if necessary, by calling \ref updateGradientImage, then draws - it. Then the axes are drawn by calling the \ref QCPAxisRect::draw base class implementation. -*/ -void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) -{ - if (mGradientImageInvalidated) - updateGradientImage(); - - bool mirrorHorz = false; - bool mirrorVert = false; - if (mParentColorScale->mColorAxis) - { - mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); - mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); - } - - painter->drawImage(rect(), mGradientImage.mirrored(mirrorHorz, mirrorVert)); - QCPAxisRect::draw(painter); -} - -/*! \internal - - Uses the current gradient of the parent \ref QCPColorScale (specified in the constructor) to - generate a gradient image. This gradient image will be used in the \ref draw method. -*/ -void QCPColorScaleAxisRectPrivate::updateGradientImage() -{ - if (rect().isEmpty()) - return; - - int n = mParentColorScale->mGradient.levelCount(); - int w, h; - QVector<double> data(n); - for (int i=0; i<n; ++i) - data[i] = i; - if (mParentColorScale->mType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) - { - w = n; - h = rect().height(); - mGradientImage = QImage(w, h, QImage::Format_RGB32); - QVector<QRgb*> pixels; - for (int y=0; y<h; ++y) - pixels.append(reinterpret_cast<QRgb*>(mGradientImage.scanLine(y))); - mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); - for (int y=1; y<h; ++y) - memcpy(pixels.at(y), pixels.first(), n*sizeof(QRgb)); - } else - { - w = rect().width(); - h = n; - mGradientImage = QImage(w, h, QImage::Format_RGB32); - for (int y=0; y<h; ++y) - { - QRgb *pixels = reinterpret_cast<QRgb*>(mGradientImage.scanLine(y)); - const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); - for (int x=0; x<w; ++x) - pixels[x] = lineColor; - } - } - mGradientImageInvalidated = false; -} - -/*! \internal - - This slot is connected to the selectionChanged signals of the four axes in the constructor. It - synchronizes the selection state of the axes. -*/ -void QCPColorScaleAxisRectPrivate::axisSelectionChanged(QCPAxis::SelectableParts selectedParts) -{ - // axis bases of four axes shall always (de-)selected synchronously: - foreach (QCPAxis::AxisType type, QList<QCPAxis::AxisType>() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight) - { - if (QCPAxis *senderAxis = qobject_cast<QCPAxis*>(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectedParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); - else - axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); - } - } -} - -/*! \internal - - This slot is connected to the selectableChanged signals of the four axes in the constructor. It - synchronizes the selectability of the axes. -*/ -void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) -{ - // synchronize axis base selectability: - foreach (QCPAxis::AxisType type, QList<QCPAxis::AxisType>() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight) - { - if (QCPAxis *senderAxis = qobject_cast<QCPAxis*>(sender())) - if (senderAxis->axisType() == type) - continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) - { - if (selectableParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); - else - axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPData - \brief Holds the data of one single data point for QCPGraph. - - The container for storing multiple data points is \ref QCPDataMap. - - The stored data is: - \li \a key: coordinate on the key axis of this data point - \li \a value: coordinate on the value axis of this data point - \li \a keyErrorMinus: negative error in the key dimension (for error bars) - \li \a keyErrorPlus: positive error in the key dimension (for error bars) - \li \a valueErrorMinus: negative error in the value dimension (for error bars) - \li \a valueErrorPlus: positive error in the value dimension (for error bars) - - \see QCPDataMap -*/ - -/*! - Constructs a data point with key, value and all errors set to zero. -*/ -QCPData::QCPData() : - key(0), - value(0), - keyErrorPlus(0), - keyErrorMinus(0), - valueErrorPlus(0), - valueErrorMinus(0) -{ -} - -/*! - Constructs a data point with the specified \a key and \a value. All errors are set to zero. -*/ -QCPData::QCPData(double key, double value) : - key(key), - value(value), - keyErrorPlus(0), - keyErrorMinus(0), - valueErrorPlus(0), - valueErrorMinus(0) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPGraph -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPGraph - \brief A plottable representing a graph in a plot. - - \image html QCPGraph.png - - Usually QCustomPlot creates graphs internally via QCustomPlot::addGraph and the resulting - instance is accessed via QCustomPlot::graph. - - To plot data, assign it with the \ref setData or \ref addData functions. Alternatively, you can - also access and modify the graph's data via the \ref data method, which returns a pointer to the - internal \ref QCPDataMap. - - Graphs are used to display single-valued data. Single-valued means that there should only be one - data point per unique key coordinate. In other words, the graph can't have \a loops. If you do - want to plot non-single-valued curves, rather use the QCPCurve plottable. - - \section appearance Changing the appearance - - The appearance of the graph is mainly determined by the line style, scatter style, brush and pen - of the graph (\ref setLineStyle, \ref setScatterStyle, \ref setBrush, \ref setPen). - - \subsection filling Filling under or between graphs - - QCPGraph knows two types of fills: Normal graph fills towards the zero-value-line parallel to - the key axis of the graph, and fills between two graphs, called channel fills. To enable a fill, - just set a brush with \ref setBrush which is neither Qt::NoBrush nor fully transparent. - - By default, a normal fill towards the zero-value-line will be drawn. To set up a channel fill - between this graph and another one, call \ref setChannelFillGraph with the other graph as - parameter. - - \see QCustomPlot::addGraph, QCustomPlot::graph, QCPLegend::addGraph -*/ - -/* start of documentation of inline functions */ - -/*! \fn QCPDataMap *QCPGraph::data() const - - Returns a pointer to the internal data storage of type \ref QCPDataMap. You may use it to - directly manipulate the data, which may be more convenient and faster than using the regular \ref - setData or \ref addData methods, in certain situations. -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a graph which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The constructed QCPGraph can be added to the plot with QCustomPlot::addPlottable, QCustomPlot - then takes ownership of the graph. - - To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. -*/ -QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis) -{ - mData = new QCPDataMap; - - setPen(QPen(Qt::blue, 0)); - setErrorPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); - setSelectedPen(QPen(QColor(80, 80, 255), 2.5)); - setSelectedBrush(Qt::NoBrush); - - setLineStyle(lsLine); - setErrorType(etNone); - setErrorBarSize(6); - setErrorBarSkipSymbol(true); - setChannelFillGraph(0); - setAdaptiveSampling(true); -} - -QCPGraph::~QCPGraph() -{ - delete mData; -} - -/*! - Replaces the current data with the provided \a data. - - If \a copy is set to true, data points in \a data will only be copied. if false, the graph - takes ownership of the passed data and replaces the internal data pointer with it. This is - significantly faster than copying for large datasets. - - Alternatively, you can also access and modify the graph's data via the \ref data method, which - returns a pointer to the internal \ref QCPDataMap. -*/ -void QCPGraph::setData(QCPDataMap *data, bool copy) -{ - if (copy) - { - *mData = *data; - } else - { - delete mData; - mData = data; - } -} - -/*! \overload - - Replaces the current data with the provided points in \a key and \a value pairs. The provided - vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. -*/ -void QCPGraph::setData(const QVector<double> &key, const QVector<double> &value) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - mData->insertMulti(newData.key, newData); - } -} - -/*! - Replaces the current data with the provided points in \a key and \a value pairs. Additionally the - symmetrical value error of the data points are set to the values in \a valueError. - For error bars to show appropriately, see \ref setErrorType. - The provided vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - For asymmetrical errors (plus different from minus), see the overloaded version of this function. -*/ -void QCPGraph::setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - n = qMin(n, valueError.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - newData.valueErrorMinus = valueError[i]; - newData.valueErrorPlus = valueError[i]; - mData->insertMulti(key[i], newData); - } -} - -/*! - \overload - Replaces the current data with the provided points in \a key and \a value pairs. Additionally the - negative value error of the data points are set to the values in \a valueErrorMinus, the positive - value error to \a valueErrorPlus. - For error bars to show appropriately, see \ref setErrorType. - The provided vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. -*/ -void QCPGraph::setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - n = qMin(n, valueErrorMinus.size()); - n = qMin(n, valueErrorPlus.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - newData.valueErrorMinus = valueErrorMinus[i]; - newData.valueErrorPlus = valueErrorPlus[i]; - mData->insertMulti(key[i], newData); - } -} - -/*! - Replaces the current data with the provided points in \a key and \a value pairs. Additionally the - symmetrical key error of the data points are set to the values in \a keyError. - For error bars to show appropriately, see \ref setErrorType. - The provided vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - For asymmetrical errors (plus different from minus), see the overloaded version of this function. -*/ -void QCPGraph::setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - n = qMin(n, keyError.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - newData.keyErrorMinus = keyError[i]; - newData.keyErrorPlus = keyError[i]; - mData->insertMulti(key[i], newData); - } -} - -/*! - \overload - Replaces the current data with the provided points in \a key and \a value pairs. Additionally the - negative key error of the data points are set to the values in \a keyErrorMinus, the positive - key error to \a keyErrorPlus. - For error bars to show appropriately, see \ref setErrorType. - The provided vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. -*/ -void QCPGraph::setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - n = qMin(n, keyErrorMinus.size()); - n = qMin(n, keyErrorPlus.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - newData.keyErrorMinus = keyErrorMinus[i]; - newData.keyErrorPlus = keyErrorPlus[i]; - mData->insertMulti(key[i], newData); - } -} - -/*! - Replaces the current data with the provided points in \a key and \a value pairs. Additionally the - symmetrical key and value errors of the data points are set to the values in \a keyError and \a valueError. - For error bars to show appropriately, see \ref setErrorType. - The provided vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. - - For asymmetrical errors (plus different from minus), see the overloaded version of this function. -*/ -void QCPGraph::setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - n = qMin(n, valueError.size()); - n = qMin(n, keyError.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - newData.keyErrorMinus = keyError[i]; - newData.keyErrorPlus = keyError[i]; - newData.valueErrorMinus = valueError[i]; - newData.valueErrorPlus = valueError[i]; - mData->insertMulti(key[i], newData); - } -} - -/*! - \overload - Replaces the current data with the provided points in \a key and \a value pairs. Additionally the - negative key and value errors of the data points are set to the values in \a keyErrorMinus and \a valueErrorMinus. The positive - key and value errors are set to the values in \a keyErrorPlus \a valueErrorPlus. - For error bars to show appropriately, see \ref setErrorType. - The provided vectors should have equal length. Else, the number of added points will be the size of the - smallest vector. -*/ -void QCPGraph::setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - n = qMin(n, valueErrorMinus.size()); - n = qMin(n, valueErrorPlus.size()); - n = qMin(n, keyErrorMinus.size()); - n = qMin(n, keyErrorPlus.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - newData.keyErrorMinus = keyErrorMinus[i]; - newData.keyErrorPlus = keyErrorPlus[i]; - newData.valueErrorMinus = valueErrorMinus[i]; - newData.valueErrorPlus = valueErrorPlus[i]; - mData->insertMulti(key[i], newData); - } -} - - -/*! - Sets how the single data points are connected in the plot. For scatter-only plots, set \a ls to - \ref lsNone and \ref setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPGraph::setLineStyle(LineStyle ls) -{ - mLineStyle = ls; -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref QCPScatterStyle::ssNone, no scatter points - are drawn (e.g. for line-only-plots with appropriate line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPGraph::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - Sets which kind of error bars (Key Error, Value Error or both) should be drawn on each data - point. If you set \a errorType to something other than \ref etNone, make sure to actually pass - error data via the specific setData functions along with the data points (e.g. \ref - setDataValueError, \ref setDataKeyError, \ref setDataBothError). - - \see ErrorType -*/ -void QCPGraph::setErrorType(ErrorType errorType) -{ - mErrorType = errorType; -} - -/*! - Sets the pen with which the error bars will be drawn. - \see setErrorBarSize, setErrorType -*/ -void QCPGraph::setErrorPen(const QPen &pen) -{ - mErrorPen = pen; -} - -/*! - Sets the width of the handles at both ends of an error bar in pixels. -*/ -void QCPGraph::setErrorBarSize(double size) -{ - mErrorBarSize = size; -} - -/*! - If \a enabled is set to true, the error bar will not be drawn as a solid line under the scatter symbol but - leave some free space around the symbol. - - This feature uses the current scatter size (\ref QCPScatterStyle::setSize) to determine the size - of the area to leave blank. So when drawing Pixmaps as scatter points (\ref - QCPScatterStyle::ssPixmap), the scatter size must be set manually to a value corresponding to the - size of the Pixmap, if the error bars should leave gaps to its boundaries. - - \ref setErrorType, setErrorBarSize, setScatterStyle -*/ -void QCPGraph::setErrorBarSkipSymbol(bool enabled) -{ - mErrorBarSkipSymbol = enabled; -} - -/*! - Sets the target graph for filling the area between this graph and \a targetGraph with the current - brush (\ref setBrush). - - When \a targetGraph is set to 0, a normal graph fill to the zero-value-line will be shown. To - disable any filling, set the brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) -{ - // prevent setting channel target to this graph itself: - if (targetGraph == this) - { - qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; - mChannelFillGraph = 0; - return; - } - // prevent setting channel target to a graph not in the plot: - if (targetGraph && targetGraph->mParentPlot != mParentPlot) - { - qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; - mChannelFillGraph = 0; - return; - } - - mChannelFillGraph = targetGraph; -} - -/*! - Sets whether adaptive sampling shall be used when plotting this graph. QCustomPlot's adaptive - sampling technique can drastically improve the replot performance for graphs with a larger number - of points (e.g. above 10,000), without notably changing the appearance of the graph. - - By default, adaptive sampling is enabled. Even if enabled, QCustomPlot decides whether adaptive - sampling shall actually be used on a per-graph basis. So leaving adaptive sampling enabled has no - disadvantage in almost all cases. - - \image html adaptive-sampling-line.png "A line plot of 500,000 points without and with adaptive sampling" - - As can be seen, line plots experience no visual degradation from adaptive sampling. Outliers are - reproduced reliably, as well as the overall shape of the data set. The replot time reduces - dramatically though. This allows QCustomPlot to display large amounts of data in realtime. - - \image html adaptive-sampling-scatter.png "A scatter plot of 100,000 points without and with adaptive sampling" - - Care must be taken when using high-density scatter plots in combination with adaptive sampling. - The adaptive sampling algorithm treats scatter plots more carefully than line plots which still - gives a significant reduction of replot times, but not quite as much as for line plots. This is - because scatter plots inherently need more data points to be preserved in order to still resemble - the original, non-adaptive-sampling plot. As shown above, the results still aren't quite - identical, as banding occurs for the outer data points. This is in fact intentional, such that - the boundaries of the data cloud stay visible to the viewer. How strong the banding appears, - depends on the point density, i.e. the number of points in the plot. - - For some situations with scatter plots it might thus be desirable to manually turn adaptive - sampling off. For example, when saving the plot to disk. This can be achieved by setting \a - enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled - back to true afterwards. -*/ -void QCPGraph::setAdaptiveSampling(bool enabled) -{ - mAdaptiveSampling = enabled; -} - -/*! - Adds the provided data points in \a dataMap to the current data. - - Alternatively, you can also access and modify the graph's data via the \ref data method, which - returns a pointer to the internal \ref QCPDataMap. - - \see removeData -*/ -void QCPGraph::addData(const QCPDataMap &dataMap) -{ - mData->unite(dataMap); -} - -/*! \overload - Adds the provided single data point in \a data to the current data. - - Alternatively, you can also access and modify the graph's data via the \ref data method, which - returns a pointer to the internal \ref QCPDataMap. - - \see removeData -*/ -void QCPGraph::addData(const QCPData &data) -{ - mData->insertMulti(data.key, data); -} - -/*! \overload - Adds the provided single data point as \a key and \a value pair to the current data. - - Alternatively, you can also access and modify the graph's data via the \ref data method, which - returns a pointer to the internal \ref QCPDataMap. - - \see removeData -*/ -void QCPGraph::addData(double key, double value) -{ - QCPData newData; - newData.key = key; - newData.value = value; - mData->insertMulti(newData.key, newData); -} - -/*! \overload - Adds the provided data points as \a key and \a value pairs to the current data. - - Alternatively, you can also access and modify the graph's data via the \ref data method, which - returns a pointer to the internal \ref QCPDataMap. - - \see removeData -*/ -void QCPGraph::addData(const QVector<double> &keys, const QVector<double> &values) -{ - int n = qMin(keys.size(), values.size()); - QCPData newData; - for (int i=0; i<n; ++i) - { - newData.key = keys[i]; - newData.value = values[i]; - mData->insertMulti(newData.key, newData); - } -} - -/*! - Removes all data points with keys smaller than \a key. - \see addData, clearData -*/ -void QCPGraph::removeDataBefore(double key) -{ - QCPDataMap::iterator it = mData->begin(); - while (it != mData->end() && it.key() < key) - it = mData->erase(it); -} - -/*! - Removes all data points with keys greater than \a key. - \see addData, clearData -*/ -void QCPGraph::removeDataAfter(double key) -{ - if (mData->isEmpty()) return; - QCPDataMap::iterator it = mData->upperBound(key); - while (it != mData->end()) - it = mData->erase(it); -} - -/*! - Removes all data points with keys between \a fromKey and \a toKey. - if \a fromKey is greater or equal to \a toKey, the function does nothing. To remove - a single data point with known key, use \ref removeData(double key). - - \see addData, clearData -*/ -void QCPGraph::removeData(double fromKey, double toKey) -{ - if (fromKey >= toKey || mData->isEmpty()) return; - QCPDataMap::iterator it = mData->upperBound(fromKey); - QCPDataMap::iterator itEnd = mData->upperBound(toKey); - while (it != itEnd) - it = mData->erase(it); -} - -/*! \overload - - Removes a single data point at \a key. If the position is not known with absolute precision, - consider using \ref removeData(double fromKey, double toKey) with a small fuzziness interval around - the suspected position, depeding on the precision with which the key is known. - - \see addData, clearData -*/ -void QCPGraph::removeData(double key) -{ - mData->remove(key); -} - -/*! - Removes all data points. - \see removeData, removeDataAfter, removeDataBefore -*/ -void QCPGraph::clearData() -{ - mData->clear(); -} - -/* inherits documentation from base class */ -double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && !mSelectable) || mData->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - return pointDistance(pos); - else - return -1; -} - -/*! \overload - - Allows to define whether error bars are taken into consideration when determining the new axis - range. - - \see rescaleKeyAxis, rescaleValueAxis, QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes -*/ -void QCPGraph::rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const -{ - rescaleKeyAxis(onlyEnlarge, includeErrorBars); - rescaleValueAxis(onlyEnlarge, includeErrorBars); -} - -/*! \overload - - Allows to define whether error bars (of kind \ref QCPGraph::etKey) are taken into consideration - when determining the new axis range. - - \see rescaleAxes, QCPAbstractPlottable::rescaleKeyAxis -*/ -void QCPGraph::rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const -{ - // this code is a copy of QCPAbstractPlottable::rescaleKeyAxis with the only change - // that getKeyRange is passed the includeErrorBars value. - if (mData->isEmpty()) return; - - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - SignDomain signDomain = sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? sdNegative : sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain, includeErrorBars); - - if (foundRange) - { - if (onlyEnlarge) - { - if (keyAxis->range().lower < newRange.lower) - newRange.lower = keyAxis->range().lower; - if (keyAxis->range().upper > newRange.upper) - newRange.upper = keyAxis->range().upper; - } - keyAxis->setRange(newRange); - } -} - -/*! \overload - - Allows to define whether error bars (of kind \ref QCPGraph::etValue) are taken into consideration - when determining the new axis range. - - \see rescaleAxes, QCPAbstractPlottable::rescaleValueAxis -*/ -void QCPGraph::rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const -{ - // this code is a copy of QCPAbstractPlottable::rescaleValueAxis with the only change - // is that getValueRange is passed the includeErrorBars value. - if (mData->isEmpty()) return; - - QCPAxis *valueAxis = mValueAxis.data(); - if (!valueAxis) { qDebug() << Q_FUNC_INFO << "invalid value axis"; return; } - - SignDomain signDomain = sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? sdNegative : sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain, includeErrorBars); - - if (foundRange) - { - if (onlyEnlarge) - { - if (valueAxis->range().lower < newRange.lower) - newRange.lower = valueAxis->range().lower; - if (valueAxis->range().upper > newRange.upper) - newRange.upper = valueAxis->range().upper; - } - valueAxis->setRange(newRange); - } -} - -/* inherits documentation from base class */ -void QCPGraph::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mData->isEmpty()) return; - if (mLineStyle == lsNone && mScatterStyle.isNone()) return; - - // allocate line and (if necessary) point vectors: - QVector<QPointF> *lineData = new QVector<QPointF>; - QVector<QCPData> *scatterData = 0; - if (!mScatterStyle.isNone()) - scatterData = new QVector<QCPData>; - - // fill vectors with data appropriate to plot style: - getPlotData(lineData, scatterData); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPDataMap::const_iterator it; - for (it = mData->constBegin(); it != mData->constEnd(); ++it) - { - if (QCP::isInvalidData(it.value().key, it.value().value) || - QCP::isInvalidData(it.value().keyErrorPlus, it.value().keyErrorMinus) || - QCP::isInvalidData(it.value().valueErrorPlus, it.value().valueErrorPlus)) - qDebug() << Q_FUNC_INFO << "Data point at" << it.key() << "invalid." << "Plottable name:" << name(); - } -#endif - - // draw fill of graph: - drawFill(painter, lineData); - - // draw line: - if (mLineStyle == lsImpulse) - drawImpulsePlot(painter, lineData); - else if (mLineStyle != lsNone) - drawLinePlot(painter, lineData); // also step plots can be drawn as a line plot - - // draw scatters: - if (scatterData) - drawScatterPlot(painter, scatterData); - - // free allocated line and point vectors: - delete lineData; - if (scatterData) - delete scatterData; -} - -/* inherits documentation from base class */ -void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - This function branches out to the line style specific "get(...)PlotData" functions, according to - the line style of the graph. - - \a lineData will be filled with raw points that will be drawn with the according draw functions, - e.g. \ref drawLinePlot and \ref drawImpulsePlot. These aren't necessarily the original data - points, since for step plots for example, additional points are needed for drawing lines that - make up steps. If the line style of the graph is \ref lsNone, the \a lineData vector will be left - untouched. - - \a scatterData will be filled with the original data points so \ref drawScatterPlot can draw the - scatter symbols accordingly. If no scatters need to be drawn, i.e. the scatter style's shape is - \ref QCPScatterStyle::ssNone, pass 0 as \a scatterData, and this step will be skipped. - - \see getScatterPlotData, getLinePlotData, getStepLeftPlotData, getStepRightPlotData, - getStepCenterPlotData, getImpulsePlotData -*/ -void QCPGraph::getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const -{ - switch(mLineStyle) - { - case lsNone: getScatterPlotData(scatterData); break; - case lsLine: getLinePlotData(lineData, scatterData); break; - case lsStepLeft: getStepLeftPlotData(lineData, scatterData); break; - case lsStepRight: getStepRightPlotData(lineData, scatterData); break; - case lsStepCenter: getStepCenterPlotData(lineData, scatterData); break; - case lsImpulse: getImpulsePlotData(lineData, scatterData); break; - } -} - -/*! \internal - - If line style is \ref lsNone and the scatter style's shape is not \ref QCPScatterStyle::ssNone, - this function serves at providing the visible data points in \a scatterData, so the \ref - drawScatterPlot function can draw the scatter points accordingly. - - If line style is not \ref lsNone, this function is not called and the data for the scatter points - are (if needed) calculated inside the corresponding other "get(...)PlotData" functions. - - \see drawScatterPlot -*/ -void QCPGraph::getScatterPlotData(QVector<QCPData> *scatterData) const -{ - getPreparedData(0, scatterData); -} - -/*! \internal - - Places the raw data points needed for a normal linearly connected graph in \a linePixelData. - - As for all plot data retrieval functions, \a scatterData just contains all unaltered data (scatter) - points that are visible for drawing scatter points, if necessary. If drawing scatter points is - disabled (i.e. the scatter style's shape is \ref QCPScatterStyle::ssNone), pass 0 as \a - scatterData, and the function will skip filling the vector. - - \see drawLinePlot -*/ -void QCPGraph::getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as linePixelData"; return; } - - QVector<QCPData> lineData; - getPreparedData(&lineData, scatterData); - linePixelData->reserve(lineData.size()+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill - linePixelData->resize(lineData.size()); - - // transform lineData points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; i<lineData.size(); ++i) - { - (*linePixelData)[i].setX(valueAxis->coordToPixel(lineData.at(i).value)); - (*linePixelData)[i].setY(keyAxis->coordToPixel(lineData.at(i).key)); - } - } else // key axis is horizontal - { - for (int i=0; i<lineData.size(); ++i) - { - (*linePixelData)[i].setX(keyAxis->coordToPixel(lineData.at(i).key)); - (*linePixelData)[i].setY(valueAxis->coordToPixel(lineData.at(i).value)); - } - } -} - -/*! - \internal - Places the raw data points needed for a step plot with left oriented steps in \a lineData. - - As for all plot data retrieval functions, \a scatterData just contains all unaltered data (scatter) - points that are visible for drawing scatter points, if necessary. If drawing scatter points is - disabled (i.e. the scatter style's shape is \ref QCPScatterStyle::ssNone), pass 0 as \a - scatterData, and the function will skip filling the vector. - - \see drawLinePlot -*/ -void QCPGraph::getStepLeftPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as lineData"; return; } - - QVector<QCPData> lineData; - getPreparedData(&lineData, scatterData); - linePixelData->reserve(lineData.size()*2+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill - linePixelData->resize(lineData.size()*2); - - // calculate steps from lineData and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastValue = valueAxis->coordToPixel(lineData.first().value); - double key; - for (int i=0; i<lineData.size(); ++i) - { - key = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+0].setX(lastValue); - (*linePixelData)[i*2+0].setY(key); - lastValue = valueAxis->coordToPixel(lineData.at(i).value); - (*linePixelData)[i*2+1].setX(lastValue); - (*linePixelData)[i*2+1].setY(key); - } - } else // key axis is horizontal - { - double lastValue = valueAxis->coordToPixel(lineData.first().value); - double key; - for (int i=0; i<lineData.size(); ++i) - { - key = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+0].setX(key); - (*linePixelData)[i*2+0].setY(lastValue); - lastValue = valueAxis->coordToPixel(lineData.at(i).value); - (*linePixelData)[i*2+1].setX(key); - (*linePixelData)[i*2+1].setY(lastValue); - } - } -} - -/*! - \internal - Places the raw data points needed for a step plot with right oriented steps in \a lineData. - - As for all plot data retrieval functions, \a scatterData just contains all unaltered data (scatter) - points that are visible for drawing scatter points, if necessary. If drawing scatter points is - disabled (i.e. the scatter style's shape is \ref QCPScatterStyle::ssNone), pass 0 as \a - scatterData, and the function will skip filling the vector. - - \see drawLinePlot -*/ -void QCPGraph::getStepRightPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as lineData"; return; } - - QVector<QCPData> lineData; - getPreparedData(&lineData, scatterData); - linePixelData->reserve(lineData.size()*2+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill - linePixelData->resize(lineData.size()*2); - - // calculate steps from lineData and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(lineData.first().key); - double value; - for (int i=0; i<lineData.size(); ++i) - { - value = valueAxis->coordToPixel(lineData.at(i).value); - (*linePixelData)[i*2+0].setX(value); - (*linePixelData)[i*2+0].setY(lastKey); - lastKey = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+1].setX(value); - (*linePixelData)[i*2+1].setY(lastKey); - } - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(lineData.first().key); - double value; - for (int i=0; i<lineData.size(); ++i) - { - value = valueAxis->coordToPixel(lineData.at(i).value); - (*linePixelData)[i*2+0].setX(lastKey); - (*linePixelData)[i*2+0].setY(value); - lastKey = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+1].setX(lastKey); - (*linePixelData)[i*2+1].setY(value); - } - } -} - -/*! - \internal - Places the raw data points needed for a step plot with centered steps in \a lineData. - - As for all plot data retrieval functions, \a scatterData just contains all unaltered data (scatter) - points that are visible for drawing scatter points, if necessary. If drawing scatter points is - disabled (i.e. the scatter style's shape is \ref QCPScatterStyle::ssNone), pass 0 as \a - scatterData, and the function will skip filling the vector. - - \see drawLinePlot -*/ -void QCPGraph::getStepCenterPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as lineData"; return; } - - QVector<QCPData> lineData; - getPreparedData(&lineData, scatterData); - linePixelData->reserve(lineData.size()*2+2); // added 2 to reserve memory for lower/upper fill base points that might be needed for fill - linePixelData->resize(lineData.size()*2); - // calculate steps from lineData and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) - { - double lastKey = keyAxis->coordToPixel(lineData.first().key); - double lastValue = valueAxis->coordToPixel(lineData.first().value); - double key; - (*linePixelData)[0].setX(lastValue); - (*linePixelData)[0].setY(lastKey); - for (int i=1; i<lineData.size(); ++i) - { - key = (keyAxis->coordToPixel(lineData.at(i).key)+lastKey)*0.5; - (*linePixelData)[i*2-1].setX(lastValue); - (*linePixelData)[i*2-1].setY(key); - lastValue = valueAxis->coordToPixel(lineData.at(i).value); - lastKey = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+0].setX(lastValue); - (*linePixelData)[i*2+0].setY(key); - } - (*linePixelData)[lineData.size()*2-1].setX(lastValue); - (*linePixelData)[lineData.size()*2-1].setY(lastKey); - } else // key axis is horizontal - { - double lastKey = keyAxis->coordToPixel(lineData.first().key); - double lastValue = valueAxis->coordToPixel(lineData.first().value); - double key; - (*linePixelData)[0].setX(lastKey); - (*linePixelData)[0].setY(lastValue); - for (int i=1; i<lineData.size(); ++i) - { - key = (keyAxis->coordToPixel(lineData.at(i).key)+lastKey)*0.5; - (*linePixelData)[i*2-1].setX(key); - (*linePixelData)[i*2-1].setY(lastValue); - lastValue = valueAxis->coordToPixel(lineData.at(i).value); - lastKey = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+0].setX(key); - (*linePixelData)[i*2+0].setY(lastValue); - } - (*linePixelData)[lineData.size()*2-1].setX(lastKey); - (*linePixelData)[lineData.size()*2-1].setY(lastValue); - } - -} - -/*! - \internal - Places the raw data points needed for an impulse plot in \a lineData. - - As for all plot data retrieval functions, \a scatterData just contains all unaltered data (scatter) - points that are visible for drawing scatter points, if necessary. If drawing scatter points is - disabled (i.e. the scatter style's shape is \ref QCPScatterStyle::ssNone), pass 0 as \a - scatterData, and the function will skip filling the vector. - - \see drawImpulsePlot -*/ -void QCPGraph::getImpulsePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (!linePixelData) { qDebug() << Q_FUNC_INFO << "null pointer passed as linePixelData"; return; } - - QVector<QCPData> lineData; - getPreparedData(&lineData, scatterData); - linePixelData->resize(lineData.size()*2); // no need to reserve 2 extra points because impulse plot has no fill - - // transform lineData points to pixels: - if (keyAxis->orientation() == Qt::Vertical) - { - double zeroPointX = valueAxis->coordToPixel(0); - double key; - for (int i=0; i<lineData.size(); ++i) - { - key = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+0].setX(zeroPointX); - (*linePixelData)[i*2+0].setY(key); - (*linePixelData)[i*2+1].setX(valueAxis->coordToPixel(lineData.at(i).value)); - (*linePixelData)[i*2+1].setY(key); - } - } else // key axis is horizontal - { - double zeroPointY = valueAxis->coordToPixel(0); - double key; - for (int i=0; i<lineData.size(); ++i) - { - key = keyAxis->coordToPixel(lineData.at(i).key); - (*linePixelData)[i*2+0].setX(key); - (*linePixelData)[i*2+0].setY(zeroPointY); - (*linePixelData)[i*2+1].setX(key); - (*linePixelData)[i*2+1].setY(valueAxis->coordToPixel(lineData.at(i).value)); - } - } -} - -/*! \internal - - Draws the fill of the graph with the specified brush. - - If the fill is a normal fill towards the zero-value-line, only the \a lineData is required (and - two extra points at the zero-value-line, which are added by \ref addFillBasePoints and removed by - \ref removeFillBasePoints after the fill drawing is done). - - If the fill is a channel fill between this QCPGraph and another QCPGraph (mChannelFillGraph), the - more complex polygon is calculated with the \ref getChannelFillPolygon function. - - \see drawLinePlot -*/ -void QCPGraph::drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const -{ - if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot - if (mainBrush().style() == Qt::NoBrush || mainBrush().color().alpha() == 0) return; - - applyFillAntialiasingHint(painter); - if (!mChannelFillGraph) - { - // draw base fill under graph, fill goes all the way to the zero-value-line: - addFillBasePoints(lineData); - painter->setPen(Qt::NoPen); - painter->setBrush(mainBrush()); - painter->drawPolygon(QPolygonF(*lineData)); - removeFillBasePoints(lineData); - } else - { - // draw channel fill between this graph and mChannelFillGraph: - painter->setPen(Qt::NoPen); - painter->setBrush(mainBrush()); - painter->drawPolygon(getChannelFillPolygon(lineData)); - } -} - -/*! \internal - - Draws scatter symbols at every data point passed in \a scatterData. scatter symbols are independent - of the line style and are always drawn if the scatter style's shape is not \ref - QCPScatterStyle::ssNone. Hence, the \a scatterData vector is outputted by all "get(...)PlotData" - functions, together with the (line style dependent) line data. - - \see drawLinePlot, drawImpulsePlot -*/ -void QCPGraph::drawScatterPlot(QCPPainter *painter, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - // draw error bars: - if (mErrorType != etNone) - { - applyErrorBarsAntialiasingHint(painter); - painter->setPen(mErrorPen); - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; i<scatterData->size(); ++i) - drawError(painter, valueAxis->coordToPixel(scatterData->at(i).value), keyAxis->coordToPixel(scatterData->at(i).key), scatterData->at(i)); - } else - { - for (int i=0; i<scatterData->size(); ++i) - drawError(painter, keyAxis->coordToPixel(scatterData->at(i).key), valueAxis->coordToPixel(scatterData->at(i).value), scatterData->at(i)); - } - } - - // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - mScatterStyle.applyTo(painter, mPen); - if (keyAxis->orientation() == Qt::Vertical) - { - for (int i=0; i<scatterData->size(); ++i) - mScatterStyle.drawShape(painter, valueAxis->coordToPixel(scatterData->at(i).value), keyAxis->coordToPixel(scatterData->at(i).key)); - } else - { - for (int i=0; i<scatterData->size(); ++i) - mScatterStyle.drawShape(painter, keyAxis->coordToPixel(scatterData->at(i).key), valueAxis->coordToPixel(scatterData->at(i).value)); - } -} - -/*! \internal - - Draws line graphs from the provided data. It connects all points in \a lineData, which was - created by one of the "get(...)PlotData" functions for line styles that require simple line - connections between the point vector they create. These are for example \ref getLinePlotData, - \ref getStepLeftPlotData, \ref getStepRightPlotData and \ref getStepCenterPlotData. - - \see drawScatterPlot, drawImpulsePlot -*/ -void QCPGraph::drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const -{ - // draw line of graph: - if (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mainPen()); - painter->setBrush(Qt::NoBrush); - - /* Draws polyline in batches, currently not used: - int p = 0; - while (p < lineData->size()) - { - int batch = qMin(25, lineData->size()-p); - if (p != 0) - { - ++batch; - --p; // to draw the connection lines between two batches - } - painter->drawPolyline(lineData->constData()+p, batch); - p += batch; - } - */ - - // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: - if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && - painter->pen().style() == Qt::SolidLine && - !painter->modes().testFlag(QCPPainter::pmVectorized)&& - !painter->modes().testFlag(QCPPainter::pmNoCaching)) - { - for (int i=1; i<lineData->size(); ++i) - painter->drawLine(lineData->at(i-1), lineData->at(i)); - } else - { - painter->drawPolyline(QPolygonF(*lineData)); - } - } -} - -/*! \internal - - Draws impulses from the provided data, i.e. it connects all line pairs in \a lineData, which was - created by \ref getImpulsePlotData. - - \see drawScatterPlot, drawLinePlot -*/ -void QCPGraph::drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const -{ - // draw impulses: - if (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - QPen pen = mainPen(); - pen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawLines(*lineData); - } -} - -/*! \internal - - Returns the \a lineData and \a scatterData that need to be plotted for this graph taking into - consideration the current axis ranges and, if \ref setAdaptiveSampling is enabled, local point - densities. - - 0 may be passed as \a lineData or \a scatterData to indicate that the respective dataset isn't - needed. For example, if the scatter style (\ref setScatterStyle) is \ref QCPScatterStyle::ssNone, \a - scatterData should be 0 to prevent unnecessary calculations. - - This method is used by the various "get(...)PlotData" methods to get the basic working set of data. -*/ -void QCPGraph::getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - // get visible data range: - QCPDataMap::const_iterator lower, upper; // note that upper is the actual upper point, and not 1 step after the upper point - getVisibleDataBounds(lower, upper); - if (lower == mData->constEnd() || upper == mData->constEnd()) - return; - - // count points in visible range, taking into account that we only need to count to the limit maxCount if using adaptive sampling: - int maxCount = std::numeric_limits<int>::max(); - if (mAdaptiveSampling) - { - int keyPixelSpan = qAbs(keyAxis->coordToPixel(lower.key())-keyAxis->coordToPixel(upper.key())); - maxCount = 2*keyPixelSpan+2; - } - int dataCount = countDataInBounds(lower, upper, maxCount); - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average - { - if (lineData) - { - QCPDataMap::const_iterator it = lower; - QCPDataMap::const_iterator upperEnd = upper+1; - double minValue = it.value().value; - double maxValue = it.value().value; - QCPDataMap::const_iterator currentIntervalFirstPoint = it; - int reversedFactor = keyAxis->rangeReversed() ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = keyAxis->rangeReversed() ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(lower.key())+reversedRound)); - double lastIntervalEndKey = currentIntervalStartKey; - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != upperEnd) - { - if (it.key() < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary - { - if (it.value().value < minValue) - minValue = it.value().value; - else if (it.value().value > maxValue) - maxValue = it.value().value; - ++intervalDataCount; - } else // new pixel interval started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint.value().value)); - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - if (it.key() > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.8, (it-1).value().value)); - } else - lineData->append(QCPData(currentIntervalFirstPoint.key(), currentIntervalFirstPoint.value().value)); - lastIntervalEndKey = (it-1).value().key; - minValue = it.value().value; - maxValue = it.value().value; - currentIntervalFirstPoint = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it.key())+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - ++it; - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster - { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint.value().value)); - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - } else - lineData->append(QCPData(currentIntervalFirstPoint.key(), currentIntervalFirstPoint.value().value)); - } - - if (scatterData) - { - double valueMaxRange = valueAxis->range().upper; - double valueMinRange = valueAxis->range().lower; - QCPDataMap::const_iterator it = lower; - QCPDataMap::const_iterator upperEnd = upper+1; - double minValue = it.value().value; - double maxValue = it.value().value; - QCPDataMap::const_iterator minValueIt = it; - QCPDataMap::const_iterator maxValueIt = it; - QCPDataMap::const_iterator currentIntervalStart = it; - int reversedFactor = keyAxis->rangeReversed() ? -1 : 1; // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = keyAxis->rangeReversed() ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(lower.key())+reversedRound)); - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) - int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != upperEnd) - { - if (it.key() < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary - { - if (it.value().value < minValue && it.value().value > valueMinRange && it.value().value < valueMaxRange) - { - minValue = it.value().value; - minValueIt = it; - } else if (it.value().value > maxValue && it.value().value > valueMinRange && it.value().value < valueMaxRange) - { - maxValue = it.value().value; - maxValueIt = it; - } - ++intervalDataCount; - } else // new pixel started - { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPDataMap::const_iterator intervalIt = currentIntervalStart; - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt.value().value > valueMinRange && intervalIt.value().value < valueMaxRange) - scatterData->append(intervalIt.value()); - ++c; - ++intervalIt; - } - } else if (currentIntervalStart.value().value > valueMinRange && currentIntervalStart.value().value < valueMaxRange) - scatterData->append(currentIntervalStart.value()); - minValue = it.value().value; - maxValue = it.value().value; - currentIntervalStart = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it.key())+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); - intervalDataCount = 1; - } - ++it; - } - // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them - { - // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average - QCPDataMap::const_iterator intervalIt = currentIntervalStart; - int c = 0; - while (intervalIt != it) - { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt.value().value > valueMinRange && intervalIt.value().value < valueMaxRange) - scatterData->append(intervalIt.value()); - ++c; - ++intervalIt; - } - } else if (currentIntervalStart.value().value > valueMinRange && currentIntervalStart.value().value < valueMaxRange) - scatterData->append(currentIntervalStart.value()); - } - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the map into the output parameters - { - QVector<QCPData> *dataVector = 0; - if (lineData) - dataVector = lineData; - else if (scatterData) - dataVector = scatterData; - if (dataVector) - { - QCPDataMap::const_iterator it = lower; - QCPDataMap::const_iterator upperEnd = upper+1; - dataVector->reserve(dataCount+2); // +2 for possible fill end points - while (it != upperEnd) - { - dataVector->append(it.value()); - ++it; - } - } - if (lineData && scatterData) - *scatterData = *dataVector; - } -} - -/*! \internal - - called by the scatter drawing function (\ref drawScatterPlot) to draw the error bars on one data - point. \a x and \a y pixel positions of the data point are passed since they are already known in - pixel coordinates in the drawing function, so we save some extra coordToPixel transforms here. \a - data is therefore only used for the errors, not key and value. -*/ -void QCPGraph::drawError(QCPPainter *painter, double x, double y, const QCPData &data) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - double a, b; // positions of error bar bounds in pixels - double barWidthHalf = mErrorBarSize*0.5; - double skipSymbolMargin = mScatterStyle.size(); // pixels left blank per side, when mErrorBarSkipSymbol is true - - if (keyAxis->orientation() == Qt::Vertical) - { - // draw key error vertically and value error horizontally - if (mErrorType == etKey || mErrorType == etBoth) - { - a = keyAxis->coordToPixel(data.key-data.keyErrorMinus); - b = keyAxis->coordToPixel(data.key+data.keyErrorPlus); - if (keyAxis->rangeReversed()) - qSwap(a,b); - // draw spine: - if (mErrorBarSkipSymbol) - { - if (a-y > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin - painter->drawLine(QLineF(x, a, x, y+skipSymbolMargin)); - if (y-b > skipSymbolMargin) - painter->drawLine(QLineF(x, y-skipSymbolMargin, x, b)); - } else - painter->drawLine(QLineF(x, a, x, b)); - // draw handles: - painter->drawLine(QLineF(x-barWidthHalf, a, x+barWidthHalf, a)); - painter->drawLine(QLineF(x-barWidthHalf, b, x+barWidthHalf, b)); - } - if (mErrorType == etValue || mErrorType == etBoth) - { - a = valueAxis->coordToPixel(data.value-data.valueErrorMinus); - b = valueAxis->coordToPixel(data.value+data.valueErrorPlus); - if (valueAxis->rangeReversed()) - qSwap(a,b); - // draw spine: - if (mErrorBarSkipSymbol) - { - if (x-a > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin - painter->drawLine(QLineF(a, y, x-skipSymbolMargin, y)); - if (b-x > skipSymbolMargin) - painter->drawLine(QLineF(x+skipSymbolMargin, y, b, y)); - } else - painter->drawLine(QLineF(a, y, b, y)); - // draw handles: - painter->drawLine(QLineF(a, y-barWidthHalf, a, y+barWidthHalf)); - painter->drawLine(QLineF(b, y-barWidthHalf, b, y+barWidthHalf)); - } - } else // mKeyAxis->orientation() is Qt::Horizontal - { - // draw value error vertically and key error horizontally - if (mErrorType == etKey || mErrorType == etBoth) - { - a = keyAxis->coordToPixel(data.key-data.keyErrorMinus); - b = keyAxis->coordToPixel(data.key+data.keyErrorPlus); - if (keyAxis->rangeReversed()) - qSwap(a,b); - // draw spine: - if (mErrorBarSkipSymbol) - { - if (x-a > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin - painter->drawLine(QLineF(a, y, x-skipSymbolMargin, y)); - if (b-x > skipSymbolMargin) - painter->drawLine(QLineF(x+skipSymbolMargin, y, b, y)); - } else - painter->drawLine(QLineF(a, y, b, y)); - // draw handles: - painter->drawLine(QLineF(a, y-barWidthHalf, a, y+barWidthHalf)); - painter->drawLine(QLineF(b, y-barWidthHalf, b, y+barWidthHalf)); - } - if (mErrorType == etValue || mErrorType == etBoth) - { - a = valueAxis->coordToPixel(data.value-data.valueErrorMinus); - b = valueAxis->coordToPixel(data.value+data.valueErrorPlus); - if (valueAxis->rangeReversed()) - qSwap(a,b); - // draw spine: - if (mErrorBarSkipSymbol) - { - if (a-y > skipSymbolMargin) // don't draw spine if error is so small it's within skipSymbolmargin - painter->drawLine(QLineF(x, a, x, y+skipSymbolMargin)); - if (y-b > skipSymbolMargin) - painter->drawLine(QLineF(x, y-skipSymbolMargin, x, b)); - } else - painter->drawLine(QLineF(x, a, x, b)); - // draw handles: - painter->drawLine(QLineF(x-barWidthHalf, a, x+barWidthHalf, a)); - painter->drawLine(QLineF(x-barWidthHalf, b, x+barWidthHalf, b)); - } - } -} - -/*! \internal - - called by \ref getPreparedData to determine which data (key) range is visible at the current key - axis range setting, so only that needs to be processed. - - \a lower returns an iterator to the lowest data point that needs to be taken into account when - plotting. Note that in order to get a clean plot all the way to the edge of the axis rect, \a - lower may still be just outside the visible range. - - \a upper returns an iterator to the highest data point. Same as before, \a upper may also lie - just outside of the visible range. - - if the graph contains no data, both \a lower and \a upper point to constEnd. -*/ -void QCPGraph::getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper) const -{ - if (!mKeyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - if (mData->isEmpty()) - { - lower = mData->constEnd(); - upper = mData->constEnd(); - return; - } - - // get visible data range as QMap iterators - QCPDataMap::const_iterator lbound = mData->lowerBound(mKeyAxis.data()->range().lower); - QCPDataMap::const_iterator ubound = mData->upperBound(mKeyAxis.data()->range().upper); - bool lowoutlier = lbound != mData->constBegin(); // indicates whether there exist points below axis range - bool highoutlier = ubound != mData->constEnd(); // indicates whether there exist points above axis range - - lower = (lowoutlier ? lbound-1 : lbound); // data point range that will be actually drawn - upper = (highoutlier ? ubound : ubound-1); // data point range that will be actually drawn -} - -/*! \internal - - Counts the number of data points between \a lower and \a upper (including them), up to a maximum - of \a maxCount. - - This function is used by \ref getPreparedData to determine whether adaptive sampling shall be - used (if enabled via \ref setAdaptiveSampling) or not. This is also why counting of data points - only needs to be done until \a maxCount is reached, which should be set to the number of data - points at which adaptive sampling sets in. -*/ -int QCPGraph::countDataInBounds(const QCPDataMap::const_iterator &lower, const QCPDataMap::const_iterator &upper, int maxCount) const -{ - if (upper == mData->constEnd() && lower == mData->constEnd()) - return 0; - QCPDataMap::const_iterator it = lower; - int count = 1; - while (it != upper && count < maxCount) - { - ++it; - ++count; - } - return count; -} - -/*! \internal - - The line data vector generated by e.g. getLinePlotData contains only the line that connects the - data points. If the graph needs to be filled, two additional points need to be added at the - value-zero-line in the lower and upper key positions of the graph. This function calculates these - points and adds them to the end of \a lineData. Since the fill is typically drawn before the line - stroke, these added points need to be removed again after the fill is done, with the - removeFillBasePoints function. - - The expanding of \a lineData by two points will not cause unnecessary memory reallocations, - because the data vector generation functions (getLinePlotData etc.) reserve two extra points when - they allocate memory for \a lineData. - - \see removeFillBasePoints, lowerFillBasePoint, upperFillBasePoint -*/ -void QCPGraph::addFillBasePoints(QVector<QPointF> *lineData) const -{ - if (!mKeyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - // append points that close the polygon fill at the key axis: - if (mKeyAxis.data()->orientation() == Qt::Vertical) - { - *lineData << upperFillBasePoint(lineData->last().y()); - *lineData << lowerFillBasePoint(lineData->first().y()); - } else - { - *lineData << upperFillBasePoint(lineData->last().x()); - *lineData << lowerFillBasePoint(lineData->first().x()); - } -} - -/*! \internal - - removes the two points from \a lineData that were added by \ref addFillBasePoints. - - \see addFillBasePoints, lowerFillBasePoint, upperFillBasePoint -*/ -void QCPGraph::removeFillBasePoints(QVector<QPointF> *lineData) const -{ - lineData->remove(lineData->size()-2, 2); -} - -/*! \internal - - called by \ref addFillBasePoints to conveniently assign the point which closes the fill polygon - on the lower side of the zero-value-line parallel to the key axis. The logarithmic axis scale - case is a bit special, since the zero-value-line in pixel coordinates is in positive or negative - infinity. So this case is handled separately by just closing the fill polygon on the axis which - lies in the direction towards the zero value. - - \a lowerKey will be the the key (in pixels) of the returned point. Depending on whether the key - axis is horizontal or vertical, \a lowerKey will end up as the x or y value of the returned - point, respectively. - - \see upperFillBasePoint, addFillBasePoints -*/ -QPointF QCPGraph::lowerFillBasePoint(double lowerKey) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF point; - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - if (keyAxis->axisType() == QCPAxis::atLeft) - { - point.setX(valueAxis->coordToPixel(0)); - point.setY(lowerKey); - } else if (keyAxis->axisType() == QCPAxis::atRight) - { - point.setX(valueAxis->coordToPixel(0)); - point.setY(lowerKey); - } else if (keyAxis->axisType() == QCPAxis::atTop) - { - point.setX(lowerKey); - point.setY(valueAxis->coordToPixel(0)); - } else if (keyAxis->axisType() == QCPAxis::atBottom) - { - point.setX(lowerKey); - point.setY(valueAxis->coordToPixel(0)); - } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic - { - // In logarithmic scaling we can't just draw to value zero so we just fill all the way - // to the axis which is in the direction towards zero - if (keyAxis->orientation() == Qt::Vertical) - { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - point.setX(keyAxis->axisRect()->right()); - else - point.setX(keyAxis->axisRect()->left()); - point.setY(lowerKey); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) - { - point.setX(lowerKey); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - point.setY(keyAxis->axisRect()->top()); - else - point.setY(keyAxis->axisRect()->bottom()); - } - } - return point; -} - -/*! \internal - - called by \ref addFillBasePoints to conveniently assign the point which closes the fill - polygon on the upper side of the zero-value-line parallel to the key axis. The logarithmic axis - scale case is a bit special, since the zero-value-line in pixel coordinates is in positive or - negative infinity. So this case is handled separately by just closing the fill polygon on the - axis which lies in the direction towards the zero value. - - \a upperKey will be the the key (in pixels) of the returned point. Depending on whether the key - axis is horizontal or vertical, \a upperKey will end up as the x or y value of the returned - point, respectively. - - \see lowerFillBasePoint, addFillBasePoints -*/ -QPointF QCPGraph::upperFillBasePoint(double upperKey) const -{ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF point; - if (valueAxis->scaleType() == QCPAxis::stLinear) - { - if (keyAxis->axisType() == QCPAxis::atLeft) - { - point.setX(valueAxis->coordToPixel(0)); - point.setY(upperKey); - } else if (keyAxis->axisType() == QCPAxis::atRight) - { - point.setX(valueAxis->coordToPixel(0)); - point.setY(upperKey); - } else if (keyAxis->axisType() == QCPAxis::atTop) - { - point.setX(upperKey); - point.setY(valueAxis->coordToPixel(0)); - } else if (keyAxis->axisType() == QCPAxis::atBottom) - { - point.setX(upperKey); - point.setY(valueAxis->coordToPixel(0)); - } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic - { - // In logarithmic scaling we can't just draw to value 0 so we just fill all the way - // to the axis which is in the direction towards 0 - if (keyAxis->orientation() == Qt::Vertical) - { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - point.setX(keyAxis->axisRect()->right()); - else - point.setX(keyAxis->axisRect()->left()); - point.setY(upperKey); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) - { - point.setX(upperKey); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - point.setY(keyAxis->axisRect()->top()); - else - point.setY(keyAxis->axisRect()->bottom()); - } - } - return point; -} - -/*! \internal - - Generates the polygon needed for drawing channel fills between this graph (data passed via \a - lineData) and the graph specified by mChannelFillGraph (data generated by calling its \ref - getPlotData function). May return an empty polygon if the key ranges have no overlap or fill - target graph and this graph don't have same orientation (i.e. both key axes horizontal or both - key axes vertical). For increased performance (due to implicit sharing), keep the returned - QPolygonF const. -*/ -const QPolygonF QCPGraph::getChannelFillPolygon(const QVector<QPointF> *lineData) const -{ - if (!mChannelFillGraph) - return QPolygonF(); - - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } - if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } - - if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) - return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) - - if (lineData->isEmpty()) return QPolygonF(); - QVector<QPointF> otherData; - mChannelFillGraph.data()->getPlotData(&otherData, 0); - if (otherData.isEmpty()) return QPolygonF(); - QVector<QPointF> thisData; - thisData.reserve(lineData->size()+otherData.size()); // because we will join both vectors at end of this function - for (int i=0; i<lineData->size(); ++i) // don't use the vector<<(vector), it squeezes internally, which ruins the performance tuning with reserve() - thisData << lineData->at(i); - - // pointers to be able to swap them, depending which data range needs cropping: - QVector<QPointF> *staticData = &thisData; - QVector<QPointF> *croppedData = &otherData; - - // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): - if (keyAxis->orientation() == Qt::Horizontal) - { - // x is key - // if an axis range is reversed, the data point keys will be descending. Reverse them, since following algorithm assumes ascending keys: - if (staticData->first().x() > staticData->last().x()) - { - int size = staticData->size(); - for (int i=0; i<size/2; ++i) - qSwap((*staticData)[i], (*staticData)[size-1-i]); - } - if (croppedData->first().x() > croppedData->last().x()) - { - int size = croppedData->size(); - for (int i=0; i<size/2; ++i) - qSwap((*croppedData)[i], (*croppedData)[size-1-i]); - } - // crop lower bound: - if (staticData->first().x() < croppedData->first().x()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexBelowX(croppedData, staticData->first().x()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data - // point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (croppedData->at(1).x()-croppedData->at(0).x() != 0) - slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); - else - slope = 0; - (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); - (*croppedData)[0].setX(staticData->first().x()); - - // crop upper bound: - if (staticData->last().x() > croppedData->last().x()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveX(croppedData, staticData->last().x()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data - // point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (croppedData->at(li).x()-croppedData->at(li-1).x() != 0) - slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); - else - slope = 0; - (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); - (*croppedData)[li].setX(staticData->last().x()); - } else // mKeyAxis->orientation() == Qt::Vertical - { - // y is key - // similar to "x is key" but switched x,y. Further, lower/upper meaning is inverted compared to x, - // because in pixel coordinates, y increases from top to bottom, not bottom to top like data coordinate. - // if an axis range is reversed, the data point keys will be descending. Reverse them, since following algorithm assumes ascending keys: - if (staticData->first().y() < staticData->last().y()) - { - int size = staticData->size(); - for (int i=0; i<size/2; ++i) - qSwap((*staticData)[i], (*staticData)[size-1-i]); - } - if (croppedData->first().y() < croppedData->last().y()) - { - int size = croppedData->size(); - for (int i=0; i<size/2; ++i) - qSwap((*croppedData)[i], (*croppedData)[size-1-i]); - } - // crop lower bound: - if (staticData->first().y() > croppedData->first().y()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexAboveY(croppedData, staticData->first().y()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); - // set lowest point of cropped data to fit exactly key position of first static data - // point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - double slope; - if (croppedData->at(1).y()-croppedData->at(0).y() != 0) // avoid division by zero in step plots - slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); - else - slope = 0; - (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); - (*croppedData)[0].setY(staticData->first().y()); - - // crop upper bound: - if (staticData->last().y() < croppedData->last().y()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexBelowY(croppedData, staticData->last().y()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); - // set highest point of cropped data to fit exactly key position of last static data - // point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (croppedData->at(li).y()-croppedData->at(li-1).y() != 0) // avoid division by zero in step plots - slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); - else - slope = 0; - (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); - (*croppedData)[li].setY(staticData->last().y()); - } - - // return joined: - for (int i=otherData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted - thisData << otherData.at(i); - return QPolygonF(thisData); -} - -/*! \internal - - Finds the smallest index of \a data, whose points x value is just above \a x. Assumes x values in - \a data points are ordered ascending, as is the case when plotting with horizontal key axis. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveX(const QVector<QPointF> *data, double x) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).x() < x) - { - if (i<data->size()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/*! \internal - - Finds the highest index of \a data, whose points x value is just below \a x. Assumes x values in - \a data points are ordered ascending, as is the case when plotting with horizontal key axis. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexBelowX(const QVector<QPointF> *data, double x) const -{ - for (int i=0; i<data->size(); ++i) - { - if (data->at(i).x() > x) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} - -/*! \internal - - Finds the smallest index of \a data, whose points y value is just above \a y. Assumes y values in - \a data points are ordered descending, as is the case when plotting with vertical key axis. - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexAboveY(const QVector<QPointF> *data, double y) const -{ - for (int i=0; i<data->size(); ++i) - { - if (data->at(i).y() < y) - { - if (i>0) - return i-1; - else - return 0; - } - } - return -1; -} - -/*! \internal - - Calculates the (minimum) distance (in pixels) the graph's representation has from the given \a - pixelPoint in pixels. This is used to determine whether the graph was clicked or not, e.g. in - \ref selectTest. - - If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape - is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns - 500. -*/ -double QCPGraph::pointDistance(const QPointF &pixelPoint) const -{ - if (mData->isEmpty()) - { - qDebug() << Q_FUNC_INFO << "requested point distance on graph" << mName << "without data"; - return 500; - } - if (mData->size() == 1) - { - QPointF dataPoint = coordsToPixels(mData->constBegin().key(), mData->constBegin().value().value); - return QVector2D(dataPoint-pixelPoint).length(); - } - - if (mLineStyle == lsNone && mScatterStyle.isNone()) - return 500; - - // calculate minimum distances to graph representation: - if (mLineStyle == lsNone) - { - // no line displayed, only calculate distance to scatter points: - QVector<QCPData> *scatterData = new QVector<QCPData>; - getScatterPlotData(scatterData); - double minDistSqr = std::numeric_limits<double>::max(); - QPointF ptA; - QPointF ptB = coordsToPixels(scatterData->at(0).key, scatterData->at(0).value); // getScatterPlotData returns in plot coordinates, so transform to pixels - for (int i=1; i<scatterData->size(); ++i) - { - ptA = ptB; - ptB = coordsToPixels(scatterData->at(i).key, scatterData->at(i).value); - double currentDistSqr = distSqrToLine(ptA, ptB, pixelPoint); - if (currentDistSqr < minDistSqr) - minDistSqr = currentDistSqr; - } - delete scatterData; - return sqrt(minDistSqr); - } else - { - // line displayed calculate distance to line segments: - QVector<QPointF> *lineData = new QVector<QPointF>; - getPlotData(lineData, 0); // unlike with getScatterPlotData we get pixel coordinates here - double minDistSqr = std::numeric_limits<double>::max(); - if (mLineStyle == lsImpulse) - { - // impulse plot differs from other line styles in that the lineData points are only pairwise connected: - for (int i=0; i<lineData->size()-1; i+=2) // iterate pairs - { - double currentDistSqr = distSqrToLine(lineData->at(i), lineData->at(i+1), pixelPoint); - if (currentDistSqr < minDistSqr) - minDistSqr = currentDistSqr; - } - } else - { - // all other line plots (line and step) connect points directly: - for (int i=0; i<lineData->size()-1; ++i) - { - double currentDistSqr = distSqrToLine(lineData->at(i), lineData->at(i+1), pixelPoint); - if (currentDistSqr < minDistSqr) - minDistSqr = currentDistSqr; - } - } - delete lineData; - return sqrt(minDistSqr); - } -} - -/*! \internal - - Finds the highest index of \a data, whose points y value is just below \a y. Assumes y values in - \a data points are ordered descending, as is the case when plotting with vertical key axis (since - keys are ordered ascending). - - Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. -*/ -int QCPGraph::findIndexBelowY(const QVector<QPointF> *data, double y) const -{ - for (int i=data->size()-1; i>=0; --i) - { - if (data->at(i).y() > y) - { - if (i<data->size()-1) - return i+1; - else - return data->size()-1; - } - } - return -1; -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getKeyRange(bool &foundRange, SignDomain inSignDomain) const -{ - // just call the specialized version which takes an additional argument whether error bars - // should also be taken into consideration for range calculation. We set this to true here. - return getKeyRange(foundRange, inSignDomain, true); -} - -/* inherits documentation from base class */ -QCPRange QCPGraph::getValueRange(bool &foundRange, SignDomain inSignDomain) const -{ - // just call the specialized version which takes an additional argument whether error bars - // should also be taken into consideration for range calculation. We set this to true here. - return getValueRange(foundRange, inSignDomain, true); -} - -/*! \overload - - Allows to specify whether the error bars should be included in the range calculation. - - \see getKeyRange(bool &foundRange, SignDomain inSignDomain) -*/ -QCPRange QCPGraph::getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const -{ - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - - double current, currentErrorMinus, currentErrorPlus; - - if (inSignDomain == sdBoth) // range may be anywhere - { - QCPDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().key; - currentErrorMinus = (includeErrors ? it.value().keyErrorMinus : 0); - currentErrorPlus = (includeErrors ? it.value().keyErrorPlus : 0); - if (current-currentErrorMinus < range.lower || !haveLower) - { - range.lower = current-currentErrorMinus; - haveLower = true; - } - if (current+currentErrorPlus > range.upper || !haveUpper) - { - range.upper = current+currentErrorPlus; - haveUpper = true; - } - ++it; - } - } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain - { - QCPDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().key; - currentErrorMinus = (includeErrors ? it.value().keyErrorMinus : 0); - currentErrorPlus = (includeErrors ? it.value().keyErrorPlus : 0); - if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) - { - range.lower = current-currentErrorMinus; - haveLower = true; - } - if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) - { - range.upper = current+currentErrorPlus; - haveUpper = true; - } - if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point. - { - if ((current < range.lower || !haveLower) && current < 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current < 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain - { - QCPDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().key; - currentErrorMinus = (includeErrors ? it.value().keyErrorMinus : 0); - currentErrorPlus = (includeErrors ? it.value().keyErrorPlus : 0); - if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) - { - range.lower = current-currentErrorMinus; - haveLower = true; - } - if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) - { - range.upper = current+currentErrorPlus; - haveUpper = true; - } - if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point. - { - if ((current < range.lower || !haveLower) && current > 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current > 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } - - foundRange = haveLower && haveUpper; - return range; -} - -/*! \overload - - Allows to specify whether the error bars should be included in the range calculation. - - \see getValueRange(bool &foundRange, SignDomain inSignDomain) -*/ -QCPRange QCPGraph::getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const -{ - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - - double current, currentErrorMinus, currentErrorPlus; - - if (inSignDomain == sdBoth) // range may be anywhere - { - QCPDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().value; - currentErrorMinus = (includeErrors ? it.value().valueErrorMinus : 0); - currentErrorPlus = (includeErrors ? it.value().valueErrorPlus : 0); - if (current-currentErrorMinus < range.lower || !haveLower) - { - range.lower = current-currentErrorMinus; - haveLower = true; - } - if (current+currentErrorPlus > range.upper || !haveUpper) - { - range.upper = current+currentErrorPlus; - haveUpper = true; - } - ++it; - } - } else if (inSignDomain == sdNegative) // range may only be in the negative sign domain - { - QCPDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().value; - currentErrorMinus = (includeErrors ? it.value().valueErrorMinus : 0); - currentErrorPlus = (includeErrors ? it.value().valueErrorPlus : 0); - if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus < 0) - { - range.lower = current-currentErrorMinus; - haveLower = true; - } - if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus < 0) - { - range.upper = current+currentErrorPlus; - haveUpper = true; - } - if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to get that point. - { - if ((current < range.lower || !haveLower) && current < 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current < 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } else if (inSignDomain == sdPositive) // range may only be in the positive sign domain - { - QCPDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().value; - currentErrorMinus = (includeErrors ? it.value().valueErrorMinus : 0); - currentErrorPlus = (includeErrors ? it.value().valueErrorPlus : 0); - if ((current-currentErrorMinus < range.lower || !haveLower) && current-currentErrorMinus > 0) - { - range.lower = current-currentErrorMinus; - haveLower = true; - } - if ((current+currentErrorPlus > range.upper || !haveUpper) && current+currentErrorPlus > 0) - { - range.upper = current+currentErrorPlus; - haveUpper = true; - } - if (includeErrors) // in case point is in valid sign domain but errobars stretch beyond it, we still want to geht that point. - { - if ((current < range.lower || !haveLower) && current > 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current > 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } - - foundRange = haveLower && haveUpper; - return range; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurveData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurveData - \brief Holds the data of one single data point for QCPCurve. - - The container for storing multiple data points is \ref QCPCurveDataMap. - - The stored data is: - \li \a t: the free parameter of the curve at this curve point (cp. the mathematical vector <em>(x(t), y(t))</em>) - \li \a key: coordinate on the key axis of this curve point - \li \a value: coordinate on the value axis of this curve point - - \see QCPCurveDataMap -*/ - -/*! - Constructs a curve data point with t, key and value set to zero. -*/ -QCPCurveData::QCPCurveData() : - t(0), - key(0), - value(0) -{ -} - -/*! - Constructs a curve data point with the specified \a t, \a key and \a value. -*/ -QCPCurveData::QCPCurveData(double t, double key, double value) : - t(t), - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPCurve - \brief A plottable representing a parametric curve in a plot. - - \image html QCPCurve.png - - Unlike QCPGraph, plottables of this type may have multiple points with the same key coordinate, - so their visual representation can have \a loops. This is realized by introducing a third - coordinate \a t, which defines the order of the points described by the other two coordinates \a - x and \a y. - - To plot data, assign it with the \ref setData or \ref addData functions. - - \section appearance Changing the appearance - - The appearance of the curve is determined by the pen and the brush (\ref setPen, \ref setBrush). - \section usage Usage - - Like all data representing objects in QCustomPlot, the QCPCurve is a plottable (QCPAbstractPlottable). So - the plottable-interface of QCustomPlot applies (QCustomPlot::plottable, QCustomPlot::addPlottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \code - QCPCurve *newCurve = new QCPCurve(customPlot->xAxis, customPlot->yAxis);\endcode - add it to the customPlot with QCustomPlot::addPlottable: - \code - customPlot->addPlottable(newCurve);\endcode - and then modify the properties of the newly created plottable, e.g.: - \code - newCurve->setName("Fermat's Spiral"); - newCurve->setData(tData, xData, yData);\endcode -*/ - -/*! - Constructs a curve which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The constructed QCPCurve can be added to the plot with QCustomPlot::addPlottable, QCustomPlot - then takes ownership of the graph. -*/ -QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis) -{ - mData = new QCPCurveDataMap; - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(Qt::blue); - mBrush.setStyle(Qt::NoBrush); - mSelectedPen = mPen; - mSelectedPen.setWidthF(2.5); - mSelectedPen.setColor(QColor(80, 80, 255)); // lighter than Qt::blue of mPen - mSelectedBrush = mBrush; - - setScatterStyle(QCPScatterStyle()); - setLineStyle(lsLine); -} - -QCPCurve::~QCPCurve() -{ - delete mData; -} - -/*! - Replaces the current data with the provided \a data. - - If \a copy is set to true, data points in \a data will only be copied. if false, the plottable - takes ownership of the passed data and replaces the internal data pointer with it. This is - significantly faster than copying for large datasets. -*/ -void QCPCurve::setData(QCPCurveDataMap *data, bool copy) -{ - if (copy) - { - *mData = *data; - } else - { - delete mData; - mData = data; - } -} - -/*! \overload - - Replaces the current data with the provided points in \a t, \a key and \a value tuples. The - provided vectors should have equal length. Else, the number of added points will be the size of - the smallest vector. -*/ -void QCPCurve::setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value) -{ - mData->clear(); - int n = t.size(); - n = qMin(n, key.size()); - n = qMin(n, value.size()); - QCPCurveData newData; - for (int i=0; i<n; ++i) - { - newData.t = t[i]; - newData.key = key[i]; - newData.value = value[i]; - mData->insertMulti(newData.t, newData); - } -} - -/*! \overload - - Replaces the current data with the provided \a key and \a value pairs. The t parameter - of each data point will be set to the integer index of the respective key/value pair. -*/ -void QCPCurve::setData(const QVector<double> &key, const QVector<double> &value) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - QCPCurveData newData; - for (int i=0; i<n; ++i) - { - newData.t = i; // no t vector given, so we assign t the index of the key/value pair - newData.key = key[i]; - newData.value = value[i]; - mData->insertMulti(newData.t, newData); - } -} - -/*! - Sets the visual appearance of single data points in the plot. If set to \ref - QCPScatterStyle::ssNone, no scatter points are drawn (e.g. for line-only plots with appropriate - line style). - - \see QCPScatterStyle, setLineStyle -*/ -void QCPCurve::setScatterStyle(const QCPScatterStyle &style) -{ - mScatterStyle = style; -} - -/*! - Sets how the single data points are connected in the plot or how they are represented visually - apart from the scatter symbol. For scatter-only plots, set \a style to \ref lsNone and \ref - setScatterStyle to the desired scatter style. - - \see setScatterStyle -*/ -void QCPCurve::setLineStyle(QCPCurve::LineStyle style) -{ - mLineStyle = style; -} - -/*! - Adds the provided data points in \a dataMap to the current data. - \see removeData -*/ -void QCPCurve::addData(const QCPCurveDataMap &dataMap) -{ - mData->unite(dataMap); -} - -/*! \overload - Adds the provided single data point in \a data to the current data. - \see removeData -*/ -void QCPCurve::addData(const QCPCurveData &data) -{ - mData->insertMulti(data.t, data); -} - -/*! \overload - Adds the provided single data point as \a t, \a key and \a value tuple to the current data - \see removeData -*/ -void QCPCurve::addData(double t, double key, double value) -{ - QCPCurveData newData; - newData.t = t; - newData.key = key; - newData.value = value; - mData->insertMulti(newData.t, newData); -} - -/*! \overload - - Adds the provided single data point as \a key and \a value pair to the current data The t - parameter of the data point is set to the t of the last data point plus 1. If there is no last - data point, t will be set to 0. - - \see removeData -*/ -void QCPCurve::addData(double key, double value) -{ - QCPCurveData newData; - if (!mData->isEmpty()) - newData.t = (mData->constEnd()-1).key()+1; - else - newData.t = 0; - newData.key = key; - newData.value = value; - mData->insertMulti(newData.t, newData); -} - -/*! \overload - Adds the provided data points as \a t, \a key and \a value tuples to the current data. - \see removeData -*/ -void QCPCurve::addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values) -{ - int n = ts.size(); - n = qMin(n, keys.size()); - n = qMin(n, values.size()); - QCPCurveData newData; - for (int i=0; i<n; ++i) - { - newData.t = ts[i]; - newData.key = keys[i]; - newData.value = values[i]; - mData->insertMulti(newData.t, newData); - } -} - -/*! - Removes all data points with curve parameter t smaller than \a t. - \see addData, clearData -*/ -void QCPCurve::removeDataBefore(double t) -{ - QCPCurveDataMap::iterator it = mData->begin(); - while (it != mData->end() && it.key() < t) - it = mData->erase(it); -} - -/*! - Removes all data points with curve parameter t greater than \a t. - \see addData, clearData -*/ -void QCPCurve::removeDataAfter(double t) -{ - if (mData->isEmpty()) return; - QCPCurveDataMap::iterator it = mData->upperBound(t); - while (it != mData->end()) - it = mData->erase(it); -} - -/*! - Removes all data points with curve parameter t between \a fromt and \a tot. if \a fromt is - greater or equal to \a tot, the function does nothing. To remove a single data point with known - t, use \ref removeData(double t). - - \see addData, clearData -*/ -void QCPCurve::removeData(double fromt, double tot) -{ - if (fromt >= tot || mData->isEmpty()) return; - QCPCurveDataMap::iterator it = mData->upperBound(fromt); - QCPCurveDataMap::iterator itEnd = mData->upperBound(tot); - while (it != itEnd) - it = mData->erase(it); -} - -/*! \overload - - Removes a single data point at curve parameter \a t. If the position is not known with absolute - precision, consider using \ref removeData(double fromt, double tot) with a small fuzziness - interval around the suspected position, depeding on the precision with which the curve parameter - is known. - - \see addData, clearData -*/ -void QCPCurve::removeData(double t) -{ - mData->remove(t); -} - -/*! - Removes all data points. - \see removeData, removeDataAfter, removeDataBefore -*/ -void QCPCurve::clearData() -{ - mData->clear(); -} - -/* inherits documentation from base class */ -double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if ((onlySelectable && !mSelectable) || mData->isEmpty()) - return -1; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - return pointDistance(pos); - else - return -1; -} - -/* inherits documentation from base class */ -void QCPCurve::draw(QCPPainter *painter) -{ - if (mData->isEmpty()) return; - - // allocate line vector: - QVector<QPointF> *lineData = new QVector<QPointF>; - - // fill with curve data: - getCurveData(lineData); - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - QCPCurveDataMap::const_iterator it; - for (it = mData->constBegin(); it != mData->constEnd(); ++it) - { - if (QCP::isInvalidData(it.value().t) || - QCP::isInvalidData(it.value().key, it.value().value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it.key() << "invalid." << "Plottable name:" << name(); - } -#endif - - // draw curve fill: - if (mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) - { - applyFillAntialiasingHint(painter); - painter->setPen(Qt::NoPen); - painter->setBrush(mainBrush()); - painter->drawPolygon(QPolygonF(*lineData)); - } - - // draw curve line: - if (mLineStyle != lsNone && mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mainPen()); - painter->setBrush(Qt::NoBrush); - // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: - if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && - painter->pen().style() == Qt::SolidLine && - !painter->modes().testFlag(QCPPainter::pmVectorized) && - !painter->modes().testFlag(QCPPainter::pmNoCaching)) - { - for (int i=1; i<lineData->size(); ++i) - painter->drawLine(lineData->at(i-1), lineData->at(i)); - } else - { - painter->drawPolyline(QPolygonF(*lineData)); - } - } - - // draw scatters: - if (!mScatterStyle.isNone()) - drawScatterPlot(painter, lineData); - - // free allocated line data: - delete lineData; -} - -/* inherits documentation from base class */ -void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw fill: - if (mBrush.style() != Qt::NoBrush) - { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); - } - // draw line vertically centered: - if (mLineStyle != lsNone) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens - } - // draw scatter symbol: - if (!mScatterStyle.isNone()) - { - applyScattersAntialiasingHint(painter); - // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) - { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else - { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); - } - } -} - -/*! \internal - - Draws scatter symbols at every data point passed in \a pointData. scatter symbols are independent of - the line style and are always drawn if scatter shape is not \ref QCPScatterStyle::ssNone. -*/ -void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const -{ - // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - mScatterStyle.applyTo(painter, mPen); - for (int i=0; i<pointData->size(); ++i) - mScatterStyle.drawShape(painter, pointData->at(i)); -} - -/*! \internal - - called by QCPCurve::draw to generate a point vector (pixels) which represents the line of the - curve. Line segments that aren't visible in the current axis rect are handled in an optimized - way. -*/ -void QCPCurve::getCurveData(QVector<QPointF> *lineData) const -{ - /* Extended sides of axis rect R divide space into 9 regions: - 1__|_4_|__7 - 2__|_R_|__8 - 3 | 6 | 9 - General idea: If the two points of a line segment are in the same region (that is not R), the line segment corner is removed. - Curves outside R become straight lines closely outside of R which greatly reduces drawing time, yet keeps the look of lines and - fills inside R consistent. - The region R has index 5. - */ - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QRect axisRect = mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); - lineData->reserve(mData->size()); - QCPCurveDataMap::const_iterator it; - int lastRegion = 5; - int currentRegion = 5; - double RLeft = keyAxis->range().lower; - double RRight = keyAxis->range().upper; - double RBottom = valueAxis->range().lower; - double RTop = valueAxis->range().upper; - double x, y; // current key/value - bool addedLastAlready = true; - bool firstPoint = true; // first point must always be drawn, to make sure fill works correctly - for (it = mData->constBegin(); it != mData->constEnd(); ++it) - { - x = it.value().key; - y = it.value().value; - // determine current region: - if (x < RLeft) // region 123 - { - if (y > RTop) - currentRegion = 1; - else if (y < RBottom) - currentRegion = 3; - else - currentRegion = 2; - } else if (x > RRight) // region 789 - { - if (y > RTop) - currentRegion = 7; - else if (y < RBottom) - currentRegion = 9; - else - currentRegion = 8; - } else // region 456 - { - if (y > RTop) - currentRegion = 4; - else if (y < RBottom) - currentRegion = 6; - else - currentRegion = 5; - } - - /* - Watch out, the next part is very tricky. It modifies the curve such that it seems like the - whole thing is still drawn, but actually the points outside the axisRect are simplified - ("optimized") greatly. There are some subtle special cases when line segments are large and - thereby each subsequent point may be in a different region or even skip some. - */ - // determine whether to keep current point: - if (currentRegion == 5 || (firstPoint && mBrush.style() != Qt::NoBrush)) // current is in R, add current and last if it wasn't added already - { - if (!addedLastAlready) // in case curve just entered R, make sure the last point outside R is also drawn correctly - lineData->append(coordsToPixels((it-1).value().key, (it-1).value().value)); // add last point to vector - else if (lastRegion != 5) // added last already. If that's the case, we probably added it at optimized position. So go back and make sure it's at original position (else the angle changes under which this segment enters R) - { - if (!firstPoint) // because on firstPoint, currentRegion is 5 and addedLastAlready is true, although there is no last point - lineData->replace(lineData->size()-1, coordsToPixels((it-1).value().key, (it-1).value().value)); - } - lineData->append(coordsToPixels(it.value().key, it.value().value)); // add current point to vector - addedLastAlready = true; // so in next iteration, we don't add this point twice - } else if (currentRegion != lastRegion) // changed region, add current and last if not added already - { - // using outsideCoordsToPixels instead of coorsToPixels for optimized point placement (places points just outside axisRect instead of potentially far away) - - // if we're coming from R or we skip diagonally over the corner regions (so line might still be visible in R), we can't place points optimized - if (lastRegion == 5 || // coming from R - ((lastRegion==2 && currentRegion==4) || (lastRegion==4 && currentRegion==2)) || // skip top left diagonal - ((lastRegion==4 && currentRegion==8) || (lastRegion==8 && currentRegion==4)) || // skip top right diagonal - ((lastRegion==8 && currentRegion==6) || (lastRegion==6 && currentRegion==8)) || // skip bottom right diagonal - ((lastRegion==6 && currentRegion==2) || (lastRegion==2 && currentRegion==6)) // skip bottom left diagonal - ) - { - // always add last point if not added already, original: - if (!addedLastAlready) - lineData->append(coordsToPixels((it-1).value().key, (it-1).value().value)); - // add current point, original: - lineData->append(coordsToPixels(it.value().key, it.value().value)); - } else // no special case that forbids optimized point placement, so do it: - { - // always add last point if not added already, optimized: - if (!addedLastAlready) - lineData->append(outsideCoordsToPixels((it-1).value().key, (it-1).value().value, currentRegion, axisRect)); - // add current point, optimized: - lineData->append(outsideCoordsToPixels(it.value().key, it.value().value, currentRegion, axisRect)); - } - addedLastAlready = true; // so that if next point enters 5, or crosses another region boundary, we don't add this point twice - } else // neither in R, nor crossed a region boundary, skip current point - { - addedLastAlready = false; - } - lastRegion = currentRegion; - firstPoint = false; - } - // If curve ends outside R, we want to add very last point so the fill looks like it should when the curve started inside R: - if (lastRegion != 5 && mBrush.style() != Qt::NoBrush && !mData->isEmpty()) - lineData->append(coordsToPixels((mData->constEnd()-1).value().key, (mData->constEnd()-1).value().value)); -} - -/*! \internal - - Calculates the (minimum) distance (in pixels) the curve's representation has from the given \a - pixelPoint in pixels. This is used to determine whether the curve was clicked or not, e.g. in - \ref selectTest. -*/ -double QCPCurve::pointDistance(const QPointF &pixelPoint) const -{ - if (mData->isEmpty()) - { - qDebug() << Q_FUNC_INFO << "requested point distance on curve" << mName << "without data"; - return 500; - } - if (mData->size() == 1) - { - QPointF dataPoint = coordsToPixels(mData->constBegin().key(), mData->constBegin().value().value); - return QVector2D(dataPoint-pixelPoint).length(); - } - - // calculate minimum distance to line segments: - QVector<QPointF> *lineData = new QVector<QPointF>; - getCurveData(lineData); - double minDistSqr = std::numeric_limits<double>::max(); - for (int i=0; i<lineData->size()-1; ++i) - { - double currentDistSqr = distSqrToLine(lineData->at(i), lineData->at(i+1), pixelPoint); - if (currentDistSqr < minDistSqr) - minDistSqr = currentDistSqr; - } - delete lineData; - return sqrt(minDistSqr); -} - -/*! \internal - - This is a specialized \ref coordsToPixels function for points that are outside the visible - axisRect and just crossing a boundary (since \ref getCurveData reduces non-visible curve segments - to those line segments that cross region boundaries, see documentation there). It only uses the - coordinate parallel to the region boundary of the axisRect. The other coordinate is picked just - outside the axisRect (how far is determined by the scatter size and the line width). Together - with the optimization in \ref getCurveData this improves performance for large curves (or zoomed - in ones) significantly while keeping the illusion the whole curve and its filling is still being - drawn for the viewer. -*/ -QPointF QCPCurve::outsideCoordsToPixels(double key, double value, int region, QRect axisRect) const -{ - int margin = qCeil(qMax(mScatterStyle.size(), (double)mPen.widthF())) + 2; - QPointF result = coordsToPixels(key, value); - switch (region) - { - case 2: result.setX(axisRect.left()-margin); break; // left - case 8: result.setX(axisRect.right()+margin); break; // right - case 4: result.setY(axisRect.top()-margin); break; // top - case 6: result.setY(axisRect.bottom()+margin); break; // bottom - case 1: result.setX(axisRect.left()-margin); - result.setY(axisRect.top()-margin); break; // top left - case 7: result.setX(axisRect.right()+margin); - result.setY(axisRect.top()-margin); break; // top right - case 9: result.setX(axisRect.right()+margin); - result.setY(axisRect.bottom()+margin); break; // bottom right - case 3: result.setX(axisRect.left()-margin); - result.setY(axisRect.bottom()+margin); break; // bottom left - } - return result; -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getKeyRange(bool &foundRange, SignDomain inSignDomain) const -{ - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - - double current; - - QCPCurveDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().key; - if (inSignDomain == sdBoth || (inSignDomain == sdNegative && current < 0) || (inSignDomain == sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPCurve::getValueRange(bool &foundRange, SignDomain inSignDomain) const -{ - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - - double current; - - QCPCurveDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().value; - if (inSignDomain == sdBoth || (inSignDomain == sdNegative && current < 0) || (inSignDomain == sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - - foundRange = haveLower && haveUpper; - return range; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBarData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBarData - \brief Holds the data of one single data point (one bar) for QCPBars. - - The container for storing multiple data points is \ref QCPBarDataMap. - - The stored data is: - \li \a key: coordinate on the key axis of this bar - \li \a value: height coordinate on the value axis of this bar - - \see QCPBarDataaMap -*/ - -/*! - Constructs a bar data point with key and value set to zero. -*/ -QCPBarData::QCPBarData() : - key(0), - value(0) -{ -} - -/*! - Constructs a bar data point with the specified \a key and \a value. -*/ -QCPBarData::QCPBarData(double key, double value) : - key(key), - value(value) -{ -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPBars -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPBars - \brief A plottable representing a bar chart in a plot. - - \image html QCPBars.png - - To plot data, assign it with the \ref setData or \ref addData functions. - - \section appearance Changing the appearance - - The appearance of the bars is determined by the pen and the brush (\ref setPen, \ref setBrush). - - Bar charts are stackable. This means, Two QCPBars plottables can be placed on top of each other - (see \ref QCPBars::moveAbove). Then, when two bars are at the same key position, they will appear - stacked. - - \section usage Usage - - Like all data representing objects in QCustomPlot, the QCPBars is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::addPlottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \code - QCPBars *newBars = new QCPBars(customPlot->xAxis, customPlot->yAxis);\endcode - add it to the customPlot with QCustomPlot::addPlottable: - \code - customPlot->addPlottable(newBars);\endcode - and then modify the properties of the newly created plottable, e.g.: - \code - newBars->setName("Country population"); - newBars->setData(xData, yData);\endcode -*/ - -/*! \fn QCPBars *QCPBars::barBelow() const - Returns the bars plottable that is directly below this bars plottable. - If there is no such plottable, returns 0. - - \see barAbove, moveBelow, moveAbove -*/ - -/*! \fn QCPBars *QCPBars::barAbove() const - Returns the bars plottable that is directly above this bars plottable. - If there is no such plottable, returns 0. - - \see barBelow, moveBelow, moveAbove -*/ - -/*! - Constructs a bar chart which uses \a keyAxis as its key axis ("x") and \a valueAxis as its value - axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and not have - the same orientation. If either of these restrictions is violated, a corresponding message is - printed to the debug output (qDebug), the construction is not aborted, though. - - The constructed QCPBars can be added to the plot with QCustomPlot::addPlottable, QCustomPlot - then takes ownership of the bar chart. -*/ -QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis) -{ - mData = new QCPBarDataMap; - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(QColor(40, 50, 255, 30)); - mBrush.setStyle(Qt::SolidPattern); - mSelectedPen = mPen; - mSelectedPen.setWidthF(2.5); - mSelectedPen.setColor(QColor(80, 80, 255)); // lighter than Qt::blue of mPen - mSelectedBrush = mBrush; - - mWidth = 0.75; -} - -QCPBars::~QCPBars() -{ - if (mBarBelow || mBarAbove) - connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking - delete mData; -} - -/*! - Sets the width of the bars in plot (key) coordinates. -*/ -void QCPBars::setWidth(double width) -{ - mWidth = width; -} - -/*! - Replaces the current data with the provided \a data. - - If \a copy is set to true, data points in \a data will only be copied. if false, the plottable - takes ownership of the passed data and replaces the internal data pointer with it. This is - significantly faster than copying for large datasets. -*/ -void QCPBars::setData(QCPBarDataMap *data, bool copy) -{ - if (copy) - { - *mData = *data; - } else - { - delete mData; - mData = data; - } -} - -/*! \overload - - Replaces the current data with the provided points in \a key and \a value tuples. The - provided vectors should have equal length. Else, the number of added points will be the size of - the smallest vector. -*/ -void QCPBars::setData(const QVector<double> &key, const QVector<double> &value) -{ - mData->clear(); - int n = key.size(); - n = qMin(n, value.size()); - QCPBarData newData; - for (int i=0; i<n; ++i) - { - newData.key = key[i]; - newData.value = value[i]; - mData->insertMulti(newData.key, newData); - } -} - -/*! - Moves this bars plottable below \a bars. In other words, the bars of this plottable will appear - below the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object below itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barAbove, barBelow -*/ -void QCPBars::moveBelow(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar below it: - if (bars) - { - if (bars->mBarBelow) - connectBars(bars->mBarBelow.data(), this); - connectBars(this, bars); - } -} - -/*! - Moves this bars plottable above \a bars. In other words, the bars of this plottable will appear - above the bars of \a bars. The move target \a bars must use the same key and value axis as this - plottable. - - Inserting into and removing from existing bar stacking is handled gracefully. If \a bars already - has a bars object below itself, this bars object is inserted between the two. If this bars object - is already between two other bars, the two other bars will be stacked on top of each other after - the operation. - - To remove this bars plottable from any stacking, set \a bars to 0. - - \see moveBelow, barBelow, barAbove -*/ -void QCPBars::moveAbove(QCPBars *bars) -{ - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) - { - qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; - return; - } - // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 - // if new bar given, insert this bar above it: - if (bars) - { - if (bars->mBarAbove) - connectBars(this, bars->mBarAbove.data()); - connectBars(bars, this); - } -} - -/*! - Adds the provided data points in \a dataMap to the current data. - \see removeData -*/ -void QCPBars::addData(const QCPBarDataMap &dataMap) -{ - mData->unite(dataMap); -} - -/*! \overload - Adds the provided single data point in \a data to the current data. - \see removeData -*/ -void QCPBars::addData(const QCPBarData &data) -{ - mData->insertMulti(data.key, data); -} - -/*! \overload - Adds the provided single data point as \a key and \a value tuple to the current data - \see removeData -*/ -void QCPBars::addData(double key, double value) -{ - QCPBarData newData; - newData.key = key; - newData.value = value; - mData->insertMulti(newData.key, newData); -} - -/*! \overload - Adds the provided data points as \a key and \a value tuples to the current data. - \see removeData -*/ -void QCPBars::addData(const QVector<double> &keys, const QVector<double> &values) -{ - int n = keys.size(); - n = qMin(n, values.size()); - QCPBarData newData; - for (int i=0; i<n; ++i) - { - newData.key = keys[i]; - newData.value = values[i]; - mData->insertMulti(newData.key, newData); - } -} - -/*! - Removes all data points with key smaller than \a key. - \see addData, clearData -*/ -void QCPBars::removeDataBefore(double key) -{ - QCPBarDataMap::iterator it = mData->begin(); - while (it != mData->end() && it.key() < key) - it = mData->erase(it); -} - -/*! - Removes all data points with key greater than \a key. - \see addData, clearData -*/ -void QCPBars::removeDataAfter(double key) -{ - if (mData->isEmpty()) return; - QCPBarDataMap::iterator it = mData->upperBound(key); - while (it != mData->end()) - it = mData->erase(it); -} - -/*! - Removes all data points with key between \a fromKey and \a toKey. if \a fromKey is - greater or equal to \a toKey, the function does nothing. To remove a single data point with known - key, use \ref removeData(double key). - - \see addData, clearData -*/ -void QCPBars::removeData(double fromKey, double toKey) -{ - if (fromKey >= toKey || mData->isEmpty()) return; - QCPBarDataMap::iterator it = mData->upperBound(fromKey); - QCPBarDataMap::iterator itEnd = mData->upperBound(toKey); - while (it != itEnd) - it = mData->erase(it); -} - -/*! \overload - - Removes a single data point at \a key. If the position is not known with absolute precision, - consider using \ref removeData(double fromKey, double toKey) with a small fuzziness interval - around the suspected position, depeding on the precision with which the key is known. - - \see addData, clearData -*/ -void QCPBars::removeData(double key) -{ - mData->remove(key); -} - -/*! - Removes all data points. - \see removeData, removeDataAfter, removeDataBefore -*/ -void QCPBars::clearData() -{ - mData->clear(); -} - -/* inherits documentation from base class */ -double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - QCPBarDataMap::ConstIterator it; - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - for (it = mData->constBegin(); it != mData->constEnd(); ++it) - { - double baseValue = getBaseValue(it.key(), it.value().value >=0); - QCPRange keyRange(it.key()-mWidth*0.5, it.key()+mWidth*0.5); - QCPRange valueRange(baseValue, baseValue+it.value().value); - if (keyRange.contains(posKey) && valueRange.contains(posValue)) - return mParentPlot->selectionTolerance()*0.99; - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPBars::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mData->isEmpty()) return; - - QCPBarDataMap::const_iterator it; - for (it = mData->constBegin(); it != mData->constEnd(); ++it) - { - // skip bar if not visible in key axis range: - if (it.key()+mWidth*0.5 < mKeyAxis.data()->range().lower || it.key()-mWidth*0.5 > mKeyAxis.data()->range().upper) - continue; - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it.value().key, it.value().value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it.key() << "of drawn range invalid." << "Plottable name:" << name(); -#endif - QPolygonF barPolygon = getBarPolygon(it.key(), it.value().value); - // draw bar fill: - if (mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) - { - applyFillAntialiasingHint(painter); - painter->setPen(Qt::NoPen); - painter->setBrush(mainBrush()); - painter->drawPolygon(barPolygon); - } - // draw bar line: - if (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0) - { - applyDefaultAntialiasingHint(painter); - painter->setPen(mainPen()); - painter->setBrush(Qt::NoBrush); - painter->drawPolyline(barPolygon); - } - } -} - -/* inherits documentation from base class */ -void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setBrush(mBrush); - painter->setPen(mPen); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! \internal - - Returns the polygon of a single bar with \a key and \a value. The Polygon is open at the bottom - and shifted according to the bar stacking (see \ref moveAbove). -*/ -QPolygonF QCPBars::getBarPolygon(double key, double value) const -{ - QPolygonF result; - double baseValue = getBaseValue(key, value >= 0); - result << coordsToPixels(key-mWidth*0.5, baseValue); - result << coordsToPixels(key-mWidth*0.5, baseValue+value); - result << coordsToPixels(key+mWidth*0.5, baseValue+value); - result << coordsToPixels(key+mWidth*0.5, baseValue); - return result; -} - -/*! \internal - - This function is called to find at which value to start drawing the base of a bar at \a key, when - it is stacked on top of another QCPBars (e.g. with \ref moveAbove). - - positive and negative bars are separated per stack (positive are stacked above 0-value upwards, - negative are stacked below 0-value downwards). This can be indicated with \a positive. So if the - bar for which we need the base value is negative, set \a positive to false. -*/ -double QCPBars::getBaseValue(double key, bool positive) const -{ - if (mBarBelow) - { - double max = 0; - // find bars of mBarBelow that are approximately at key and find largest one: - QCPBarDataMap::const_iterator it = mBarBelow.data()->mData->lowerBound(key-mWidth*0.1); - QCPBarDataMap::const_iterator itEnd = mBarBelow.data()->mData->upperBound(key+mWidth*0.1); - while (it != itEnd) - { - if ((positive && it.value().value > max) || - (!positive && it.value().value < max)) - max = it.value().value; - ++it; - } - // recurse down the bar-stack to find the total height: - return max + mBarBelow.data()->getBaseValue(key, positive); - } else - return 0; -} - -/*! \internal - - Connects \a below and \a above to each other via their mBarAbove/mBarBelow properties. - The bar(s) currently below lower and upper will become disconnected to lower/upper. - - If lower is zero, upper will be disconnected at the bottom. - If upper is zero, lower will be disconnected at the top. -*/ -void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) -{ - if (!lower && !upper) return; - - if (!lower) // disconnect upper at bottom - { - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - upper->mBarBelow = 0; - } else if (!upper) // disconnect lower at top - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - lower->mBarAbove = 0; - } else // connect lower and upper - { - // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) - lower->mBarAbove.data()->mBarBelow = 0; - // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) - upper->mBarBelow.data()->mBarAbove = 0; - lower->mBarAbove = upper; - upper->mBarBelow = lower; - } -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getKeyRange(bool &foundRange, SignDomain inSignDomain) const -{ - QCPRange range; - bool haveLower = false; - bool haveUpper = false; - - double current; - double barWidthHalf = mWidth*0.5; - QCPBarDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().key; - if (inSignDomain == sdBoth || (inSignDomain == sdNegative && current+barWidthHalf < 0) || (inSignDomain == sdPositive && current-barWidthHalf > 0)) - { - if (current-barWidthHalf < range.lower || !haveLower) - { - range.lower = current-barWidthHalf; - haveLower = true; - } - if (current+barWidthHalf > range.upper || !haveUpper) - { - range.upper = current+barWidthHalf; - haveUpper = true; - } - } - ++it; - } - - foundRange = haveLower && haveUpper; - return range; -} - -/* inherits documentation from base class */ -QCPRange QCPBars::getValueRange(bool &foundRange, SignDomain inSignDomain) const -{ - QCPRange range; - bool haveLower = true; // set to true, because 0 should always be visible in bar charts - bool haveUpper = true; // set to true, because 0 should always be visible in bar charts - - double current; - - QCPBarDataMap::const_iterator it = mData->constBegin(); - while (it != mData->constEnd()) - { - current = it.value().value + getBaseValue(it.value().key, it.value().value >= 0); - if (inSignDomain == sdBoth || (inSignDomain == sdNegative && current < 0) || (inSignDomain == sdPositive && current > 0)) - { - if (current < range.lower || !haveLower) - { - range.lower = current; - haveLower = true; - } - if (current > range.upper || !haveUpper) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - - foundRange = true; // return true because bar charts always have the 0-line visible - return range; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPStatisticalBox -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPStatisticalBox - \brief A plottable representing a single statistical box in a plot. - - \image html QCPStatisticalBox.png - - To plot data, assign it with the individual parameter functions or use \ref setData to set all - parameters at once. The individual functions are: - \li \ref setMinimum - \li \ref setLowerQuartile - \li \ref setMedian - \li \ref setUpperQuartile - \li \ref setMaximum - - Additionally you can define a list of outliers, drawn as scatter datapoints: - \li \ref setOutliers - - \section appearance Changing the appearance - - The appearance of the box itself is controlled via \ref setPen and \ref setBrush. You may change - the width of the box with \ref setWidth in plot coordinates (not pixels). - - Analog functions exist for the minimum/maximum-whiskers: \ref setWhiskerPen, \ref - setWhiskerBarPen, \ref setWhiskerWidth. The whisker width is the width of the bar at the top - (maximum) and bottom (minimum). - - The median indicator line has its own pen, \ref setMedianPen. - - If the whisker backbone pen is changed, make sure to set the capStyle to Qt::FlatCap. Else, the - backbone line might exceed the whisker bars by a few pixels due to the pen cap being not - perfectly flat. - - The Outlier data points are drawn as normal scatter points. Their look can be controlled with - \ref setOutlierStyle - - \section usage Usage - - Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::addPlottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \code - QCPStatisticalBox *newBox = new QCPStatisticalBox(customPlot->xAxis, customPlot->yAxis);\endcode - add it to the customPlot with QCustomPlot::addPlottable: - \code - customPlot->addPlottable(newBox);\endcode - and then modify the properties of the newly created plottable, e.g.: - \code - newBox->setName("Measurement Series 1"); - newBox->setData(1, 3, 4, 5, 7); - newBox->setOutliers(QVector<double>() << 0.5 << 0.64 << 7.2 << 7.42);\endcode -*/ - -/*! - Constructs a statistical box which uses \a keyAxis as its key axis ("x") and \a valueAxis as its - value axis ("y"). \a keyAxis and \a valueAxis must reside in the same QCustomPlot instance and - not have the same orientation. If either of these restrictions is violated, a corresponding - message is printed to the debug output (qDebug), the construction is not aborted, though. - - The constructed statistical box can be added to the plot with QCustomPlot::addPlottable, - QCustomPlot then takes ownership of the statistical box. -*/ -QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mKey(0), - mMinimum(0), - mLowerQuartile(0), - mMedian(0), - mUpperQuartile(0), - mMaximum(0) -{ - setOutlierStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::blue, 6)); - setWhiskerWidth(0.2); - setWidth(0.5); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2.5)); - setMedianPen(QPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap)); - setWhiskerPen(QPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap)); - setWhiskerBarPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -/*! - Sets the key coordinate of the statistical box. -*/ -void QCPStatisticalBox::setKey(double key) -{ - mKey = key; -} - -/*! - Sets the parameter "minimum" of the statistical box plot. This is the position of the lower - whisker, typically the minimum measurement of the sample that's not considered an outlier. - - \see setMaximum, setWhiskerPen, setWhiskerBarPen, setWhiskerWidth -*/ -void QCPStatisticalBox::setMinimum(double value) -{ - mMinimum = value; -} - -/*! - Sets the parameter "lower Quartile" of the statistical box plot. This is the lower end of the - box. The lower and the upper quartiles are the two statistical quartiles around the median of the - sample, they contain 50% of the sample data. - - \see setUpperQuartile, setPen, setBrush, setWidth -*/ -void QCPStatisticalBox::setLowerQuartile(double value) -{ - mLowerQuartile = value; -} - -/*! - Sets the parameter "median" of the statistical box plot. This is the value of the median mark - inside the quartile box. The median separates the sample data in half (50% of the sample data is - below/above the median). - - \see setMedianPen -*/ -void QCPStatisticalBox::setMedian(double value) -{ - mMedian = value; -} - -/*! - Sets the parameter "upper Quartile" of the statistical box plot. This is the upper end of the - box. The lower and the upper quartiles are the two statistical quartiles around the median of the - sample, they contain 50% of the sample data. - - \see setLowerQuartile, setPen, setBrush, setWidth -*/ -void QCPStatisticalBox::setUpperQuartile(double value) -{ - mUpperQuartile = value; -} - -/*! - Sets the parameter "maximum" of the statistical box plot. This is the position of the upper - whisker, typically the maximum measurement of the sample that's not considered an outlier. - - \see setMinimum, setWhiskerPen, setWhiskerBarPen, setWhiskerWidth -*/ -void QCPStatisticalBox::setMaximum(double value) -{ - mMaximum = value; -} - -/*! - Sets a vector of outlier values that will be drawn as scatters. Any data points in the sample - that are not within the whiskers (\ref setMinimum, \ref setMaximum) should be considered outliers - and displayed as such. - - \see setOutlierStyle -*/ -void QCPStatisticalBox::setOutliers(const QVector<double> &values) -{ - mOutliers = values; -} - -/*! - Sets all parameters of the statistical box plot at once. - - \see setKey, setMinimum, setLowerQuartile, setMedian, setUpperQuartile, setMaximum -*/ -void QCPStatisticalBox::setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum) -{ - setKey(key); - setMinimum(minimum); - setLowerQuartile(lowerQuartile); - setMedian(median); - setUpperQuartile(upperQuartile); - setMaximum(maximum); -} - -/*! - Sets the width of the box in key coordinates. - - \see setWhiskerWidth -*/ -void QCPStatisticalBox::setWidth(double width) -{ - mWidth = width; -} - -/*! - Sets the width of the whiskers (\ref setMinimum, \ref setMaximum) in key coordinates. - - \see setWidth -*/ -void QCPStatisticalBox::setWhiskerWidth(double width) -{ - mWhiskerWidth = width; -} - -/*! - Sets the pen used for drawing the whisker backbone (That's the line parallel to the value axis). - - Make sure to set the \a pen capStyle to Qt::FlatCap to prevent the whisker backbone from reaching - a few pixels past the whisker bars, when using a non-zero pen width. - - \see setWhiskerBarPen -*/ -void QCPStatisticalBox::setWhiskerPen(const QPen &pen) -{ - mWhiskerPen = pen; -} - -/*! - Sets the pen used for drawing the whisker bars (Those are the lines parallel to the key axis at - each end of the whisker backbone). - - \see setWhiskerPen -*/ -void QCPStatisticalBox::setWhiskerBarPen(const QPen &pen) -{ - mWhiskerBarPen = pen; -} - -/*! - Sets the pen used for drawing the median indicator line inside the statistical box. -*/ -void QCPStatisticalBox::setMedianPen(const QPen &pen) -{ - mMedianPen = pen; -} - -/*! - Sets the appearance of the outlier data points. - - \see setOutliers -*/ -void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) -{ - mOutlierStyle = style; -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::clearData() -{ - setOutliers(QVector<double>()); - setKey(0); - setMinimum(0); - setLowerQuartile(0); - setMedian(0); - setUpperQuartile(0); - setMaximum(0); -} - -/* inherits documentation from base class */ -double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - // quartile box: - QCPRange keyRange(mKey-mWidth*0.5, mKey+mWidth*0.5); - QCPRange valueRange(mLowerQuartile, mUpperQuartile); - if (keyRange.contains(posKey) && valueRange.contains(posValue)) - return mParentPlot->selectionTolerance()*0.99; - - // min/max whiskers: - if (QCPRange(mMinimum, mMaximum).contains(posValue)) - return qAbs(mKeyAxis.data()->coordToPixel(mKey)-mKeyAxis.data()->coordToPixel(posKey)); - } - return -1; -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::draw(QCPPainter *painter) -{ - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - // check data validity if flag set: -#ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(mKey, mMedian) || - QCP::isInvalidData(mLowerQuartile, mUpperQuartile) || - QCP::isInvalidData(mMinimum, mMaximum)) - qDebug() << Q_FUNC_INFO << "Data point at" << mKey << "of drawn range has invalid data." << "Plottable name:" << name(); - for (int i=0; i<mOutliers.size(); ++i) - if (QCP::isInvalidData(mOutliers.at(i))) - qDebug() << Q_FUNC_INFO << "Data point outlier at" << mKey << "of drawn range invalid." << "Plottable name:" << name(); -#endif - - QRectF quartileBox; - drawQuartileBox(painter, &quartileBox); - - painter->save(); - painter->setClipRect(quartileBox, Qt::IntersectClip); - drawMedian(painter); - painter->restore(); - - drawWhiskers(painter); - drawOutliers(painter); -} - -/* inherits documentation from base class */ -void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->setBrush(mBrush); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); -} - -/*! \internal - - Draws the quartile box. \a box is an output parameter that returns the quartile box (in pixel - coordinates) which is used to set the clip rect of the painter before calling \ref drawMedian (so - the median doesn't draw outside the quartile box). -*/ -void QCPStatisticalBox::drawQuartileBox(QCPPainter *painter, QRectF *quartileBox) const -{ - QRectF box; - box.setTopLeft(coordsToPixels(mKey-mWidth*0.5, mUpperQuartile)); - box.setBottomRight(coordsToPixels(mKey+mWidth*0.5, mLowerQuartile)); - applyDefaultAntialiasingHint(painter); - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(box); - if (quartileBox) - *quartileBox = box; -} - -/*! \internal - - Draws the median line inside the quartile box. -*/ -void QCPStatisticalBox::drawMedian(QCPPainter *painter) const -{ - QLineF medianLine; - medianLine.setP1(coordsToPixels(mKey-mWidth*0.5, mMedian)); - medianLine.setP2(coordsToPixels(mKey+mWidth*0.5, mMedian)); - applyDefaultAntialiasingHint(painter); - painter->setPen(mMedianPen); - painter->drawLine(medianLine); -} - -/*! \internal - - Draws both whisker backbones and bars. -*/ -void QCPStatisticalBox::drawWhiskers(QCPPainter *painter) const -{ - QLineF backboneMin, backboneMax, barMin, barMax; - backboneMax.setPoints(coordsToPixels(mKey, mUpperQuartile), coordsToPixels(mKey, mMaximum)); - backboneMin.setPoints(coordsToPixels(mKey, mLowerQuartile), coordsToPixels(mKey, mMinimum)); - barMax.setPoints(coordsToPixels(mKey-mWhiskerWidth*0.5, mMaximum), coordsToPixels(mKey+mWhiskerWidth*0.5, mMaximum)); - barMin.setPoints(coordsToPixels(mKey-mWhiskerWidth*0.5, mMinimum), coordsToPixels(mKey+mWhiskerWidth*0.5, mMinimum)); - applyErrorBarsAntialiasingHint(painter); - painter->setPen(mWhiskerPen); - painter->drawLine(backboneMin); - painter->drawLine(backboneMax); - painter->setPen(mWhiskerBarPen); - painter->drawLine(barMin); - painter->drawLine(barMax); -} - -/*! \internal - - Draws the outlier scatter points. -*/ -void QCPStatisticalBox::drawOutliers(QCPPainter *painter) const -{ - applyScattersAntialiasingHint(painter); - mOutlierStyle.applyTo(painter, mPen); - for (int i=0; i<mOutliers.size(); ++i) - mOutlierStyle.drawShape(painter, coordsToPixels(mKey, mOutliers.at(i))); -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, SignDomain inSignDomain) const -{ - foundRange = true; - if (inSignDomain == sdBoth) - { - return QCPRange(mKey-mWidth*0.5, mKey+mWidth*0.5); - } else if (inSignDomain == sdNegative) - { - if (mKey+mWidth*0.5 < 0) - return QCPRange(mKey-mWidth*0.5, mKey+mWidth*0.5); - else if (mKey < 0) - return QCPRange(mKey-mWidth*0.5, mKey); - else - { - foundRange = false; - return QCPRange(); - } - } else if (inSignDomain == sdPositive) - { - if (mKey-mWidth*0.5 > 0) - return QCPRange(mKey-mWidth*0.5, mKey+mWidth*0.5); - else if (mKey > 0) - return QCPRange(mKey, mKey+mWidth*0.5); - else - { - foundRange = false; - return QCPRange(); - } - } - foundRange = false; - return QCPRange(); -} - -/* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, SignDomain inSignDomain) const -{ - QVector<double> values; // values that must be considered (i.e. all outliers and the five box-parameters) - values.reserve(mOutliers.size() + 5); - values << mMaximum << mUpperQuartile << mMedian << mLowerQuartile << mMinimum; - values << mOutliers; - // go through values and find the ones in legal range: - bool haveUpper = false; - bool haveLower = false; - double upper = 0; - double lower = 0; - for (int i=0; i<values.size(); ++i) - { - if ((inSignDomain == sdNegative && values.at(i) < 0) || - (inSignDomain == sdPositive && values.at(i) > 0) || - (inSignDomain == sdBoth)) - { - if (values.at(i) > upper || !haveUpper) - { - upper = values.at(i); - haveUpper = true; - } - if (values.at(i) < lower || !haveLower) - { - lower = values.at(i); - haveLower = true; - } - } - } - // return the bounds if we found some sensible values: - if (haveLower && haveUpper) - { - foundRange = true; - return QCPRange(lower, upper); - } else // might happen if all values are in other sign domain - { - foundRange = false; - return QCPRange(); - } -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorMapData -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorMapData - \brief Holds the two-dimensional data of a QCPColorMap plottable. - - This class is a data storage for \ref QCPColorMap. It holds a two-dimensional array, which \ref - QCPColorMap then displays as a 2D image in the plot, where the array values are represented by a - color, depending on the value. - - The size of the array can be controlled via \ref setSize (or \ref setKeySize, \ref setValueSize). - Which plot coordinates these cells correspond to can be configured with \ref setRange (or \ref - setKeyRange, \ref setValueRange). - - The data cells can be accessed in two ways: They can be directly addressed by an integer index - with \ref setCell. This is the fastest method. Alternatively, they can be addressed by their plot - coordinate with \ref setData. plot coordinate to cell index transformations and vice versa are - provided by the functions \ref coordToCell and \ref cellToCoord. - - This class also buffers the minimum and maximum values that are in the data set, to provide - QCPColorMap::rescaleDataRange with the necessary information quickly. Setting a cell to a value - that is greater than the current maximum increases this maximum to the new value. However, - setting the cell that currently holds the maximum value to a smaller value doesn't decrease the - maximum again, because finding the true new maximum would require going through the entire data - array, which might be time consuming. The same holds for the data minimum. This functionality is - given by \ref recalculateDataBounds, such that you can decide when it is sensible to find the - true current minimum and maximum. The method QCPColorMap::rescaleDataRange offers a convenience - parameter \a recalculateDataBounds which may be set to true to automatically call \ref - recalculateDataBounds internally. -*/ - -/* start of documentation of inline functions */ - -/*! \fn bool QCPColorMapData::isEmpty() const - - Returns whether this instance carries no data. This is equivalent to having a size where at least - one of the dimensions is 0 (see \ref setSize). -*/ - -/* end of documentation of inline functions */ - -/*! - Constructs a new QCPColorMapData instance. The instance has \a keySize cells in the key direction - and \a valueSize cells in the value direction. These cells will be displayed by the \ref QCPColorMap - at the coordinates \a keyRange and \a valueRange. - - \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange -*/ -QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : - mKeySize(0), - mValueSize(0), - mKeyRange(keyRange), - mValueRange(valueRange), - mIsEmpty(true), - mData(0), - mDataModified(true) -{ - setSize(keySize, valueSize); - fill(0); -} - -QCPColorMapData::~QCPColorMapData() -{ - if (mData) - delete[] mData; -} - -/*! - Constructs a new QCPColorMapData instance copying the data and range of \a other. -*/ -QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : - mKeySize(0), - mValueSize(0), - mIsEmpty(true), - mData(0), - mDataModified(true) -{ - *this = other; -} - -/*! - Overwrites this color map data instance with the data stored in \a other. -*/ -QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) -{ - if (&other != this) - { - const int keySize = other.keySize(); - const int valueSize = other.valueSize(); - setSize(keySize, valueSize); - setRange(other.keyRange(), other.valueRange()); - if (!mIsEmpty) - memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); - mDataBounds = other.mDataBounds; - mDataModified = true; - } - return *this; -} - -/* undocumented getter */ -double QCPColorMapData::data(double key, double value) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (1.0-(value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower))*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - return mData[valueCell*mKeySize + keyCell]; - else - return 0; -} - -/* undocumented getter */ -double QCPColorMapData::cell(int keyIndex, int valueIndex) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mData[valueIndex*mKeySize + keyIndex]; - else - return 0; -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension and \a valueSize cells in - the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting at least one of \a keySize or \a valueSize to zero frees the internal data array and \ref - isEmpty returns true. - - \see setRange, setKeySize, setValueSize -*/ -void QCPColorMapData::setSize(int keySize, int valueSize) -{ - if (keySize != mKeySize || valueSize != mValueSize) - { - mKeySize = keySize; - mValueSize = valueSize; - if (mData) - delete[] mData; - mIsEmpty = mKeySize == 0 || mValueSize == 0; - if (!mIsEmpty) - { -#ifdef __EXCEPTIONS - try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message -#endif - mData = new double[mKeySize*mValueSize]; -#ifdef __EXCEPTIONS - } catch (...) { mData = 0; } -#endif - if (mData) - fill(0); - else - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; - } else - mData = 0; - mDataModified = true; - } -} - -/*! - Resizes the data array to have \a keySize cells in the key dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a keySize to zero frees the internal data array and \ref isEmpty returns true. - - \see setKeyRange, setSize, setValueSize -*/ -void QCPColorMapData::setKeySize(int keySize) -{ - setSize(keySize, mValueSize); -} - -/*! - Resizes the data array to have \a valueSize cells in the value dimension. - - The current data is discarded and the map cells are set to 0, unless the map had already the - requested size. - - Setting \a valueSize to zero frees the internal data array and \ref isEmpty returns true. - - \see setValueRange, setSize, setKeySize -*/ -void QCPColorMapData::setValueSize(int valueSize) -{ - setSize(mKeySize, valueSize); -} - -/*! - Sets the coordinate ranges the data shall be distributed over. This defines the rectangular area - covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to <tt>QCPRange(2, 3)</tt> there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setSize -*/ -void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) -{ - setKeyRange(keyRange); - setValueRange(valueRange); -} - -/*! - Sets the coordinate range the data shall be distributed over in the key dimension. Together with - the value range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the key size (\ref setKeySize) is 3 and \a keyRange is set to <tt>QCPRange(2, 3)</tt> there will - be cells centered on the key coordinates 2, 2.5 and 3. - - \see setRange, setValueRange, setSize -*/ -void QCPColorMapData::setKeyRange(const QCPRange &keyRange) -{ - mKeyRange = keyRange; -} - -/*! - Sets the coordinate range the data shall be distributed over in the value dimension. Together with - the key range, This defines the rectangular area covered by the color map in plot coordinates. - - The outer cells will be centered on the range boundaries given to this function. For example, if - the value size (\ref setValueSize) is 3 and \a valueRange is set to <tt>QCPRange(2, 3)</tt> there - will be cells centered on the value coordinates 2, 2.5 and 3. - - \see setRange, setKeyRange, setSize -*/ -void QCPColorMapData::setValueRange(const QCPRange &valueRange) -{ - mValueRange = valueRange; -} - -/*! - Sets the data of the cell, which lies at the plot coordinates given by \a key and \a value, to \a - z. - - \see setCell, setRange -*/ -void QCPColorMapData::setData(double key, double value, double z) -{ - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - { - mData[valueCell*mKeySize + keyCell] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } -} - -/*! - Sets the data of the cell with indices \a keyIndex and \a valueIndex to \a z. The indices - enumerate the cells starting from zero, up to the map's size-1 in the respective dimension (see - \ref setSize). - - In the standard plot configuration (horizontal key axis and vertical value axis, both not - range-reversed), the cell with indices (0, 0) is in the bottom left corner and the cell with - indices (keySize-1, valueSize-1) is in the top right corner of the color map. - - \see setData, setSize -*/ -void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) -{ - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - { - mData[valueIndex*mKeySize + keyIndex] = z; - if (z < mDataBounds.lower) - mDataBounds.lower = z; - if (z > mDataBounds.upper) - mDataBounds.upper = z; - mDataModified = true; - } -} - -/*! - Goes through the data and updates the buffered minimum and maximum data values. - - Calling this method is only advised if you are about to call \ref QCPColorMap::rescaleDataRange - and can not guarantee that the cells holding the maximum or minimum data haven't been overwritten - with a smaller or larger value respectively, since the buffered maximum/minimum values have been - updated the last time. Why this is the case is explained in the class description (\ref - QCPColorMapData). - - Note that the method \ref QCPColorMap::rescaleDataRange provides a parameter \a - recalculateDataBounds for convenience. Setting this to true will call this method for you, before - doing the rescale. -*/ -void QCPColorMapData::recalculateDataBounds() -{ - if (mKeySize > 0 && mValueSize > 0) - { - double minHeight = mData[0]; - double maxHeight = mData[0]; - const int dataCount = mValueSize*mKeySize; - for (int i=0; i<dataCount; ++i) - { - if (mData[i] > maxHeight) - maxHeight = mData[i]; - if (mData[i] < minHeight) - minHeight = mData[i]; - } - mDataBounds.lower = minHeight; - mDataBounds.upper = maxHeight; - } -} - -/*! - Frees the internal data memory. - - This is equivalent to calling \ref setSize "setSize(0, 0)". -*/ -void QCPColorMapData::clear() -{ - setSize(0, 0); -} - -/*! - Sets all cells to the value \a z. -*/ -void QCPColorMapData::fill(double z) -{ - const int dataCount = mValueSize*mKeySize; - for (int i=0; i<dataCount; ++i) - mData[i] = z; - mDataBounds = QCPRange(z, z); -} - -/*! - Transforms plot coordinates given by \a key and \a value to cell indices of this QCPColorMapData - instance. The resulting cell indices are returned via the output parameters \a keyIndex and \a - valueIndex. - - The retrieved key/value cell indices can then be used for example with \ref setCell. - - If you are only interested in a key or value index, you may pass 0 as \a valueIndex or \a - keyIndex. - - \see cellToCoord, QCPAxis::coordToPixel -*/ -void QCPColorMapData::coordToCell(double key, double value, int *keyIndex, int *valueIndex) const -{ - if (keyIndex) - *keyIndex = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - if (valueIndex) - *valueIndex = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; -} - -/*! - Transforms cell indices given by \a keyIndex and \a valueIndex to cell indices of this QCPColorMapData - instance. The resulting coordinates are returned via the output parameters \a key and \a - value. - - If you are only interested in a key or value coordinate, you may pass 0 as \a key or \a - value. - - \see coordToCell, QCPAxis::pixelToCoord -*/ -void QCPColorMapData::cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const -{ - if (key) - *key = keyIndex/(double)(mKeySize-1)*(mKeyRange.upper-mKeyRange.lower)+mKeyRange.lower; - if (value) - *value = valueIndex/(double)(mValueSize-1)*(mValueRange.upper-mValueRange.lower)+mValueRange.lower; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPColorMap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPColorMap - \brief A plottable representing a two-dimensional color map in a plot. - - \image html QCPColorMap.png - - The data is stored in the class \ref QCPColorMapData, which can be accessed via the data() - method. - - A color map has three dimensions to represent a data point: The \a key dimension, the \a value - dimension and the \a data dimension. As with other plottables such as graphs, \a key and \a value - correspond to two orthogonal axes on the QCustomPlot surface that you specify in the QColorMap - constructor. The \a data dimension however is encoded as the color of the point at (\a key, \a - value). - - Set the number of points (or \a cells) in the key/value dimension via \ref - QCPColorMapData::setSize. The plot coordinate range over which these points will be displayed is - specified via \ref QCPColorMapData::setRange. The first cell will be centered on the lower range - boundary and the last cell will be centered on the upper range boundary. The data can be set by - either accessing the cells directly with QCPColorMapData::setCell or by addressing the cells via - their plot coordinates with \ref QCPColorMapData::setData. If possible, you should prefer - setCell, since it doesn't need to do any coordinate transformation and thus performs a bit - better. - - The cell with index (0, 0) is at the bottom left, if the color map uses normal (i.e. not reversed) - key and value axes. - - To show the user which colors correspond to which \a data values, a \ref QCPColorScale is - typically placed to the right of the axis rect. See the documentation there for details on how to - add and use a color scale. - - \section appearance Changing the appearance - - The central part of the appearance is the color gradient, which can be specified via \ref - setGradient. See the documentation of \ref QCPColorGradient for details on configuring a color - gradient. - - The \a data range that is mapped to the colors of the gradient can be specified with \ref - setDataRange. To make the data range encompass the whole data set minimum to maximum, call \ref - rescaleDataRange. - - \section usage Usage - - Like all data representing objects in QCustomPlot, the QCPColorMap is a plottable - (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies - (QCustomPlot::plottable, QCustomPlot::addPlottable, QCustomPlot::removePlottable, etc.) - - Usually, you first create an instance: - \code - QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis, customPlot->yAxis);\endcode - add it to the customPlot with QCustomPlot::addPlottable: - \code - customPlot->addPlottable(colorMap);\endcode - and then modify the properties of the newly created color map, e.g.: - \code - colorMap->data()->setSize(50, 50); - colorMap->data()->setRange(QCPRange(0, 2), QCPRange(0, 2)); - for (int x=0; x<50; ++x) - for (int y=0; y<50; ++y) - colorMap->data()->setCell(x, y, qCos(x/10.0)+qSin(y/10.0)); - colorMap->setGradient(QCPColorGradient::gpPolar); - colorMap->rescaleDataRange(true); - customPlot->rescaleAxes(); - customPlot->replot(); - \endcode - - \note The QCPColorMap always displays the data at equal key/value intervals, even if the key or - value axis is set to a logarithmic scaling. If you want to use QCPColorMap with logarithmic axes, - you shouldn't use the \ref QCPColorMapData::setData method as it uses a linear transformation to - determine the cell index. Rather directly access the cell index with \ref - QCPColorMapData::setCell. -*/ - -/* start documentation of inline functions */ - -/*! \fn QCPColorMapData *QCPColorMap::data() const - - Returns a pointer to the internal data storage of type \ref QCPColorMapData. Access this to - modify data points (cells) and the color map key/value range. - - \see setData -*/ - -/* end documentation of inline functions */ - -/* start documentation of signals */ - -/*! \fn void QCPColorMap::dataRangeChanged(QCPRange newRange); - - This signal is emitted when the data range changes. - - \see setDataRange -*/ - -/*! \fn void QCPColorMap::dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - - This signal is emitted when the data scale type changes. - - \see setDataScaleType -*/ - -/*! \fn void QCPColorMap::gradientChanged(QCPColorGradient newGradient); - - This signal is emitted when the gradient changes. - - \see setGradient -*/ - -/* end documentation of signals */ - -/*! - Constructs a color map with the specified \a keyAxis and \a valueAxis. - - The constructed QCPColorMap can be added to the plot with QCustomPlot::addPlottable, QCustomPlot - then takes ownership of the color map. -*/ -QCPColorMap::QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataScaleType(QCPAxis::stLinear), - mMapData(new QCPColorMapData(10, 10, QCPRange(0, 5), QCPRange(0, 5))), - mInterpolate(true), - mTightBoundary(false), - mMapImageInvalidated(true) -{ -} - -QCPColorMap::~QCPColorMap() -{ - delete mMapData; -} - -/*! - Replaces the current \ref data with the provided \a data. - - If \a copy is set to true, the \a data object will only be copied. if false, the color map - takes ownership of the passed data and replaces the internal data pointer with it. This is - significantly faster than copying for large datasets. -*/ -void QCPColorMap::setData(QCPColorMapData *data, bool copy) -{ - if (copy) - { - *mMapData = *data; - } else - { - delete mMapData; - mMapData = data; - } - mMapImageInvalidated = true; -} - -/*! - Sets the data range of this color map to \a dataRange. The data range defines which data values - are mapped to the color gradient. - - To make the data range span the full range of the data set, use \ref rescaleDataRange. - - \see QCPColorScale::setDataRange -*/ -void QCPColorMap::setDataRange(const QCPRange &dataRange) -{ - if (!QCPRange::validRange(dataRange)) return; - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) - { - if (mDataScaleType == QCPAxis::stLogarithmic) - mDataRange = dataRange.sanitizedForLogScale(); - else - mDataRange = dataRange.sanitizedForLinScale(); - mMapImageInvalidated = true; - emit dataRangeChanged(mDataRange); - } -} - -/*! - Sets whether the data is correlated with the color gradient linearly or logarithmically. - - \see QCPColorScale::setDataScaleType -*/ -void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) -{ - if (mDataScaleType != scaleType) - { - mDataScaleType = scaleType; - mMapImageInvalidated = true; - emit dataScaleTypeChanged(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - } -} - -/*! - Sets the color gradient that is used to represent the data. For more details on how to create an - own gradient or use one of the preset gradients, see \ref QCPColorGradient. - - The colors defined by the gradient will be used to represent data values in the currently set - data range, see \ref setDataRange. Data points that are outside this data range will either be - colored uniformly with the respective gradient boundary color, or the gradient will repeat, - depending on \ref QCPColorGradient::setPeriodic. - - \see QCPColorScale::setGradient -*/ -void QCPColorMap::setGradient(const QCPColorGradient &gradient) -{ - if (mGradient != gradient) - { - mGradient = gradient; - mMapImageInvalidated = true; - emit gradientChanged(mGradient); - } -} - -/*! - Sets whether the color map image shall use bicubic interpolation when displaying the color map - shrinked or expanded, and not at a 1:1 pixel-to-data scale. - - \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" -*/ -void QCPColorMap::setInterpolate(bool enabled) -{ - mInterpolate = enabled; -} - -/*! - Sets whether the outer most data rows and columns are clipped to the specified key and value - range (see \ref QCPColorMapData::setKeyRange, \ref QCPColorMapData::setValueRange). - - if \a enabled is set to false, the data points at the border of the color map are drawn with the - same width and height as all other data points. Since the data points are represented by - rectangles of one color centered on the data coordinate, this means that the shown color map - extends by half a data point over the specified key/value range in each direction. - - \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" -*/ -void QCPColorMap::setTightBoundary(bool enabled) -{ - mTightBoundary = enabled; -} - -/*! - Associates the color scale \a colorScale with this color map. - - This means that both the color scale and the color map synchronize their gradient, data range and - data scale type (\ref setGradient, \ref setDataRange, \ref setDataScaleType). Multiple color maps - can be associated with one single color scale. This causes the color maps to also synchronize - those properties, via the mutual color scale. - - This function causes the color map to adopt the current color gradient, data range and data scale - type of \a colorScale. After this call, you may change these properties at either the color map - or the color scale, and the setting will be applied to both. - - Pass 0 as \a colorScale to disconnect the color scale from this color map again. -*/ -void QCPColorMap::setColorScale(QCPColorScale *colorScale) -{ - if (mColorScale) // unconnect signals from old color scale - { - disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } - mColorScale = colorScale; - if (mColorScale) // connect signals to new color scale - { - setGradient(mColorScale.data()->gradient()); - setDataRange(mColorScale.data()->dataRange()); - setDataScaleType(mColorScale.data()->dataScaleType()); - connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - } -} - -/*! - Sets the data range (\ref setDataRange) to span the minimum and maximum values that occur in the - current data set. This corresponds to the \ref rescaleKeyAxis or \ref rescaleValueAxis methods, - only for the third data dimension of the color map. - - The minimum and maximum values of the data set are buffered in the internal QCPColorMapData - instance (\ref data). As data is updated via its \ref QCPColorMapData::setCell or \ref - QCPColorMapData::setData, the buffered minimum and maximum values are updated, too. For - performance reasons, however, they are only updated in an expanding fashion. So the buffered - maximum can only increase and the buffered minimum can only decrease. In consequence, changes to - the data that actually lower the maximum of the data set (by overwriting the cell holding the - current maximum with a smaller value), aren't recognized and the buffered maximum overestimates - the true maximum of the data set. The same happens for the buffered minimum. To recalculate the - true minimum and maximum by explicitly looking at each cell, the method - QCPColorMapData::recalculateDataBounds can be used. For convenience, setting the parameter \a - recalculateDataBounds calls this method before setting the data range to the buffered minimum and - maximum. - - \see setDataRange -*/ -void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) -{ - if (recalculateDataBounds) - mMapData->recalculateDataBounds(); - setDataRange(mMapData->dataBounds()); -} - -/*! - Takes the current appearance of the color map and updates the legend icon, which is used to - represent this color map in the legend (see \ref QCPLegend). - - The \a transformMode specifies whether the rescaling is done by a faster, low quality image - scaling algorithm (Qt::FastTransformation) or by a slower, higher quality algorithm - (Qt::SmoothTransformation). - - The current color map appearance is scaled down to \a thumbSize. Ideally, this should be equal to - the size of the legend icon (see \ref QCPLegend::setIconSize). If it isn't exactly the configured - legend icon size, the thumb will be rescaled during drawing of the legend item. - - \see setDataRange -*/ -void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) -{ - if (mMapImage.isNull() && !data()->isEmpty()) - updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) - - if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again - { - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); - } -} - -/*! - Clears the colormap data by calling \ref QCPColorMapData::clear() on the internal data. This also - resizes the map to 0x0 cells. -*/ -void QCPColorMap::clearData() -{ - mMapData->clear(); -} - -/* inherits documentation from base class */ -double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) - { - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) - return mParentPlot->selectionTolerance()*0.99; - } - return -1; -} - -/*! \internal - - Updates the internal map image buffer by going through the internal \ref QCPColorMapData and - turning the data values into color pixels with \ref QCPColorGradient::colorize. - - This method is called by \ref QCPColorMap::draw if either the data has been modified or the map image - has been invalidated for a different reason (e.g. a change of the data range with \ref - setDataRange). -*/ -void QCPColorMap::updateMapImage() -{ - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) return; - - // resize mMapImage to correct dimensions, according to key/value axes orientation: - if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.size().width() != mMapData->keySize() || mMapImage.size().height() != mMapData->valueSize())) - mMapImage = QImage(QSize(mMapData->keySize(), mMapData->valueSize()), QImage::Format_RGB32); - else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.size().width() != mMapData->valueSize() || mMapImage.size().height() != mMapData->keySize())) - mMapImage = QImage(QSize(mMapData->valueSize(), mMapData->keySize()), QImage::Format_RGB32); - - const int keySize = mMapData->keySize(); - const int valueSize = mMapData->valueSize(); - const double *rawData = mMapData->mData; - - if (keyAxis->orientation() == Qt::Horizontal) - { - const int lineCount = valueSize; - const int rowCount = keySize; - for (int line=0; line<lineCount; ++line) - { - QRgb* pixels = reinterpret_cast<QRgb*>(mMapImage.scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); - } - } else // keyAxis->orientation() == Qt::Vertical - { - const int lineCount = keySize; - const int rowCount = valueSize; - for (int line=0; line<lineCount; ++line) - { - QRgb* pixels = reinterpret_cast<QRgb*>(mMapImage.scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); - } - } - - mMapData->mDataModified = false; - mMapImageInvalidated = false; -} - -/* inherits documentation from base class */ -void QCPColorMap::draw(QCPPainter *painter) -{ - if (mMapData->isEmpty()) return; - if (!mKeyAxis || !mValueAxis) return; - applyDefaultAntialiasingHint(painter); - - if (mMapData->mDataModified || mMapImageInvalidated) - updateMapImage(); - - double halfSampleKey = 0; - double halfSampleValue = 0; - if (mMapData->keySize() > 1) - halfSampleKey = 0.5*mMapData->keyRange().size()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfSampleValue = 0.5*mMapData->valueRange().size()/(double)(mMapData->valueSize()-1); - QRectF imageRect(coordsToPixels(mMapData->keyRange().lower-halfSampleKey, mMapData->valueRange().lower-halfSampleValue), - coordsToPixels(mMapData->keyRange().upper+halfSampleKey, mMapData->valueRange().upper+halfSampleValue)); - imageRect = imageRect.normalized(); - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - bool smoothBackup = painter->renderHints().testFlag(QPainter::SmoothPixmapTransform); - painter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); - QRegion clipBackup; - if (mTightBoundary) - { - clipBackup = painter->clipRegion(); - painter->setClipRect(QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(), Qt::IntersectClip); - } - painter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); - if (mTightBoundary) - painter->setClipRegion(clipBackup); - painter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); -} - -/* inherits documentation from base class */ -void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const -{ - applyDefaultAntialiasingHint(painter); - // draw map thumbnail: - if (!mLegendIcon.isNull()) - { - QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); - QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); - iconRect.moveCenter(rect.center()); - painter->drawPixmap(iconRect.topLeft(), scaledIcon); - } - /* - // draw frame: - painter->setBrush(Qt::NoBrush); - painter->setPen(Qt::black); - painter->drawRect(rect.adjusted(1, 1, 0, 0)); - */ -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getKeyRange(bool &foundRange, SignDomain inSignDomain) const -{ - foundRange = true; - QCPRange result = mMapData->keyRange(); - result.normalize(); - if (inSignDomain == QCPAbstractPlottable::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCPAbstractPlottable::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - -/* inherits documentation from base class */ -QCPRange QCPColorMap::getValueRange(bool &foundRange, SignDomain inSignDomain) const -{ - foundRange = true; - QCPRange result = mMapData->valueRange(); - result.normalize(); - if (inSignDomain == QCPAbstractPlottable::sdPositive) - { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) - foundRange = false; - } else if (inSignDomain == QCPAbstractPlottable::sdNegative) - { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) - foundRange = false; - } - return result; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemStraightLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemStraightLine - \brief A straight line that spans infinitely in both directions - - \image html QCPItemStraightLine.png "Straight line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a point1 and \a point2, which define the straight line. -*/ - -/*! - Creates a straight line item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - point1(createPosition("point1")), - point2(createPosition("point2")) -{ - point1->setCoords(0, 0); - point2->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemStraightLine::~QCPItemStraightLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemStraightLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemStraightLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return distToStraightLine(QVector2D(point1->pixelPoint()), QVector2D(point2->pixelPoint()-point1->pixelPoint()), QVector2D(pos)); -} - -/* inherits documentation from base class */ -void QCPItemStraightLine::draw(QCPPainter *painter) -{ - QVector2D start(point1->pixelPoint()); - QVector2D end(point2->pixelPoint()); - // get visible segment of straight line inside clipRect: - double clipPad = mainPen().widthF(); - QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - } -} - -/*! \internal - - finds the shortest distance of \a point to the straight line defined by the base point \a - base and the direction vector \a vec. - - This is a helper function for \ref selectTest. -*/ -double QCPItemStraightLine::distToStraightLine(const QVector2D &base, const QVector2D &vec, const QVector2D &point) const -{ - return qAbs((base.y()-point.y())*vec.x()-(base.x()-point.x())*vec.y())/vec.length(); -} - -/*! \internal - - Returns the section of the straight line defined by \a base and direction vector \a - vec, that is visible in the specified \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemStraightLine::getRectClippedStraightLine(const QVector2D &base, const QVector2D &vec, const QRect &rect) const -{ - double bx, by; - double gamma; - QLineF result; - if (vec.x() == 0 && vec.y() == 0) - return result; - if (qFuzzyIsNull(vec.x())) // line is vertical - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical - } else if (qFuzzyIsNull(vec.y())) // line is horizontal - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal - } else // line is skewed - { - QList<QVector2D> pointVectors; - // check top of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QVector2D(bx+gamma, by)); - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QVector2D(bx+gamma, by)); - // check left of rect: - bx = rect.left(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QVector2D(bx, by+gamma)); - // check right of rect: - bx = rect.right(); - by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QVector2D(bx, by+gamma)); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QVector2D pv1, pv2; - for (int i=0; i<pointVectors.size()-1; ++i) - { - for (int k=i+1; k<pointVectors.size(); ++k) - { - double distSqr = (pointVectors.at(i)-pointVectors.at(k)).lengthSquared(); - if (distSqr > distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemStraightLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemLine -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemLine - \brief A line from one point to another - - \image html QCPItemLine.png "Line example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a start and \a end, which define the end points of the line. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an arrow. -*/ - -/*! - Creates a line item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition("start")), - end(createPosition("end")) -{ - start->setCoords(0, 0); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemLine::~QCPItemLine() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemLine::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemLine::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemLine::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemLine::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return qSqrt(distSqrToLine(start->pixelPoint(), end->pixelPoint(), pos)); -} - -/* inherits documentation from base class */ -void QCPItemLine::draw(QCPPainter *painter) -{ - QVector2D startVec(start->pixelPoint()); - QVector2D endVec(end->pixelPoint()); - if (startVec.toPoint() == endVec.toPoint()) - return; - // get visible segment of straight line inside clipRect: - double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); - clipPad = qMax(clipPad, (double)mainPen().widthF()); - QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); - // paint visible segment, if existent: - if (!line.isNull()) - { - painter->setPen(mainPen()); - painter->drawLine(line); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, startVec-endVec); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, endVec-startVec); - } -} - -/*! \internal - - Returns the section of the line defined by \a start and \a end, that is visible in the specified - \a rect. - - This is a helper function for \ref draw. -*/ -QLineF QCPItemLine::getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const -{ - bool containsStart = rect.contains(start.x(), start.y()); - bool containsEnd = rect.contains(end.x(), end.y()); - if (containsStart && containsEnd) - return QLineF(start.toPointF(), end.toPointF()); - - QVector2D base = start; - QVector2D vec = end-start; - double bx, by; - double gamma, mu; - QLineF result; - QList<QVector2D> pointVectors; - - if (!qFuzzyIsNull(vec.y())) // line is not horizontal - { - // check top of rect: - bx = rect.left(); - by = rect.top(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QVector2D(bx+gamma, by)); - } - // check bottom of rect: - bx = rect.left(); - by = rect.bottom(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) - { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QVector2D(bx+gamma, by)); - } - } - if (!qFuzzyIsNull(vec.x())) // line is not vertical - { - // check left of rect: - bx = rect.left(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QVector2D(bx, by+gamma)); - } - // check right of rect: - bx = rect.right(); - by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) - { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QVector2D(bx, by+gamma)); - } - } - - if (containsStart) - pointVectors.append(start); - if (containsEnd) - pointVectors.append(end); - - // evaluate points: - if (pointVectors.size() == 2) - { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) - { - // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: - double distSqrMax = 0; - QVector2D pv1, pv2; - for (int i=0; i<pointVectors.size()-1; ++i) - { - for (int k=i+1; k<pointVectors.size(); ++k) - { - double distSqr = (pointVectors.at(i)-pointVectors.at(k)).lengthSquared(); - if (distSqr > distSqrMax) - { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); - distSqrMax = distSqr; - } - } - } - result.setPoints(pv1.toPointF(), pv2.toPointF()); - } - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemLine::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemCurve -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemCurve - \brief A curved line from one point to another - - \image html QCPItemCurve.png "Curve example. Blue dotted circles are anchors, solid blue discs are positions." - - It has four positions, \a start and \a end, which define the end points of the line, and two - control points which define the direction the line exits from the start and the direction from - which it approaches the end: \a startDir and \a endDir. - - With \ref setHead and \ref setTail you may set different line ending styles, e.g. to create an - arrow. - - Often it is desirable for the control points to stay at fixed relative positions to the start/end - point. This can be achieved by setting the parent anchor e.g. of \a startDir simply to \a start, - and then specify the desired pixel offset with QCPItemPosition::setCoords on \a startDir. -*/ - -/*! - Creates a curve item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition("start")), - startDir(createPosition("startDir")), - endDir(createPosition("endDir")), - end(createPosition("end")) -{ - start->setCoords(0, 0); - startDir->setCoords(0.5, 0); - endDir->setCoords(0, 0.5); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); -} - -QCPItemCurve::~QCPItemCurve() -{ -} - -/*! - Sets the pen that will be used to draw the line - - \see setSelectedPen -*/ -void QCPItemCurve::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line when selected - - \see setPen, setSelected -*/ -void QCPItemCurve::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the line ending style of the head. The head corresponds to the \a end position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setHead(QCPLineEnding::esSpikeArrow) \endcode - - \see setTail -*/ -void QCPItemCurve::setHead(const QCPLineEnding &head) -{ - mHead = head; -} - -/*! - Sets the line ending style of the tail. The tail corresponds to the \a start position. - - Note that due to the overloaded QCPLineEnding constructor, you may directly specify - a QCPLineEnding::EndingStyle here, e.g. \code setTail(QCPLineEnding::esSpikeArrow) \endcode - - \see setHead -*/ -void QCPItemCurve::setTail(const QCPLineEnding &tail) -{ - mTail = tail; -} - -/* inherits documentation from base class */ -double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF startVec(start->pixelPoint()); - QPointF startDirVec(startDir->pixelPoint()); - QPointF endDirVec(endDir->pixelPoint()); - QPointF endVec(end->pixelPoint()); - - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - - QPolygonF polygon = cubicPath.toSubpathPolygons().first(); - double minDistSqr = std::numeric_limits<double>::max(); - for (int i=1; i<polygon.size(); ++i) - { - double distSqr = distSqrToLine(polygon.at(i-1), polygon.at(i), pos); - if (distSqr < minDistSqr) - minDistSqr = distSqr; - } - return qSqrt(minDistSqr); -} - -/* inherits documentation from base class */ -void QCPItemCurve::draw(QCPPainter *painter) -{ - QPointF startVec(start->pixelPoint()); - QPointF startDirVec(startDir->pixelPoint()); - QPointF endDirVec(endDir->pixelPoint()); - QPointF endVec(end->pixelPoint()); - if (QVector2D(endVec-startVec).length() > 1e10f) // too large curves cause crash - return; - - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - - // paint visible segment, if existent: - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - QRect cubicRect = cubicPath.controlPointRect().toRect(); - if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position - cubicRect.adjust(0, 0, 1, 1); - if (clip.intersects(cubicRect)) - { - painter->setPen(mainPen()); - painter->drawPath(cubicPath); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, QVector2D(startVec), M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, QVector2D(endVec), -cubicPath.angleAtPercent(1)/180.0*M_PI); - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemCurve::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemRect -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemRect - \brief A rectangle - - \image html QCPItemRect.png "Rectangle example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle. -*/ - -/*! - Creates a rectangle item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition("topLeft")), - bottomRight(createPosition("bottomRight")), - top(createAnchor("top", aiTop)), - topRight(createAnchor("topRight", aiTopRight)), - right(createAnchor("right", aiRight)), - bottom(createAnchor("bottom", aiBottom)), - bottomLeft(createAnchor("bottomLeft", aiBottomLeft)), - left(createAnchor("left", aiLeft)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemRect::~QCPItemRect() -{ -} - -/*! - Sets the pen that will be used to draw the line of the rectangle - - \see setSelectedPen, setBrush -*/ -void QCPItemRect::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the rectangle when selected - - \see setPen, setSelected -*/ -void QCPItemRect::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the rectangle. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemRect::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the rectangle when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemRect::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QRectF rect = QRectF(topLeft->pixelPoint(), bottomRight->pixelPoint()).normalized(); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectSelectTest(rect, pos, filledRect); -} - -/* inherits documentation from base class */ -void QCPItemRect::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPoint(); - QPointF p2 = bottomRight->pixelPoint(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF rect = QRectF(p1, p2).normalized(); - double clipPad = mainPen().widthF(); - QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(rect); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemRect::anchorPixelPoint(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPoint(), bottomRight->pixelPoint()); - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemRect::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemRect::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemText -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemText - \brief A text label - - \image html QCPItemText.png "Text example. Blue dotted circles are anchors, solid blue discs are positions." - - Its position is defined by the member \a position and the setting of \ref setPositionAlignment. - The latter controls which part of the text rect shall be aligned with \a position. - - The text alignment itself (i.e. left, center, right) can be controlled with \ref - setTextAlignment. - - The text may be rotated around the \a position point with \ref setRotation. -*/ - -/*! - Creates a text item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemText::QCPItemText(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition("position")), - topLeft(createAnchor("topLeft", aiTopLeft)), - top(createAnchor("top", aiTop)), - topRight(createAnchor("topRight", aiTopRight)), - right(createAnchor("right", aiRight)), - bottomRight(createAnchor("bottomRight", aiBottomRight)), - bottom(createAnchor("bottom", aiBottom)), - bottomLeft(createAnchor("bottomLeft", aiBottomLeft)), - left(createAnchor("left", aiLeft)) -{ - position->setCoords(0, 0); - - setRotation(0); - setTextAlignment(Qt::AlignTop|Qt::AlignHCenter); - setPositionAlignment(Qt::AlignCenter); - setText("text"); - - setPen(Qt::NoPen); - setSelectedPen(Qt::NoPen); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setColor(Qt::black); - setSelectedColor(Qt::blue); -} - -QCPItemText::~QCPItemText() -{ -} - -/*! - Sets the color of the text. -*/ -void QCPItemText::setColor(const QColor &color) -{ - mColor = color; -} - -/*! - Sets the color of the text that will be used when the item is selected. -*/ -void QCPItemText::setSelectedColor(const QColor &color) -{ - mSelectedColor = color; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text. To disable the - border, set \a pen to Qt::NoPen. - - \see setSelectedPen, setBrush, setPadding -*/ -void QCPItemText::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used do draw a rectangular border around the text, when the item is - selected. To disable the border, set \a pen to Qt::NoPen. - - \see setPen -*/ -void QCPItemText::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used do fill the background of the text. To disable the - background, set \a brush to Qt::NoBrush. - - \see setSelectedBrush, setPen, setPadding -*/ -void QCPItemText::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used do fill the background of the text, when the item is selected. To disable the - background, set \a brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemText::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the font of the text. - - \see setSelectedFont, setColor -*/ -void QCPItemText::setFont(const QFont &font) -{ - mFont = font; -} - -/*! - Sets the font of the text that will be used when the item is selected. - - \see setFont -*/ -void QCPItemText::setSelectedFont(const QFont &font) -{ - mSelectedFont = font; -} - -/*! - Sets the text that will be displayed. Multi-line texts are supported by inserting a line break - character, e.g. '\n'. - - \see setFont, setColor, setTextAlignment -*/ -void QCPItemText::setText(const QString &text) -{ - mText = text; -} - -/*! - Sets which point of the text rect shall be aligned with \a position. - - Examples: - \li If \a alignment is <tt>Qt::AlignHCenter | Qt::AlignTop</tt>, the text will be positioned such - that the top of the text rect will be horizontally centered on \a position. - \li If \a alignment is <tt>Qt::AlignLeft | Qt::AlignBottom</tt>, \a position will indicate the - bottom left corner of the text rect. - - If you want to control the alignment of (multi-lined) text within the text rect, use \ref - setTextAlignment. -*/ -void QCPItemText::setPositionAlignment(Qt::Alignment alignment) -{ - mPositionAlignment = alignment; -} - -/*! - Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). -*/ -void QCPItemText::setTextAlignment(Qt::Alignment alignment) -{ - mTextAlignment = alignment; -} - -/*! - Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated - around \a position. -*/ -void QCPItemText::setRotation(double degrees) -{ - mRotation = degrees; -} - -/*! - Sets the distance between the border of the text rectangle and the text. The appearance (and - visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. -*/ -void QCPItemText::setPadding(const QMargins &padding) -{ - mPadding = padding; -} - -/* inherits documentation from base class */ -double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - // The rect may be rotated, so we transform the actual clicked pos to the rotated - // coordinate system, so we can use the normal rectSelectTest function for non-rotated rects: - QPointF positionPixels(position->pixelPoint()); - QTransform inputTransform; - inputTransform.translate(positionPixels.x(), positionPixels.y()); - inputTransform.rotate(-mRotation); - inputTransform.translate(-positionPixels.x(), -positionPixels.y()); - QPointF rotatedPos = inputTransform.map(pos); - QFontMetrics fontMetrics(mFont); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); - textBoxRect.moveTopLeft(textPos.toPoint()); - - return rectSelectTest(textBoxRect, rotatedPos, true); -} - -/* inherits documentation from base class */ -void QCPItemText::draw(QCPPainter *painter) -{ - QPointF pos(position->pixelPoint()); - QTransform transform = painter->transform(); - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - painter->setFont(mainFont()); - QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); - textBoxRect.moveTopLeft(textPos.toPoint()); - double clipPad = mainPen().widthF(); - QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) - { - painter->setTransform(transform); - if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || - (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(textBoxRect); - } - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(mainColor())); - painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); - } -} - -/* inherits documentation from base class */ -QPointF QCPItemText::anchorPixelPoint(int anchorId) const -{ - // get actual rect points (pretty much copied from draw function): - QPointF pos(position->pixelPoint()); - QTransform transform; - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - QFontMetrics fontMetrics(mainFont()); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textBoxRect.moveTopLeft(textPos.toPoint()); - QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); - - switch (anchorId) - { - case aiTopLeft: return rectPoly.at(0); - case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; - case aiTopRight: return rectPoly.at(1); - case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; - case aiBottomRight: return rectPoly.at(2); - case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; - case aiBottomLeft: return rectPoly.at(3); - case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the point that must be given to the QPainter::drawText function (which expects the top - left point of the text rect), according to the position \a pos, the text bounding box \a rect and - the requested \a positionAlignment. - - For example, if \a positionAlignment is <tt>Qt::AlignLeft | Qt::AlignBottom</tt> the returned point - will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally - drawn at that point, the lower left corner of the resulting text rect is at \a pos. -*/ -QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const -{ - if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) - return pos; - - QPointF result = pos; // start at top left - if (positionAlignment.testFlag(Qt::AlignHCenter)) - result.rx() -= rect.width()/2.0; - else if (positionAlignment.testFlag(Qt::AlignRight)) - result.rx() -= rect.width(); - if (positionAlignment.testFlag(Qt::AlignVCenter)) - result.ry() -= rect.height()/2.0; - else if (positionAlignment.testFlag(Qt::AlignBottom)) - result.ry() -= rect.height(); - return result; -} - -/*! \internal - - Returns the font that should be used for drawing text. Returns mFont when the item is not selected - and mSelectedFont when it is. -*/ -QFont QCPItemText::mainFont() const -{ - return mSelected ? mSelectedFont : mFont; -} - -/*! \internal - - Returns the color that should be used for drawing text. Returns mColor when the item is not - selected and mSelectedColor when it is. -*/ -QColor QCPItemText::mainColor() const -{ - return mSelected ? mSelectedColor : mColor; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemText::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemText::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemEllipse -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemEllipse - \brief An ellipse - - \image html QCPItemEllipse.png "Ellipse example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rect the ellipse will be drawn in. -*/ - -/*! - Creates an ellipse item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition("topLeft")), - bottomRight(createPosition("bottomRight")), - topLeftRim(createAnchor("topLeftRim", aiTopLeftRim)), - top(createAnchor("top", aiTop)), - topRightRim(createAnchor("topRightRim", aiTopRightRim)), - right(createAnchor("right", aiRight)), - bottomRightRim(createAnchor("bottomRightRim", aiBottomRightRim)), - bottom(createAnchor("bottom", aiBottom)), - bottomLeftRim(createAnchor("bottomLeftRim", aiBottomLeftRim)), - left(createAnchor("left", aiLeft)), - center(createAnchor("center", aiCenter)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); -} - -QCPItemEllipse::~QCPItemEllipse() -{ -} - -/*! - Sets the pen that will be used to draw the line of the ellipse - - \see setSelectedPen, setBrush -*/ -void QCPItemEllipse::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the ellipse when selected - - \see setPen, setSelected -*/ -void QCPItemEllipse::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to fill the ellipse. To disable filling, set \a brush to - Qt::NoBrush. - - \see setSelectedBrush, setPen -*/ -void QCPItemEllipse::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to fill the ellipse when selected. To disable filling, set \a - brush to Qt::NoBrush. - - \see setBrush -*/ -void QCPItemEllipse::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/* inherits documentation from base class */ -double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - double result = -1; - QPointF p1 = topLeft->pixelPoint(); - QPointF p2 = bottomRight->pixelPoint(); - QPointF center((p1+p2)/2.0); - double a = qAbs(p1.x()-p2.x())/2.0; - double b = qAbs(p1.y()-p2.y())/2.0; - double x = pos.x()-center.x(); - double y = pos.y()-center.y(); - - // distance to border: - double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); - result = qAbs(c-1)*qSqrt(x*x+y*y); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (x*x/(a*a) + y*y/(b*b) <= 1) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; -} - -/* inherits documentation from base class */ -void QCPItemEllipse::draw(QCPPainter *painter) -{ - QPointF p1 = topLeft->pixelPoint(); - QPointF p2 = bottomRight->pixelPoint(); - if (p1.toPoint() == p2.toPoint()) - return; - QRectF ellipseRect = QRectF(p1, p2).normalized(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect - { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); -#ifdef __EXCEPTIONS - try // drawEllipse sometimes throws exceptions if ellipse is too big - { -#endif - painter->drawEllipse(ellipseRect); -#ifdef __EXCEPTIONS - } catch (...) - { - qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; - setVisible(false); - } -#endif - } -} - -/* inherits documentation from base class */ -QPointF QCPItemEllipse::anchorPixelPoint(int anchorId) const -{ - QRectF rect = QRectF(topLeft->pixelPoint(), bottomRight->pixelPoint()); - switch (anchorId) - { - case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemEllipse::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemEllipse::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemPixmap -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemPixmap - \brief An arbitrary pixmap - - \image html QCPItemPixmap.png "Pixmap example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a topLeft and \a bottomRight, which define the rectangle the pixmap will - be drawn in. Depending on the scale setting (\ref setScaled), the pixmap will be either scaled to - fit the rectangle or be drawn aligned to the topLeft position. - - If scaling is enabled and \a topLeft is further to the bottom/right than \a bottomRight (as shown - on the right side of the example image), the pixmap will be flipped in the respective - orientations. -*/ - -/*! - Creates a rectangle item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition("topLeft")), - bottomRight(createPosition("bottomRight")), - top(createAnchor("top", aiTop)), - topRight(createAnchor("topRight", aiTopRight)), - right(createAnchor("right", aiRight)), - bottom(createAnchor("bottom", aiBottom)), - bottomLeft(createAnchor("bottomLeft", aiBottomLeft)), - left(createAnchor("left", aiLeft)) -{ - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(Qt::NoPen); - setSelectedPen(QPen(Qt::blue)); - setScaled(false, Qt::KeepAspectRatio); -} - -QCPItemPixmap::~QCPItemPixmap() -{ -} - -/*! - Sets the pixmap that will be displayed. -*/ -void QCPItemPixmap::setPixmap(const QPixmap &pixmap) -{ - mPixmap = pixmap; - if (mPixmap.isNull()) - qDebug() << Q_FUNC_INFO << "pixmap is null"; -} - -/*! - Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a - bottomRight positions. -*/ -void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode) -{ - mScaled = scaled; - mAspectRatioMode = aspectRatioMode; - updateScaledPixmap(); -} - -/*! - Sets the pen that will be used to draw a border around the pixmap. - - \see setSelectedPen, setBrush -*/ -void QCPItemPixmap::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw a border around the pixmap when selected - - \see setPen, setSelected -*/ -void QCPItemPixmap::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/* inherits documentation from base class */ -double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - return rectSelectTest(getFinalRect(), pos, true); -} - -/* inherits documentation from base class */ -void QCPItemPixmap::draw(QCPPainter *painter) -{ - bool flipHorz = false; - bool flipVert = false; - QRect rect = getFinalRect(&flipHorz, &flipVert); - double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); - QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) - { - updateScaledPixmap(rect, flipHorz, flipVert); - painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); - QPen pen = mainPen(); - if (pen.style() != Qt::NoPen) - { - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawRect(rect); - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemPixmap::anchorPixelPoint(int anchorId) const -{ - bool flipHorz; - bool flipVert; - QRect rect = getFinalRect(&flipHorz, &flipVert); - // we actually want denormal rects (negative width/height) here, so restore - // the flipped state: - if (flipHorz) - rect.adjust(rect.width(), 0, -rect.width(), 0); - if (flipVert) - rect.adjust(0, rect.height(), 0, -rect.height()); - - switch (anchorId) - { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; - } - - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Creates the buffered scaled image (\a mScaledPixmap) to fit the specified \a finalRect. The - parameters \a flipHorz and \a flipVert control whether the resulting image shall be flipped - horizontally or vertically. (This is used when \a topLeft is further to the bottom/right than \a - bottomRight.) - - This function only creates the scaled pixmap when the buffered pixmap has a different size than - the expected result, so calling this function repeatedly, e.g. in the \ref draw function, does - not cause expensive rescaling every time. - - If scaling is disabled, sets mScaledPixmap to a null QPixmap. -*/ -void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) -{ - if (mPixmap.isNull()) - return; - - if (mScaled) - { - if (finalRect.isNull()) - finalRect = getFinalRect(&flipHorz, &flipVert); - if (finalRect.size() != mScaledPixmap.size()) - { - mScaledPixmap = mPixmap.scaled(finalRect.size(), mAspectRatioMode, Qt::SmoothTransformation); - if (flipHorz || flipVert) - mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); - } - } else if (!mScaledPixmap.isNull()) - mScaledPixmap = QPixmap(); -} - -/*! \internal - - Returns the final (tight) rect the pixmap is drawn in, depending on the current item positions - and scaling settings. - - The output parameters \a flippedHorz and \a flippedVert return whether the pixmap should be drawn - flipped horizontally or vertically in the returned rect. (The returned rect itself is always - normalized, i.e. the top left corner of the rect is actually further to the top/left than the - bottom right corner). This is the case when the item position \a topLeft is further to the - bottom/right than \a bottomRight. - - If scaling is disabled, returns a rect with size of the original pixmap and the top left corner - aligned with the item position \a topLeft. The position \a bottomRight is ignored. -*/ -QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const -{ - QRect result; - bool flipHorz = false; - bool flipVert = false; - QPoint p1 = topLeft->pixelPoint().toPoint(); - QPoint p2 = bottomRight->pixelPoint().toPoint(); - if (p1 == p2) - return QRect(p1, QSize(0, 0)); - if (mScaled) - { - QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); - QPoint topLeft = p1; - if (newSize.width() < 0) - { - flipHorz = true; - newSize.rwidth() *= -1; - topLeft.setX(p2.x()); - } - if (newSize.height() < 0) - { - flipVert = true; - newSize.rheight() *= -1; - topLeft.setY(p2.y()); - } - QSize scaledSize = mPixmap.size(); - scaledSize.scale(newSize, mAspectRatioMode); - result = QRect(topLeft, scaledSize); - } else - { - result = QRect(p1, mPixmap.size()); - } - if (flippedHorz) - *flippedHorz = flipHorz; - if (flippedVert) - *flippedVert = flipVert; - return result; -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemPixmap::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemTracer -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemTracer - \brief Item that sticks to QCPGraph data points - - \image html QCPItemTracer.png "Tracer example. Blue dotted circles are anchors, solid blue discs are positions." - - The tracer can be connected with a QCPGraph via \ref setGraph. Then it will automatically adopt - the coordinate axes of the graph and update its \a position to be on the graph's data. This means - the key stays controllable via \ref setGraphKey, but the value will follow the graph data. If a - QCPGraph is connected, note that setting the coordinates of the tracer item directly via \a - position will have no effect because they will be overriden in the next redraw (this is when the - coordinate update happens). - - If the specified key in \ref setGraphKey is outside the key bounds of the graph, the tracer will - stay at the corresponding end of the graph. - - With \ref setInterpolating you may specify whether the tracer may only stay exactly on data - points or whether it interpolates data points linearly, if given a key that lies between two data - points of the graph. - - The tracer has different visual styles, see \ref setStyle. It is also possible to make the tracer - have no own visual appearance (set the style to \ref tsNone), and just connect other item - positions to the tracer \a position (used as an anchor) via \ref - QCPItemPosition::setParentAnchor. - - \note The tracer position is only automatically updated upon redraws. So when the data of the - graph changes and immediately afterwards (without a redraw) the a position coordinates of the - tracer are retrieved, they will not reflect the updated data of the graph. In this case \ref - updatePosition must be called manually, prior to reading the tracer coordinates. -*/ - -/*! - Creates a tracer item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition("position")), - mGraph(0) -{ - position->setCoords(0, 0); - - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setStyle(tsCrosshair); - setSize(6); - setInterpolating(false); - setGraphKey(0); -} - -QCPItemTracer::~QCPItemTracer() -{ -} - -/*! - Sets the pen that will be used to draw the line of the tracer - - \see setSelectedPen, setBrush -*/ -void QCPItemTracer::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the line of the tracer when selected - - \see setPen, setSelected -*/ -void QCPItemTracer::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer - - \see setSelectedBrush, setPen -*/ -void QCPItemTracer::setBrush(const QBrush &brush) -{ - mBrush = brush; -} - -/*! - Sets the brush that will be used to draw any fills of the tracer, when selected. - - \see setBrush, setSelected -*/ -void QCPItemTracer::setSelectedBrush(const QBrush &brush) -{ - mSelectedBrush = brush; -} - -/*! - Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare - does, \ref tsCrosshair does not). -*/ -void QCPItemTracer::setSize(double size) -{ - mSize = size; -} - -/*! - Sets the style/visual appearance of the tracer. - - If you only want to use the tracer \a position as an anchor for other items, set \a style to - \ref tsNone. -*/ -void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) -{ - mStyle = style; -} - -/*! - Sets the QCPGraph this tracer sticks to. The tracer \a position will be set to type - QCPItemPosition::ptPlotCoords and the axes will be set to the axes of \a graph. - - To free the tracer from any graph, set \a graph to 0. The tracer \a position can then be placed - freely like any other item position. This is the state the tracer will assume when its graph gets - deleted while still attached to it. - - \see setGraphKey -*/ -void QCPItemTracer::setGraph(QCPGraph *graph) -{ - if (graph) - { - if (graph->parentPlot() == mParentPlot) - { - position->setType(QCPItemPosition::ptPlotCoords); - position->setAxes(graph->keyAxis(), graph->valueAxis()); - mGraph = graph; - updatePosition(); - } else - qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; - } else - { - mGraph = 0; - } -} - -/*! - Sets the key of the graph's data point the tracer will be positioned at. This is the only free - coordinate of a tracer when attached to a graph. - - Depending on \ref setInterpolating, the tracer will be either positioned on the data point - closest to \a key, or will stay exactly at \a key and interpolate the value linearly. - - \see setGraph, setInterpolating -*/ -void QCPItemTracer::setGraphKey(double key) -{ - mGraphKey = key; -} - -/*! - Sets whether the value of the graph's data points shall be interpolated, when positioning the - tracer. - - If \a enabled is set to false and a key is given with \ref setGraphKey, the tracer is placed on - the data point of the graph which is closest to the key, but which is not necessarily exactly - there. If \a enabled is true, the tracer will be positioned exactly at the specified key, and - the appropriate value will be interpolated from the graph's data points linearly. - - \see setGraph, setGraphKey -*/ -void QCPItemTracer::setInterpolating(bool enabled) -{ - mInterpolating = enabled; -} - -/* inherits documentation from base class */ -double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QPointF center(position->pixelPoint()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return -1; - case tsPlus: - { - if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - return qSqrt(qMin(distSqrToLine(center+QPointF(-w, 0), center+QPointF(w, 0), pos), - distSqrToLine(center+QPointF(0, -w), center+QPointF(0, w), pos))); - break; - } - case tsCrosshair: - { - return qSqrt(qMin(distSqrToLine(QPointF(clip.left(), center.y()), QPointF(clip.right(), center.y()), pos), - distSqrToLine(QPointF(center.x(), clip.top()), QPointF(center.x(), clip.bottom()), pos))); - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - // distance to border: - double centerDist = QVector2D(center-pos).length(); - double circleLine = w; - double result = qAbs(centerDist-circleLine); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (centerDist <= circleLine) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; - } - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectSelectTest(rect, pos, filledRect); - } - break; - } - } - return -1; -} - -/* inherits documentation from base class */ -void QCPItemTracer::draw(QCPPainter *painter) -{ - updatePosition(); - if (mStyle == tsNone) - return; - - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - QPointF center(position->pixelPoint()); - double w = mSize/2.0; - QRect clip = clipRect(); - switch (mStyle) - { - case tsNone: return; - case tsPlus: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); - painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); - } - break; - } - case tsCrosshair: - { - if (center.y() > clip.top() && center.y() < clip.bottom()) - painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); - if (center.x() > clip.left() && center.x() < clip.right()) - painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); - break; - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawEllipse(center, w, w); - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); - break; - } - } -} - -/*! - If the tracer is connected with a graph (\ref setGraph), this function updates the tracer's \a - position to reside on the graph data, depending on the configured key (\ref setGraphKey). - - It is called automatically on every redraw and normally doesn't need to be called manually. One - exception is when you want to read the tracer coordinates via \a position and are not sure that - the graph's data (or the tracer key with \ref setGraphKey) hasn't changed since the last redraw. - In that situation, call this function before accessing \a position, to make sure you don't get - out-of-date coordinates. - - If there is no graph set on this tracer, this function does nothing. -*/ -void QCPItemTracer::updatePosition() -{ - if (mGraph) - { - if (mParentPlot->hasPlottable(mGraph)) - { - if (mGraph->data()->size() > 1) - { - QCPDataMap::const_iterator first = mGraph->data()->constBegin(); - QCPDataMap::const_iterator last = mGraph->data()->constEnd()-1; - if (mGraphKey < first.key()) - position->setCoords(first.key(), first.value().value); - else if (mGraphKey > last.key()) - position->setCoords(last.key(), last.value().value); - else - { - QCPDataMap::const_iterator it = mGraph->data()->lowerBound(mGraphKey); - if (it != first) // mGraphKey is somewhere between iterators - { - QCPDataMap::const_iterator prevIt = it-1; - if (mInterpolating) - { - // interpolate between iterators around mGraphKey: - double slope = 0; - if (!qFuzzyCompare((double)it.key(), (double)prevIt.key())) - slope = (it.value().value-prevIt.value().value)/(it.key()-prevIt.key()); - position->setCoords(mGraphKey, (mGraphKey-prevIt.key())*slope+prevIt.value().value); - } else - { - // find iterator with key closest to mGraphKey: - if (mGraphKey < (prevIt.key()+it.key())*0.5) - it = prevIt; - position->setCoords(it.key(), it.value().value); - } - } else // mGraphKey is exactly on first iterator - position->setCoords(it.key(), it.value().value); - } - } else if (mGraph->data()->size() == 1) - { - QCPDataMap::const_iterator it = mGraph->data()->constBegin(); - position->setCoords(it.key(), it.value().value); - } else - qDebug() << Q_FUNC_INFO << "graph has no data"; - } else - qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; - } -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the item is not selected - and mSelectedPen when it is. -*/ -QPen QCPItemTracer::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - -/*! \internal - - Returns the brush that should be used for drawing fills of the item. Returns mBrush when the item - is not selected and mSelectedBrush when it is. -*/ -QBrush QCPItemTracer::mainBrush() const -{ - return mSelected ? mSelectedBrush : mBrush; -} - - -//////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////// QCPItemBracket -//////////////////////////////////////////////////////////////////////////////////////////////////// - -/*! \class QCPItemBracket - \brief A bracket for referencing/highlighting certain parts in the plot. - - \image html QCPItemBracket.png "Bracket example. Blue dotted circles are anchors, solid blue discs are positions." - - It has two positions, \a left and \a right, which define the span of the bracket. If \a left is - actually farther to the left than \a right, the bracket is opened to the bottom, as shown in the - example image. - - The bracket supports multiple styles via \ref setStyle. The length, i.e. how far the bracket - stretches away from the embraced span, can be controlled with \ref setLength. - - \image html QCPItemBracket-length.png - <center>Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.</center> - - It provides an anchor \a center, to allow connection of other items, e.g. an arrow (QCPItemLine - or QCPItemCurve) or a text label (QCPItemText), to the bracket. -*/ - -/*! - Creates a bracket item and sets default values. - - The constructed item can be added to the plot with QCustomPlot::addItem. -*/ -QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - left(createPosition("left")), - right(createPosition("right")), - center(createAnchor("center", aiCenter)) -{ - left->setCoords(0, 0); - right->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setLength(8); - setStyle(bsCalligraphic); -} - -QCPItemBracket::~QCPItemBracket() -{ -} - -/*! - Sets the pen that will be used to draw the bracket. - - Note that when the style is \ref bsCalligraphic, only the color will be taken from the pen, the - stroke and width are ignored. To change the apparent stroke width of a calligraphic bracket, use - \ref setLength, which has a similar effect. - - \see setSelectedPen -*/ -void QCPItemBracket::setPen(const QPen &pen) -{ - mPen = pen; -} - -/*! - Sets the pen that will be used to draw the bracket when selected - - \see setPen, setSelected -*/ -void QCPItemBracket::setSelectedPen(const QPen &pen) -{ - mSelectedPen = pen; -} - -/*! - Sets the \a length in pixels how far the bracket extends in the direction towards the embraced - span of the bracket (i.e. perpendicular to the <i>left</i>-<i>right</i>-direction) - - \image html QCPItemBracket-length.png - <center>Demonstrating the effect of different values for \ref setLength, for styles \ref - bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.</center> -*/ -void QCPItemBracket::setLength(double length) -{ - mLength = length; -} - -/*! - Sets the style of the bracket, i.e. the shape/visual appearance. - - \see setPen -*/ -void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) -{ - mStyle = style; -} - -/* inherits documentation from base class */ -double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const -{ - Q_UNUSED(details) - if (onlySelectable && !mSelectable) - return -1; - - QVector2D leftVec(left->pixelPoint()); - QVector2D rightVec(right->pixelPoint()); - if (leftVec.toPoint() == rightVec.toPoint()) - return -1; - - QVector2D widthVec = (rightVec-leftVec)*0.5f; - QVector2D lengthVec(-widthVec.y(), widthVec.x()); - lengthVec = lengthVec.normalized()*mLength; - QVector2D centerVec = (rightVec+leftVec)*0.5f-lengthVec; - - return qSqrt(distSqrToLine((centerVec-widthVec).toPointF(), (centerVec+widthVec).toPointF(), pos)); -} - -/* inherits documentation from base class */ -void QCPItemBracket::draw(QCPPainter *painter) -{ - QVector2D leftVec(left->pixelPoint()); - QVector2D rightVec(right->pixelPoint()); - if (leftVec.toPoint() == rightVec.toPoint()) - return; - - QVector2D widthVec = (rightVec-leftVec)*0.5f; - QVector2D lengthVec(-widthVec.y(), widthVec.x()); - lengthVec = lengthVec.normalized()*mLength; - QVector2D centerVec = (rightVec+leftVec)*0.5f-lengthVec; - - QPolygon boundingPoly; - boundingPoly << leftVec.toPoint() << rightVec.toPoint() - << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (clip.intersects(boundingPoly.boundingRect())) - { - painter->setPen(mainPen()); - switch (mStyle) - { - case bsSquare: - { - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - break; - } - case bsRound: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCurly: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec-lengthVec*0.8f).toPointF(), (centerVec+0.4f*widthVec+lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4f*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8f).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCalligraphic: - { - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(mainPen().color())); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec+widthVec-lengthVec*0.8f).toPointF(), (centerVec+0.4f*widthVec+0.8f*lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4f*widthVec+0.8f*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8f).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec-widthVec-lengthVec*0.5f).toPointF(), (centerVec-0.2f*widthVec+1.2f*lengthVec).toPointF(), (centerVec+lengthVec*0.2f).toPointF()); - path.cubicTo((centerVec+0.2f*widthVec+1.2f*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5f).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - - painter->drawPath(path); - break; - } - } - } -} - -/* inherits documentation from base class */ -QPointF QCPItemBracket::anchorPixelPoint(int anchorId) const -{ - QVector2D leftVec(left->pixelPoint()); - QVector2D rightVec(right->pixelPoint()); - if (leftVec.toPoint() == rightVec.toPoint()) - return leftVec.toPointF(); - - QVector2D widthVec = (rightVec-leftVec)*0.5f; - QVector2D lengthVec(-widthVec.y(), widthVec.x()); - lengthVec = lengthVec.normalized()*mLength; - QVector2D centerVec = (rightVec+leftVec)*0.5f-lengthVec; - - switch (anchorId) - { - case aiCenter: - return centerVec.toPointF(); - } - qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; - return QPointF(); -} - -/*! \internal - - Returns the pen that should be used for drawing lines. Returns mPen when the - item is not selected and mSelectedPen when it is. -*/ -QPen QCPItemBracket::mainPen() const -{ - return mSelected ? mSelectedPen : mPen; -} - diff --git a/SAS/Scheduler/src/qcustomplot.h b/SAS/Scheduler/src/qcustomplot.h deleted file mode 100644 index 2ec78b02666f524b84c126606532d4eff0b141d9..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/qcustomplot.h +++ /dev/null @@ -1,3529 +0,0 @@ -/*************************************************************************** -** ** -** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer ** -** ** -** This program is free software: you can redistribute it and/or modify ** -** it under the terms of the GNU General Public License as published by ** -** the Free Software Foundation, either version 3 of the License, or ** -** (at your option) any later version. ** -** ** -** This program is distributed in the hope that it will be useful, ** -** but WITHOUT ANY WARRANTY; without even the implied warranty of ** -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** -** GNU General Public License for more details. ** -** ** -** You should have received a copy of the GNU General Public License ** -** along with this program. If not, see http://www.gnu.org/licenses/. ** -** ** -**************************************************************************** -** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 07.04.14 ** -** Version: 1.2.1 ** -****************************************************************************/ - -#ifndef QCUSTOMPLOT_H -#define QCUSTOMPLOT_H - -#include <QObject> -#include <QPointer> -#include <QWidget> -#include <QPainter> -#include <QPaintEvent> -#include <QMouseEvent> -#include <QPixmap> -#include <QVector> -#include <QString> -#include <QDateTime> -#include <QMultiMap> -#include <QFlags> -#include <QDebug> -#include <QVector2D> -#include <QStack> -#include <QCache> -#include <QMargins> -#include <qmath.h> -#include <limits> -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# include <qnumeric.h> -# include <QPrinter> -# include <QPrintEngine> -#else -# include <QtNumeric> -# include <QtPrintSupport> -#endif - -class QCPPainter; -class QCustomPlot; -class QCPLayerable; -class QCPLayoutElement; -class QCPLayout; -class QCPAxis; -class QCPAxisRect; -class QCPAxisPainterPrivate; -class QCPAbstractPlottable; -class QCPGraph; -class QCPAbstractItem; -class QCPItemPosition; -class QCPLayer; -class QCPPlotTitle; -class QCPLegend; -class QCPAbstractLegendItem; -class QCPColorMap; -class QCPColorScale; - - -/*! \file */ - - -// decl definitions for shared library compilation/usage: -#if defined(QCUSTOMPLOT_COMPILE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_EXPORT -#elif defined(QCUSTOMPLOT_USE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_IMPORT -#else -# define QCP_LIB_DECL -#endif - -/*! - The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library -*/ -namespace QCP -{ -/*! - Defines the sides of a rectangular entity to which margins can be applied. - - \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins -*/ -enum MarginSide { msLeft = 0x01 ///< <tt>0x01</tt> left margin - ,msRight = 0x02 ///< <tt>0x02</tt> right margin - ,msTop = 0x04 ///< <tt>0x04</tt> top margin - ,msBottom = 0x08 ///< <tt>0x08</tt> bottom margin - ,msAll = 0xFF ///< <tt>0xFF</tt> all margins - ,msNone = 0x00 ///< <tt>0x00</tt> no margin - }; -Q_DECLARE_FLAGS(MarginSides, MarginSide) - -/*! - Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is - neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective - element how it is drawn. Typically it provides a \a setAntialiased function for this. - - \c AntialiasedElements is a flag of or-combined elements of this enum type. - - \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements -*/ -enum AntialiasedElement { aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks - ,aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines - ,aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines - ,aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box - ,aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items - ,aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see element \ref aeErrorBars) - ,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items - ,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) - ,aeErrorBars = 0x0100 ///< <tt>0x0100</tt> Error bars - ,aeFills = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs) - ,aeZeroLine = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen - ,aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements - ,aeNone = 0x0000 ///< <tt>0x0000</tt> No elements - }; -Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement) - -/*! - Defines plotting hints that control various aspects of the quality and speed of plotting. - - \see QCustomPlot::setPlottingHints -*/ -enum PlottingHint { phNone = 0x000 ///< <tt>0x000</tt> No hints are set - ,phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality - ///< especially of the line segment joins. (Only relevant for solid line pens.) - ,phForceRepaint = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint. - ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). - ,phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance. - }; -Q_DECLARE_FLAGS(PlottingHints, PlottingHint) - -/*! - Defines the mouse interactions possible with QCustomPlot. - - \c Interactions is a flag of or-combined elements of this enum type. - - \see QCustomPlot::setInteractions -*/ -enum Interaction { iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) - ,iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) - ,iMultiSelect = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking - ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) - ,iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) - ,iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts) - ,iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) - ,iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...) - }; -Q_DECLARE_FLAGS(Interactions, Interaction) - -/*! \internal - - Returns whether the specified \a value is considered an invalid data value for plottables (i.e. - is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the - compiler flag \c QCUSTOMPLOT_CHECK_DATA is set. -*/ -inline bool isInvalidData(double value) -{ - return qIsNaN(value) || qIsInf(value); -} - -/*! \internal - \overload - - Checks two arguments instead of one. -*/ -inline bool isInvalidData(double value1, double value2) -{ - return isInvalidData(value1) || isInvalidData(value2); -} - -/*! \internal - - Sets the specified \a side of \a margins to \a value - - \see getMarginValue -*/ -inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) -{ - switch (side) - { - case QCP::msLeft: margins.setLeft(value); break; - case QCP::msRight: margins.setRight(value); break; - case QCP::msTop: margins.setTop(value); break; - case QCP::msBottom: margins.setBottom(value); break; - case QCP::msAll: margins = QMargins(value, value, value, value); break; - default: break; - } -} - -/*! \internal - - Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or - \ref QCP::msAll, returns 0. - - \see setMarginValue -*/ -inline int getMarginValue(const QMargins &margins, QCP::MarginSide side) -{ - switch (side) - { - case QCP::msLeft: return margins.left(); - case QCP::msRight: return margins.right(); - case QCP::msTop: return margins.top(); - case QCP::msBottom: return margins.bottom(); - default: break; - } - return 0; -} - -} // end of namespace QCP - -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) - - -class QCP_LIB_DECL QCPScatterStyle -{ - Q_GADGET -public: - /*! - Defines the shape used for scatter points. - - On plottables/items that draw scatters, the sizes of these visualizations (with exception of - \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are - drawn with the pen and brush specified with \ref setPen and \ref setBrush. - */ - Q_ENUMS(ScatterShape) - enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) - ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) - ,ssCross ///< \enumimage{ssCross.png} a cross - ,ssPlus ///< \enumimage{ssPlus.png} a plus - ,ssCircle ///< \enumimage{ssCircle.png} a circle - ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) - ,ssSquare ///< \enumimage{ssSquare.png} a square - ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond - ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus - ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline - ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner - ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside - ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside - ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside - ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside - ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines - ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates - ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) - }; - - QCPScatterStyle(); - QCPScatterStyle(ScatterShape shape, double size=6); - QCPScatterStyle(ScatterShape shape, const QColor &color, double size); - QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size); - QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size); - QCPScatterStyle(const QPixmap &pixmap); - QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6); - - // getters: - double size() const { return mSize; } - ScatterShape shape() const { return mShape; } - QPen pen() const { return mPen; } - QBrush brush() const { return mBrush; } - QPixmap pixmap() const { return mPixmap; } - QPainterPath customPath() const { return mCustomPath; } - - // setters: - void setSize(double size); - void setShape(ScatterShape shape); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setPixmap(const QPixmap &pixmap); - void setCustomPath(const QPainterPath &customPath); - - // non-property methods: - bool isNone() const { return mShape == ssNone; } - bool isPenDefined() const { return mPenDefined; } - void applyTo(QCPPainter *painter, const QPen &defaultPen) const; - void drawShape(QCPPainter *painter, QPointF pos) const; - void drawShape(QCPPainter *painter, double x, double y) const; - -protected: - // property members: - double mSize; - ScatterShape mShape; - QPen mPen; - QBrush mBrush; - QPixmap mPixmap; - QPainterPath mCustomPath; - - // non-property members: - bool mPenDefined; -}; -Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE); - - -class QCP_LIB_DECL QCPPainter : public QPainter -{ - Q_GADGET -public: - /*! - Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, - depending on whether they are wanted on the respective output device. - */ - enum PainterMode { pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices - ,pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. - ,pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels - ,pmNonCosmetic = 0x04 ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.) - }; - Q_FLAGS(PainterMode PainterModes) - Q_DECLARE_FLAGS(PainterModes, PainterMode) - - QCPPainter(); - QCPPainter(QPaintDevice *device); - ~QCPPainter(); - - // getters: - bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); } - PainterModes modes() const { return mModes; } - - // setters: - void setAntialiasing(bool enabled); - void setMode(PainterMode mode, bool enabled=true); - void setModes(PainterModes modes); - - // methods hiding non-virtual base class functions (QPainter bug workarounds): - bool begin(QPaintDevice *device); - void setPen(const QPen &pen); - void setPen(const QColor &color); - void setPen(Qt::PenStyle penStyle); - void drawLine(const QLineF &line); - void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));} - void save(); - void restore(); - - // non-virtual methods: - void makeNonCosmetic(); - -protected: - // property members: - PainterModes mModes; - bool mIsAntialiasing; - - // non-property members: - QStack<bool> mAntialiasingStack; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes) - - -class QCP_LIB_DECL QCPLayer : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QString name READ name) - Q_PROPERTY(int index READ index) - Q_PROPERTY(QList<QCPLayerable*> children READ children) - Q_PROPERTY(bool visible READ visible WRITE setVisible) - /// \endcond -public: - QCPLayer(QCustomPlot* parentPlot, const QString &layerName); - ~QCPLayer(); - - // getters: - QCustomPlot *parentPlot() const { return mParentPlot; } - QString name() const { return mName; } - int index() const { return mIndex; } - QList<QCPLayerable*> children() const { return mChildren; } - bool visible() const { return mVisible; } - - // setters: - void setVisible(bool visible); - -protected: - // property members: - QCustomPlot *mParentPlot; - QString mName; - int mIndex; - QList<QCPLayerable*> mChildren; - bool mVisible; - - // non-virtual methods: - void addChild(QCPLayerable *layerable, bool prepend); - void removeChild(QCPLayerable *layerable); - -private: - Q_DISABLE_COPY(QCPLayer) - - friend class QCustomPlot; - friend class QCPLayerable; -}; - -class QCP_LIB_DECL QCPLayerable : public QObject -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable) - Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged) - Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased) - /// \endcond -public: - QCPLayerable(QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0); - ~QCPLayerable(); - - // getters: - bool visible() const { return mVisible; } - QCustomPlot *parentPlot() const { return mParentPlot; } - QCPLayerable *parentLayerable() const { return mParentLayerable.data(); } - QCPLayer *layer() const { return mLayer; } - bool antialiased() const { return mAntialiased; } - - // setters: - void setVisible(bool on); - Q_SLOT bool setLayer(QCPLayer *layer); - bool setLayer(const QString &layerName); - void setAntialiased(bool enabled); - - // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-property methods: - bool realVisibility() const; - -signals: - void layerChanged(QCPLayer *newLayer); - -protected: - // property members: - bool mVisible; - QCustomPlot *mParentPlot; - QPointer<QCPLayerable> mParentLayerable; - QCPLayer *mLayer; - bool mAntialiased; - - // introduced virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot); - virtual QCP::Interaction selectionCategory() const; - virtual QRect clipRect() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0; - virtual void draw(QCPPainter *painter) = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - - // non-property methods: - void initializeParentPlot(QCustomPlot *parentPlot); - void setParentLayerable(QCPLayerable* parentLayerable); - bool moveToLayer(QCPLayer *layer, bool prepend); - void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const; - -private: - Q_DISABLE_COPY(QCPLayerable) - - friend class QCustomPlot; - friend class QCPAxisRect; -}; - - -class QCP_LIB_DECL QCPRange -{ -public: - double lower, upper; - - QCPRange(); - QCPRange(double lower, double upper); - - bool operator==(const QCPRange& other) { return lower == other.lower && upper == other.upper; } - bool operator!=(const QCPRange& other) { return !(*this == other); } - - QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; } - QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; } - QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; } - QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; } - friend inline const QCPRange operator+(const QCPRange&, double); - friend inline const QCPRange operator+(double, const QCPRange&); - friend inline const QCPRange operator-(const QCPRange& range, double value); - friend inline const QCPRange operator*(const QCPRange& range, double value); - friend inline const QCPRange operator*(double value, const QCPRange& range); - friend inline const QCPRange operator/(const QCPRange& range, double value); - - double size() const; - double center() const; - void normalize(); - void expand(const QCPRange &otherRange); - QCPRange expanded(const QCPRange &otherRange) const; - QCPRange sanitizedForLogScale() const; - QCPRange sanitizedForLinScale() const; - bool contains(double value) const; - - static bool validRange(double lower, double upper); - static bool validRange(const QCPRange &range); - static const double minRange; //1e-280; - static const double maxRange; //1e280; - -}; -Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE); - -/* documentation of inline functions */ - -/*! \fn QCPRange &QCPRange::operator+=(const double& value) - - Adds \a value to both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator-=(const double& value) - - Subtracts \a value from both boundaries of the range. -*/ - -/*! \fn QCPRange &QCPRange::operator*=(const double& value) - - Multiplies both boundaries of the range by \a value. -*/ - -/*! \fn QCPRange &QCPRange::operator/=(const double& value) - - Divides both boundaries of the range by \a value. -*/ - -/* end documentation of inline functions */ - -/*! - Adds \a value to both boundaries of the range. -*/ -inline const QCPRange operator+(const QCPRange& range, double value) -{ - QCPRange result(range); - result += value; - return result; -} - -/*! - Adds \a value to both boundaries of the range. -*/ -inline const QCPRange operator+(double value, const QCPRange& range) -{ - QCPRange result(range); - result += value; - return result; -} - -/*! - Subtracts \a value from both boundaries of the range. -*/ -inline const QCPRange operator-(const QCPRange& range, double value) -{ - QCPRange result(range); - result -= value; - return result; -} - -/*! - Multiplies both boundaries of the range by \a value. -*/ -inline const QCPRange operator*(const QCPRange& range, double value) -{ - QCPRange result(range); - result *= value; - return result; -} - -/*! - Multiplies both boundaries of the range by \a value. -*/ -inline const QCPRange operator*(double value, const QCPRange& range) -{ - QCPRange result(range); - result *= value; - return result; -} - -/*! - Divides both boundaries of the range by \a value. -*/ -inline const QCPRange operator/(const QCPRange& range, double value) -{ - QCPRange result(range); - result /= value; - return result; -} - - -class QCP_LIB_DECL QCPMarginGroup : public QObject -{ - Q_OBJECT -public: - QCPMarginGroup(QCustomPlot *parentPlot); - ~QCPMarginGroup(); - - // non-virtual methods: - QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); } - bool isEmpty() const; - void clear(); - -protected: - // non-property members: - QCustomPlot *mParentPlot; - QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren; - - // non-virtual methods: - int commonMargin(QCP::MarginSide side) const; - void addChild(QCP::MarginSide side, QCPLayoutElement *element); - void removeChild(QCP::MarginSide side, QCPLayoutElement *element); - -private: - Q_DISABLE_COPY(QCPMarginGroup) - - friend class QCPLayoutElement; -}; - - -class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLayout* layout READ layout) - Q_PROPERTY(QRect rect READ rect) - Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect) - Q_PROPERTY(QMargins margins READ margins WRITE setMargins) - Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) - Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) - Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) - /// \endcond -public: - /*! - Defines the phases of the update process, that happens just before a replot. At each phase, - \ref update is called with the according UpdatePhase value. - */ - enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout - ,upMargins ///< Phase in which the margins are calculated and set - ,upLayout ///< Final phase in which the layout system places the rects of the elements - }; - Q_ENUMS(UpdatePhase) - - explicit QCPLayoutElement(QCustomPlot *parentPlot=0); - virtual ~QCPLayoutElement(); - - // getters: - QCPLayout *layout() const { return mParentLayout; } - QRect rect() const { return mRect; } - QRect outerRect() const { return mOuterRect; } - QMargins margins() const { return mMargins; } - QMargins minimumMargins() const { return mMinimumMargins; } - QCP::MarginSides autoMargins() const { return mAutoMargins; } - QSize minimumSize() const { return mMinimumSize; } - QSize maximumSize() const { return mMaximumSize; } - QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); } - QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; } - - // setters: - void setOuterRect(const QRect &rect); - void setMargins(const QMargins &margins); - void setMinimumMargins(const QMargins &margins); - void setAutoMargins(QCP::MarginSides sides); - void setMinimumSize(const QSize &size); - void setMinimumSize(int width, int height); - void setMaximumSize(const QSize &size); - void setMaximumSize(int width, int height); - void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group); - - // introduced virtual methods: - virtual void update(UpdatePhase phase); - virtual QSize minimumSizeHint() const; - virtual QSize maximumSizeHint() const; - virtual QList<QCPLayoutElement*> elements(bool recursive) const; - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -protected: - // property members: - QCPLayout *mParentLayout; - QSize mMinimumSize, mMaximumSize; - QRect mRect, mOuterRect; - QMargins mMargins, mMinimumMargins; - QCP::MarginSides mAutoMargins; - QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups; - - // introduced virtual methods: - virtual int calculateAutoMargin(QCP::MarginSide side); - // events: - virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)} - virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)} - virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)} - virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)} - virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)} - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) } - virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) } - virtual void parentPlotInitialized(QCustomPlot *parentPlot); - -private: - Q_DISABLE_COPY(QCPLayoutElement) - - friend class QCustomPlot; - friend class QCPLayout; - friend class QCPMarginGroup; -}; - - -class QCP_LIB_DECL QCPLayout : public QCPLayoutElement -{ - Q_OBJECT -public: - explicit QCPLayout(); - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase); - virtual QList<QCPLayoutElement*> elements(bool recursive) const; - - // introduced virtual methods: - virtual int elementCount() const = 0; - virtual QCPLayoutElement* elementAt(int index) const = 0; - virtual QCPLayoutElement* takeAt(int index) = 0; - virtual bool take(QCPLayoutElement* element) = 0; - virtual void simplify(); - - // non-virtual methods: - bool removeAt(int index); - bool remove(QCPLayoutElement* element); - void clear(); - -protected: - // introduced virtual methods: - virtual void updateLayout(); - - // non-virtual methods: - void sizeConstraintsChanged() const; - void adoptElement(QCPLayoutElement *el); - void releaseElement(QCPLayoutElement *el); - QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const; - -private: - Q_DISABLE_COPY(QCPLayout) - friend class QCPLayoutElement; -}; - - -class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(int rowCount READ rowCount) - Q_PROPERTY(int columnCount READ columnCount) - Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors) - Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - /// \endcond -public: - explicit QCPLayoutGrid(); - virtual ~QCPLayoutGrid(); - - // getters: - int rowCount() const; - int columnCount() const; - QList<double> columnStretchFactors() const { return mColumnStretchFactors; } - QList<double> rowStretchFactors() const { return mRowStretchFactors; } - int columnSpacing() const { return mColumnSpacing; } - int rowSpacing() const { return mRowSpacing; } - - // setters: - void setColumnStretchFactor(int column, double factor); - void setColumnStretchFactors(const QList<double> &factors); - void setRowStretchFactor(int row, double factor); - void setRowStretchFactors(const QList<double> &factors); - void setColumnSpacing(int pixels); - void setRowSpacing(int pixels); - - // reimplemented virtual methods: - virtual void updateLayout(); - virtual int elementCount() const; - virtual QCPLayoutElement* elementAt(int index) const; - virtual QCPLayoutElement* takeAt(int index); - virtual bool take(QCPLayoutElement* element); - virtual QList<QCPLayoutElement*> elements(bool recursive) const; - virtual void simplify(); - virtual QSize minimumSizeHint() const; - virtual QSize maximumSizeHint() const; - - // non-virtual methods: - QCPLayoutElement *element(int row, int column) const; - bool addElement(int row, int column, QCPLayoutElement *element); - bool hasElement(int row, int column); - void expandTo(int newRowCount, int newColumnCount); - void insertRow(int newIndex); - void insertColumn(int newIndex); - -protected: - // property members: - QList<QList<QCPLayoutElement*> > mElements; - QList<double> mColumnStretchFactors; - QList<double> mRowStretchFactors; - int mColumnSpacing, mRowSpacing; - - // non-virtual methods: - void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const; - void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const; - -private: - Q_DISABLE_COPY(QCPLayoutGrid) -}; - - -class QCP_LIB_DECL QCPLayoutInset : public QCPLayout -{ - Q_OBJECT -public: - /*! - Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset. - */ - enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect - ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment - }; - - explicit QCPLayoutInset(); - virtual ~QCPLayoutInset(); - - // getters: - InsetPlacement insetPlacement(int index) const; - Qt::Alignment insetAlignment(int index) const; - QRectF insetRect(int index) const; - - // setters: - void setInsetPlacement(int index, InsetPlacement placement); - void setInsetAlignment(int index, Qt::Alignment alignment); - void setInsetRect(int index, const QRectF &rect); - - // reimplemented virtual methods: - virtual void updateLayout(); - virtual int elementCount() const; - virtual QCPLayoutElement* elementAt(int index) const; - virtual QCPLayoutElement* takeAt(int index); - virtual bool take(QCPLayoutElement* element); - virtual void simplify() {} - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-virtual methods: - void addElement(QCPLayoutElement *element, Qt::Alignment alignment); - void addElement(QCPLayoutElement *element, const QRectF &rect); - -protected: - // property members: - QList<QCPLayoutElement*> mElements; - QList<InsetPlacement> mInsetPlacement; - QList<Qt::Alignment> mInsetAlignment; - QList<QRectF> mInsetRect; - -private: - Q_DISABLE_COPY(QCPLayoutInset) -}; - - -class QCP_LIB_DECL QCPLineEnding -{ - Q_GADGET -public: - /*! - Defines the type of ending decoration for line-like items, e.g. an arrow. - - \image html QCPLineEnding.png - - The width and length of these decorations can be controlled with the functions \ref setWidth - and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only - support a width, the length property is ignored. - - \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding - */ - Q_ENUMS(EndingStyle) - enum EndingStyle { esNone ///< No ending decoration - ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) - ,esSpikeArrow ///< A filled arrow head with an indented back - ,esLineArrow ///< A non-filled arrow head with open back - ,esDisc ///< A filled circle - ,esSquare ///< A filled square - ,esDiamond ///< A filled diamond (45° rotated square) - ,esBar ///< A bar perpendicular to the line - ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) - ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) - }; - - QCPLineEnding(); - QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false); - - // getters: - EndingStyle style() const { return mStyle; } - double width() const { return mWidth; } - double length() const { return mLength; } - bool inverted() const { return mInverted; } - - // setters: - void setStyle(EndingStyle style); - void setWidth(double width); - void setLength(double length); - void setInverted(bool inverted); - - // non-property methods: - double boundingDistance() const; - double realLength() const; - void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const; - void draw(QCPPainter *painter, const QVector2D &pos, double angle) const; - -protected: - // property members: - EndingStyle mStyle; - double mWidth, mLength; - bool mInverted; -}; -Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE); - - -class QCP_LIB_DECL QCPGrid :public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible) - Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid) - Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen) - Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen) - /// \endcond -public: - QCPGrid(QCPAxis *parentAxis); - - // getters: - bool subGridVisible() const { return mSubGridVisible; } - bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } - bool antialiasedZeroLine() const { return mAntialiasedZeroLine; } - QPen pen() const { return mPen; } - QPen subGridPen() const { return mSubGridPen; } - QPen zeroLinePen() const { return mZeroLinePen; } - - // setters: - void setSubGridVisible(bool visible); - void setAntialiasedSubGrid(bool enabled); - void setAntialiasedZeroLine(bool enabled); - void setPen(const QPen &pen); - void setSubGridPen(const QPen &pen); - void setZeroLinePen(const QPen &pen); - -protected: - // property members: - bool mSubGridVisible; - bool mAntialiasedSubGrid, mAntialiasedZeroLine; - QPen mPen, mSubGridPen, mZeroLinePen; - // non-property members: - QCPAxis *mParentAxis; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual void draw(QCPPainter *painter); - - // non-virtual methods: - void drawGridLines(QCPPainter *painter) const; - void drawSubGridLines(QCPPainter *painter) const; - - friend class QCPAxis; -}; - - -class QCP_LIB_DECL QCPAxis : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(AxisType axisType READ axisType) - Q_PROPERTY(QCPAxisRect* axisRect READ axisRect) - Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged) - Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase) - Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged) - Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed) - Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks) - Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount) - Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels) - Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep) - Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks) - Q_PROPERTY(bool ticks READ ticks WRITE setTicks) - Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels) - Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding) - Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType) - Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont) - Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor) - Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation) - Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat) - Q_PROPERTY(Qt::TimeSpec dateTimeSpec READ dateTimeSpec WRITE setDateTimeSpec) - Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat) - Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision) - Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep) - Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector) - Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels) - Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn) - Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut) - Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount) - Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn) - Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut) - Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen) - Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen) - Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen) - Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) - Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding) - Q_PROPERTY(int padding READ padding WRITE setPadding) - Q_PROPERTY(int offset READ offset WRITE setOffset) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged) - Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont) - Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont) - Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor) - Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor) - Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen) - Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen) - Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen) - Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding) - Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding) - Q_PROPERTY(QCPGrid* grid READ grid) - /// \endcond -public: - /*! - Defines at which side of the axis rect the axis will appear. This also affects how the tick - marks are drawn, on which side the labels are placed etc. - */ - enum AxisType { atLeft = 0x01 ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect - ,atRight = 0x02 ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect - ,atTop = 0x04 ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect - ,atBottom = 0x08 ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect - }; - Q_FLAGS(AxisType AxisTypes) - Q_DECLARE_FLAGS(AxisTypes, AxisType) - /*! - When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the - coordinate of the tick is interpreted, i.e. translated into a string. - - \see setTickLabelType - */ - enum LabelType { ltNumber ///< Tick coordinate is regarded as normal number and will be displayed as such. (see \ref setNumberFormat) - ,ltDateTime ///< Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC) and will be displayed and formatted as such. (for details, see \ref setDateTimeFormat) - }; - Q_ENUMS(LabelType) - /*! - Defines the scale of an axis. - \see setScaleType - */ - enum ScaleType { stLinear ///< Linear scaling - ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see \ref setScaleLogBase). - }; - Q_ENUMS(ScaleType) - /*! - Defines the selectable parts of an axis. - \see setSelectableParts, setSelectedParts - */ - enum SelectablePart { spNone = 0 ///< None of the selectable parts - ,spAxis = 0x001 ///< The axis backbone and tick marks - ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) - ,spAxisLabel = 0x004 ///< The axis label - }; - Q_FLAGS(SelectablePart SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPAxis(QCPAxisRect *parent, AxisType type); - virtual ~QCPAxis(); - - // getters: - AxisType axisType() const { return mAxisType; } - QCPAxisRect *axisRect() const { return mAxisRect; } - ScaleType scaleType() const { return mScaleType; } - double scaleLogBase() const { return mScaleLogBase; } - const QCPRange range() const { return mRange; } - bool rangeReversed() const { return mRangeReversed; } - bool autoTicks() const { return mAutoTicks; } - int autoTickCount() const { return mAutoTickCount; } - bool autoTickLabels() const { return mAutoTickLabels; } - bool autoTickStep() const { return mAutoTickStep; } - bool autoSubTicks() const { return mAutoSubTicks; } - bool ticks() const { return mTicks; } - bool tickLabels() const { return mTickLabels; } - int tickLabelPadding() const; - LabelType tickLabelType() const { return mTickLabelType; } - QFont tickLabelFont() const { return mTickLabelFont; } - QColor tickLabelColor() const { return mTickLabelColor; } - double tickLabelRotation() const; - QString dateTimeFormat() const { return mDateTimeFormat; } - Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } - QString numberFormat() const; - int numberPrecision() const { return mNumberPrecision; } - double tickStep() const { return mTickStep; } - QVector<double> tickVector() const { return mTickVector; } - QVector<QString> tickVectorLabels() const { return mTickVectorLabels; } - int tickLengthIn() const; - int tickLengthOut() const; - int subTickCount() const { return mSubTickCount; } - int subTickLengthIn() const; - int subTickLengthOut() const; - QPen basePen() const { return mBasePen; } - QPen tickPen() const { return mTickPen; } - QPen subTickPen() const { return mSubTickPen; } - QFont labelFont() const { return mLabelFont; } - QColor labelColor() const { return mLabelColor; } - QString label() const { return mLabel; } - int labelPadding() const; - int padding() const { return mPadding; } - int offset() const; - SelectableParts selectedParts() const { return mSelectedParts; } - SelectableParts selectableParts() const { return mSelectableParts; } - QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; } - QFont selectedLabelFont() const { return mSelectedLabelFont; } - QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; } - QColor selectedLabelColor() const { return mSelectedLabelColor; } - QPen selectedBasePen() const { return mSelectedBasePen; } - QPen selectedTickPen() const { return mSelectedTickPen; } - QPen selectedSubTickPen() const { return mSelectedSubTickPen; } - QCPLineEnding lowerEnding() const; - QCPLineEnding upperEnding() const; - QCPGrid *grid() const { return mGrid; } - - // setters: - Q_SLOT void setScaleType(QCPAxis::ScaleType type); - void setScaleLogBase(double base); - Q_SLOT void setRange(const QCPRange &range); - void setRange(double lower, double upper); - void setRange(double position, double size, Qt::AlignmentFlag alignment); - void setRangeLower(double lower); - void setRangeUpper(double upper); - void setRangeReversed(bool reversed); - void setAutoTicks(bool on); - void setAutoTickCount(int approximateCount); - void setAutoTickLabels(bool on); - void setAutoTickStep(bool on); - void setAutoSubTicks(bool on); - void setTicks(bool show); - void setTickLabels(bool show); - void setTickLabelPadding(int padding); - void setTickLabelType(LabelType type); - void setTickLabelFont(const QFont &font); - void setTickLabelColor(const QColor &color); - void setTickLabelRotation(double degrees); - void setDateTimeFormat(const QString &format); - void setDateTimeSpec(const Qt::TimeSpec &timeSpec); - void setNumberFormat(const QString &formatCode); - void setNumberPrecision(int precision); - void setTickStep(double step); - void setTickVector(const QVector<double> &vec); - void setTickVectorLabels(const QVector<QString> &vec); - void setTickLength(int inside, int outside=0); - void setTickLengthIn(int inside); - void setTickLengthOut(int outside); - void setSubTickCount(int count); - void setSubTickLength(int inside, int outside=0); - void setSubTickLengthIn(int inside); - void setSubTickLengthOut(int outside); - void setBasePen(const QPen &pen); - void setTickPen(const QPen &pen); - void setSubTickPen(const QPen &pen); - void setLabelFont(const QFont &font); - void setLabelColor(const QColor &color); - void setLabel(const QString &str); - void setLabelPadding(int padding); - void setPadding(int padding); - void setOffset(int offset); - void setSelectedTickLabelFont(const QFont &font); - void setSelectedLabelFont(const QFont &font); - void setSelectedTickLabelColor(const QColor &color); - void setSelectedLabelColor(const QColor &color); - void setSelectedBasePen(const QPen &pen); - void setSelectedTickPen(const QPen &pen); - void setSelectedSubTickPen(const QPen &pen); - Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); - void setLowerEnding(const QCPLineEnding &ending); - void setUpperEnding(const QCPLineEnding &ending); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-property methods: - Qt::Orientation orientation() const { return mOrientation; } - void moveRange(double diff); - void scaleRange(double factor, double center); - void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0); - void rescale(bool onlyVisiblePlottables=false); - double pixelToCoord(double value) const; - double coordToPixel(double value) const; - SelectablePart getPartAt(const QPointF &pos) const; - QList<QCPAbstractPlottable*> plottables() const; - QList<QCPGraph*> graphs() const; - QList<QCPAbstractItem*> items() const; - - static AxisType marginSideToAxisType(QCP::MarginSide side); - static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } - static AxisType opposite(AxisType type); - -signals: - void ticksRequest(); - void rangeChanged(const QCPRange &newRange); - void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); - void scaleTypeChanged(QCPAxis::ScaleType scaleType); - void selectionChanged(const QCPAxis::SelectableParts &parts); - void selectableChanged(const QCPAxis::SelectableParts &parts); - -protected: - // property members: - // axis base: - AxisType mAxisType; - QCPAxisRect *mAxisRect; - //int mOffset; // in QCPAxisPainter - int mPadding; - Qt::Orientation mOrientation; - SelectableParts mSelectableParts, mSelectedParts; - QPen mBasePen, mSelectedBasePen; - //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter - // axis label: - //int mLabelPadding; // in QCPAxisPainter - QString mLabel; - QFont mLabelFont, mSelectedLabelFont; - QColor mLabelColor, mSelectedLabelColor; - // tick labels: - //int mTickLabelPadding; // in QCPAxisPainter - bool mTickLabels, mAutoTickLabels; - //double mTickLabelRotation; // in QCPAxisPainter - LabelType mTickLabelType; - QFont mTickLabelFont, mSelectedTickLabelFont; - QColor mTickLabelColor, mSelectedTickLabelColor; - QString mDateTimeFormat; - Qt::TimeSpec mDateTimeSpec; - int mNumberPrecision; - char mNumberFormatChar; - bool mNumberBeautifulPowers; - //bool mNumberMultiplyCross; // QCPAxisPainter - // ticks and subticks: - bool mTicks; - double mTickStep; - int mSubTickCount, mAutoTickCount; - bool mAutoTicks, mAutoTickStep, mAutoSubTicks; - //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter - QPen mTickPen, mSelectedTickPen; - QPen mSubTickPen, mSelectedSubTickPen; - // scale and range: - QCPRange mRange; - bool mRangeReversed; - ScaleType mScaleType; - double mScaleLogBase, mScaleLogBaseLogInv; - - // non-property members: - QCPGrid *mGrid; - QCPAxisPainterPrivate *mAxisPainter; - int mLowestVisibleTick, mHighestVisibleTick; - QVector<double> mTickVector; - QVector<QString> mTickVectorLabels; - QVector<double> mSubTickVector; - bool mCachedMarginValid; - int mCachedMargin; - - // introduced virtual methods: - virtual void setupTickVectors(); - virtual void generateAutoTicks(); - virtual int calculateAutoSubTickCount(double tickStep) const; - virtual int calculateMargin(); - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual void draw(QCPPainter *painter); - virtual QCP::Interaction selectionCategory() const; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - - // non-virtual methods: - void visibleTickBounds(int &lowIndex, int &highIndex) const; - double baseLog(double value) const; - double basePow(double value) const; - QPen getBasePen() const; - QPen getTickPen() const; - QPen getSubTickPen() const; - QFont getTickLabelFont() const; - QFont getLabelFont() const; - QColor getTickLabelColor() const; - QColor getLabelColor() const; - -private: - Q_DISABLE_COPY(QCPAxis) - - friend class QCustomPlot; - friend class QCPGrid; - friend class QCPAxisRect; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes) -Q_DECLARE_METATYPE(QCPAxis::SelectablePart) - - -class QCPAxisPainterPrivate -{ -public: - explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot); - virtual ~QCPAxisPainterPrivate(); - - virtual void draw(QCPPainter *painter); - virtual int size() const; - void clearCache(); - - QRect axisSelectionBox() const { return mAxisSelectionBox; } - QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; } - QRect labelSelectionBox() const { return mLabelSelectionBox; } - - // public property members: - QCPAxis::AxisType type; - QPen basePen; - QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters - int labelPadding; // directly accessed by QCPAxis setters/getters - QFont labelFont; - QColor labelColor; - QString label; - int tickLabelPadding; // directly accessed by QCPAxis setters/getters - double tickLabelRotation; // directly accessed by QCPAxis setters/getters - bool substituteExponent; - bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters - int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters - QPen tickPen, subTickPen; - QFont tickLabelFont; - QColor tickLabelColor; - QRect alignmentRect, viewportRect; - double offset; // directly accessed by QCPAxis setters/getters - bool abbreviateDecimalPowers; - bool reversedEndings; - - QVector<double> subTickPositions; - QVector<double> tickPositions; - QVector<QString> tickLabels; - -protected: - struct CachedLabel - { - QPointF offset; - QPixmap pixmap; - }; - struct TickLabelData - { - QString basePart, expPart; - QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds; - QFont baseFont, expFont; - }; - QCustomPlot *mParentPlot; - QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters - QCache<QString, CachedLabel> mLabelCache; - QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox; - - virtual QByteArray generateLabelParameterHash() const; - - virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize); - virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const; - virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const; - virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const; - virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; -}; - - -class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill) - Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters) - Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis) - Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis); - - // getters: - QString name() const { return mName; } - bool antialiasedFill() const { return mAntialiasedFill; } - bool antialiasedScatters() const { return mAntialiasedScatters; } - bool antialiasedErrorBars() const { return mAntialiasedErrorBars; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setName(const QString &name); - void setAntialiasedFill(bool enabled); - void setAntialiasedScatters(bool enabled); - void setAntialiasedErrorBars(bool enabled); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setKeyAxis(QCPAxis *axis); - void setValueAxis(QCPAxis *axis); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // introduced virtual methods: - virtual void clearData() = 0; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0; - virtual bool addToLegend(); - virtual bool removeFromLegend() const; - - // non-property methods: - void rescaleAxes(bool onlyEnlarge=false) const; - void rescaleKeyAxis(bool onlyEnlarge=false) const; - void rescaleValueAxis(bool onlyEnlarge=false) const; - -signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - /*! - Represents negative and positive sign domain for passing to \ref getKeyRange and \ref getValueRange. - */ - enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero - ,sdBoth ///< Both sign domains, including zero, i.e. all (rational) numbers - ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero - }; - - // property members: - QString mName; - bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars; - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - QPointer<QCPAxis> mKeyAxis, mValueAxis; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QRect clipRect() const; - virtual void draw(QCPPainter *painter) = 0; - virtual QCP::Interaction selectionCategory() const; - void applyDefaultAntialiasingHint(QCPPainter *painter) const; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - - // introduced virtual methods: - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0; - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0; - - // non-virtual methods: - void coordsToPixels(double key, double value, double &x, double &y) const; - const QPointF coordsToPixels(double key, double value) const; - void pixelsToCoords(double x, double y, double &key, double &value) const; - void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const; - QPen mainPen() const; - QBrush mainBrush() const; - void applyFillAntialiasingHint(QCPPainter *painter) const; - void applyScattersAntialiasingHint(QCPPainter *painter) const; - void applyErrorBarsAntialiasingHint(QCPPainter *painter) const; - double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const; - -private: - Q_DISABLE_COPY(QCPAbstractPlottable) - - friend class QCustomPlot; - friend class QCPAxis; - friend class QCPPlottableLegendItem; -}; - - -class QCP_LIB_DECL QCPItemAnchor -{ -public: - QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1); - virtual ~QCPItemAnchor(); - - // getters: - QString name() const { return mName; } - virtual QPointF pixelPoint() const; - -protected: - // property members: - QString mName; - - // non-property members: - QCustomPlot *mParentPlot; - QCPAbstractItem *mParentItem; - int mAnchorId; - QSet<QCPItemPosition*> mChildren; - - // introduced virtual methods: - virtual QCPItemPosition *toQCPItemPosition() { return 0; } - - // non-virtual methods: - void addChild(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChild(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - -private: - Q_DISABLE_COPY(QCPItemAnchor) - - friend class QCPItemPosition; -}; - - - -class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor -{ -public: - /*! - Defines the ways an item position can be specified. Thus it defines what the numbers passed to - \ref setCoords actually mean. - - \see setType - */ - enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. - ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the viewport/widget, etc. - ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. - ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). - }; - - QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name); - virtual ~QCPItemPosition(); - - // getters: - PositionType type() const { return mPositionType; } - QCPItemAnchor *parentAnchor() const { return mParentAnchor; } - double key() const { return mKey; } - double value() const { return mValue; } - QPointF coords() const { return QPointF(mKey, mValue); } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - QCPAxisRect *axisRect() const; - virtual QPointF pixelPoint() const; - - // setters: - void setType(PositionType type); - bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - void setCoords(double key, double value); - void setCoords(const QPointF &coords); - void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); - void setAxisRect(QCPAxisRect *axisRect); - void setPixelPoint(const QPointF &pixelPoint); - -protected: - // property members: - PositionType mPositionType; - QPointer<QCPAxis> mKeyAxis, mValueAxis; - QPointer<QCPAxisRect> mAxisRect; - double mKey, mValue; - QCPItemAnchor *mParentAnchor; - - // reimplemented virtual methods: - virtual QCPItemPosition *toQCPItemPosition() { return this; } - -private: - Q_DISABLE_COPY(QCPItemPosition) - -}; - - -class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect) - Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - QCPAbstractItem(QCustomPlot *parentPlot); - virtual ~QCPAbstractItem(); - - // getters: - bool clipToAxisRect() const { return mClipToAxisRect; } - QCPAxisRect *clipAxisRect() const; - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setClipToAxisRect(bool clip); - void setClipAxisRect(QCPAxisRect *rect); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0; - - // non-virtual methods: - QList<QCPItemPosition*> positions() const { return mPositions; } - QList<QCPItemAnchor*> anchors() const { return mAnchors; } - QCPItemPosition *position(const QString &name) const; - QCPItemAnchor *anchor(const QString &name) const; - bool hasAnchor(const QString &name) const; - -signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - bool mClipToAxisRect; - QPointer<QCPAxisRect> mClipAxisRect; - QList<QCPItemPosition*> mPositions; - QList<QCPItemAnchor*> mAnchors; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QCP::Interaction selectionCategory() const; - virtual QRect clipRect() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual void draw(QCPPainter *painter) = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - - // introduced virtual methods: - virtual QPointF anchorPixelPoint(int anchorId) const; - - // non-virtual methods: - double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const; - double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const; - QCPItemPosition *createPosition(const QString &name); - QCPItemAnchor *createAnchor(const QString &name, int anchorId); - -private: - Q_DISABLE_COPY(QCPAbstractItem) - - friend class QCustomPlot; - friend class QCPItemAnchor; -}; - - -class QCP_LIB_DECL QCustomPlot : public QWidget -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QRect viewport READ viewport WRITE setViewport) - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout) - Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend) - Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance) - Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag) - Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier) - /// \endcond -public: - /*! - Defines how a layer should be inserted relative to an other layer. - - \see addLayer, moveLayer - */ - enum LayerInsertMode { limBelow ///< Layer is inserted below other layer - ,limAbove ///< Layer is inserted above other layer - }; - Q_ENUMS(LayerInsertMode) - - /*! - Defines with what timing the QCustomPlot surface is refreshed after a replot. - - \see replot - */ - enum RefreshPriority { rpImmediate ///< The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot - ,rpQueued ///< Queues the refresh such that it is performed at a slightly delayed point in time after the replot, by calling QWidget::update() after the replot - ,rpHint ///< Whether to use immediate repaint or queued update depends on whether the plotting hint \ref QCP::phForceRepaint is set, see \ref setPlottingHints. - }; - - explicit QCustomPlot(QWidget *parent = 0); - virtual ~QCustomPlot(); - - // getters: - QRect viewport() const { return mViewport; } - QPixmap background() const { return mBackgroundPixmap; } - bool backgroundScaled() const { return mBackgroundScaled; } - Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - QCPLayoutGrid *plotLayout() const { return mPlotLayout; } - QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; } - QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; } - bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; } - const QCP::Interactions interactions() const { return mInteractions; } - int selectionTolerance() const { return mSelectionTolerance; } - bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; } - QCP::PlottingHints plottingHints() const { return mPlottingHints; } - Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; } - - // setters: - void setViewport(const QRect &rect); - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements); - void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true); - void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements); - void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true); - void setAutoAddPlottableToLegend(bool on); - void setInteractions(const QCP::Interactions &interactions); - void setInteraction(const QCP::Interaction &interaction, bool enabled=true); - void setSelectionTolerance(int pixels); - void setNoAntialiasingOnDrag(bool enabled); - void setPlottingHints(const QCP::PlottingHints &hints); - void setPlottingHint(QCP::PlottingHint hint, bool enabled=true); - void setMultiSelectModifier(Qt::KeyboardModifier modifier); - - // non-property methods: - // plottable interface: - QCPAbstractPlottable *plottable(int index); - QCPAbstractPlottable *plottable(); - bool addPlottable(QCPAbstractPlottable *plottable); - bool removePlottable(QCPAbstractPlottable *plottable); - bool removePlottable(int index); - int clearPlottables(); - int plottableCount() const; - QList<QCPAbstractPlottable*> selectedPlottables() const; - QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasPlottable(QCPAbstractPlottable *plottable) const; - - // specialized interface for QCPGraph: - QCPGraph *graph(int index) const; - QCPGraph *graph() const; - QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); - bool removeGraph(QCPGraph *graph); - bool removeGraph(int index); - int clearGraphs(); - int graphCount() const; - QList<QCPGraph*> selectedGraphs() const; - - // item interface: - QCPAbstractItem *item(int index) const; - QCPAbstractItem *item() const; - bool addItem(QCPAbstractItem* item); - bool removeItem(QCPAbstractItem *item); - bool removeItem(int index); - int clearItems(); - int itemCount() const; - QList<QCPAbstractItem*> selectedItems() const; - QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasItem(QCPAbstractItem *item) const; - - // layer interface: - QCPLayer *layer(const QString &name) const; - QCPLayer *layer(int index) const; - QCPLayer *currentLayer() const; - bool setCurrentLayer(const QString &name); - bool setCurrentLayer(QCPLayer *layer); - int layerCount() const; - bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove); - bool removeLayer(QCPLayer *layer); - bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove); - - // axis rect/layout interface: - int axisRectCount() const; - QCPAxisRect* axisRect(int index=0) const; - QList<QCPAxisRect*> axisRects() const; - QCPLayoutElement* layoutElementAt(const QPointF &pos) const; - Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); - - QList<QCPAxis*> selectedAxes() const; - QList<QCPLegend*> selectedLegends() const; - Q_SLOT void deselectAll(); - - bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0, const QString &pdfCreator="", const QString &pdfTitle=""); - bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1); - bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1); - bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0); - bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1); - QPixmap toPixmap(int width=0, int height=0, double scale=1.0); - void toPainter(QCPPainter *painter, int width=0, int height=0); - Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpHint); - - QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - QCPLegend *legend; - -signals: - void mouseDoubleClick(QMouseEvent *event); - void mousePress(QMouseEvent *event); - void mouseMove(QMouseEvent *event); - void mouseRelease(QMouseEvent *event); - void mouseWheel(QWheelEvent *event); - - void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event); - void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event); - void itemClick(QCPAbstractItem *item, QMouseEvent *event); - void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event); - void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - void titleClick(QMouseEvent *event, QCPPlotTitle *title); - void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title); - - void selectionChangedByUser(); - void beforeReplot(); - void afterReplot(); - -protected: - // property members: - QRect mViewport; - QCPLayoutGrid *mPlotLayout; - bool mAutoAddPlottableToLegend; - QList<QCPAbstractPlottable*> mPlottables; - QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph - QList<QCPAbstractItem*> mItems; - QList<QCPLayer*> mLayers; - QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements; - QCP::Interactions mInteractions; - int mSelectionTolerance; - bool mNoAntialiasingOnDrag; - QBrush mBackgroundBrush; - QPixmap mBackgroundPixmap; - QPixmap mScaledBackgroundPixmap; - bool mBackgroundScaled; - Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayer *mCurrentLayer; - QCP::PlottingHints mPlottingHints; - Qt::KeyboardModifier mMultiSelectModifier; - - // non-property members: - QPixmap mPaintBuffer; - QPoint mMousePressPos; - QPointer<QCPLayoutElement> mMouseEventElement; - bool mReplotting; - - // reimplemented virtual methods: - virtual QSize minimumSizeHint() const; - virtual QSize sizeHint() const; - virtual void paintEvent(QPaintEvent *event); - virtual void resizeEvent(QResizeEvent *event); - virtual void mouseDoubleClickEvent(QMouseEvent *event); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent *event); - - // introduced virtual methods: - virtual void draw(QCPPainter *painter); - virtual void axisRemoved(QCPAxis *axis); - virtual void legendRemoved(QCPLegend *legend); - - // non-virtual methods: - void updateLayerIndices() const; - QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const; - void drawBackground(QCPPainter *painter); - - friend class QCPLegend; - friend class QCPAxis; - friend class QCPLayer; - friend class QCPAxisRect; -}; - - -class QCP_LIB_DECL QCPColorGradient -{ - Q_GADGET -public: - /*! - Defines the color spaces in which color interpolation between gradient stops can be performed. - - \see setColorInterpolation - */ - enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated - ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) - }; - Q_ENUMS(ColorInterpolation) - - /*! - Defines the available presets that can be loaded with \ref loadPreset. See the documentation - there for an image of the presets. - */ - enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) - ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) - ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) - ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) - ,gpCandy ///< Blue over pink to white - ,gpGeography ///< Colors suitable to represent different elevations on geographical maps - ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) - ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white - ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values - ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) - ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) - ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) - }; - Q_ENUMS(GradientPreset) - - QCPColorGradient(GradientPreset preset=gpCold); - bool operator==(const QCPColorGradient &other) const; - bool operator!=(const QCPColorGradient &other) const { return !(*this == other); } - - // getters: - int levelCount() const { return mLevelCount; } - QMap<double, QColor> colorStops() const { return mColorStops; } - ColorInterpolation colorInterpolation() const { return mColorInterpolation; } - bool periodic() const { return mPeriodic; } - - // setters: - void setLevelCount(int n); - void setColorStops(const QMap<double, QColor> &colorStops); - void setColorStopAt(double position, const QColor &color); - void setColorInterpolation(ColorInterpolation interpolation); - void setPeriodic(bool enabled); - - // non-property methods: - void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - QRgb color(double position, const QCPRange &range, bool logarithmic=false); - void loadPreset(GradientPreset preset); - void clearColorStops(); - QCPColorGradient inverted() const; - -protected: - void updateColorBuffer(); - - // property members: - int mLevelCount; - QMap<double, QColor> mColorStops; - ColorInterpolation mColorInterpolation; - bool mPeriodic; - - // non-property members: - QVector<QRgb> mColorBuffer; - bool mColorBufferInvalidated; -}; - - -class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom) - /// \endcond -public: - explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true); - virtual ~QCPAxisRect(); - - // getters: - QPixmap background() const { return mBackgroundPixmap; } - bool backgroundScaled() const { return mBackgroundScaled; } - Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - Qt::Orientations rangeDrag() const { return mRangeDrag; } - Qt::Orientations rangeZoom() const { return mRangeZoom; } - QCPAxis *rangeDragAxis(Qt::Orientation orientation); - QCPAxis *rangeZoomAxis(Qt::Orientation orientation); - double rangeZoomFactor(Qt::Orientation orientation); - - // setters: - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setRangeDrag(Qt::Orientations orientations); - void setRangeZoom(Qt::Orientations orientations); - void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeZoomFactor(double horizontalFactor, double verticalFactor); - void setRangeZoomFactor(double factor); - - // non-property methods: - int axisCount(QCPAxis::AxisType type) const; - QCPAxis *axis(QCPAxis::AxisType type, int index=0) const; - QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const; - QList<QCPAxis*> axes() const; - QCPAxis *addAxis(QCPAxis::AxisType type); - QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types); - bool removeAxis(QCPAxis *axis); - QCPLayoutInset *insetLayout() const { return mInsetLayout; } - - void setupFullAxesBox(bool connectRanges=false); - QList<QCPAbstractPlottable*> plottables() const; - QList<QCPGraph*> graphs() const; - QList<QCPAbstractItem*> items() const; - - // read-only interface imitating a QRect: - int left() const { return mRect.left(); } - int right() const { return mRect.right(); } - int top() const { return mRect.top(); } - int bottom() const { return mRect.bottom(); } - int width() const { return mRect.width(); } - int height() const { return mRect.height(); } - QSize size() const { return mRect.size(); } - QPoint topLeft() const { return mRect.topLeft(); } - QPoint topRight() const { return mRect.topRight(); } - QPoint bottomLeft() const { return mRect.bottomLeft(); } - QPoint bottomRight() const { return mRect.bottomRight(); } - QPoint center() const { return mRect.center(); } - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase); - virtual QList<QCPLayoutElement*> elements(bool recursive) const; - -protected: - // property members: - QBrush mBackgroundBrush; - QPixmap mBackgroundPixmap; - QPixmap mScaledBackgroundPixmap; - bool mBackgroundScaled; - Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayoutInset *mInsetLayout; - Qt::Orientations mRangeDrag, mRangeZoom; - QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis; - double mRangeZoomFactorHorz, mRangeZoomFactorVert; - // non-property members: - QCPRange mDragStartHorzRange, mDragStartVertRange; - QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; - QPoint mDragStart; - bool mDragging; - QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual void draw(QCPPainter *painter); - virtual int calculateAutoMargin(QCP::MarginSide side); - // events: - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent *event); - - // non-property methods: - void drawBackground(QCPPainter *painter); - void updateAxesOffset(QCPAxis::AxisType type); - -private: - Q_DISABLE_COPY(QCPAxisRect) - - friend class QCustomPlot; -}; - - -class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLegend* parentLegend READ parentLegend) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged) - /// \endcond -public: - explicit QCPAbstractLegendItem(QCPLegend *parent); - - // getters: - QCPLegend *parentLegend() const { return mParentLegend; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - QCPLegend *mParentLegend; - QFont mFont; - QColor mTextColor; - QFont mSelectedFont; - QColor mSelectedTextColor; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual QCP::Interaction selectionCategory() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual QRect clipRect() const; - virtual void draw(QCPPainter *painter) = 0; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - -private: - Q_DISABLE_COPY(QCPAbstractLegendItem) - - friend class QCPLegend; -}; - - -class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem -{ - Q_OBJECT -public: - QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable); - - // getters: - QCPAbstractPlottable *plottable() { return mPlottable; } - -protected: - // property members: - QCPAbstractPlottable *mPlottable; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual QSize minimumSizeHint() const; - - // non-virtual methods: - QPen getIconBorderPen() const; - QColor getTextColor() const; - QFont getFont() const; -}; - - -class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) - Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding) - Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged) - Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen) - Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - /// \endcond -public: - /*! - Defines the selectable parts of a legend - - \see setSelectedParts, setSelectableParts - */ - enum SelectablePart { spNone = 0x000 ///< <tt>0x000</tt> None - ,spLegendBox = 0x001 ///< <tt>0x001</tt> The legend box (frame) - ,spItems = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems) - }; - Q_FLAGS(SelectablePart SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPLegend(); - virtual ~QCPLegend(); - - // getters: - QPen borderPen() const { return mBorderPen; } - QBrush brush() const { return mBrush; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QSize iconSize() const { return mIconSize; } - int iconTextPadding() const { return mIconTextPadding; } - QPen iconBorderPen() const { return mIconBorderPen; } - SelectableParts selectableParts() const { return mSelectableParts; } - SelectableParts selectedParts() const; - QPen selectedBorderPen() const { return mSelectedBorderPen; } - QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; } - QBrush selectedBrush() const { return mSelectedBrush; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - - // setters: - void setBorderPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setIconSize(const QSize &size); - void setIconSize(int width, int height); - void setIconTextPadding(int padding); - void setIconBorderPen(const QPen &pen); - Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); - void setSelectedBorderPen(const QPen &pen); - void setSelectedIconBorderPen(const QPen &pen); - void setSelectedBrush(const QBrush &brush); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-virtual methods: - QCPAbstractLegendItem *item(int index) const; - QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const; - int itemCount() const; - bool hasItem(QCPAbstractLegendItem *item) const; - bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const; - bool addItem(QCPAbstractLegendItem *item); - bool removeItem(int index); - bool removeItem(QCPAbstractLegendItem *item); - void clearItems(); - QList<QCPAbstractLegendItem*> selectedItems() const; - -signals: - void selectionChanged(QCPLegend::SelectableParts parts); - void selectableChanged(QCPLegend::SelectableParts parts); - -protected: - // property members: - QPen mBorderPen, mIconBorderPen; - QBrush mBrush; - QFont mFont; - QColor mTextColor; - QSize mIconSize; - int mIconTextPadding; - SelectableParts mSelectedParts, mSelectableParts; - QPen mSelectedBorderPen, mSelectedIconBorderPen; - QBrush mSelectedBrush; - QFont mSelectedFont; - QColor mSelectedTextColor; - - // reimplemented virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot); - virtual QCP::Interaction selectionCategory() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual void draw(QCPPainter *painter); - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - - // non-virtual methods: - QPen getBorderPen() const; - QBrush getBrush() const; - -private: - Q_DISABLE_COPY(QCPLegend) - - friend class QCustomPlot; - friend class QCPAbstractLegendItem; -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts) -Q_DECLARE_METATYPE(QCPLegend::SelectablePart) - - -class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) - /// \endcond -public: - explicit QCPPlotTitle(QCustomPlot *parentPlot); - explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text); - - // getters: - QString text() const { return mText; } - QFont font() const { return mFont; } - QColor textColor() const { return mTextColor; } - QFont selectedFont() const { return mSelectedFont; } - QColor selectedTextColor() const { return mSelectedTextColor; } - bool selectable() const { return mSelectable; } - bool selected() const { return mSelected; } - - // setters: - void setText(const QString &text); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - -protected: - // property members: - QString mText; - QFont mFont; - QColor mTextColor; - QFont mSelectedFont; - QColor mSelectedTextColor; - QRect mTextBoundingRect; - bool mSelectable, mSelected; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - virtual void draw(QCPPainter *painter); - virtual QSize minimumSizeHint() const; - virtual QSize maximumSizeHint() const; - // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); - - // non-virtual methods: - QFont mainFont() const; - QColor mainTextColor() const; - -private: - Q_DISABLE_COPY(QCPPlotTitle) -}; - - -class QCPColorScaleAxisRectPrivate : public QCPAxisRect -{ - Q_OBJECT -public: - explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale); -protected: - QCPColorScale *mParentColorScale; - QImage mGradientImage; - bool mGradientImageInvalidated; - // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale - using QCPAxisRect::calculateAutoMargin; - using QCPAxisRect::mousePressEvent; - using QCPAxisRect::mouseMoveEvent; - using QCPAxisRect::mouseReleaseEvent; - using QCPAxisRect::wheelEvent; - using QCPAxisRect::update; - virtual void draw(QCPPainter *painter); - void updateGradientImage(); - Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); - Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); - friend class QCPColorScale; -}; - - -class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType) - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth) - Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom) - /// \endcond -public: - explicit QCPColorScale(QCustomPlot *parentPlot); - virtual ~QCPColorScale(); - - // getters: - QCPAxis *axis() const { return mColorAxis.data(); } - QCPAxis::AxisType type() const { return mType; } - QCPRange dataRange() const { return mDataRange; } - QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } - QCPColorGradient gradient() const { return mGradient; } - QString label() const; - int barWidth () const { return mBarWidth; } - bool rangeDrag() const; - bool rangeZoom() const; - - // setters: - void setType(QCPAxis::AxisType type); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setLabel(const QString &str); - void setBarWidth(int width); - void setRangeDrag(bool enabled); - void setRangeZoom(bool enabled); - - // non-property methods: - QList<QCPColorMap*> colorMaps() const; - void rescaleDataRange(bool onlyVisibleMaps); - - // reimplemented virtual methods: - virtual void update(UpdatePhase phase); - -signals: - void dataRangeChanged(QCPRange newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(QCPColorGradient newGradient); - -protected: - // property members: - QCPAxis::AxisType mType; - QCPRange mDataRange; - QCPAxis::ScaleType mDataScaleType; - QCPColorGradient mGradient; - int mBarWidth; - - // non-property members: - QPointer<QCPColorScaleAxisRectPrivate> mAxisRect; - QPointer<QCPAxis> mColorAxis; - - // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const; - // events: - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent *event); - -private: - Q_DISABLE_COPY(QCPColorScale) - - friend class QCPColorScaleAxisRectPrivate; -}; - - -/*! \file */ - - - -class QCP_LIB_DECL QCPData -{ -public: - QCPData(); - QCPData(double key, double value); - double key, value; - double keyErrorPlus, keyErrorMinus; - double valueErrorPlus, valueErrorMinus; -}; -Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE); - -/*! \typedef QCPDataMap - Container for storing QCPData items in a sorted fashion. The key of the map - is the key member of the QCPData instance. - - This is the container in which QCPGraph holds its data. - \see QCPData, QCPGraph::setData -*/ -typedef QMap<double, QCPData> QCPDataMap; -typedef QMapIterator<double, QCPData> QCPDataMapIterator; -typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator; - - -class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType) - Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen) - Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize) - Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol) - Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph) - Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling) - /// \endcond -public: - /*! - Defines how the graph's line is represented visually in the plot. The line is drawn with the - current pen of the graph (\ref setPen). - \see setLineStyle - */ - enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented - ///< with symbols according to the scatter style, see \ref setScatterStyle) - ,lsLine ///< data points are connected by a straight line - ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point - ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point - ,lsStepCenter ///< line is drawn as steps where the step is in between two data points - ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line - }; - Q_ENUMS(LineStyle) - /*! - Defines what kind of error bars are drawn for each data point - */ - enum ErrorType { etNone ///< No error bars are shown - ,etKey ///< Error bars for the key dimension of the data point are shown - ,etValue ///< Error bars for the value dimension of the data point are shown - ,etBoth ///< Error bars for both key and value dimensions of the data point are shown - }; - Q_ENUMS(ErrorType) - - explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPGraph(); - - // getters: - QCPDataMap *data() const { return mData; } - LineStyle lineStyle() const { return mLineStyle; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - ErrorType errorType() const { return mErrorType; } - QPen errorPen() const { return mErrorPen; } - double errorBarSize() const { return mErrorBarSize; } - bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; } - QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); } - bool adaptiveSampling() const { return mAdaptiveSampling; } - - // setters: - void setData(QCPDataMap *data, bool copy=false); - void setData(const QVector<double> &key, const QVector<double> &value); - void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError); - void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus); - void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError); - void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus); - void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError); - void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus); - void setLineStyle(LineStyle ls); - void setScatterStyle(const QCPScatterStyle &style); - void setErrorType(ErrorType errorType); - void setErrorPen(const QPen &pen); - void setErrorBarSize(double size); - void setErrorBarSkipSymbol(bool enabled); - void setChannelFillGraph(QCPGraph *targetGraph); - void setAdaptiveSampling(bool enabled); - - // non-property methods: - void addData(const QCPDataMap &dataMap); - void addData(const QCPData &data); - void addData(double key, double value); - void addData(const QVector<double> &keys, const QVector<double> &values); - void removeDataBefore(double key); - void removeDataAfter(double key); - void removeData(double fromKey, double toKey); - void removeData(double key); - - // reimplemented virtual methods: - virtual void clearData(); - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - using QCPAbstractPlottable::rescaleAxes; - using QCPAbstractPlottable::rescaleKeyAxis; - using QCPAbstractPlottable::rescaleValueAxis; - void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface - void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface - void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface - -protected: - // property members: - QCPDataMap *mData; - QPen mErrorPen; - LineStyle mLineStyle; - QCPScatterStyle mScatterStyle; - ErrorType mErrorType; - double mErrorBarSize; - bool mErrorBarSkipSymbol; - QPointer<QCPGraph> mChannelFillGraph; - bool mAdaptiveSampling; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface - - // introduced virtual methods: - virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const; - virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *scatterData) const; - virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const; - virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const; - - // non-virtual methods: - void getPreparedData(QVector<QCPData> *lineData, QVector<QCPData> *scatterData) const; - void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *scatterData) const; - void getScatterPlotData(QVector<QCPData> *scatterData) const; - void getLinePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; - void getStepLeftPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; - void getStepRightPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; - void getStepCenterPlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; - void getImpulsePlotData(QVector<QPointF> *linePixelData, QVector<QCPData> *scatterData) const; - void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const; - void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper) const; - int countDataInBounds(const QCPDataMap::const_iterator &lower, const QCPDataMap::const_iterator &upper, int maxCount) const; - void addFillBasePoints(QVector<QPointF> *lineData) const; - void removeFillBasePoints(QVector<QPointF> *lineData) const; - QPointF lowerFillBasePoint(double lowerKey) const; - QPointF upperFillBasePoint(double upperKey) const; - const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const; - int findIndexBelowX(const QVector<QPointF> *data, double x) const; - int findIndexAboveX(const QVector<QPointF> *data, double x) const; - int findIndexBelowY(const QVector<QPointF> *data, double y) const; - int findIndexAboveY(const QVector<QPointF> *data, double y) const; - double pointDistance(const QPointF &pixelPoint) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - - -/*! \file */ - - - -class QCP_LIB_DECL QCPCurveData -{ -public: - QCPCurveData(); - QCPCurveData(double t, double key, double value); - double t, key, value; -}; -Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE); - -/*! \typedef QCPCurveDataMap - Container for storing QCPCurveData items in a sorted fashion. The key of the map - is the t member of the QCPCurveData instance. - - This is the container in which QCPCurve holds its data. - \see QCPCurveData, QCPCurve::setData -*/ - -typedef QMap<double, QCPCurveData> QCPCurveDataMap; -typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator; -typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator; - - -class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - /// \endcond -public: - /*! - Defines how the curve's line is represented visually in the plot. The line is drawn with the - current pen of the curve (\ref setPen). - \see setLineStyle - */ - enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters) - ,lsLine ///< Data points are connected with a straight line - }; - explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPCurve(); - - // getters: - QCPCurveDataMap *data() const { return mData; } - QCPScatterStyle scatterStyle() const { return mScatterStyle; } - LineStyle lineStyle() const { return mLineStyle; } - - // setters: - void setData(QCPCurveDataMap *data, bool copy=false); - void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value); - void setData(const QVector<double> &key, const QVector<double> &value); - void setScatterStyle(const QCPScatterStyle &style); - void setLineStyle(LineStyle style); - - // non-property methods: - void addData(const QCPCurveDataMap &dataMap); - void addData(const QCPCurveData &data); - void addData(double t, double key, double value); - void addData(double key, double value); - void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values); - void removeDataBefore(double t); - void removeDataAfter(double t); - void removeData(double fromt, double tot); - void removeData(double t); - - // reimplemented virtual methods: - virtual void clearData(); - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -protected: - // property members: - QCPCurveDataMap *mData; - QCPScatterStyle mScatterStyle; - LineStyle mLineStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - - // introduced virtual methods: - virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const; - - // non-virtual methods: - void getCurveData(QVector<QPointF> *lineData) const; - double pointDistance(const QPointF &pixelPoint) const; - QPointF outsideCoordsToPixels(double key, double value, int region, QRect axisRect) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - - -/*! \file */ - - - -class QCP_LIB_DECL QCPBarData -{ -public: - QCPBarData(); - QCPBarData(double key, double value); - double key, value; -}; -Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE); - -/*! \typedef QCPBarDataMap - Container for storing QCPBarData items in a sorted fashion. The key of the map - is the key member of the QCPBarData instance. - - This is the container in which QCPBars holds its data. - \see QCPBarData, QCPBars::setData -*/ -typedef QMap<double, QCPBarData> QCPBarDataMap; -typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator; -typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator; - - -class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(QCPBars* barBelow READ barBelow) - Q_PROPERTY(QCPBars* barAbove READ barAbove) - /// \endcond -public: - explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPBars(); - - // getters: - double width() const { return mWidth; } - QCPBars *barBelow() const { return mBarBelow.data(); } - QCPBars *barAbove() const { return mBarAbove.data(); } - QCPBarDataMap *data() const { return mData; } - - // setters: - void setWidth(double width); - void setData(QCPBarDataMap *data, bool copy=false); - void setData(const QVector<double> &key, const QVector<double> &value); - - // non-property methods: - void moveBelow(QCPBars *bars); - void moveAbove(QCPBars *bars); - void addData(const QCPBarDataMap &dataMap); - void addData(const QCPBarData &data); - void addData(double key, double value); - void addData(const QVector<double> &keys, const QVector<double> &values); - void removeDataBefore(double key); - void removeDataAfter(double key); - void removeData(double fromKey, double toKey); - void removeData(double key); - - // reimplemented virtual methods: - virtual void clearData(); - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -protected: - // property members: - QCPBarDataMap *mData; - double mWidth; - QPointer<QCPBars> mBarBelow, mBarAbove; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - - // non-virtual methods: - QPolygonF getBarPolygon(double key, double value) const; - double getBaseValue(double key, bool positive) const; - static void connectBars(QCPBars* lower, QCPBars* upper); - - friend class QCustomPlot; - friend class QCPLegend; -}; - - -/*! \file */ - - - -class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double key READ key WRITE setKey) - Q_PROPERTY(double minimum READ minimum WRITE setMinimum) - Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile) - Q_PROPERTY(double median READ median WRITE setMedian) - Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile) - Q_PROPERTY(double maximum READ maximum WRITE setMaximum) - Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers) - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) - Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen) - Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen) - Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen) - Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle) - /// \endcond -public: - explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis); - - // getters: - double key() const { return mKey; } - double minimum() const { return mMinimum; } - double lowerQuartile() const { return mLowerQuartile; } - double median() const { return mMedian; } - double upperQuartile() const { return mUpperQuartile; } - double maximum() const { return mMaximum; } - QVector<double> outliers() const { return mOutliers; } - double width() const { return mWidth; } - double whiskerWidth() const { return mWhiskerWidth; } - QPen whiskerPen() const { return mWhiskerPen; } - QPen whiskerBarPen() const { return mWhiskerBarPen; } - QPen medianPen() const { return mMedianPen; } - QCPScatterStyle outlierStyle() const { return mOutlierStyle; } - - // setters: - void setKey(double key); - void setMinimum(double value); - void setLowerQuartile(double value); - void setMedian(double value); - void setUpperQuartile(double value); - void setMaximum(double value); - void setOutliers(const QVector<double> &values); - void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum); - void setWidth(double width); - void setWhiskerWidth(double width); - void setWhiskerPen(const QPen &pen); - void setWhiskerBarPen(const QPen &pen); - void setMedianPen(const QPen &pen); - void setOutlierStyle(const QCPScatterStyle &style); - - // non-property methods: - virtual void clearData(); - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -protected: - // property members: - QVector<double> mOutliers; - double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum; - double mWidth; - double mWhiskerWidth; - QPen mWhiskerPen, mWhiskerBarPen, mMedianPen; - QCPScatterStyle mOutlierStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - - // introduced virtual methods: - virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const; - virtual void drawMedian(QCPPainter *painter) const; - virtual void drawWhiskers(QCPPainter *painter) const; - virtual void drawOutliers(QCPPainter *painter) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - - -class QCP_LIB_DECL QCPColorMapData -{ -public: - QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange); - ~QCPColorMapData(); - QCPColorMapData(const QCPColorMapData &other); - QCPColorMapData &operator=(const QCPColorMapData &other); - - // getters: - int keySize() const { return mKeySize; } - int valueSize() const { return mValueSize; } - QCPRange keyRange() const { return mKeyRange; } - QCPRange valueRange() const { return mValueRange; } - QCPRange dataBounds() const { return mDataBounds; } - double data(double key, double value); - double cell(int keyIndex, int valueIndex); - - // setters: - void setSize(int keySize, int valueSize); - void setKeySize(int keySize); - void setValueSize(int valueSize); - void setRange(const QCPRange &keyRange, const QCPRange &valueRange); - void setKeyRange(const QCPRange &keyRange); - void setValueRange(const QCPRange &valueRange); - void setData(double key, double value, double z); - void setCell(int keyIndex, int valueIndex, double z); - - // non-property methods: - void recalculateDataBounds(); - void clear(); - void fill(double z); - bool isEmpty() const { return mIsEmpty; } - void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const; - void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const; - -protected: - // property members: - int mKeySize, mValueSize; - QCPRange mKeyRange, mValueRange; - bool mIsEmpty; - // non-property members: - double *mData; - QCPRange mDataBounds; - bool mDataModified; - - friend class QCPColorMap; -}; - - -class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate) - Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary) - Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale) - /// \endcond -public: - explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis); - virtual ~QCPColorMap(); - - // getters: - QCPColorMapData *data() const { return mMapData; } - QCPRange dataRange() const { return mDataRange; } - QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } - bool interpolate() const { return mInterpolate; } - bool tightBoundary() const { return mTightBoundary; } - QCPColorGradient gradient() const { return mGradient; } - QCPColorScale *colorScale() const { return mColorScale.data(); } - - // setters: - void setData(QCPColorMapData *data, bool copy=false); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setInterpolate(bool enabled); - void setTightBoundary(bool enabled); - void setColorScale(QCPColorScale *colorScale); - - // non-property methods: - void rescaleDataRange(bool recalculateDataBounds=false); - Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); - - // reimplemented virtual methods: - virtual void clearData(); - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - -signals: - void dataRangeChanged(QCPRange newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(QCPColorGradient newGradient); - -protected: - // property members: - QCPRange mDataRange; - QCPAxis::ScaleType mDataScaleType; - QCPColorMapData *mMapData; - QCPColorGradient mGradient; - bool mInterpolate; - bool mTightBoundary; - QPointer<QCPColorScale> mColorScale; - // non-property members: - QImage mMapImage; - QPixmap mLegendIcon; - bool mMapImageInvalidated; - - // introduced virtual methods: - virtual void updateMapImage(); - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const; - virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const; - - friend class QCustomPlot; - friend class QCPLegend; -}; - - -class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - /// \endcond -public: - QCPItemStraightLine(QCustomPlot *parentPlot); - virtual ~QCPItemStraightLine(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const point1; - QCPItemPosition * const point2; - -protected: - // property members: - QPen mPen, mSelectedPen; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - - // non-virtual methods: - double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const; - QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const; - QPen mainPen() const; -}; - - -class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) - /// \endcond -public: - QCPItemLine(QCustomPlot *parentPlot); - virtual ~QCPItemLine(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QCPLineEnding head() const { return mHead; } - QCPLineEnding tail() const { return mTail; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const start; - QCPItemPosition * const end; - -protected: - // property members: - QPen mPen, mSelectedPen; - QCPLineEnding mHead, mTail; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - - // non-virtual methods: - QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const; - QPen mainPen() const; -}; - - -class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) - /// \endcond -public: - QCPItemCurve(QCustomPlot *parentPlot); - virtual ~QCPItemCurve(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QCPLineEnding head() const { return mHead; } - QCPLineEnding tail() const { return mTail; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const start; - QCPItemPosition * const startDir; - QCPItemPosition * const endDir; - QCPItemPosition * const end; - -protected: - // property members: - QPen mPen, mSelectedPen; - QCPLineEnding mHead, mTail; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - - // non-virtual methods: - QPen mainPen() const; -}; - - -class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - /// \endcond -public: - QCPItemRect(QCustomPlot *parentPlot); - virtual ~QCPItemRect(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual QPointF anchorPixelPoint(int anchorId) const; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - - -class QCP_LIB_DECL QCPItemText : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment) - Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) - Q_PROPERTY(double rotation READ rotation WRITE setRotation) - Q_PROPERTY(QMargins padding READ padding WRITE setPadding) - /// \endcond -public: - QCPItemText(QCustomPlot *parentPlot); - virtual ~QCPItemText(); - - // getters: - QColor color() const { return mColor; } - QColor selectedColor() const { return mSelectedColor; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - QFont font() const { return mFont; } - QFont selectedFont() const { return mSelectedFont; } - QString text() const { return mText; } - Qt::Alignment positionAlignment() const { return mPositionAlignment; } - Qt::Alignment textAlignment() const { return mTextAlignment; } - double rotation() const { return mRotation; } - QMargins padding() const { return mPadding; } - - // setters; - void setColor(const QColor &color); - void setSelectedColor(const QColor &color); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setFont(const QFont &font); - void setSelectedFont(const QFont &font); - void setText(const QString &text); - void setPositionAlignment(Qt::Alignment alignment); - void setTextAlignment(Qt::Alignment alignment); - void setRotation(double degrees); - void setPadding(const QMargins &padding); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const position; - QCPItemAnchor * const topLeft; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRight; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QColor mColor, mSelectedColor; - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - QFont mFont, mSelectedFont; - QString mText; - Qt::Alignment mPositionAlignment; - Qt::Alignment mTextAlignment; - double mRotation; - QMargins mPadding; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual QPointF anchorPixelPoint(int anchorId) const; - - // non-virtual methods: - QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const; - QFont mainFont() const; - QColor mainColor() const; - QPen mainPen() const; - QBrush mainBrush() const; -}; - - -class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - /// \endcond -public: - QCPItemEllipse(QCustomPlot *parentPlot); - virtual ~QCPItemEllipse(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const topLeftRim; - QCPItemAnchor * const top; - QCPItemAnchor * const topRightRim; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRightRim; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeftRim; - QCPItemAnchor * const left; - QCPItemAnchor * const center; - -protected: - enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter}; - - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual QPointF anchorPixelPoint(int anchorId) const; - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - - -class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) - Q_PROPERTY(bool scaled READ scaled WRITE setScaled) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - /// \endcond -public: - QCPItemPixmap(QCustomPlot *parentPlot); - virtual ~QCPItemPixmap(); - - // getters: - QPixmap pixmap() const { return mPixmap; } - bool scaled() const { return mScaled; } - Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; } - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - - // setters; - void setPixmap(const QPixmap &pixmap); - void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - -protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - - // property members: - QPixmap mPixmap; - QPixmap mScaledPixmap; - bool mScaled; - Qt::AspectRatioMode mAspectRatioMode; - QPen mPen, mSelectedPen; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual QPointF anchorPixelPoint(int anchorId) const; - - // non-virtual methods: - void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); - QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const; - QPen mainPen() const; -}; - - -class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(double size READ size WRITE setSize) - Q_PROPERTY(TracerStyle style READ style WRITE setStyle) - Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph) - Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey) - Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating) - /// \endcond -public: - /*! - The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize. - - \see setStyle - */ - enum TracerStyle { tsNone ///< The tracer is not visible - ,tsPlus ///< A plus shaped crosshair with limited size - ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect - ,tsCircle ///< A circle - ,tsSquare ///< A square - }; - Q_ENUMS(TracerStyle) - - QCPItemTracer(QCustomPlot *parentPlot); - virtual ~QCPItemTracer(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - QBrush brush() const { return mBrush; } - QBrush selectedBrush() const { return mSelectedBrush; } - double size() const { return mSize; } - TracerStyle style() const { return mStyle; } - QCPGraph *graph() const { return mGraph; } - double graphKey() const { return mGraphKey; } - bool interpolating() const { return mInterpolating; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setSize(double size); - void setStyle(TracerStyle style); - void setGraph(QCPGraph *graph); - void setGraphKey(double key); - void setInterpolating(bool enabled); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - // non-virtual methods: - void updatePosition(); - - QCPItemPosition * const position; - -protected: - // property members: - QPen mPen, mSelectedPen; - QBrush mBrush, mSelectedBrush; - double mSize; - TracerStyle mStyle; - QCPGraph *mGraph; - double mGraphKey; - bool mInterpolating; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - - // non-virtual methods: - QPen mainPen() const; - QBrush mainBrush() const; -}; - - -class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem -{ - Q_OBJECT - /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(double length READ length WRITE setLength) - Q_PROPERTY(BracketStyle style READ style WRITE setStyle) - /// \endcond -public: - enum BracketStyle { bsSquare ///< A brace with angled edges - ,bsRound ///< A brace with round edges - ,bsCurly ///< A curly brace - ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression - }; - - QCPItemBracket(QCustomPlot *parentPlot); - virtual ~QCPItemBracket(); - - // getters: - QPen pen() const { return mPen; } - QPen selectedPen() const { return mSelectedPen; } - double length() const { return mLength; } - BracketStyle style() const { return mStyle; } - - // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setLength(double length); - void setStyle(BracketStyle style); - - // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; - - QCPItemPosition * const left; - QCPItemPosition * const right; - QCPItemAnchor * const center; - -protected: - // property members: - enum AnchorIndex {aiCenter}; - QPen mPen, mSelectedPen; - double mLength; - BracketStyle mStyle; - - // reimplemented virtual methods: - virtual void draw(QCPPainter *painter); - virtual QPointF anchorPixelPoint(int anchorId) const; - - // non-virtual methods: - QPen mainPen() const; -}; - -#endif // QCUSTOMPLOT_H - diff --git a/SAS/Scheduler/src/qlofardatamodel.cpp b/SAS/Scheduler/src/qlofardatamodel.cpp deleted file mode 100644 index f37a23841928bf950ed7cac08e783e22ab27e289..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/qlofardatamodel.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* - * qlofardatamodel.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jun 5, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/qlofardatamodel.cpp $ - * - */ - -//#include <vector> -//#include <algorithm> -#include "qlofardatamodel.h" -#include "lofar_scheduler.h" -#include "task.h" - -QLofarDataModel::QLofarDataModel(QObject *parent) -: QStandardItemModel(parent) /*, parentGUI(0) */ -{ -} - -QLofarDataModel::QLofarDataModel(int rows, int columns, QObject *parent/*, SchedulerGUI * gui*/) -: QStandardItemModel(rows, columns, parent) -{ -// parentGUI = gui; -} - -QLofarDataModel::~QLofarDataModel() { -} - -int QLofarDataModel::findTaskRow(unsigned taskID) const { - int nrRows = this->rowCount(QModelIndex()); - for (int row = 0; row <= nrRows; ++row) { - if (this->data(this->index(row,TASK_ID)).toUInt() == taskID) return row; // if this is the row with the right task ID - } - return -1; -} - - -QVariant QLofarDataModel::data(const QModelIndex & index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (role == Qt::BackgroundRole) { - if (isErrorIndex(index)) // error - return QColor(Qt::red); - else { - int task_status = index.model()->data(index.model()->index(index.row(),TASK_STATUS),USERDATA_ROLE).toInt(); - if (task_status == Task::FINISHED) { - return QColor(145,255,145); // this task has finished, should not be editable (greenish background) - } - if (task_status == Task::COMPLETING) { - return QColor(170,170,255); // this task is completing, should not be editable (purple background) - } - else if (task_status == Task::ABORTED) { - return QColor(254,151,39);// 255,173,119); // orange-ish - } - else if (task_status == Task::ACTIVE) { - return QColor(255,255,0); - } - else { - int task_type = index.model()->data(index.model()->index(index.row(),TASK_TYPE),USERDATA_ROLE).toInt(); - if (task_type == Task::RESERVATION) { - return QColor(254,108,108); // for non-editable cells -// switch (static_cast<data_headers>(index.column())) { -// case TASK_ID: -// case SAS_ID: -// case PROJECT_ID: -// case TASK_NAME: -// case TASK_DESCRIPTION: -// case CONTACT_NAME: -// case CONTACT_PHONE: -// case CONTACT_EMAIL: -// case STATION_ID: -// case ANTENNA_MODE: -// case CLOCK_FREQUENCY: -// case FILTER_TYPE: -// case TASK_DURATION: -// case PLANNED_START: -// case PLANNED_END: -// case TASK_STATUS: -// return Qt::white; -// break; -// default: -// return QColor(220,220,220); // for non-editable cells -// break; -// } - } - else if (task_type == Task::MAINTENANCE) { - return QColor(127,199,254); // for editable cells (blue-ish) -// switch (static_cast<data_headers>(index.column())) { -// case TASK_ID: -// case SAS_ID: -// case PROJECT_ID: -// case TASK_NAME: -// case TASK_DESCRIPTION: -// case CONTACT_NAME: -// case CONTACT_PHONE: -// case CONTACT_EMAIL: -// case STATION_ID: -// case TASK_DURATION: -// case PLANNED_START: -// case PLANNED_END: -// case TASK_STATUS: -// return QColor(127,199,254); // for editable cells (blue-ish) -// //return Qt::white; // for editable cells -// break; -// default: -// return QColor(220,220,220); // for non-editable cells -// break; -// } - } - else { // regular tasks - return QColor(Qt::white); - } - } - } - } - else if (role == Qt::ForegroundRole ) { - if (isErrorIndex(index)) // error - return QColor(Qt::white); - else { - int task_status = index.model()->data(index.model()->index(index.row(),TASK_STATUS),USERDATA_ROLE).toInt(); - if ((task_status >= Task::COMPLETING) && (task_status <= Task::ABORTED)) { - return QColor(Qt::black); - } - else { - int task_type = index.model()->data(index.model()->index(index.row(),TASK_TYPE),USERDATA_ROLE).toInt(); - if (task_type == Task::RESERVATION) { - switch (static_cast<data_headers>(index.column())) { - case TASK_ID: - case SAS_ID: - case PROJECT_ID: - case TASK_NAME: - case TASK_DESCRIPTION: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - case STATION_ID: - case ANTENNA_MODE: - case CLOCK_FREQUENCY: - case FILTER_TYPE: - case TASK_DURATION: - case PLANNED_START: - case PLANNED_END: - case TASK_STATUS: - return QColor(Qt::black); // for editable cells - break; - default: - return QColor(Qt::darkGray); // for non-editable cells - break; - } - } - else if (task_type == Task::MAINTENANCE) { - switch (static_cast<data_headers>(index.column())) { - case TASK_ID: - case SAS_ID: - case PROJECT_ID: - case TASK_NAME: - case TASK_DESCRIPTION: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - case STATION_ID: - case TASK_DURATION: - case PLANNED_START: - case PLANNED_END: - case TASK_STATUS: - return QColor(Qt::black); // for editable cells - break; - default: - return QColor(Qt::darkGray); // for non-editable cells - break; - } - } - else { // regular tasks - return QColor(Qt::black); - } - } - } - } -// else if (role == Qt::DisplayRole) { -//// QVariant value = QStandardItemModel::data(index, role); -// return QStandardItemModel::data(index, role); -// } - else { -// QVariant value = QStandardItemModel::data(index, role); - return QStandardItemModel::data(index, role); - } - - return QVariant(); -} - -/* -void QLofarDataModel::clearErrorIndices(void) { - errorIndices.clear(); -} -*/ -void QLofarDataModel::clearErrorIndex(const QModelIndex &index) { - for (std::vector<QModelIndex>::iterator it = errorIndices.begin(); it != errorIndices.end(); ++it) { - if (it->row() == index.row() && it->column() == index.column()) { - errorIndices.erase(it); - return; - } - } -} - -void QLofarDataModel::clearErrorCell(unsigned int taskID, data_headers header) { - // Remove the error from the internal error-cell list - int nrRows = this->rowCount(QModelIndex()); - for (int row = 0; row <= nrRows; ++row) { - if (this->data(this->index(row,TASK_ID)).toUInt() == taskID) { // if this is the row with the right task ID - for (std::vector<QModelIndex>::iterator it = errorIndices.begin(); it != errorIndices.end(); ++it) { - if (it->row() == row && it->column() == header) { - // Remove the erroneous cell from the internal data model (which is used to write table) - setData(*it, QString("")); - // now also clear the error from the internal error-cell list - errorIndices.erase(it); - return; - } - } - return; // if index not found no need to continue searching - } - } -} - -void QLofarDataModel::addErrorIndex(const QModelIndex &index) { - if (!isErrorIndex(index)) // check if not already in error list - errorIndices.push_back(index); -} - -bool QLofarDataModel::isErrorIndex(const QModelIndex &index) const { - for (std::vector<QModelIndex>::const_iterator it = errorIndices.begin(); it != errorIndices.end(); ++it) { - if (it->row() == index.row() && it->column() == index.column()) - return true; - } - return false; -} - -void QLofarDataModel::setErrorCells(const errorTasksMap & errorTasks) { - int nrRows = this->rowCount(QModelIndex()); - clearErrorIndices(); - for (errorTasksMap::const_iterator it = errorTasks.begin(); it != errorTasks.end(); ++it) { - // find the row containing the error tasks according to task ID - for (int row = 0; row <= nrRows; ++row) { - if (this->data(this->index(row, TASK_ID)).toUInt() == it->first) { // if this is the row with the right task ID - for (std::vector<data_headers>::const_iterator dit = it->second.begin(); dit != it->second.end(); ++dit) { - addErrorIndex(this->index(row, *dit)); - } - break; - } - } - } -} - - diff --git a/SAS/Scheduler/src/qlofardatamodel.h b/SAS/Scheduler/src/qlofardatamodel.h deleted file mode 100644 index d0e1207b98e7e0f622f6f43869edc3335579ae37..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/qlofardatamodel.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * qlofardatamodel.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jun 5, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/qlofardatamodel.h $ - * - */ - -#ifndef QLOFARDATAMODEL_H_ -#define QLOFARDATAMODEL_H_ - -#include <vector> -#include "lofar_scheduler.h" -#include "qstandarditemmodel.h" - -// define the user roles for the model which are used to store and retrieve user data in the model -#define USERDATA_ROLE 35 - -class QLofarDataModel : public QStandardItemModel { - - Q_OBJECT - -public: - - QLofarDataModel(QObject *parent); - QLofarDataModel(int rows, int columns, QObject *parent = 0 /*, SchedulerGUI * gui = 0 */ ); - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual ~QLofarDataModel(); - - void setErrorCells(const errorTasksMap & errorTasks); - void clearErrorCell(unsigned int taskID, data_headers header); - void addErrorIndex(const QModelIndex &index); - bool isErrorIndex(const QModelIndex &index) const; - void clearErrorIndex(const QModelIndex &index); - void clearErrorIndices(void) {errorIndices.clear();} - - int findTaskRow(unsigned taskID) const; - -// bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); - -private: -// SchedulerGUI * parentGUI; - std::vector<QModelIndex> errorIndices; - -}; - -#endif /* QLOFARDATAMODEL_H_ */ - - - - diff --git a/SAS/Scheduler/src/qtcreator_READ.ME b/SAS/Scheduler/src/qtcreator_READ.ME deleted file mode 100644 index f6d0ee370680b3dc92ae030249c935ca4242b078..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/qtcreator_READ.ME +++ /dev/null @@ -1,43 +0,0 @@ -The qtcreator GUI design tool can be used to edit, run, and debug the Scheduler. To do so, follow these steps: - ------------------ -Build in qtcreator ------------------ - -0) Go to the SAS/Scheduler/src source directory - -1) Run `qtcreator' - -2) Open the menu: - File -> Open File or Project... - -3) Select - 'CMakeLists.txt', - click - 'Open'. - -4) Set the build directory to (remove the full path) - 'gnu_debug' or 'gnu_opt', - click - 'Next >' - -5) CMake arguments: - ../../../.. -DBUILD_PACKAGES=Scheduler -6) Click 'Run CMake', and scan the output for errors -7) Click 'Finish' - -Note that the build will be running in the src/gnu_{debug,opt}/SAS/Scheduler/src directory. - ------------------ -First run ------------------ - -The Scheduler needs to have the .default_settings.set available in the running directory. -To make it available, simply symlink it from the source directory. In SAS/Scheduler/src, run: - - ln -sf `pwd`/.default_settings.set gnu_*/SAS/Scheduler/src/ - -(Note that gnu_* will match either gnu_debug or gnu_opt). - -Enjoy! - diff --git a/SAS/Scheduler/src/redistributetasksdialog.cpp b/SAS/Scheduler/src/redistributetasksdialog.cpp deleted file mode 100644 index be2d130062814ea699756dd2a3a04f594889df41..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/redistributetasksdialog.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * redistributetasksdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 26-oct-2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/redistributetasksdialog.cpp $ - * - */ - -#include "redistributetasksdialog.h" - -redistributeTasksDialog::redistributeTasksDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); -} - -redistributeTasksDialog::~redistributeTasksDialog() -{ - -} - -void redistributeTasksDialog::setRedistributeMode(void) { - ui.dateTimeEditStartTime->show(); - ui.labelDateTimeEditStart->show(); - ui.labelNrTasksInParallel->show(); - ui.spinBoxNrParallelTasks->show(); - ui.labelTimeStep1->setText("Time gap 1:"); - ui.labelTimeStep2->show(); - ui.timeEditTimeStep2->show(); -} - -void redistributeTasksDialog::setAfterPredecessorMode(void) { - ui.dateTimeEditStartTime->hide(); - ui.labelDateTimeEditStart->hide(); - ui.labelNrTasksInParallel->hide(); - ui.spinBoxNrParallelTasks->hide(); - ui.labelTimeStep1->setText("Distance to predecessor:"); - ui.labelTimeStep2->hide(); - ui.timeEditTimeStep2->hide(); -} diff --git a/SAS/Scheduler/src/redistributetasksdialog.h b/SAS/Scheduler/src/redistributetasksdialog.h deleted file mode 100644 index f2650a2b7acd631a7da08a52e6c25bfe8d4e4cb3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/redistributetasksdialog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * redistributetasksdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 26-oct-2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/redistributetasksdialog.h $ - * - */ - -#ifndef REDISTRIBUTETASKSDIALOG_H -#define REDISTRIBUTETASKSDIALOG_H - -#include <QDialog> -#include "ui_redistributetasksdialog.h" - -class redistributeTasksDialog : public QDialog -{ - Q_OBJECT - -public: - redistributeTasksDialog(QWidget *parent = 0); - ~redistributeTasksDialog(); - - void setStartTime(const QDateTime &start_time) {ui.dateTimeEditStartTime->setDateTime(start_time);} - void setTimeStep1(const QTime &gap1) {ui.timeEditTimeStep1->setTime(gap1);} - void setTimeStep2(const QTime &gap2) {ui.timeEditTimeStep2->setTime(gap2);} - - QDateTime getStartTime(void) const {return ui.dateTimeEditStartTime->dateTime();} - QTime getTimeStep1(void) const {return ui.timeEditTimeStep1->time();} - QTime getTimeStep2(void) const {return ui.timeEditTimeStep2->time();} - int getNrParallelTasks(void) const {return ui.spinBoxNrParallelTasks->value();} - - void setRedistributeMode(void); - void setAfterPredecessorMode(void); - void setMoveToLSTType(void) {ui.labelDateTimeEditStart->setText("Center LST time:");} - void setMoveToStartType(void) {ui.labelDateTimeEditStart->setText("Start time:");} - -private: - Ui::redistributeTasksDialogClass ui; -}; - -#endif // REDISTRIBUTETASKSDIALOG_H diff --git a/SAS/Scheduler/src/redistributetasksdialog.ui b/SAS/Scheduler/src/redistributetasksdialog.ui deleted file mode 100644 index e37891e07aab77a6e885f8c1aa16a3917c2dc96e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/redistributetasksdialog.ui +++ /dev/null @@ -1,159 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>redistributeTasksDialogClass</class> - <widget class="QDialog" name="redistributeTasksDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>343</width> - <height>169</height> - </rect> - </property> - <property name="windowTitle"> - <string>redistributeTasksDialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="0"> - <widget class="QLabel" name="labelDateTimeEditStart"> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Start time:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="1" column="1" colspan="2"> - <widget class="QDateTimeEdit" name="dateTimeEditStartTime"> - <property name="displayFormat"> - <string>yyyy-MM-dd hh:mm:ss</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelTimeStep1"> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Time gap 1:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QTimeEdit" name="timeEditTimeStep1"> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="4" column="1"> - <widget class="QPushButton" name="pushButtonCancel"> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item row="4" column="2"> - <widget class="QPushButton" name="pushButtonOK"> - <property name="text"> - <string>Ok</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="spinBoxNrParallelTasks"> - <property name="toolTip"> - <string>specifies how many tasks may be executed in parallel</string> - </property> - <property name="value"> - <number>1</number> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelNrTasksInParallel"> - <property name="text"> - <string>Nr. of tasks in parallel:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelTimeStep2"> - <property name="text"> - <string>Time gap 2:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QTimeEdit" name="timeEditTimeStep2"> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButtonOK</sender> - <signal>clicked()</signal> - <receiver>redistributeTasksDialogClass</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>279</x> - <y>139</y> - </hint> - <hint type="destinationlabel"> - <x>317</x> - <y>122</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonCancel</sender> - <signal>clicked()</signal> - <receiver>redistributeTasksDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>163</x> - <y>142</y> - </hint> - <hint type="destinationlabel"> - <x>138</x> - <y>142</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/sasconnectdialog.cpp b/SAS/Scheduler/src/sasconnectdialog.cpp deleted file mode 100644 index 15058048ca4b19ca2b85eb684e7e0e0c06a7198d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasconnectdialog.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * sasconnectdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Aug 23, 2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/sasconnectdialog.cpp $ - * - */ - -#include "sasconnectdialog.h" - -SASConnectDialog::SASConnectDialog(QWidget *parent, const QString &username, const QString &password, const QStringList &DBName, const QString &hostname) - : QDialog(parent), itsDBName(DBName), itsHostName(hostname), itsUserName(username), itsPassword(password) -{ - ui.setupUi(this); - ui.lineEditHostName->setText(hostname); - ui.lineEditDatabaseName->setText(DBName.join(";")); - ui.lineEditUserName->setText(username); - ui.lineEditPassword->setText(password); - connect(ui.pushButtonOk, SIGNAL(clicked()), this, SLOT(accept(void))); - connect(ui.pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject(void))); -} - -SASConnectDialog::~SASConnectDialog() -{ - -} - -void SASConnectDialog::setData(const QString &username, const QString &password, const QStringList &DBName, const QString &hostname) { - itsUserName = username; - itsHostName = hostname; - itsDBName = DBName; - itsPassword = password; -} - -void SASConnectDialog::accept(void) { - itsUserName = ui.lineEditUserName->text(); - itsPassword = ui.lineEditPassword->text(); - itsHostName = ui.lineEditHostName->text(); - itsDBName = ui.lineEditDatabaseName->text().split(";"); - - done(1); -} diff --git a/SAS/Scheduler/src/sasconnectdialog.h b/SAS/Scheduler/src/sasconnectdialog.h deleted file mode 100644 index bd9037d2397739820f4c941d39fe77bc3ca7bc4a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasconnectdialog.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SASConnectDialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Aug 23, 2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/sasconnectdialog.h $ - * - */ - -#ifndef SASCONNECTDIALOG_H -#define SASCONNECTDIALOG_H - -#include <QDialog> -#include "ui_sasconnectdialog.h" -#include <QString> -#include <QStringList> - -class SASConnectDialog : public QDialog -{ - Q_OBJECT - -public: - SASConnectDialog(QWidget *parent, const QString &username = "paulus", const QString &password = "boskabouter", const QStringList &DBName = QStringList(QString("LOFAR_1;LOFAR_2;LOFAR_3;LOFAR_4")), const QString &hostname = "sas003.control.lofar"); - ~SASConnectDialog(); - void setData(const QString &username, const QString &password, const QStringList &DBName, const QString &hostname); - const QString & getUserName(void) {return itsUserName;} - const QString & getPassword(void) {return itsPassword;} - const QStringList & getDBName(void) {return itsDBName;} - const QString & getHostName(void) {return itsHostName;} - -private slots: - void accept(void); - -private: - Ui::SASConnectDialogClass ui; - QStringList itsDBName; - QString itsHostName, itsUserName, itsPassword; -}; - -#endif // SASCONNECTDIALOG_H diff --git a/SAS/Scheduler/src/sasconnectdialog.ui b/SAS/Scheduler/src/sasconnectdialog.ui deleted file mode 100644 index fc5caf1536219a9d17e05163e6906ea5922b1c0a..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasconnectdialog.ui +++ /dev/null @@ -1,141 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SASConnectDialogClass</class> - <widget class="QDialog" name="SASConnectDialogClass"> - <property name="windowModality"> - <enum>Qt::WindowModal</enum> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>348</width> - <height>175</height> - </rect> - </property> - <property name="windowTitle"> - <string>SASConnectDialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="5" column="2"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="1" column="1" colspan="3"> - <widget class="QLineEdit" name="lineEditDatabaseName"> - <property name="toolTip"> - <string>can enter multiple separated by semicolon</string> - </property> - <property name="text"> - <string>LOFAR_4</string> - </property> - </widget> - </item> - <item row="2" column="1" colspan="3"> - <widget class="QLineEdit" name="lineEditUserName"> - <property name="text"> - <string>paulus</string> - </property> - </widget> - </item> - <item row="3" column="1" colspan="3"> - <widget class="QLineEdit" name="lineEditPassword"> - <property name="text"> - <string>boskabouter</string> - </property> - <property name="echoMode"> - <enum>QLineEdit::Password</enum> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Host:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Database(s):</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>User:</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Password:</string> - </property> - </widget> - </item> - <item row="4" column="2"> - <widget class="QPushButton" name="pushButtonCancel"> - <property name="text"> - <string>Cancel</string> - </property> - <property name="autoDefault"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="4" column="3"> - <widget class="QPushButton" name="pushButtonOk"> - <property name="text"> - <string>Ok</string> - </property> - <property name="default"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="4" column="1"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="1" colspan="3"> - <widget class="QLineEdit" name="lineEditHostName"> - <property name="text"> - <string>sas003.control.lofar</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <tabstops> - <tabstop>lineEditHostName</tabstop> - <tabstop>lineEditDatabaseName</tabstop> - <tabstop>lineEditUserName</tabstop> - <tabstop>lineEditPassword</tabstop> - <tabstop>pushButtonCancel</tabstop> - <tabstop>pushButtonOk</tabstop> - </tabstops> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/sasprogressdialog.cpp b/SAS/Scheduler/src/sasprogressdialog.cpp deleted file mode 100644 index fae894a0741090ef136c2232d47133b0adf8ef09..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasprogressdialog.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "sasprogressdialog.h" - -SASProgressDialog::SASProgressDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); - clear(); -} - -SASProgressDialog::~SASProgressDialog() -{ - -} - -void SASProgressDialog::addText(const QString &text) { - QListWidgetItem *item = new QListWidgetItem(text, ui.listWidget_Progress); - ui.listWidget_Progress->scrollToItem(item); -// ui.listWidget_Progress->repaint(); -// repaint(); - QCoreApplication::processEvents(); // force an immediate redraw -} - -void SASProgressDialog::addError(const QString &text) { - QListWidgetItem *item = new QListWidgetItem(text, ui.listWidget_Progress); - item->setForeground(QBrush(Qt::red)); - ui.listWidget_Progress->scrollToItem(item); -// ui.listWidget_Progress->repaint(); -// repaint(); - QCoreApplication::processEvents(); -} diff --git a/SAS/Scheduler/src/sasprogressdialog.h b/SAS/Scheduler/src/sasprogressdialog.h deleted file mode 100644 index 652b9841c92ffe0b01cac6a27ed0beeeee9ae685..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasprogressdialog.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef SASPROGRESSDIALOG_H -#define SASPROGRESSDIALOG_H - -#include <QDialog> -#include "ui_sasprogressdialog.h" - -class SASProgressDialog : public QDialog -{ - Q_OBJECT - -public: - SASProgressDialog(QWidget *parent = 0); - ~SASProgressDialog(); - - void addText(const QString &text); // force an immediate redraw - void addError(const QString &text); - void setProgressPercentage(int value) {ui.progressBar->setValue(value);} - void clear(void) { - ui.listWidget_Progress->clear(); - ui.progressBar->setValue(0); - disableClose(); - } - void disableClose(void) { - ui.pushButton_Close->setText("Please wait"); - ui.pushButton_Close->setEnabled(false); - } - void enableClose(void) { - ui.pushButton_Close->setText("Close"); - ui.pushButton_Close->setEnabled(true); - } - - Ui::SASProgressDialogClass* getUi(){return &ui;} - -private: - Ui::SASProgressDialogClass ui; -}; - -#endif // SASPROGRESSDIALOG_H diff --git a/SAS/Scheduler/src/sasprogressdialog.ui b/SAS/Scheduler/src/sasprogressdialog.ui deleted file mode 100644 index 811157878249c26160e32507734be21d7ab81202..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasprogressdialog.ui +++ /dev/null @@ -1,99 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SASProgressDialogClass</class> - <widget class="QDialog" name="SASProgressDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>599</width> - <height>297</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>SAS connection</string> - </property> - <property name="toolTip"> - <string>copy data to clipboard by selecting and normal copying</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <property name="modal"> - <bool>false</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="3"> - <widget class="QListWidget" name="listWidget_Progress"> - <property name="selectionMode"> - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - </widget> - </item> - <item row="1" column="0" colspan="2"> - <widget class="QProgressBar" name="progressBar"> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="value"> - <number>24</number> - </property> - <property name="textVisible"> - <bool>true</bool> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="textDirection"> - <enum>QProgressBar::TopToBottom</enum> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QPushButton" name="pushButton_Close"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="maximumSize"> - <size> - <width>65</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Please wait</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButton_Close</sender> - <signal>clicked()</signal> - <receiver>SASProgressDialogClass</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>370</x> - <y>251</y> - </hint> - <hint type="destinationlabel"> - <x>396</x> - <y>255</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/sasstatusdialog.cpp b/SAS/Scheduler/src/sasstatusdialog.cpp deleted file mode 100644 index 64783052a6c5cbfe344c03b4d0194f7e59ab51ea..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasstatusdialog.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "sasstatusdialog.h" - -SASStatusDialog::SASStatusDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); -} - -SASStatusDialog::~SASStatusDialog() -{ - -} diff --git a/SAS/Scheduler/src/sasstatusdialog.h b/SAS/Scheduler/src/sasstatusdialog.h deleted file mode 100644 index bda129521459209f5e957d08460268918bcf2054..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasstatusdialog.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SASSTATUSDIALOG_H -#define SASSTATUSDIALOG_H - -#include <QDialog> -#include "ui_sasstatusdialog.h" - -class SASStatusDialog : public QDialog -{ - Q_OBJECT - -public: - SASStatusDialog(QWidget *parent = 0); - ~SASStatusDialog(); - - void addText(const QString &text) { - QListWidgetItem *item = new QListWidgetItem(text, ui.listWidget_Status); - ui.listWidget_Status->addItem(item); - ui.listWidget_Status->scrollToItem(item); - } - - void addError(const QString &text) { - QListWidgetItem *item = new QListWidgetItem(text); - item->setForeground(QBrush(Qt::red)); - ui.listWidget_Status->addItem(item); - ui.listWidget_Status->scrollToItem(item); - } - - void clear(void) {ui.listWidget_Status->clear();} - -private: - Ui::SASStatusDialogClass ui; -}; - -#endif // SASSTATUSDIALOG_H diff --git a/SAS/Scheduler/src/sasstatusdialog.ui b/SAS/Scheduler/src/sasstatusdialog.ui deleted file mode 100644 index fe1c9968766f33c0f9a6a1be3191ea05adbc4b4e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasstatusdialog.ui +++ /dev/null @@ -1,66 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SASStatusDialogClass</class> - <widget class="QDialog" name="SASStatusDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>507</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>SAS connection and database status check</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButton_Close"> - <property name="text"> - <string>Close</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0" colspan="2"> - <widget class="QListWidget" name="listWidget_Status"> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButton_Close</sender> - <signal>clicked()</signal> - <receiver>SASStatusDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>446</x> - <y>280</y> - </hint> - <hint type="destinationlabel"> - <x>398</x> - <y>278</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/sasuploaddialog.cpp b/SAS/Scheduler/src/sasuploaddialog.cpp deleted file mode 100644 index 42d95aedc1f8519028fcfa6e91af5a3d8fad58b2..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasuploaddialog.cpp +++ /dev/null @@ -1,422 +0,0 @@ -#include "sasuploaddialog.h" -#include "Controller.h" -#include <QMessageBox> - -SASUploadDialog::SASUploadDialog(QWidget *parent, Controller *controller) - : QDialog(parent), itsController(controller), nrOfNewSchedulerTasks(0), nrOfDeletedSchedulerTasks(0), nrOfNewSASTasks(0), - nrOfDeletedSASTasks(0), nrOfChangedTasks(0), nrOfUnchangedTasks(0) -{ - ui.setupUi(this); - setupUploadDialog(); - ui.tableWidget_NewAndDeletedScheduleTasks->setSortingEnabled(true); - ui.tableWidget_NewAndDeletedSASTasks->setSortingEnabled(true); - ui.tableWidget_ChangedTasks->setSortingEnabled(true); - ui.tableWidget_UnchangedTasks->setSortingEnabled(true); - // set default size of columns - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(0,22); // +/- - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(1,40); // task id - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(2,50); // tree id - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(3,100); // task name - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(4,100); // project name - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(5,80); // status - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(6,110); // scheduled start - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(7,110); // scheduled end - - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(0,22); // +/- - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(1,40); // task id - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(2,50); // tree id - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(3,100); // task name - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(4,100); // project name - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(5,85); // status - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(6,110); // scheduled start - ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(7,110); // scheduled end - - ui.tableWidget_ChangedTasks->setColumnWidth(0,40); // task id - ui.tableWidget_ChangedTasks->setColumnWidth(1,50); // tree id - ui.tableWidget_ChangedTasks->setColumnWidth(2,100); // task name - ui.tableWidget_ChangedTasks->setColumnWidth(3,100); // project name - ui.tableWidget_ChangedTasks->setColumnWidth(4,85); // status - ui.tableWidget_ChangedTasks->setColumnWidth(5,300); // changes - ui.tableWidget_ChangedTasks->horizontalHeader()->setStretchLastSection(true); - - ui.tableWidget_UnchangedTasks->setColumnWidth(0,40); // task id - ui.tableWidget_UnchangedTasks->setColumnWidth(1,50); // tree id - ui.tableWidget_UnchangedTasks->setColumnWidth(2,100); // task name - ui.tableWidget_UnchangedTasks->setColumnWidth(3,100); // project name - ui.tableWidget_UnchangedTasks->setColumnWidth(4,85); // status - ui.tableWidget_UnchangedTasks->setColumnWidth(5,110); // scheduled start - ui.tableWidget_UnchangedTasks->setColumnWidth(6,110); // scheduled end - - if (itsController->autoPublishAllowed()) { - ui.checkBoxAutoPublish->setEnabled(true); - ui.checkBoxAutoPublish->setChecked(true); - connect(ui.checkBoxAutoPublish,SIGNAL(clicked()),this,SLOT(setAutoPublish(void))); - } - else { - ui.checkBoxAutoPublish->setEnabled(false); - ui.checkBoxAutoPublish->setChecked(false); - ui.checkBoxAutoPublish->setToolTip("Auto publishing is only allowed for user lofarsys"); - } -} - -SASUploadDialog::~SASUploadDialog() -{ - -} - -void SASUploadDialog::setAutoPublish(void) { - itsController->setAutoPublish(ui.checkBoxAutoPublish->isChecked()); -} - -void SASUploadDialog::show(void) { - updateSchedulerTasksLabel(); - updateSASTasksLabel(); - updateChangedTasksLabel(); - updateUnChangedTasksLabel(); - if ((nrOfChangedTasks == 0) && (nrOfDeletedSchedulerTasks == 0) && (nrOfNewSchedulerTasks == 0)) { - showNormal(); - if (nrOfDeletedSASTasks == 0) { - QMessageBox::information(0, QObject::tr("No schedule changes"), QObject::tr("There are no schedule changes that need uploading")); - ui.pushButton_Cancel->hide(); - ui.pushButton_Commit->setText(QObject::tr("Close")); - itsController->clearStatusText(); - } - else { - QMessageBox::warning(0, QObject::tr("Some tasks deleted"), QObject::tr("Some tasks were deleted externally.\nThey will also be deleted from the scheduler")); - ui.pushButton_Cancel->show(); - ui.pushButton_Commit->setText(QObject::tr("Commit")); - } - } - else { - ui.pushButton_Cancel->show(); - ui.pushButton_Commit->setText(QObject::tr("Commit")); - showNormal(); - } -} - -void SASUploadDialog::cancelUpload(void) { - if (ui.pushButton_Commit->text() == "Commit") { - itsController->setStatusText("Upload to SAS canceled by user"); - } - this->reject(); -} - -void SASUploadDialog::clear(void) { - ui.tableWidget_NewAndDeletedScheduleTasks->clearContents(); - ui.tableWidget_NewAndDeletedScheduleTasks->setRowCount(0); - ui.tableWidget_NewAndDeletedSASTasks->clearContents(); - ui.tableWidget_NewAndDeletedSASTasks->setRowCount(0); - ui.tableWidget_ChangedTasks->clearContents(); - ui.tableWidget_ChangedTasks->setRowCount(0); - ui.tableWidget_UnchangedTasks->clearContents(); - ui.tableWidget_UnchangedTasks->setRowCount(0); - nrOfNewSchedulerTasks = 0; - nrOfDeletedSchedulerTasks = 0; - nrOfNewSASTasks = 0; - nrOfDeletedSASTasks = 0; - nrOfChangedTasks = 0; - nrOfUnchangedTasks = 0; - ui.label_SchedulerTasks->setText("Schedule (empty)"); - ui.label_SASTasks->setText("SAS database (empty)"); -} - -void SASUploadDialog::setupUploadDialog(void) { - - - // add headers to the different tables - QStringList labels1, labels2, labels3, labels4; - - // New and deleted schedule tasks table - labels1 << "+/-" << "ID" << "tree ID" << QObject::tr("Task name") << QObject::tr("Project name") << QObject::tr("Status") - << QObject::tr("Start") << QObject::tr("End"); - ui.tableWidget_NewAndDeletedScheduleTasks->setColumnCount(8); - ui.tableWidget_NewAndDeletedScheduleTasks->horizontalHeader()->setDefaultSectionSize(75); - ui.tableWidget_NewAndDeletedScheduleTasks->setHorizontalHeaderLabels(labels1); -// ui.tableWidget_NewAndDeletedScheduleTasks->setColumnWidth(0, 25); - ui.tableWidget_NewAndDeletedScheduleTasks->verticalHeader()->setDefaultSectionSize(16); - ui.tableWidget_NewAndDeletedScheduleTasks->setSelectionMode(QAbstractItemView::NoSelection); - ui.tableWidget_NewAndDeletedScheduleTasks->setEditTriggers(QAbstractItemView::NoEditTriggers); - - - // New and deleted SAS tasks table - labels2 << "+/-" << "ID" << "tree ID" << QObject::tr("Task name") << QObject::tr("Project name") << QObject::tr("Status") - << QObject::tr("Start") << QObject::tr("End"); - ui.tableWidget_NewAndDeletedSASTasks->setColumnCount(8); - ui.tableWidget_NewAndDeletedSASTasks->horizontalHeader()->setDefaultSectionSize(75); - ui.tableWidget_NewAndDeletedSASTasks->setHorizontalHeaderLabels(labels2); -// ui.tableWidget_NewAndDeletedSASTasks->setColumnWidth(0, 25); - ui.tableWidget_NewAndDeletedSASTasks->verticalHeader()->setDefaultSectionSize(16); - - // Changed tasks table - labels3 << "ID" << "tree ID" << QObject::tr("Task name") << QObject::tr("Project name") << QObject::tr("Status") - << QObject::tr("Changes"); - ui.tableWidget_ChangedTasks->setColumnCount(6); - ui.tableWidget_ChangedTasks->horizontalHeader()->setDefaultSectionSize(75); - ui.tableWidget_ChangedTasks->setHorizontalHeaderLabels(labels3); -// ui.tableWidget_ChangedTasks->setColumnWidth(3, 200); - ui.tableWidget_ChangedTasks->verticalHeader()->setDefaultSectionSize(16); - - // Unchanged tasks table - labels4 << "ID" << "tree ID" << QObject::tr("Task name") << QObject::tr("Project name") << QObject::tr("Status") - << QObject::tr("Start") << QObject::tr("End"); - ui.tableWidget_UnchangedTasks->setColumnCount(7); - ui.tableWidget_UnchangedTasks->horizontalHeader()->setDefaultSectionSize(75); - ui.tableWidget_UnchangedTasks->setHorizontalHeaderLabels(labels4); - ui.tableWidget_UnchangedTasks->verticalHeader()->setDefaultSectionSize(16); - - connect(ui.pushButton_Commit, SIGNAL(clicked()), this, SLOT(commitScheduleToSAS())); - connect(ui.pushButton_Cancel, SIGNAL(clicked()), this, SLOT(cancelUpload())); - // tableWidget_NewAndDeletedScheduleTasks -// tableWidget_NewAndDeletedSASTasks -// tableWidget_ChangedTasks -// tableWidget_UnchangedTasks -} - -void SASUploadDialog::commitScheduleToSAS(void) { - if ((nrOfChangedTasks == 0) && (nrOfDeletedSchedulerTasks == 0) && (nrOfNewSchedulerTasks == 0) && (nrOfDeletedSASTasks == 0)) { - this->hide(); - } else { - itsController->commitScheduleToSAS(); - } -} - -void SASUploadDialog::addNewSchedulerTask(const Task &task) { - int id = task.getID(); - int row = ui.tableWidget_NewAndDeletedScheduleTasks->rowCount(); - ++nrOfNewSchedulerTasks; -// updateSchedulerTasksLabel(); - ui.tableWidget_NewAndDeletedScheduleTasks->insertRow(row); - QTableWidgetItem *item = new QTableWidgetItem("+"); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 0, item); - item = new QTableWidgetItem(); - item->setData(0,id); // we have to use setData to get correct number sorting for this column - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 1, item); - item = new QTableWidgetItem(task.getTaskName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 3, item); // column 2 is skipped (treeID not set for new tasks) - item = new QTableWidgetItem(task.getProjectName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 4, item); - item = new QTableWidgetItem(task.getStatusStr()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 5, item); - item = new QTableWidgetItem(task.getScheduledStart().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 6, item); - item = new QTableWidgetItem(task.getScheduledEnd().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 7, item); -} - -void SASUploadDialog::addDeletedSchedulerTask(const Task *task) { - unsigned id = task->getID(); - int row = ui.tableWidget_NewAndDeletedScheduleTasks->rowCount(); - ++nrOfDeletedSchedulerTasks; - ui.tableWidget_NewAndDeletedScheduleTasks->insertRow(row); - QTableWidgetItem *item = new QTableWidgetItem("-"); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 0, item); - item = new QTableWidgetItem(); - item->setData(0,id); // we have to use setData to get correct number sorting for this column - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 1, item); - item = new QTableWidgetItem(); - item->setData(0,task->getSASTreeID()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 2, item); - item = new QTableWidgetItem(task->getTaskName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 3, item); - item = new QTableWidgetItem(task->getProjectName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 4, item); - item = new QTableWidgetItem(task->getStatusStr()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 5, item); - item = new QTableWidgetItem(task->getScheduledStart().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 6, item); - item = new QTableWidgetItem(task->getScheduledEnd().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedScheduleTasks->setItem(row, 7, item); -} - -void SASUploadDialog::addNewSASTask(const Task *task) { - int id = task->getID(); - int row = ui.tableWidget_NewAndDeletedSASTasks->rowCount(); - ++nrOfNewSASTasks; - ui.tableWidget_NewAndDeletedSASTasks->insertRow(row); - QTableWidgetItem *item = new QTableWidgetItem("+"); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 0, item); - item = new QTableWidgetItem(); - item->setData(0,id); // we have to use setData to get correct number sorting for this column - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 1, item); - item = new QTableWidgetItem(); - item->setData(0,task->getSASTreeID()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 2, item); - item = new QTableWidgetItem(task->getTaskName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 3, item); - item = new QTableWidgetItem(task->getProjectName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 4, item); - item = new QTableWidgetItem(task->getStatusStr()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 5, item); - item = new QTableWidgetItem(task->getScheduledStart().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 6, item); - item = new QTableWidgetItem(task->getScheduledEnd().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 7, item); -} - -void SASUploadDialog::addDeletedSASTask(const Task *task) { - int id = task->getID(); - int row = ui.tableWidget_NewAndDeletedSASTasks->rowCount(); - ++nrOfDeletedSASTasks; -// updateSASTasksLabel(); - ui.tableWidget_NewAndDeletedSASTasks->insertRow(row); - QTableWidgetItem *item = new QTableWidgetItem("-"); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 0, item); - item = new QTableWidgetItem(); - item->setData(0,id); // we have to use setData to get correct number sorting for this column - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 1, item); - item = new QTableWidgetItem(); - item->setData(0,task->getSASTreeID()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 2, item); - item = new QTableWidgetItem(task->getTaskName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 3, item); - item = new QTableWidgetItem(task->getProjectName()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 4, item); - item = new QTableWidgetItem(task->getStatusStr()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 5, item); - item = new QTableWidgetItem(task->getScheduledStart().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 6, item); - item = new QTableWidgetItem(task->getScheduledEnd().toString().c_str()); - item->setData(100, id); - ui.tableWidget_NewAndDeletedSASTasks->setItem(row, 7, item); -} - -void SASUploadDialog::addChangedTask(const Task &task, const QString &diffStr, bool conflict) { - int id = task.getID(); - int row = ui.tableWidget_ChangedTasks->rowCount(); - ++nrOfChangedTasks; - ui.tableWidget_ChangedTasks->insertRow(row); - - QColor textColor; - - QTableWidgetItem *item = new QTableWidgetItem(); - - textColor = conflict ? Qt::red : Qt::black; - item->setData(0,id); // we have to use setData to get correct number sorting for this column - item->setData(100, id); - item->setTextColor(textColor); - ui.tableWidget_ChangedTasks->setItem(row, 0, item); - item = new QTableWidgetItem(QString::number(task.getSASTreeID())); - item->setData(100, id); - item->setTextColor(textColor); - ui.tableWidget_ChangedTasks->setItem(row, 1, item); - item = new QTableWidgetItem(task.getTaskName()); - item->setData(100, id); - item->setTextColor(textColor); - ui.tableWidget_ChangedTasks->setItem(row, 2, item); - item = new QTableWidgetItem(task.getProjectName()); - item->setData(100, id); - item->setTextColor(textColor); - ui.tableWidget_ChangedTasks->setItem(row, 3, item); - item = new QTableWidgetItem(task.getStatusStr()); - item->setData(100, id); - item->setTextColor(textColor); - ui.tableWidget_ChangedTasks->setItem(row, 4, item); - item = new QTableWidgetItem(diffStr); - item->setToolTip(QString(diffStr).replace(",","\n")); - item->setData(100, id); - item->setTextColor(textColor); - ui.tableWidget_ChangedTasks->setItem(row, 5, item); -} - -void SASUploadDialog::addUnchangedTask(const Task &task) { - int id = task.getID(); - int row = ui.tableWidget_UnchangedTasks->rowCount(); - ++nrOfUnchangedTasks; -// updateUnChangedTasksLabel(); - ui.tableWidget_UnchangedTasks->insertRow(row); - QTableWidgetItem *item = new QTableWidgetItem(); - item->setData(0,id); // we have to use setData to get correct number sorting for this column - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 0, item); - item = new QTableWidgetItem(); - item->setData(0,task.getSASTreeID()); - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 1, item); - item = new QTableWidgetItem(task.getTaskName()); - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 2, item); - item = new QTableWidgetItem(task.getProjectName()); - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 3, item); - item = new QTableWidgetItem(task.getStatusStr()); - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 4, item); - item = new QTableWidgetItem(task.getScheduledStart().toString().c_str()); - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 5, item); - item = new QTableWidgetItem(task.getScheduledEnd().toString().c_str()); - item->setData(100, id); - ui.tableWidget_UnchangedTasks->setItem(row, 6, item); -} - -void SASUploadDialog::updateSchedulerTasksLabel(void) { - QString str("Schedule (+"); - str += QString::number(nrOfNewSchedulerTasks); - str += "/-"; - str += QString::number(nrOfDeletedSchedulerTasks); - str += ")"; - ui.label_SchedulerTasks->setText(str); -} - -void SASUploadDialog::updateSASTasksLabel(void) { - QString str("SAS database (+"); - str += QString::number(nrOfNewSASTasks); - str += "/-"; - str += QString::number(nrOfDeletedSASTasks); - str += ")"; - ui.label_SASTasks->setText(str); -} - -void SASUploadDialog::updateChangedTasksLabel(void) { - QString str("Changed tasks ("); - if (nrOfChangedTasks) { - str += QString::number(nrOfChangedTasks); - } - else { - str += "No changed tasks"; - } - str += ")"; - ui.groupBox_ChangedTasks->setTitle(str); -} - -void SASUploadDialog::updateUnChangedTasksLabel(void) { - QString str("Unchanged tasks ("); - if (nrOfUnchangedTasks) { - str += QString::number(nrOfUnchangedTasks); - } - else { - str += "No unchanged tasks"; - } - str += ")"; - ui.groupBox_UnchangedTasks->setTitle(str); -} diff --git a/SAS/Scheduler/src/sasuploaddialog.h b/SAS/Scheduler/src/sasuploaddialog.h deleted file mode 100644 index 8cb6e512f1f15933eadc9d1d5a7da12dd9a398ae..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasuploaddialog.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SASUPLOADDIALOG_H -#define SASUPLOADDIALOG_H - -#include <QDialog> -#include "ui_sasuploaddialog.h" -#include "task.h" - -class Controller; - -class SASUploadDialog : public QDialog -{ - Q_OBJECT - -public: - SASUploadDialog(QWidget *parent = 0, Controller *controller = 0); - ~SASUploadDialog(); - - void clear(void); - void show(void); - - void addNewSchedulerTask(const Task &task); - void addDeletedSASTask(const Task *task); - void addDeletedSchedulerTask(const Task *task); - void addNewSASTask(const Task *task); - void addChangedTask(const Task &task, const QString &diffStr, bool conflict = false); - void addUnchangedTask(const Task &task); - void setAutoPublishEnabled(bool enable) {ui.checkBoxAutoPublish->setChecked(enable);} - bool autoPublish(void) const {return ui.checkBoxAutoPublish->isChecked();} - -private: - void setupUploadDialog(void); - void updateSchedulerTasksLabel(void); - void updateSASTasksLabel(void); - void updateChangedTasksLabel(void); - void updateUnChangedTasksLabel(void); - -signals: - void SASUploadCanceled(void) const; - -private slots: - void cancelUpload(void); - void commitScheduleToSAS(void); - void setAutoPublish(void); - -private: - Ui::SASUploadDialogClass ui; - Controller *itsController; - unsigned nrOfNewSchedulerTasks, nrOfDeletedSchedulerTasks, nrOfNewSASTasks, - nrOfDeletedSASTasks, nrOfChangedTasks, nrOfUnchangedTasks; -}; - -#endif // SASUPLOADDIALOG_H diff --git a/SAS/Scheduler/src/sasuploaddialog.ui b/SAS/Scheduler/src/sasuploaddialog.ui deleted file mode 100644 index 312d32ae88aa5d048b04ff2abeb824026bf902f2..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/sasuploaddialog.ui +++ /dev/null @@ -1,175 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SASUploadDialogClass</class> - <widget class="QDialog" name="SASUploadDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>600</width> - <height>600</height> - </rect> - </property> - <property name="windowTitle"> - <string>Schedule changes</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <property name="modal"> - <bool>false</bool> - </property> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="5" column="1"> - <widget class="QPushButton" name="pushButton_Cancel"> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item row="1" column="0" colspan="3"> - <widget class="QGroupBox" name="groupBox_ChangedTasks"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="title"> - <string>Changed tasks (none)</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QTableWidget" name="tableWidget_ChangedTasks"> - <property name="whatsThis"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">This table summarizes the tasks that have been changed in the schedule when compared with the current schedule in the SAS database. These changes will be committed to the SAS database once the schedule is uploaded.</span></p></body></html></string> - </property> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="2" column="0" colspan="3"> - <widget class="QGroupBox" name="groupBox_UnchangedTasks"> - <property name="title"> - <string>Unchanged tasks (none)</string> - </property> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="0" column="0" colspan="3"> - <widget class="QTableWidget" name="tableWidget_UnchangedTasks"> - <property name="whatsThis"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">This table summarizes the tasks that have not been changed in the new schedule when compared to the current schedule in the SAS database. These tasks will remain the same after the upload is committed.</span></p></body></html></string> - </property> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="5" column="2"> - <widget class="QPushButton" name="pushButton_Commit"> - <property name="text"> - <string>Commit</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0" colspan="3"> - <widget class="QGroupBox" name="groupBox_NewAndDeletedTasks"> - <property name="title"> - <string>New && deleted tasks</string> - </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="1"> - <widget class="QLabel" name="label_SchedulerTasks"> - <property name="text"> - <string>Schedule (no new or deleted tasks)</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QLabel" name="label_SASTasks"> - <property name="text"> - <string>SAS database (no new or deleted tasks)</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QTableWidget" name="tableWidget_NewAndDeletedScheduleTasks"> - <property name="whatsThis"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">These tasks are either new or deleted tasks in the schedule that is going to be uploaded to SAS. </span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">- Tasks which are marked with a '+' in this table are added to the scheduler's schedule by you. These tasks will be uploaded to the SAS database. </span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">- Tasks which are marked with a</span><span style=" font-size:8pt; font-weight:600;"> </span><span style=" font-size:8pt;">'-' in this table have been deleted by you and will be deleted from the SAS database when the new schedule is committed.</span></p></body></html></string> - </property> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QTableWidget" name="tableWidget_NewAndDeletedSASTasks"> - <property name="whatsThis"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">These tasks are either new or deleted tasks in the SAS database. </span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">- Tasks which are marked with a '+' in this table were added to the SAS database from outside of the scheduler application. They have not been taken into account in the schedule that is about to be uploaded to SAS. (This might cause conflicts between tasks)</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">- Tasks marked with a '-' have been deleted from the SAS database from outside of the scheduler application. </span><span style=" font-size:8pt; text-decoration: underline;">They will be deleted from the schedule once the upload is committed.</span></p></body></html></string> - </property> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="4" column="0"> - <widget class="QCheckBox" name="checkBoxAutoPublish"> - <property name="toolTip"> - <string>If checked, all weeks with changes will be automatically published to the web server</string> - </property> - <property name="text"> - <string>Auto publish changes to web schedule</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections/> - <slots> - <slot>cancelUpload()</slot> - </slots> -</ui> diff --git a/SAS/Scheduler/src/schedulerLib.cpp b/SAS/Scheduler/src/schedulerLib.cpp deleted file mode 100644 index fe4b0cb9c09316b4e9da1e9b4713f1931b6a5d48..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulerLib.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * main.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 29, 2009 - * URL : $URL: https://svn.astron.nl/ROD/branches/LOFAR_Scheduler-Task6767/main.cpp $ - * - */ - -#include <QtGui> -#include <QApplication> -#include <QDir> -#include "lofar_scheduler.h" -#include "Controller.h" -#include "schedulergui.h" -#include "signalhandler.h" - -#include <exception> -#include <iostream> - -#undef main - -QString currentUser; - -SignalHandler *handler; - - -int signalForward(std::string functionName, std::string parameter) -{ - // The signalForward is depending on handler* that is instantiated created in a different thread - // Assure that it is assigned/created - if (!handler) - throw new std::exception(); - - // Forward the signal and set return value - return handler->signalForward(functionName, parameter); -} - -int main_function(int argc, char *argv[]) -{ - // remember the user running the scheduler, to know if - //certain functionality like publish and cleaning data should be enabled - // TODO: What is the function of this code? Description is sparce - QStringList env(QProcess::systemEnvironment()); - env = env.filter("USER"); - if (!env.isEmpty()) { - currentUser = env.front().split("=").back(); - } - // Create app and controller - QApplication app(argc, argv); - Controller c(app); // The controller is the intermediary between the SchedulerGUI (the view) and the Scheduler - - // Assign the handler with the adresses of the app and the controller - // TODO: MVC seperation, where is the model? The M should be instantiated as a - // specific object - handler = new SignalHandler(&app, &c); - - #ifdef Q_OS_MACX - if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_8) - { //OSX 10.9+, we find and set the directory of the .app, otherwise QDir::currentPath can be empty. - QDir dir = app.applicationDirPath(); - dir.cdUp(); - dir.cdUp(); - dir.cdUp(); //To get from the executable in the bundle to the .app location - QDir::setCurrent(dir.absolutePath()); - } - #endif - - // c.start() does not return it does this after closing gui window. - try { - c.start(); // controller starts the GUI - } - catch (...) - { // On all exception cough gracefully quit() - // TODO: Might be problematic when memory exception. This feels like a desctructor - c.quit(); - } - return app.exec(); -} diff --git a/SAS/Scheduler/src/schedulerLib.h b/SAS/Scheduler/src/schedulerLib.h deleted file mode 100644 index 22f16c1d906090bdbc3e13401f27d6a4ed380e0f..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulerLib.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SCHEDULERLIB_H -#define SCHEDULERLIB_H - -#include <string> - -int main_function(int argc, char *argv[]); - -int signalForward(std::string functionName, std::string parameter); - -#endif // SCHEDULERLIB_H diff --git a/SAS/Scheduler/src/scheduler_resources.qrc b/SAS/Scheduler/src/scheduler_resources.qrc deleted file mode 100644 index 97885bc381a29ef92f4fab7b51446f62a8986e10..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/scheduler_resources.qrc +++ /dev/null @@ -1,32 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>icons/add_task.png</file> - <file>icons/align-left.png</file> - <file>icons/close16x16.png</file> - <file>icons/create_initial_schedule.png</file> - <file>icons/delete_task.png</file> - <file>icons/find.png</file> - <file>icons/load-balancing.png</file> - <file>icons/new_schedule.png</file> - <file>icons/open.png</file> - <file>icons/optimize.png</file> - <file>icons/printer.png</file> - <file>icons/publish.png</file> - <file>icons/redo.png</file> - <file>icons/save.png</file> - <file>icons/settings.png</file> - <file>icons/taskcolormode.png</file> - <file>icons/undo.png</file> - <file>icons/zoomin.png</file> - <file>icons/zoomout.png</file> - <file>icons/empty_trash.png</file> - <file>icons/full_trash.png</file> - <file>icons/cross.png</file> - <file>icons/clock.png</file> - <file>icons/connect_datamonitor.png</file> - <file>icons/download.png</file> - <file>icons/synchronize.png</file> - <file>images/timeline_day.png</file> - <file>images/timeline_day_long.png</file> - </qresource> -</RCC> diff --git a/SAS/Scheduler/src/schedulerdata.cpp b/SAS/Scheduler/src/schedulerdata.cpp deleted file mode 100644 index 167c90f11e548acb67237f59fe8aaac200c7a1a2..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulerdata.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * schedulerdata.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 26, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulerdata.cpp $ - * - */ - -#ifdef DEBUG_SCHEDULER -#include <iostream> -#endif -#include "schedulerdata.h" -#include "schedulerdatablock.h" -#include "lofar_scheduler.h" -#include "task.h" -#include "Controller.h" - -SchedulerData::SchedulerData() { -} - -SchedulerData::~SchedulerData() { -} - -void SchedulerData::cleanup(void) { - // create a fresh data block - itsData.cleanup(); - itsUndoStack.clear(); // TODO: check if this calls the destructor of every SchedulerDataBlock and cleans up the task objects - itsRedoStack.clear(); - // create the stations if any were defined in the scheduler settings - updateStations(); -} - -bool SchedulerData::undo(bool store_redo) { - if (!itsUndoStack.empty()) { - if (store_redo) { - itsRedoStack.push_back(itsData); - } - itsData = itsUndoStack.back(); - itsUndoStack.pop_back(); - return true; - } - else return false; // no more undo levels -} - -bool SchedulerData::redo(void) { - if (!itsRedoStack.empty()) { - itsUndoStack.push_back(itsData); - itsData = itsRedoStack.back(); - itsRedoStack.pop_back(); - return true; - } - else return false; // no more undo levels -} - -void SchedulerData::setDataHeaders(std::vector<std::string> const &headers) { - itsDataHeaders.clear(); - for (std::vector<std::string>::const_iterator it = headers.begin(); it != headers.end(); ++it){ - itsDataHeaders.push_back(*it); - } -} diff --git a/SAS/Scheduler/src/schedulerdata.h b/SAS/Scheduler/src/schedulerdata.h deleted file mode 100644 index 8557890ab97a801af7a1f4380fa052a60e2108fd..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulerdata.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * schedulerdata.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 26, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulerdata.h $ - * - */ - -#ifndef SCHEDULERDATA_H_ -#define SCHEDULERDATA_H_ - -#include <vector> -#include <map> -#include <string> -#include <fstream> -#include "schedulerdatablock.h" - -// TODO: Why not include the headerfiles? -// OR create a master include that includes all the pipelines in one go? -class Pipeline; -class CalibrationPipeline; -class ImagingPipeline; -class PulsarPipeline; -class LongBaselinePipeline; - -class SchedulerData -{ -public: - SchedulerData(); - SchedulerData(unsigned short undo_levels); - virtual ~SchedulerData(); - - friend QDataStream& operator<< (QDataStream &out, const SchedulerData &data); // used for writing the data to binary file - friend QDataStream& operator>> (QDataStream &in, SchedulerData &data); // used for reading binary scheduling project from file - - void cleanup(void); // clean up data objects - void addUsedTaskID(unsigned int taskID) {itsData.addUsedTaskID(taskID);} - void addUsedTaskIDs(const std::vector<unsigned> &taskIDs) {itsData.addUsedTaskIDs(taskIDs);} - void setSASUsedTaskIDs(const std::vector<unsigned int> &task_ids) {itsData.setSASUsedTaskIDs(task_ids);} - void updateUsedTaskIDs(void) {itsData.updateUsedTaskIDs();} // adds the task IDs currently used in the current schedulerDataBlock - bool addTask(Task *task, bool check_ID_unused = true) {return itsData.addTask(task, check_ID_unused);} // adds a new task to the list of unscheduled tasks -// bool addPipeline(Pipeline *pPipe, bool dont_check_free_id = false) {return itsData.addPipeline(pPipe, dont_check_free_id);} - StationTask *newReservation(unsigned task_id, bool override_SAS_taskIDs = false) {return itsData.newReservation(task_id, override_SAS_taskIDs);} // create a new reservation with task ID equal to task_id, return pointer to task object or 0 when task_id already exists - Pipeline *newPipeline(unsigned task_id, pipelineType type, bool override_SAS_taskIDs = false) {return itsData.newPipeline(task_id, type, override_SAS_taskIDs);} // create a new pipeline with task ID equal to task_id, return pointer to task object or 0 when task_id already exists - Observation *newObservation(unsigned int task_id, bool override_SAS_taskIDs = false) {return itsData.newObservation(task_id, override_SAS_taskIDs);} // create a new task with task ID equal to task_id, return pointer to task or 0 when task_id already exists - Task *newTask(unsigned int task_id, bool override_SAS_taskIDs = false) {return itsData.newTask(task_id, override_SAS_taskIDs);} // create a new task with task ID equal to task_id, return pointer to task or 0 when task_id already exists - Task *newTask(unsigned int task_id, const OTDBtree &SAS_tree, bool override_SAS_taskIDs = false) {return itsData.newTask(task_id, SAS_tree, override_SAS_taskIDs);} - // removeTask: remove a task from the scheduler and return it. CAUTION The task is not actually deleted from memory. - // If you want to free the memory you should call delete on the returned task object - Task *deleteTask(unsigned id, id_type IDtype = ID_SCHEDULER, bool erase = true) {return itsData.deleteTask(id, IDtype, erase);} - bool getSaveRequired(void) {return itsData.getSaveRequired();} // controls if data changes need to be saved - bool getUploadRequired(void) {return itsData.getUploadRequired();} - bool getNextTask(Task &task) {return itsData.getNextTask(task);} // returns true if the next unscheduled task was found. parameter task contains the task - bool scheduleNextTask(AstroDateTime const &schedule_time) {return itsData.scheduleNextTask(schedule_time);} // schedules the next unscheduled task (which can be obtained with getNextTask - bool scheduleTask(Task * pTask) { return itsData.scheduleTask(pTask); } - bool moveTaskToInactive(unsigned taskID) {return itsData.moveTaskToInactive(taskID);} - Task * moveTaskFromInactive(unsigned task_id) {return itsData.moveTaskFromInactive(task_id);} - std::vector<unsigned> moveTask(Task *pTask, const AstroDateTime &new_start, bool unschedule_conflicting_tasks) {return itsData.moveTask(pTask, new_start, unschedule_conflicting_tasks); } // moves the task to the new start time (always succeeds) throwing out conflicting tasks - bool shiftTask(unsigned int task_id, bool unschedule_conflicting_tasks) {return itsData.shiftTask(task_id, unschedule_conflicting_tasks);} // shifts the task over its duration in its current preferred direction if possible - bool rescheduleTask(unsigned int task_id, const AstroDateTime &new_start_time) {return itsData.rescheduleTask(task_id, new_start_time);} // tries to reschedule the task at the given new start time - bool rescheduleAbortedTask(unsigned task_id, const AstroDateTime & new_start) {return itsData.rescheduleAbortedTask(task_id, new_start);} // reschedules an aborted task at the first opportunity in the future - void holdNextTask(const std::string & reason) {itsData.holdNextTask(reason);} // puts the next unscheduled task at the end of the unscheduled task list - void tryScheduleUnscheduledTasks(void) {itsData.tryScheduleUnscheduledTasks();} // iterates over all unscheduled tasks to try and schedule them - // the following change.. functions change a task's schedule times without checking conflicts with other tasks - bool changeTaskStartTime(unsigned task_id, const AstroDateTime &new_start) {return itsData.changeTaskStartTime(task_id, new_start);} - bool changeTaskEndTime(unsigned task_id, const AstroDateTime &new_end) {return itsData.changeTaskEndTime(task_id, new_end);} - bool changeTaskDuration(unsigned task_id, const AstroTime &new_duration) {return itsData.changeTaskDuration(task_id, new_duration);} - bool changeTaskSchedule(unsigned task_id, const AstroDateTime &new_start, const AstroDateTime &new_end) {return itsData.changeTaskSchedule(task_id, new_start, new_end);} - void scheduleFixedTasks(void) {itsData.scheduleFixedTasks();} // schedules tasks marked with fixed day or fixed time - void updateTasksStationIDs(void) {itsData.updateTasksStationIDs();} - bool undo(bool store_redo = true); // undo the last operation on the scheduler data - bool redo(void); // redo the last undo operation - void create_undo_level(void) {itsUndoStack.push_back(itsData);} - void deleteLastStoredUndo(void) {itsUndoStack.pop_back();} - const Storage &getStorage(void) const {return itsData.getStorage();} - - // get methods - std::vector<unsigned> tasksInGroup(unsigned groupID, selector_types type = SEL_ALL_TASKS) const {return itsData.tasksInGroup(groupID, type);} - const SchedulerDataBlock & getCurrentSchedule(void) const { return itsData;} - size_t getNrScheduled(void) const { return itsData.getNrScheduled();} - size_t getNrUnscheduled(void) const {return itsData.getNrUnscheduled();} - size_t getNrReservations(void) const {return itsData.getNrReservations();} - size_t getNrInactive(void) const {return itsData.getNrInactive();} - size_t getNrPipelines(void) const {return itsData.getNrPipelines();} - const unscheduledTasksDeque &getUnscheduledTasks(void) const { return itsData.getUnscheduledTasks(); } - const scheduledTasksMap &getScheduledTasks(void) const {return itsData.getScheduledTasks();} - const reservationsMap &getReservations(void) const {return itsData.getReservations();} - const pipelinesMap &getPipelineTasks(void) const {return itsData.getPipelineTasks();} - StationTask *getScheduledTask(unsigned task_id) {return itsData.getScheduledTask(task_id);} - const StationTask *getScheduledTask(unsigned task_id) const { return itsData.getScheduledTask(task_id); } - const inActiveTasksMap &getInactiveTasks(void) const {return itsData.getInactiveTasks();} - std::vector<Task *> getReservationsVector(void) const {return itsData.getReservationsVector();} - std::vector<Task *> getMaintenanceVector(void) const {return itsData.getMaintenanceVector();} - std::vector<Task *> getScheduledTasksVector(void) const {return itsData.getScheduledTasksVector();} // no pipelines - std::vector<Task *> getInactiveTaskVector(void) const {return itsData.getInactiveTaskVector();} - std::vector<Task *> getUnScheduledTasksVector(void) const {return itsData.getUnScheduledTasksVector();} - std::vector<Task *> getPipelinesVector(void) const {return itsData.getPipelinesVector();} - std::vector<Pipeline *> getScheduledPipelinesVector(void) const {return itsData.getScheduledPipelinesVector();} - const Task *getTask(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getTask(taskID, IDtype);} - const StationTask *getReservation(unsigned reservation_id) const { return itsData.getReservation(reservation_id); } - const Task *getInactiveTask(unsigned task_id) const { return itsData.getInactiveTask(task_id); } - const Task *getUnscheduledTask(unsigned task_id) const { return itsData.getUnscheduledTask(task_id); } - const StationTask *getStationTask(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getStationTask(taskID, IDtype);} - const Observation *getObservation(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getObservation(taskID, IDtype);} - const Pipeline *getPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getPipeline(taskID, IDtype);} - const CalibrationPipeline *getCalibrationPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getCalibrationPipeline(taskID, IDtype);} - const ImagingPipeline *getImagingPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getImagingPipeline(taskID, IDtype);} - const PulsarPipeline *getPulsarPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getPulsarPipeline(taskID, IDtype);} - const LongBaselinePipeline *getLongBaselinePipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const {return itsData.getLongBaselinePipeline(taskID, IDtype);} - - const Observation *getScheduledObservation(unsigned task_id) const { return itsData.getScheduledObservation(task_id); } - Task *getTaskForChange(unsigned task_id, id_type IDtype = ID_SCHEDULER) { return itsData.getTaskForChange(task_id, IDtype); } - StationTask *getReservationForChange(unsigned task_id) { return itsData.getReservationForChange(task_id); } - Pipeline *getPipelineForChange(unsigned task_id) { return itsData.getPipelineForChange(task_id); } // returns the task with id equal to task_id so the caller can edit its properties - std::vector<Task *> getTasksInScheduleSortStartTime(void) const {return itsData.getTasksInScheduleSortStartTime();} - std::vector<Task *> getScheduledTasksSortStartTime(void) const {return itsData.getScheduledTasksSortStartTime();} - std::vector<Task *> getScheduledObservationsSortStartTime(void) const {return itsData.getScheduledObservationsSortStartTime();} - std::vector<Task *> getPreScheduledObservationsSortStartTime(void) const {return itsData.getPreScheduledObservationsSortStartTime();} - std::vector<Task *> getPreScheduledTasksSortStartTime(void) const {return itsData.getPreScheduledTasksSortStartTime();} - std::vector<Observation *> getFutureObservationsSortStartTime(void) const {return itsData.getFutureObservationsSortStartTime();} - std::vector<Task *> getUnScheduledTasksSortFirstDate(void) const {return itsData.getUnScheduledTasksSortFirstDate();} - std::map<unsigned, std::vector<Task *> > getGroupedTasks(Task::task_status state) const {return itsData.getGroupedTasks(state);} // key = groupID - std::map<unsigned, std::vector<Task *> > getGroupedObservations(Task::task_status state = Task::TASK_STATUS_END) const {return itsData.getGroupedObservations(state);} // key = groupID - const std::map<std::string, std::vector<Task *> > getPublishTasks(const AstroDateTime &start, const AstroDateTime &end) const {return itsData.getPublishTasks(start, end);} - const Station *getStation(unsigned int station_id) const {return itsData.getStation(station_id);} - const stationsMap &getStations(void) const {return itsData.getStations();} - size_t getNrTasks() const { return itsData.getNrTasks(); } // number of columns equals the number of data headers - std::vector<std::string> const & getDataHeaders(void) const { return itsDataHeaders; } // the data headers - unsigned int calcCurrentPenalty(void) { return itsData.calculatePenalty(); } - unsigned int getPenalty(void) const {return itsData.getPenalty();} -// unsigned int getCurrentDataLevel(void) {return current_data_level;} - const errorTasksMap &getErrorTasks(void) const {return itsData.getErrorTasks();} - bool newErrorTasks(void) {return itsData.newErrorTasks();} - void clearError(unsigned int taskID, data_headers header) { itsData.clearError(taskID, header);} - void markErrorTasksStatus(void) { itsData.markErrorTasksStatus(); } - size_t nrOfErrorTasks(void) const { return itsData.nrOfErrorTasks(); } - bool stationExist(const std::string &stationName) const;// { return itsData.stationExist(stationID); } -// unsigned int getNewTaskID(const std::vector<unsigned> &exclude_IDs) const { return itsData.getNewTaskID(exclude_IDs); }; - unsigned int getNewTaskID(bool override_SAS_taskIDs = false) const { return itsData.getNewTaskID(override_SAS_taskIDs); } - inline bool isTaskIDFree(unsigned taskID) const {return itsData.isTaskIDFree(taskID);} - void checkStatusChanges(void) {itsData.checkStatusChanges();} - bool checkStationConflicts(StationTask *pTask) {return itsData.checkStationConflicts(pTask);} - unscheduled_reasons checkTaskStations(StationTask *pTask) {return itsData.checkTaskStations(pTask);} // check stations of the given task - - //set methods - bool addStation(unsigned int station_id, const std::string &name) { return itsData.addStation(station_id, name); } - void setChangesMadeFlag(void) {itsData.setChangesMadeFlag();} - void clearChangesMadeFlag(void) {itsData.clearChangesMadeFlag();} - void clearUploadRequiredFlag(void) {itsData.clearUploadRequiredFlag();} - bool setUndoLevels(unsigned short nr_levels); - void setDataHeaders(std::vector<std::string> const &headers); - void moveUnscheduledTask(unsigned int from, unsigned int to) { itsData.moveUnscheduledTask(from, to); } - void setCurrentSchedule(SchedulerDataBlock &new_schedule) {itsData = new_schedule; } - void sortUnscheduledTasks2Priority() { itsData.sortUnscheduledTasks2Priority(); } // sort the unscheduled tasks according to priority - bool unscheduleTask(unsigned int task_id) {return itsData.unscheduleTask(task_id);} - bool unscheduleReservation(unsigned reservation_id) {return itsData.unscheduleReservation(reservation_id);} // unschedule a reservation (putting it ON HOLD and removing it from the stations - void unscheduleAll(void) { itsData.unscheduleAll(); } - void setTaskStationIDs(Task *task); // sets the correct station IDs in the task - void updateStations(void) {itsData.updateStations();} - void initStorage(void) {itsData.initStorage();} - void clearStorageClaims(void) {itsData.clearStorageClaims();} - std::vector<storageResult> checkAssignedTaskStorage(Task *pTask, dataProductTypes dataProduct) {return itsData.checkAssignedTaskStorage(pTask, dataProduct);} - storageLocationOptions getStorageLocationOptions(dataProductTypes dataProduct, const AstroDateTime &startTime, const AstroDateTime &endTime, const double &fileSize, const double &bandWidth, unsigned minNrFiles, sortMode sort_mode = SORT_NONE, const std::vector<int> &nodes = std::vector<int>()) { - return itsData.getStorageLocationOptions(dataProduct, startTime, endTime, fileSize, bandWidth, minNrFiles, sort_mode, nodes); - } - const std::vector<storageResult> &getLastStorageCheckResult(void) const {return itsData.getLastStorageCheckResult();} - void setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts) {itsData.setAllowedStorageHosts(allowedStorageHosts);} - - // task checking methods - bool checkTasksForErrors(void) {return itsData.checkTasksForErrors();} // check all tasks for all errors - bool predecessorExists(unsigned int predID) const {return itsData.predecessorExists(predID);} - bool checkTaskBoundaries(const Task &task) const {return itsData.checkTaskBoundaries(task);} - bool checkTask(Task *pTask) {return itsData.checkTask(pTask);} - //checks and possibly fixes tasks that have non-existing predecessors - bool findFirstOpportunity(const Task *pTask, AstroDateTime &start_time, unsigned reservation_id = 0) {return itsData.findFirstOpportunity(pTask, start_time, reservation_id);} - -private: - SchedulerDataBlock itsData; - std::vector<SchedulerDataBlock> itsUndoStack; - std::vector<SchedulerDataBlock> itsRedoStack; - std::vector<std::string> itsDataHeaders; -}; - -inline QDataStream& operator<< (QDataStream &out, const SchedulerData &data) -{ - out << data.itsData; - return out; -} - -inline QDataStream& operator>> (QDataStream &in, SchedulerData &data) -{ - in >> data.itsData; - data.updateUsedTaskIDs(); - return in; -} - -#endif /* SCHEDULERDATA_H_ */ - diff --git a/SAS/Scheduler/src/schedulerdatablock.cpp b/SAS/Scheduler/src/schedulerdatablock.cpp deleted file mode 100644 index ab18fd792b0a7f1d3245ff817c76212ae5b8ee6d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulerdatablock.cpp +++ /dev/null @@ -1,2939 +0,0 @@ -/* - * schedulerdatablock.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 12, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulerdatablock.cpp $ - * - */ - -#include <vector> -#include <map> -#include <deque> -#include <algorithm> -#include <math.h> -#include <iostream> -#include <sstream> -#include <string> -#include <QDateTime> -#include <QDataStream> -#include "lofar_scheduler.h" -#include "schedulerdatablock.h" -#include "schedulersettings.h" -#include "task.h" -#include "astrodatetime.h" -#include "Controller.h" -#include "station.h" -#include "SASConnection.h" -#include "calibrationpipeline.h" -#include "imagingpipeline.h" -#include "pulsarpipeline.h" -#include "longbaselinepipeline.h" -using std::map; -using std::string; -using std::stringstream; -using std::vector; -using std::deque; -using std::max; -using std::min; - -SchedulerDataBlock::SchedulerDataBlock() : - itsSaveRequired(false), itsUploadRequired(false), nullTask(0) { -} - -SchedulerDataBlock::SchedulerDataBlock(const SchedulerDataBlock &other) { - *this = other; -} - -SchedulerDataBlock::~SchedulerDataBlock() { - for (unscheduledTasksDeque::iterator i = unscheduledTasks.begin(); i != unscheduledTasks.end(); ++i) - delete *i; - // do the same for scheduledTasks - for (scheduledTasksMap::iterator i = scheduledTasks.begin(); i != scheduledTasks.end(); ++i) - delete i->second; - //and for reservations - for (reservationsMap::iterator i = itsReservations.begin(); i != itsReservations.end(); ++i) - delete i->second; - // do the same for inactiveTasks - for (inActiveTasksMap::iterator i = inactiveTasks.begin(); i != inactiveTasks.end(); ++i) - delete i->second; - -} - -QDataStream& operator<<(QDataStream &out, const SchedulerDataBlock &data) { - if (out.status() == QDataStream::Ok) { - - out << (quint32)data.itsUsedTaskIDs.size(); // number of taskIDs - for (std::vector<unsigned>::const_iterator it = data.itsUsedTaskIDs.begin(); it != data.itsUsedTaskIDs.end(); ++it) { - out << (quint32) *it; - } - - out << (quint32)data.unscheduledTasks.size(); // number of unscheduled tasks - for (unscheduledTasksDeque::const_iterator it = data.unscheduledTasks.begin(); it != data.unscheduledTasks.end(); ++it) { - data.writeTaskToStream(out, *it); // writes a task object - } - - out << (quint32)data.scheduledTasks.size(); - for (scheduledTasksMap::const_iterator it = data.scheduledTasks.begin(); it != data.scheduledTasks.end(); ++it) { - out << (quint32) it->first; - data.writeTaskToStream(out, it->second); // write a task object - } - - out << (quint32)data.itsPipelines.size(); - for (pipelinesMap::const_iterator it = data.itsPipelines.begin(); it != data.itsPipelines.end(); ++it) { - out << (quint32) it->first; - data.writeTaskToStream(out, it->second); // write a task object - } - - out << (quint32)data.itsReservations.size(); - for (reservationsMap::const_iterator it = data.itsReservations.begin(); it != data.itsReservations.end(); ++it) { - out << (quint32) it->first; - data.writeTaskToStream(out, it->second); // write a task object - } - - out << (quint32)data.inactiveTasks.size(); - for (inActiveTasksMap::const_iterator it = data.inactiveTasks.begin(); it != data.inactiveTasks.end(); ++it) { - out << (quint32) it->first; - data.writeTaskToStream(out, it->second); // write a task object - } - - out << (quint32)data.errorTasks.size(); - for (errorTasksMap::const_iterator it = data.errorTasks.begin(); it != data.errorTasks.end(); ++it) { - out << (quint32) it->first // task ID - << (quint32) it->second.size(); - for (std::vector<data_headers>::const_iterator dit = it->second.begin(); dit != it->second.end(); ++dit) { - out << (quint16) *dit; // error column - } - } - - out << (quint32)data.itsStations.size(); - for (stationsMap::const_iterator it = data.itsStations.begin(); it != data.itsStations.end(); ++it) { - out << (quint32) it->first << it->second; // write Station object - } - - out << (quint32) data.itsPenalty; - } - return out; -} - -QDataStream& operator>>(QDataStream &in, SchedulerDataBlock &data) { - if (in.status() == QDataStream::Ok) { - quint32 nrOfObjects(0), nrOfObjects2(0), ID(0); - quint16 column(0); - data.unscheduledTasks.clear(); - data.scheduledTasks.clear(); - data.errorTasks.clear(); - data.itsStations.clear(); - data.itsPipelines.clear(); - data.inactiveTasks.clear(); - data.itsUsedTaskIDs.clear(); - - in >> nrOfObjects; // read the number of used task IDs - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID; - data.itsUsedTaskIDs.push_back(ID); - } - - in >> nrOfObjects; // read the number of unscheduled tasks - for (quint32 i = 0; i < nrOfObjects; ++i) { - data.unscheduledTasks.push_back(data.readTaskFromStream(in)); - } - - in >> nrOfObjects; // read the number of scheduled tasks - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID; - data.scheduledTasks[ID] = static_cast<StationTask *>(data.readTaskFromStream(in)); - } - - in >> nrOfObjects; // read the number of pipeline tasks - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID; - data.itsPipelines[ID] = static_cast<Pipeline *>(data.readTaskFromStream(in)); - } - - in >> nrOfObjects; // read the number of reservation tasks - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID; - data.itsReservations[ID] = static_cast<StationTask *>(data.readTaskFromStream(in)); - } - - if (Controller::itsFileVersion >= 3) { - in >> nrOfObjects; // read the number of inactive tasks - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID; - data.inactiveTasks[ID] = data.readTaskFromStream(in); - } - } - - in >> nrOfObjects; // read the number of error tasks - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> column;// error column number - data.errorTasks[ID].push_back((data_headers) column); - } - } - - in >> nrOfObjects; // read the number of stations - Station station; - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> ID >> station; // read a station object - data.itsStations[ID] = station; - } - - in >> data.itsPenalty; - } - return in; -} - -void SchedulerDataBlock::writeTaskToStream(QDataStream &out, Task *pTask) const { - out << (quint8) pTask->getType(); - switch (pTask->getType()) { - case Task::OBSERVATION: - out << static_cast<Observation &>(*pTask); - break; - case Task::PIPELINE: - { - // TODO: OO code smell. Create a virtual static stream function on the pipeline classes - Pipeline *pipe = static_cast<Pipeline *>(pTask); - out << (quint8) pipe->pipelinetype(); - switch (pipe->pipelinetype()) { - case PIPELINE_CALIBRATION: - out << static_cast<CalibrationPipeline &>(*pTask); - break; - case PIPELINE_IMAGING: - out << static_cast<ImagingPipeline &>(*pTask); - break; - case PIPELINE_PULSAR: - out << static_cast<PulsarPipeline &>(*pTask); - break; - case PIPELINE_LONGBASELINE: - out << static_cast<LongBaselinePipeline &>(*pTask); - break; - default: - break; - } - break; - } - case Task::RESERVATION: - case Task::MAINTENANCE: - out << static_cast<StationTask &>(*pTask); - break; - case Task::SYSTEM: - out << *pTask; - break; - default: - break; - } -} - -Task *SchedulerDataBlock::readTaskFromStream(QDataStream &in) { - Task *pTask(0); - quint8 iVal; - in >> iVal; - Task::task_type type = static_cast<Task::task_type>(iVal); - switch (type) { - case Task::OBSERVATION: - pTask = new Observation(); - in >> static_cast<Observation &>(*pTask); // read Observation properties into pTask - break; - case Task::PIPELINE: - in >> iVal; // read the pipeline type - switch (static_cast<pipelineType>(iVal)) { - case PIPELINE_CALIBRATION: - pTask = new CalibrationPipeline(); - in >> static_cast<CalibrationPipeline &>(*pTask); // read Calibration Pipeline properties into pTask - break; - case PIPELINE_IMAGING: - pTask = new ImagingPipeline(); - in >> static_cast<ImagingPipeline &>(*pTask); // read Observation properties into pTask - break; - case PIPELINE_PULSAR: - pTask = new PulsarPipeline(); - in >> static_cast<PulsarPipeline &>(*pTask); // read Pulsar Pipeline properties into pTask - break; - case PIPELINE_LONGBASELINE: - pTask = new LongBaselinePipeline(); - in >> static_cast<LongBaselinePipeline &>(*pTask); // read Long-Baseline Pipeline properties into pTask - break; - default: - pTask = new Pipeline(); - in >> static_cast<Pipeline &>(*pTask); // read Pipeline properties into pTask - } - break; - case Task::RESERVATION: - case Task::MAINTENANCE: - pTask = new StationTask(type); - in >> static_cast<StationTask &>(*pTask); // read StationTask properties into pTask - break; - case Task::SYSTEM: - pTask = new Task(); - in >> *pTask; // read Task properties into pTask - break; - default: - break; - } - return pTask; -} - -SchedulerDataBlock & SchedulerDataBlock::operator=(const SchedulerDataBlock &rhs) { - if (this != &rhs) { - //unscheduled tasks - if (!(unscheduledTasks.empty())) { - for (unscheduledTasksDeque::iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - delete *it; - *it = 0; - } - unscheduledTasks.clear(); - } - for (unscheduledTasksDeque::const_iterator it = rhs.getUnscheduledTasks().begin(); it != rhs.getUnscheduledTasks().end(); ++it) { - Task *pTask = new Task(*(*it)); - this->addTask(pTask, DONT_CHECK_FREE_ID); // the NO_CHECK skips the check to see if the ID is free. (we already know it is free) - } - - // scheduled tasks - if (!(scheduledTasks.empty())) { - for (scheduledTasksMap::iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - delete it->second; - it->second = 0; - } - scheduledTasks.clear(); - } - for (scheduledTasksMap::const_iterator it = rhs.getScheduledTasks().begin(); it != rhs.getScheduledTasks().end(); ++it) { - Task *pTask = cloneTask(it->second); - if (pTask) { - scheduledTasks.insert(std::pair<unsigned, StationTask *>(it->second->getID(), static_cast<StationTask *>(pTask))); - } - } - - // pipeline tasks - if (!(itsPipelines.empty())) { - for (pipelinesMap::iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - delete it->second; - it->second = 0; - } - itsPipelines.clear(); - } - for (pipelinesMap::const_iterator it = rhs.getPipelineTasks().begin(); it != rhs.getPipelineTasks().end(); ++it) { - Task *pTask = cloneTask(it->second); - if (pTask) { - itsPipelines.insert(std::pair<unsigned, Pipeline *>(it->second->getID(), static_cast<Pipeline *>(pTask))); - } - } - - //reservations - if (!(itsReservations.empty())) { - for (reservationsMap::iterator it = itsReservations.begin(); it != itsReservations.end(); ++it) { - delete it->second; - it->second = 0; - } - itsReservations.clear(); - } - for (reservationsMap::const_iterator it = rhs.getReservations().begin(); it != rhs.getReservations().end(); ++it) { - Task *pTask = cloneTask(it->second); - if (pTask) { - itsReservations.insert(std::pair<unsigned, StationTask *>(it->second->getID(), static_cast<StationTask *>(pTask))); - } - } - - // inactive tasks - if (!(inactiveTasks.empty())) { - for (inActiveTasksMap::iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++it) { - delete it->second; - it->second = 0; - } - inactiveTasks.clear(); - } - for (inActiveTasksMap::const_iterator it = rhs.getInactiveTasks().begin(); it != rhs.getInactiveTasks().end(); ++it) { - Task *pTask = cloneTask(it->second); - if (pTask) { - inactiveTasks.insert(std::pair<unsigned, Task *>(it->second->getID(), pTask)); - } - } - - itsStations = rhs.getStations(); - errorTasks = rhs.getErrorTasks(); - itsUsedTaskIDs = rhs.getUsedTaskIDs(); - itsStorage = rhs.getStorage(); - itsUsedTaskIDs = rhs.getUsedTaskIDs(); - itsExistingSASTaskIDs = rhs.getSASUsedTaskIDs(); - itsPenalty = rhs.getPenalty(); - itsSaveRequired = rhs.getSaveRequired(); - itsUploadRequired = rhs.getUploadRequired(); - } - return *this; -} - -// adds a new task to the list of unscheduled tasks -bool SchedulerDataBlock::addTask(Task *task, bool check_ID_free) { - unsigned id(task->getID()); - if (check_ID_free) { - if (!isTaskIDFree(task->getID())) { - debugWarn("sis","could not add task: ", task->getID(), " because that ID is already used."); - return false; - } - } - if (task->isPipeline()) { - itsPipelines[id] = static_cast<Pipeline *>(task); - } - else if (task->isMaintenance() || task->isReservation()) { - itsReservations[id] = static_cast<StationTask *>(task); - } - else { - unscheduledTasks.push_back(task); - } - itsUsedTaskIDs.push_back(id); - return true; -} - -void SchedulerDataBlock::addUsedTaskID(unsigned taskID) { - if (isTaskIDFree(taskID)) { - itsUsedTaskIDs.push_back(taskID); - } -} - -void SchedulerDataBlock::addUsedTaskIDs(const std::vector<unsigned> &taskIDs) { - for (std::vector<unsigned>::const_iterator it = taskIDs.begin(); it != taskIDs.end(); ++it) { - if (isTaskIDFree(*it)) { - itsUsedTaskIDs.push_back(*it); - } - } -} - -void SchedulerDataBlock::updateUsedTaskIDs(void) { - itsUsedTaskIDs.clear(); - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - itsUsedTaskIDs.push_back(it->first); - } - for (reservationsMap::const_iterator it = itsReservations.begin(); it != itsReservations.end(); ++it) { - itsUsedTaskIDs.push_back(it->first); - } - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - itsUsedTaskIDs.push_back((*it)->getID()); - } - for (inActiveTasksMap::const_iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++it) { - itsUsedTaskIDs.push_back(it->first); - } - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - itsUsedTaskIDs.push_back(it->first); - } -} - -void SchedulerDataBlock::removeUsedTaskID(unsigned task_id) { - std::vector<unsigned>::iterator erit = find(itsUsedTaskIDs.begin(), itsUsedTaskIDs.end(), task_id); - if (erit != itsUsedTaskIDs.end()) { - itsUsedTaskIDs.erase(erit); - return; - } - - debugWarn("sis","could not remove task id: ", task_id, " because it was not in the list of used task IDs."); -} - -unsigned SchedulerDataBlock::getNewTaskID(bool override_SAS_taskIDs) const { - unsigned id; - for (id = 1; id < MAX_UNSIGNED; ++id) { - if (isTaskIDFree(id)) { - if (!override_SAS_taskIDs) { - if (isTaskIDFreeInSAS(id)) { - return id; - } - } - else return id; - } - } - return 0; -} - -/* -unsigned SchedulerDataBlock::getNewTaskID(const std::vector<unsigned> &exclude_IDs) const { - for (unsigned id = 1; id < MAX_UNSIGNED; ++id) { - if (find(exclude_IDs.begin(), exclude_IDs.end(), id) == exclude_IDs.end()) { - if (isTaskIDFree(id)) - return id; - } - } - return 0; -} -*/ - -bool SchedulerDataBlock::moveTaskToInactive(unsigned taskID) { - for (unscheduledTasksDeque::iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - if ((*it)->getID() == taskID) { - if ((*it)->getStatus() >= Task::FINISHED) { - // move the task from unscheduled deque to inactive tasks map - inactiveTasks.insert(inActiveTasksMap::value_type((*it)->getID(), (*it))); - unscheduledTasks.erase(it); - return true; - } - else return false; - } - } - for (scheduledTasksMap::iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if (it->second->getID() == taskID) { - if (it->second->getStatus() >= Task::FINISHED) { - // move the task from scheduled tasks map to inactive tasks map - inactiveTasks.insert(inActiveTasksMap::value_type(it->second->getID(), it->second)); - it->second = 0; - scheduledTasks.erase(it); - return true; - } - } - } - for (pipelinesMap::iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - if (it->second->getID() == taskID) { - if (it->second->getStatus() >= Task::FINISHED) { - // move the task from pipelines tasks map to inactive tasks map - inactiveTasks.insert(inActiveTasksMap::value_type(it->second->getID(), it->second)); - it->second = 0; - itsPipelines.erase(it); - return true; - } - } - } - return false; -} - -void SchedulerDataBlock::printUsedTaskIDs(void) const { - if (!itsUsedTaskIDs.empty()) { - std::cout << "Task IDs in use: "; - for (std::vector<unsigned>::const_iterator it = itsUsedTaskIDs.begin(); it != itsUsedTaskIDs.end()-1; ++it) { - std::cout << *it << ","; - } - std::cout << itsUsedTaskIDs.back() << std::endl; - } - else { - std::cout << "no task IDs in use" << std::endl; - } -} - - -StationTask *SchedulerDataBlock::newReservation(unsigned task_id, bool override_SAS_taskIDs) { - if ((task_id == 0) || (!isTaskIDFree(task_id))) { // reservation ID=zero means get a new ID - task_id = getNewTaskID(override_SAS_taskIDs); - } - if (!override_SAS_taskIDs) { - if (!isTaskIDFreeInSAS(task_id)) - return 0; - } - StationTask *r = new StationTask(task_id, Task::RESERVATION); - itsReservations[task_id] = r; - itsUsedTaskIDs.push_back(task_id); - return r; -} - -Observation *SchedulerDataBlock::newObservation(unsigned task_id, bool override_SAS_taskIDs) { - Observation *pTask(0); - task_id = getTaskID(task_id, override_SAS_taskIDs); - if (task_id) { - pTask = new Observation(task_id); - unscheduledTasks.push_back(pTask); - itsUsedTaskIDs.push_back(task_id); - } - return pTask; -} - -Pipeline *SchedulerDataBlock::newPipeline(unsigned task_id, pipelineType type, bool override_SAS_taskIDs) { - Pipeline *pTask(0); - task_id = getTaskID(task_id, override_SAS_taskIDs); - if (task_id) { - switch (type) { - case PIPELINE_CALIBRATION: - pTask = new CalibrationPipeline(task_id); - break; - case PIPELINE_IMAGING: - pTask = new ImagingPipeline(task_id); - break; - case PIPELINE_PULSAR: - pTask = new PulsarPipeline(task_id); - break; - case PIPELINE_LONGBASELINE: - pTask = new LongBaselinePipeline(task_id); - break; - default: - pTask = new Pipeline(task_id); - debugWarn("sis", "SchedulerDataBlock::newPipeline: Pipeline with task id: ", task_id, " is of unknown type."); - break; - } - itsPipelines[task_id] = pTask; - itsUsedTaskIDs.push_back(task_id); - } - return pTask; -} - -unsigned SchedulerDataBlock::getTaskID(unsigned task_id, bool override_SAS_taskIDs) { - if (task_id == 0) return getNewTaskID(override_SAS_taskIDs); // provided task_id = 0, generate a new task_id - else if (isTaskIDFree(task_id)) return task_id; // provided task_id is is not used yet, use it. - else return getNewTaskID(override_SAS_taskIDs); // generate a new ID -} - -Task *SchedulerDataBlock::newTask(unsigned task_id, const OTDBtree &SAS_tree, bool override_SAS_taskIDs) { - task_id = getTaskID(task_id, override_SAS_taskIDs); - Task *t = new Task(task_id, SAS_tree); - unscheduledTasks.push_back(t); - itsUsedTaskIDs.push_back(task_id); - return t; -} - -Task *SchedulerDataBlock::newTask(unsigned task_id, bool override_SAS_taskIDs) { - task_id = getTaskID(task_id, override_SAS_taskIDs); - Task *t = new Task(task_id); - unscheduledTasks.push_back(t); - itsUsedTaskIDs.push_back(task_id); - return t; -} - -Task *SchedulerDataBlock::deleteTask(unsigned id, id_type IDtype, bool erase) { - const Task *pTask(getTask(id, IDtype)); - Task * retTask(0); - if (pTask) { - unsigned task_id(pTask->getID()); - - if (pTask->isScheduled()) { - unscheduleTask(task_id); // moves the task to the unscheduled queue as well - } - removeUsedTaskID(task_id); - - // no need to search for the task in the scheduledTasksMap because the task is unscheduled now - unscheduledTasksDeque::iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getID() == task_id) { - if (erase) delete *uit; else retTask = *uit; - unscheduledTasks.erase(uit); - return retTask; - } - ++uit; - } - - pipelinesMap::iterator pit = itsPipelines.find(task_id); - if (pit != itsPipelines.end()) { - if (erase) delete pit->second; else retTask = pit->second; - itsPipelines.erase(pit); - return retTask; - } - - inActiveTasksMap::iterator it = inactiveTasks.find(task_id); - if (it != inactiveTasks.end()) { - if (it->second->isStationTask() && it->second->getStatus() >= Task::SCHEDULED) { // if status is greater or equal to scheduled it means that is has been planned on the stations - removeTaskFromStations(static_cast<StationTask *>(it->second)); - } - if (erase) delete it->second; else retTask = it->second; - inactiveTasks.erase(it); - return retTask; - } - - reservationsMap::iterator rit = itsReservations.find(task_id); - if (rit != itsReservations.end()) { - if (erase) delete rit->second; else retTask = rit->second; - itsReservations.erase(rit); - return retTask; - } - } - - return 0; -} - - -// remove a task is inactive (finished, aborted, etc) from the stations -void SchedulerDataBlock::removeTaskFromStations(StationTask *task) { - stationsMap::iterator ssit; - const std::map<std::string, unsigned> &stations = task->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - ssit = itsStations.find(sit->second); // first check if the station still exists, the user may have deleted it with the settingsdialog - if (ssit != itsStations.end()) { - ssit->second.removeTask(task->getID()); - } - } -} - -void SchedulerDataBlock::unscheduleAll(void) { - for (scheduledTasksMap::iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - unscheduledTasks.push_back(it->second); - it->second->setStatus(Task::UNSCHEDULED); - } - scheduledTasks.clear(); - for (stationsMap::iterator sit = itsStations.begin(); sit != itsStations.end(); ++sit) { - sit->second.removeAllTasks(); - } -} - -/* -void SchedulerDataBlock::unscheduleAll(bool forced_unschedule) { - if (forced_unschedule) { - for (scheduledTasksMap::iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - unscheduledTasks.push_back(it->second); - it->second->setStatus(Task::UNSCHEDULED); - } - scheduledTasks.clear(); - for (stationsMap::iterator sit = itsStations.begin(); sit != itsStations.end(); ++sit) { - sit->second.removeAllTasks(); - } - } - else { // forced_unschedule = false -> we may not unschedule tasks with their may_not_unschedule flag set (this automatically includes reservations) - std::vector<unsigned> taskIDs; - for (scheduledTasksMap::iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - taskIDs.push_back(it->first); - } - for (std::vector<unsigned>::const_iterator it = taskIDs.begin(); it != taskIDs.end(); ++it) { - unscheduleTask(*it, false); - } - } -} -*/ - -bool SchedulerDataBlock::unscheduleTask(unsigned task_id) { - Task *pTask(0); - scheduledTasksMap::iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) { - pTask = it->second; - scheduledTasks.erase(it); - pTask->setStatus(Task::UNSCHEDULED); - unscheduledTasks.push_back(pTask); - } - else { - pipelinesMap::iterator it = itsPipelines.find(task_id); - if (it != itsPipelines.end()) { - pTask = it->second; - pTask->setStatus(Task::UNSCHEDULED); - } - else { - reservationsMap::iterator it = itsReservations.find(task_id); - if (it != itsReservations.end()) { - pTask = it->second; - // debugInfo("sis", "Reservation: ", task_id, " is being unscheduled"); - pTask->setStatus(Task::ON_HOLD); - } - } - } - if (pTask) { - if (pTask->isStationTask()) { - stationsMap::iterator ssit; - const std::map<std::string, unsigned> &stations = static_cast<StationTask *>(pTask)->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - ssit = itsStations.find(sit->second); // first check if the station still exists, the user may have deleted it with the settingsdialog - if (ssit != itsStations.end()) { - ssit->second.removeTask(task_id); - } - } - } - return true; - } - else { -// debugWarn("sis", "Could not unschedule task: ", task_id, " because it is not scheduled"); - return false; - } -} - -std::vector<unsigned> SchedulerDataBlock::moveTask(Task *pTask, const AstroDateTime &new_start, bool unschedule_conflicting_tasks) { - std::vector<unsigned> conflictIDs; - - AstroDateTime new_end = new_start + pTask->getDuration(); - - if (pTask->isStationTask()) { - // go by all Stations in this task to see if we have to kick out conflicting tasks - // check if any of the conflicting tasks are SCHEDULED - // only PRESCHEDULED tasks may be thrown out of the schedule - StationTask *psTask(static_cast<StationTask *>(pTask)); - const std::map<std::string, unsigned> &stations = psTask->getStations(); - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - conflictIDs = itsStations[sit->second].getTaskswithinTimeSpan(new_start, new_end); - if (unschedule_conflicting_tasks) { - for (std::vector<unsigned>::const_iterator tit = conflictIDs.begin(); tit != conflictIDs.end(); ++tit) { - const Task *pTask = getTask(*tit); - if (pTask->getStatus() == Task::SCHEDULED) { // only PRESCHEDULED tasks may be unscheduled - return conflictIDs; // we cannot continue with the move because of conflicting tasks that cannot be unscheduled - } - } - // apparently there are no conflicting fixed tasks, continue with the unscheduling of conflicting tasks - for (std::vector<unsigned>::const_iterator uit = conflictIDs.begin(); uit != conflictIDs.end(); ++uit) { - unscheduleTask(*uit); - } - } - else if (!conflictIDs.empty()) { - return conflictIDs; - } - } // else leave conflicting task in the schedule and continue with the move - - // update the stations bookkeeping - stationsMap::iterator sit; - for (std::map<std::string, unsigned>::const_iterator sidit = stations.begin(); sidit != stations.end(); ++sidit) { - if ((sit = itsStations.find(sidit->second)) != itsStations.end()) { - sit->second.moveTask(pTask->getID(), pTask->getScheduledStart(), pTask->getScheduledEnd()); - } - } - } - - // do the actual move - pTask->setScheduledStart(new_start); - pTask->syncStartStopTimes(); // also update the start and stop time in the meta-data of OTDBtree - - return conflictIDs; -} - -// function to check if the task is still within predecessor range -// return value: -// -1: both the lower limit and upper limit have been reached (no movement possible) -// 0: clear of both limits can move left (earlier) or right (later) -// 1: lower limit reached, can move right (later) -// 2: upper limit reached, can move left (earlier) -short int SchedulerDataBlock::withinPredecessorsRange(const Task *task, const AstroDateTime &new_start) const { - const IDvector &predecessors(task->getPredecessors()); -// const AstroDateTime &start(task->getScheduledStart()), &end(task->getScheduledEnd()); - bool uppper_limit_reached(false), lower_limit_reached(false); - for (IDvector::const_iterator it = predecessors.begin(); it != predecessors.end(); ++it) { - const Task *predecessor(getTask(it->second, it->first)); - -// const AstroDateTime &pred_start(predecessor->getScheduledStart()); - const AstroDateTime &pred_end(predecessor->getScheduledEnd()); - if (!uppper_limit_reached) { - if (new_start > pred_end + task->getPredecessorMaxTimeDif()) uppper_limit_reached = true; - } - if (!lower_limit_reached) { - if (new_start < pred_end + task->getPredecessorMaxTimeDif()) lower_limit_reached = true; - } - if (lower_limit_reached && uppper_limit_reached) return -1; - } - if (lower_limit_reached && uppper_limit_reached) return -1; - else if (lower_limit_reached) return 1; - else if (uppper_limit_reached) return 2; - else return 0; -} - -bool SchedulerDataBlock::tryMoveTaskToAdjacentDay(unsigned task_id, bool unschedule_conflicting_tasks) { - std::pair<bool, std::vector<unsigned> > result; - result.first = false; - Task *task = getTaskForChange(task_id); - AstroDateTime new_start; - if (task->hasPredecessors()) { - if (task->getShiftDirection() == SHIFT_RIGHT) { - new_start = task->getScheduledStart().addDays(1); - int w(withinPredecessorsRange(task,new_start)); // test ranges to predecessors - if (w == 2) { // upper limit reached - task->setShiftDirection(SHIFT_LEFT); // task would move out of predecessor range, change direction - new_start = task->getScheduledStart().subtractDays(1); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else if ((w == 0) || (w == 1)) { // no limit or only lower limit reached - if ((new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay()) || - (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - return false; - } - if ((new_start < task->getFirstPossibleDateTime()) || (new_start > task->getLastPossibleDateTime())) { - return false; - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else return false; // no movement possible - } - else { // shift left - new_start = task->getScheduledStart().subtractDays(1); - int w(withinPredecessorsRange(task,new_start)); // test ranges to predecessors - if (w == 1) { // upper limit reached - task->setShiftDirection(SHIFT_RIGHT); // task would move out of predecessor range, change direction - new_start = task->getScheduledStart().addDays(1); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else if ((w == 0) || (w == 2)) { // no limit or only upper limit reached - if ((new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay()) || - (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - return false; - } - if ((new_start < task->getFirstPossibleDateTime()) || (new_start > task->getLastPossibleDateTime())) { - return false; - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else return false; // no movement possible - } - } - // task doesn't have predecessors - if (task->getShiftDirection() == SHIFT_RIGHT) { - new_start = task->getScheduledStart().addDays(1); - if ((new_start > task->getLastPossibleDateTime()) || (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - task->setShiftDirection(SHIFT_LEFT); - new_start = task->getScheduledStart().subtractDays(1); - } - } - else { // shift left - new_start = task->getScheduledStart().subtractDays(1); - if ((new_start < task->getFirstPossibleDateTime()) || (new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay())) { - task->setShiftDirection(SHIFT_RIGHT); - new_start = task->getScheduledStart().addDays(1); - } - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); -} - -bool SchedulerDataBlock::tryShiftTaskWithinDay(unsigned task_id, bool unschedule_conflicting_tasks) { - Task *task = getTaskForChange(task_id); - AstroDateTime new_start; - if (task->getShiftDirection() == SHIFT_RIGHT) { - new_start = task->getScheduledEnd() + task->getDuration(); - if (new_start.getDate() == task->getScheduledEnd().getDate()) { // still on same day? - int w(withinPredecessorsRange(task,new_start)); // test ranges to predecessors - if (w == 2) { // upper limit reached - task->setShiftDirection(SHIFT_LEFT); // task would move out of predecessor range, change direction - new_start = task->getScheduledStart() - task->getDuration(); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else if ((w == 0) || (w == 1)) { // no limit or only lower limit reached - if ((new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay()) | - (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - return false; - } - if ((new_start < task->getFirstPossibleDateTime()) || (new_start > task->getLastPossibleDateTime())) { - return false; - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else return false; // no movement possible - } - else { - task->setShiftDirection(SHIFT_LEFT); - new_start = task->getScheduledStart() - task->getDuration(); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - } - else { // shift left - new_start = task->getScheduledStart() - task->getDuration(); - if (new_start.getDate() == task->getScheduledEnd().getDate()) { // still on same day? - int w(withinPredecessorsRange(task,new_start)); // test ranges to predecessors - if (w == 1) { // upper predecessor limit reached - task->setShiftDirection(SHIFT_RIGHT); // task would move out of predecessor range, change direction - new_start = task->getScheduledStart() + task->getDuration(); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else if ((w == 0) || (w == 2)) { // no limit or only upper limit reached - if ((new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay()) || - (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - return false; - } - if ((new_start < task->getFirstPossibleDateTime()) || (new_start > task->getLastPossibleDateTime())) { - return false; - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else return false; // no movement possible - } - else { - task->setShiftDirection(SHIFT_RIGHT); - new_start = task->getScheduledStart() + task->getDuration(); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - } -} - -/* -bool SchedulerDataBlock::tryShiftTask(unsigned task_id, bool unschedule_conflicting_tasks) { - Task *task = getTaskForChange(task_id); - if (task->hasPredecessor()) { - unsigned predTaskID = task->getPredecessor(); - const Task *predecessor = getTask(predTaskID); - if (getTask(predTaskID)->getStatus() == Task::SCHEDULED) { - if (task->getShiftDirection() == SHIFT_RIGHT) { - if (task->getScheduledEnd() > predecessor->getScheduledEnd() + task->getPredecessorMaxTimeDif()) { - task->setShiftDirection(SHIFT_LEFT); // task would move out of predecessor range, change direction - return shiftTask(task_id, SHIFT_LEFT, unschedule_conflicting_tasks); - } - } - else { // shift left - if (task->getScheduledStart() - task->getDuration() < predecessor->getScheduledEnd() + task->getPredecessorMinTimeDif()) { - task->setShiftDirection(SHIFT_RIGHT); // task would move to close to predecessor, change direction - return shiftTask(task_id, SHIFT_RIGHT, unschedule_conflicting_tasks); - } - } - } - } - return shiftTask(task->getID(), task->getShiftDirection(), unschedule_conflicting_tasks); -} -*/ -bool SchedulerDataBlock::shiftTask(unsigned task_id, bool unschedule_conflicting_tasks) { - Task *task = getTaskForChange(task_id); - AstroDateTime new_start; - if (task->hasPredecessors()) { - if (task->getShiftDirection() == SHIFT_RIGHT) { - new_start = task->getScheduledStart() + task->getDuration(); - int w(withinPredecessorsRange(task,new_start)); // test ranges to predecessors - if (w == 2) { // upper limit reached - task->setShiftDirection(SHIFT_LEFT); // task would move out of predecessor range, change direction - new_start = task->getScheduledStart() - task->getDuration(); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else if ((w == 0) || (w == 1)) { // no limit or only lower limit reached - if ((new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay()) || - (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - return false; - } - if ((new_start < task->getFirstPossibleDateTime()) || (new_start > task->getLastPossibleDateTime())) { - return false; - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else return false; // no movement possible - } - else { // shift left - new_start = task->getScheduledStart() - task->getDuration(); - int w(withinPredecessorsRange(task,new_start)); // test ranges to predecessors - if (w == 1) { // upper predecessor limit reached - task->setShiftDirection(SHIFT_RIGHT); // task would move out of predecessor range, change direction - new_start = task->getScheduledStart() + task->getDuration(); - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else if ((w == 0) || (w == 2)) { // no limit or only upper limit reached - if ((new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay()) || - (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - return false; - } - if ((new_start < task->getFirstPossibleDateTime()) || (new_start > task->getLastPossibleDateTime())) { - return false; - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); - } - else return false; // no movement possible - } - } - // task doesn't have predecessors - if (task->getShiftDirection() == SHIFT_RIGHT) { - new_start = task->getScheduledStart() + task->getDuration(); - if ((new_start > task->getLastPossibleDateTime()) || (new_start > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - task->setShiftDirection(SHIFT_LEFT); - new_start = task->getScheduledStart() - task->getDuration(); - } - } - else { // shift left - new_start = task->getScheduledStart() - task->getDuration(); - if ((new_start < task->getFirstPossibleDateTime()) || (new_start < Controller::theSchedulerSettings.getEarliestSchedulingDay())) { - task->setShiftDirection(SHIFT_RIGHT); - new_start = task->getScheduledStart() + task->getDuration(); - } - } - return (moveTask(task, new_start, unschedule_conflicting_tasks).empty()); -} - -bool SchedulerDataBlock::changeTaskStartTime(unsigned task_id, const AstroDateTime &new_start) { - Task *pTask = getTaskForChange(task_id); - if (pTask) { - pTask->setScheduledStart(new_start); - if (pTask->isStationTask()) { - StationTask *psTask(static_cast<StationTask *>(pTask)); - const taskStationsMap &stations = psTask->getStations(); - for (taskStationsMap::const_iterator stit = stations.begin(); stit != stations.end(); ++stit) { - stationsMap::iterator statit = itsStations.find(stit->second); - if (statit != itsStations.end()) { - statit->second.moveTask(task_id, new_start, new_start + psTask->getDuration()); - } - } - } - return true; - } - else return false; -} - -bool SchedulerDataBlock::changeTaskEndTime(unsigned task_id, const AstroDateTime &new_end) { - Task *pTask = getTaskForChange(task_id); - if (pTask) { - pTask->setScheduledEnd(new_end); - if (pTask->isStationTask()) { - StationTask *psTask(static_cast<StationTask *>(pTask)); - const taskStationsMap &stations = psTask->getStations(); - for (taskStationsMap::const_iterator stit = stations.begin(); stit != stations.end(); ++stit) { - stationsMap::iterator statit = itsStations.find(stit->second); - if (statit != itsStations.end()) { - statit->second.moveTask(task_id, new_end - psTask->getDuration(), new_end); - } - } - } - return true; - } - else return false; -} - -bool SchedulerDataBlock::changeTaskDuration(unsigned task_id, const AstroTime &new_duration) { - Task *pTask = getTaskForChange(task_id); - if (pTask) { - pTask->setDuration(new_duration); - if (pTask->isStationTask()) { - StationTask *psTask(static_cast<StationTask *>(pTask)); - const taskStationsMap &stations = psTask->getStations(); - AstroDateTime new_end(psTask->getScheduledStart() + new_duration); - for (taskStationsMap::const_iterator stit = stations.begin(); stit != stations.end(); ++stit) { - stationsMap::iterator statit = itsStations.find(stit->second); - if (statit != itsStations.end()) { - statit->second.moveTask(task_id, psTask->getScheduledStart(), new_end); - } - } - } - return true; - } - else return false; -} - -bool SchedulerDataBlock::changeTaskSchedule(unsigned task_id, const AstroDateTime &new_start, const AstroDateTime &new_end) { - Task *pTask(0); - scheduledTasksMap::iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) { - pTask = it->second; - } - else { - reservationsMap::iterator it = itsReservations.find(task_id); - if (it != itsReservations.end()) { - pTask = it->second; - } - } - if (pTask) { - pTask->setScheduledStart(new_start); - pTask->setScheduledEnd(new_end); - if (pTask->isStationTask()) { - StationTask *psTask(static_cast<StationTask *>(pTask)); - const taskStationsMap &stations = psTask->getStations(); - for (taskStationsMap::const_iterator stit = stations.begin(); stit != stations.end(); ++stit) { - stationsMap::iterator statit = itsStations.find(stit->second); - if (statit != itsStations.end()) { - statit->second.moveTask(task_id, new_start, new_end); - } - } - } - return true; - } - else return false; // task not found -} - -bool SchedulerDataBlock::rescheduleAbortedTask(unsigned task_id, const AstroDateTime &start) { - inActiveTasksMap::iterator it = inactiveTasks.find(task_id); - if (it != inactiveTasks.end()) { - Task * pTask = it->second; - AstroDateTime new_start(start); - if (findFirstOpportunity(pTask, new_start)) { - // this is an aborted (inactiveTask) task and therefore it is not scheduled, so no need to unschedule it - pTask->setScheduledStart(new_start); - scheduleTask(pTask); - pTask->setStatus(Task::PRESCHEDULED); - return true; - } - } - return false; -} - - -bool SchedulerDataBlock::rescheduleTask(unsigned task_id, const AstroDateTime &new_start) { - size_t count(0); - Task * pTask(0); - scheduledTasksMap::const_iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) { - pTask = it->second; - } - else { - reservationsMap::const_iterator rit = itsReservations.find(task_id); - if (rit != itsReservations.end()) { - pTask = rit->second; - } - } - if (pTask) { - if (pTask->isStationTask()) { - StationTask *psTask(static_cast<StationTask *>(pTask)); - - Task::task_type type = psTask->getType(); - if ((type == Task::RESERVATION) | (type == Task::MAINTENANCE)) { - // a reservation or maintenance task is always rescheduled at the requested new_start time (even if it conflicts with other tasks) - psTask->setScheduledStart(new_start); - stationsMap::iterator sit; - // go by all stations to reschedule the task in the stations their task lists - const taskStationsMap &stations = psTask->getStations(); - for (taskStationsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - sit = itsStations.find(it->second); - if (sit != itsStations.end()) { - sit->second.moveTask(task_id, psTask->getScheduledStart(), psTask->getScheduledEnd()); - } - } - return true; - } - else { // try reschedule regular task - const AstroTime &min_time_between_tasks = Controller::theSchedulerSettings.getMinimumTimeBetweenTasks(); - Station * pStation = 0; - bool opening_found = true, found_mutual_opening = false; - AstroDateTime first_opening(new_start), previous_opening; - const taskStationsMap &stations = psTask->getStations(); - vector<unsigned int> checkStations; - // first remove the task from the stations So that its time slot is not occupied anymore - stationsMap::iterator sit; - for (taskStationsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - sit = itsStations.find(it->second); - if (sit != itsStations.end()) { - sit->second.removeTask(task_id); - checkStations.push_back(it->second); - } - else { - debugErr("sssis", "SchedulerDataBlock::rescheduleTask: Station ", - it->first.c_str(), " in the list of task ", psTask->getID(), " which doesn't seem to exist!"); - } - } - - if (!checkStations.empty()) { - // now find a new mutual time slot on the stations - while (!found_mutual_opening && opening_found) { - count = 0; - for (vector<unsigned int>::const_iterator sit = checkStations.begin(); sit != checkStations.end(); ++sit) { - ++count; - previous_opening = first_opening; - if ((pStation = getStationForChange(*sit))) { - if (pStation->findFirstOpportunity(*psTask, first_opening, min_time_between_tasks)) { // if possible to schedule at this station then first_possible holds the possible start time - if (first_opening != previous_opening) { - if (psTask->hasPredecessors()) { - if (withinPredecessorsRange(psTask,first_opening) != 0) { - opening_found = false; - holdNextTask(MAX_DISTANCE_PREDECESSOR); - break; - } - } - if (count != 1) { - break; // starts again to ask all stations starting from the last found opening - } - } - if (count == checkStations.size()) { - found_mutual_opening = true; - } - } else { // one of the stations didn't find a possible scheduling time, skip other stations - opening_found = false; - break; // break out for loop, don't ask other stations for schedule opening - } - } - } - } - if (found_mutual_opening && (psTask->getStations().size() > 0)) { - // schedule the task at the stations on its new position - psTask->setScheduledStart(first_opening); - } - - // go by all stations to add the task again in the stations their task lists - for (vector<unsigned int>::const_iterator it = checkStations.begin(); it != checkStations.end(); ++it) { - sit = itsStations.find(*it); - sit->second.addTasktoStation(task_id, psTask->getScheduledStart(), psTask->getScheduledEnd()); - } - - if (found_mutual_opening && (psTask->getStations().size() > 0)) - return true; - else - return false; - } - else return false; // no existing stations left in task list - } - } - } - return false; -} - - -bool SchedulerDataBlock::findFirstOpportunity(const Task *pTask, AstroDateTime &start_time, unsigned reservation_id) { - if (pTask->isStationTask()) { - const StationTask *psTask(static_cast<const StationTask *>(pTask)); - AstroDateTime first_opening(start_time), previous_opening; - size_t count(0); - const std::map<std::string, unsigned> &stations = psTask->getStations(); - if (!stations.empty()) { - Station * pStation = 0; - while (1) { - count = 0; - for (std::map<std::string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - ++count; - previous_opening = first_opening; - if ((pStation = getStationForChange(sit->second))) { - if (pStation->findFirstOpportunity(*psTask, first_opening, Controller::theSchedulerSettings.getMinimumTimeBetweenTasks(), reservation_id)) { // if possible to schedule at this station then first_possible holds the possible start time - if (first_opening != previous_opening) { - if (count != 1) { - break; // starts again to ask all stations starting from the last found opening - } - } - if (count == stations.size()) { - start_time = first_opening; - return true; - } - } - else return false; - } - else return false; - } - } - } - } - return true; -} - -void SchedulerDataBlock::updateTasksStationIDs(void) { - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - if ((*it)->isStationTask()) { - static_cast<StationTask *>(*it)->updateStationIDs(); - } - } - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if ((it->second)->isStationTask()) { - static_cast<StationTask *>(it->second)->updateStationIDs(); - } - } - for (inActiveTasksMap::const_iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++it) { - if ((it->second)->isStationTask()) { - static_cast<StationTask *>(it->second)->updateStationIDs(); - } - } -} - -void SchedulerDataBlock::tryScheduleUnscheduledTasks(void) { - //TODO: SchedulerDataBlock::tryScheduleUnscheduledTasks Needs a complete rewrite!!! - /* - const AstroTime &min_time_between_tasks = Controller::theSchedulerSettings.getMinimumTimeBetweenTasks(); - Task task; - Task::task_status status; - Station *pStation = 0; - bool opening_found, found_mutual_opening; -#ifdef DEBUG_SCHEDULER - const Task * pTask(0); -#endif - size_t count(0); - AstroDateTime previous_opening, first_opening; - unsigned nr_unscheduled = getNrUnscheduled(); - for (unsigned i = 0; i != nr_unscheduled; ++i) { // iterate over all unscheduled tasks - opening_found = true; - found_mutual_opening = false; - if (getNextTask(task)) { - status = task.getStatus(); - if (status == Task::ON_HOLD) { - holdNextTask(TASK_ON_HOLD); - opening_found = false; - } - else if (status == Task::ERROR) { - holdNextTask(); - opening_found = false; - } - else if (checkTaskBoundaries(task)) { - // check with the stations requested by the task if the requested time is already occupied. If not schedule the task - first_opening = task.getFirstPossibleDateTime(); - if (task.hasLinkedTask()) { - // TODO: Maybe the user should have a choice if he doesn't want a task to be scheduled if this doesn't fit with a predecessor or a successor - if (task.hasPredecessors()) { - if (getTaskStatus(task.getPredecessor()) == Task::SCHEDULED) { // don't schedule the task if the predecessor isn't scheduled - first_opening = max(getTaskEndTime(task.getPredecessor()) + task.getPredecessorMinTimeDif(), first_opening); - if (first_opening > Controller::theSchedulerSettings.getLatestSchedulingDay()) { - holdNextTask(OUTSIDE_SCHEDULE_BOUNDS); - opening_found= false; - } - } else { - holdNextTask(PREDECESSOR_UNSCHEDULED); // don't schedule task if predecessor isn't scheduled - opening_found = false; - } - } - //TODO: A Task can have multiple successors! So calculate for all predecessors and take the latest time - if (task.hasSuccesors()) { - for (std::vector<unsigned>::const_iterator it = task.getSuccessors().begin(); it != task.getSuccessors().end(); ++it) { - first_opening = max(getTaskFirstPossibleDate(*it) - getTaskPredecessorMaxTimeDif(*it) - task.getDuration(), first_opening); - } - if ((first_opening < Controller::theSchedulerSettings.getEarliestSchedulingDay()) | - (first_opening > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - holdNextTask(OUTSIDE_SCHEDULE_BOUNDS); - opening_found= false; - } - } - } - } - else { // task has first possible and last possible dates out of schedule bounds - holdNextTask(OUTSIDE_SCHEDULE_BOUNDS); - opening_found = false; - } - while (!found_mutual_opening && opening_found) { - count = 0; - const std::map<std::string, unsigned> &stations = task.getStations(); - for (std::map<std::string, unsigned>::const_iterator it = stations.begin(); it != stations.end(); ++it) { - ++count; - if ((pStation = getStationForChange(it->second))) { - previous_opening = first_opening; - if (pStation->findFirstOpportunity(task, first_opening, min_time_between_tasks)) { - // if possible to schedule at this station then first_possible holds the possible start time - if (first_opening != previous_opening) { - // check if the opening found is not too far from the predecessor if there is a predecessor - if (task.hasPredecessor()) { - if (first_opening > getTaskEndTime(task.getPredecessor()) + task.getPredecessorMaxTimeDif()) { - opening_found = false; - holdNextTask(MAX_DISTANCE_PREDECESSOR); - break; - } - } - if (count != 1) { - break; // starts again to ask all stations starting from the last found opening - } - } - if (count == stations.size()) { - found_mutual_opening = true; - } - } else { // one of the stations didn't find a possible scheduling time, skip other stations - opening_found = false; - holdNextTask(NO_MUTUAL_OPENING_FOUND); - break; // break out for loop, don't ask other stations for schedule opening - } - } else { - debugErr("sssisis", "SchedulerDataBlock::tryScheduleUnscheduledTasks: Station ", it->first.c_str(), ", with ID: ", it->second, " in the list of task ", task.getID(), " which doesn't seem to exist!"); - opening_found = false; - holdNextTask(NON_EXISTING_STATION); - break; // break out for loop, don't ask other stations for schedule opening - } - } - } - if (found_mutual_opening && (task.getStations().size() > 0)) { - if (scheduleNextTask(first_opening)) { -#ifdef DEBUG_SCHEDULER - if ((pTask = getScheduledTask(task.getID()))) { - debugInfo("sissss", "Task: ", pTask->getID(), " is scheduled at start: ", - pTask->getScheduledStart().toString().c_str(), " and end: ", pTask->getScheduledEnd().toString().c_str()); - //std::cout << "Task: " << pTask->getID() << " is scheduled at start: " << pTask->getScheduledStart().toString() - // << " and end: " << pTask->getScheduledEnd().toString() << "." << std::endl; - } else { - debugErr( - "sis", "SchedulerDataBlock::tryScheduleUnscheduledTasks: scheduled task ", task.getID(), - "was not correctly scheduled!"); - } -#endif - } - } - } - } - */ -} - -void SchedulerDataBlock::scheduleFixedTasks(void) { - Task * pTask; - for (unsigned i = 0; i < unscheduledTasks.size(); ++i) { - //pTask = getTaskForChange(unscheduledTasks.at(i)->getID()); - pTask = unscheduledTasks.at(i); - if (pTask->getFixedDay() && pTask->getFixedTime()) { - if (pTask->getStatus() == Task::UNSCHEDULED) { // do not schedule or move task when state is other than APPROVED - if (checkTaskBoundaries(*pTask)) { - if (pTask->getScheduledStart().isSet()) { - if (pTask->getDuration().isSet()) { - pTask->setScheduledEnd(pTask->getScheduledStart() + pTask->getDuration()); - scheduleTask(pTask); - } else if (pTask->getScheduledEnd().isSet()) { - pTask->setDuration(pTask->getScheduledEnd() - pTask->getScheduledStart()); - scheduleTask(pTask); - } - } else if (pTask->getFirstPossibleDateTime().isSet()) { - if (pTask->getDuration().isSet()) { - pTask->setScheduledStart(pTask->getFirstPossibleDateTime()); - scheduleTask(pTask); - } - } - } - else { - pTask->setReason(OUTSIDE_SCHEDULE_BOUNDS); - } - } - } - } -} - -void SchedulerDataBlock::moveUnscheduledTask(unsigned from, unsigned to) { - unscheduledTasks.insert(unscheduledTasks.begin() + to, unscheduledTasks.at(from)); // insert the element before the successor - if (to < from) { - ++from; // increase from by one to compensate for the inserted element before the from element - } - unscheduledTasks.at(from) = 0; // prevents destruction of the task object pointed to by the pointer at the from position - unscheduledTasks.erase(unscheduledTasks.begin() + from); // now we can safely erase the element from the old position -} - -void SchedulerDataBlock::sortUnscheduledTasks2Priority(void) { - // TODO: SchedulerDataBlock::sortUnscheduledTasks2Priority needs complete rewrite!!! - /* - // first sort then put the predecessors before their successors - if (!unscheduledTasks.empty()) { - sort(unscheduledTasks.begin(), unscheduledTasks.end(), cmp_TaskPriority()); - vector<unsigned> predecessor_chain; - unsigned predecessor; - bool end_of_chain_reached; - // now move the predecessors before their successors - for (unsigned i = 0; i != unscheduledTasks.size() - 1; ++i) { // cannot use iterators because they are invalidated after erase and insert operations later on - predecessor = unscheduledTasks.at(i)->getPredecessor(); - if (predecessor) { - predecessor_chain.push_back(predecessor); - end_of_chain_reached = false; - while (true) { - // find the predecessor in the list of unscheduled tasks - unsigned ipre = i + 1; - for (; ipre != unscheduledTasks.size(); ++ipre) { //only search AFTER the current task, predecessors before it don't have to be moved! - if (unscheduledTasks.at(ipre)->getID() == predecessor) { // found the predecessor in the unscheduled tasks after current task - predecessor = unscheduledTasks.at(ipre)->getPredecessor(); - if (!predecessor) { - end_of_chain_reached = true; - break; - } - predecessor_chain.push_back(predecessor); - } - } - if (end_of_chain_reached | (ipre >= unscheduledTasks.size())) - break; // while loop - } - // we arrived at the front of the chain of sequential tasks - // now reverse the list and place the tasks in the right sequence - for (std::vector<unsigned>::reverse_iterator rit = - predecessor_chain.rbegin(); rit != predecessor_chain.rend(); ++rit) { - for (unsigned ipre = i + 1; ipre != unscheduledTasks.size(); ++ipre) { //only search AFTER the current task, predecessors before it don't have to be moved! - if (unscheduledTasks.at(ipre)->getID() == *rit) { // found the predecessor in the unscheduled tasks after current task - moveUnscheduledTask(ipre, i++); - break; // break out of search loop - } - } - } - predecessor_chain.clear(); - } - } - } - */ -} - -bool SchedulerDataBlock::checkTaskBoundaries(const Task &task) const { - if (task.getFirstPossibleDateTime() > Controller::theSchedulerSettings.getLatestSchedulingDay()) { - return false; - } - if (task.getLastPossibleDateTime() < Controller::theSchedulerSettings.getEarliestSchedulingDay()) { - return false; - } - return true; -} - -bool SchedulerDataBlock::taskExists(unsigned task_id) const { - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - if ((*it)->getID() == task_id) - return true; - } - if (scheduledTasks.find(task_id) != scheduledTasks.end()) { - return true; - } - if (itsPipelines.find(task_id) != itsPipelines.end()) { - return true; - } - if (inactiveTasks.find(task_id) != inactiveTasks.end()) { - return true; - } - return false; -} - - -const Task *SchedulerDataBlock::getTask(unsigned task_id, id_type IDtype) const { - switch (IDtype) { - case ID_SCHEDULER: - return getTaskByTaskID(task_id); - break; - case ID_MOM: - return getTaskByMomID(task_id); - break; - case ID_SAS: - return getTaskBySASTreeID(task_id); - break; - } - return 0; -} - -const Observation *SchedulerDataBlock::getObservation(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const Observation *>(getTask(taskID, IDtype)); // will return 0 if task is not an observation -} - -const StationTask *SchedulerDataBlock::getStationTask(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const StationTask *>(getTask(taskID, IDtype)); // will return 0 if task is not a StationTask -} - -const Pipeline *SchedulerDataBlock::getPipeline(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const Pipeline *>(getTask(taskID, IDtype)); // will return 0 if task is not an pipeline -} - -const CalibrationPipeline *SchedulerDataBlock::getCalibrationPipeline(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const CalibrationPipeline *>(getTask(taskID, IDtype)); // will return 0 if task is not an CalibrationPipeline -} - -const ImagingPipeline *SchedulerDataBlock::getImagingPipeline(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const ImagingPipeline *>(getTask(taskID, IDtype)); // will return 0 if task is not an ImagingPipeline -} - -const PulsarPipeline *SchedulerDataBlock::getPulsarPipeline(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const PulsarPipeline *>(getTask(taskID, IDtype)); // will return 0 if task is not an PulsarPipeline -} - -const LongBaselinePipeline *SchedulerDataBlock::getLongBaselinePipeline(unsigned taskID, id_type IDtype) const { - return dynamic_cast<const LongBaselinePipeline *>(getTask(taskID, IDtype)); // will return 0 if task is not an LongBaselinePipeline -} - -const StationTask *SchedulerDataBlock::getReservation(unsigned reservation_id) const { - reservationsMap::const_iterator it = itsReservations.find(reservation_id); - if (it != itsReservations.end()) { - return it->second; - } else return 0; -} - -const StationTask *SchedulerDataBlock::getScheduledTask(unsigned task_id) const { - scheduledTasksMap::const_iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) { - return it->second; - } - else { - reservationsMap::const_iterator rit = itsReservations.find(task_id); - if (rit != itsReservations.end()) return rit->second; - } - return 0; -} - -StationTask *SchedulerDataBlock::getScheduledTask(unsigned task_id) { - scheduledTasksMap::const_iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) { - return it->second; - } - else { - reservationsMap::const_iterator rit = itsReservations.find(task_id); - if (rit != itsReservations.end()) return rit->second; - } - return 0; -} - -const Observation *SchedulerDataBlock::getScheduledObservation(unsigned task_id) const { - scheduledTasksMap::const_iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) { - return dynamic_cast<Observation *>(it->second); - } - return 0; -} - - -const Pipeline *SchedulerDataBlock::getPipelineTask(unsigned task_id) const { - pipelinesMap::const_iterator it = itsPipelines.find(task_id); - if (it != itsPipelines.end()) { - return it->second; - } - return 0; -} - -const Task *SchedulerDataBlock::getInactiveTask(unsigned task_id) const { - inActiveTasksMap::const_iterator it = inactiveTasks.find(task_id); - if (it != inactiveTasks.end()) { - return it->second; - } - else return 0; -} - -const Task *SchedulerDataBlock::getUnscheduledTask(unsigned task_id) const { - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it - != unscheduledTasks.end(); ++it) { - if ((*it)->getID() == task_id) { - return *it; - } - } - return 0; -} - -Task *SchedulerDataBlock::getInactiveTaskForChange(unsigned task_id) const { - inActiveTasksMap::const_iterator it = inactiveTasks.find(task_id); - if (it != inactiveTasks.end()) { - return it->second; - } else { - return 0; - } -} - -Task *SchedulerDataBlock::getUnscheduledTaskForChange(unsigned task_id) const { - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - if ((*it)->getID() == task_id) { - return *it; - } - } - return 0; -} - -StationTask *SchedulerDataBlock::getReservationForChange(unsigned task_id) { - reservationsMap::const_iterator it = itsReservations.find(task_id); - if (it != itsReservations.end()) { - return it->second; - } - else return 0; -} - -Pipeline *SchedulerDataBlock::getPipelineForChange(unsigned task_id) { - pipelinesMap::const_iterator it = itsPipelines.find(task_id); - if (it != itsPipelines.end()) { - return it->second; - } - else return 0; -} - -Task *SchedulerDataBlock::getTaskForChange(unsigned task_id, id_type type) { - switch (type) { - case ID_SCHEDULER: - return getTaskForChangeByTaskID(task_id); - break; - case ID_MOM: - return getTaskForChangeByMomID(task_id); - break; - case ID_SAS: - return getTaskForChangeBySASTreeID(task_id); - break; - } - return 0; -} - -const Task *SchedulerDataBlock::getTaskByTaskID(unsigned task_id) const { - scheduledTasksMap::const_iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) - return it->second; - - unscheduledTasksDeque::const_iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getID() == task_id) return *uit; - ++uit; - } - - pipelinesMap::const_iterator pit = itsPipelines.find(task_id); - if (pit != itsPipelines.end()) - return pit->second; - - inActiveTasksMap::const_iterator iti = inactiveTasks.find(task_id); - if (iti != inactiveTasks.end()) - return iti->second; - - reservationsMap::const_iterator rit = itsReservations.find(task_id); - if (rit != itsReservations.end()) { - return rit->second; - } - - return 0; -} - -const Task *SchedulerDataBlock::getTaskBySASTreeID(quint32 sas_tree_id) const { - scheduledTasksMap::const_iterator it = scheduledTasks.begin(); - while(it != scheduledTasks.end()) { - if (it->second->getSASTreeID() == sas_tree_id) return it->second; - ++it; - } - - inActiveTasksMap::const_iterator iit = inactiveTasks.begin(); - while(iit != inactiveTasks.end()) { - if (iit->second->getSASTreeID() == sas_tree_id) return iit->second; - ++iit; - } - - reservationsMap::const_iterator rit = itsReservations.begin(); - while(rit != itsReservations.end()) { - if (rit->second->getSASTreeID() == sas_tree_id) return rit->second; - ++rit; - } - - unscheduledTasksDeque::const_iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getSASTreeID() == sas_tree_id) return *uit; - ++uit; - } - - pipelinesMap::const_iterator pit = itsPipelines.begin(); - while(pit != itsPipelines.end()) { - if (pit->second->getSASTreeID() == sas_tree_id) return pit->second; - ++pit; - } - - return 0; -} - -const Task *SchedulerDataBlock::getTaskByMomID(quint32 momID) const { - scheduledTasksMap::const_iterator it = scheduledTasks.begin(); - while(it != scheduledTasks.end()) { - if (it->second->getMomID() == momID) return it->second; - ++it; - } - - inActiveTasksMap::const_iterator iit = inactiveTasks.begin(); - while(iit != inactiveTasks.end()) { - if (iit->second->getMomID() == momID) return iit->second; - ++iit; - } - - reservationsMap::const_iterator rit = itsReservations.begin(); - while(rit != itsReservations.end()) { - if (rit->second->getMomID() == momID) return rit->second; - ++rit; - } - - unscheduledTasksDeque::const_iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getMomID() == momID) return *uit; - ++uit; - } - - pipelinesMap::const_iterator pit = itsPipelines.begin(); - while(pit != itsPipelines.end()) { - if (pit->second->getMomID() == momID) return pit->second; - ++pit; - } - - return 0; -} - -Task *SchedulerDataBlock::getTaskForChangeByTaskID(unsigned task_id) const { - scheduledTasksMap::const_iterator it = scheduledTasks.find(task_id); - if (it != scheduledTasks.end()) - return it->second; - - unscheduledTasksDeque::const_iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getID() == task_id) return *uit; - ++uit; - } - - pipelinesMap::const_iterator pit = itsPipelines.find(task_id); - if (pit != itsPipelines.end()) - return pit->second; - - reservationsMap::const_iterator rit = itsReservations.find(task_id); - if (rit != itsReservations.end()) { - return rit->second; - } - - inActiveTasksMap::const_iterator iti = inactiveTasks.find(task_id); - if (iti != inactiveTasks.end()) - return iti->second; - - return 0; -} - -Task *SchedulerDataBlock::getTaskForChangeBySASTreeID(quint32 sas_tree_id) const { - scheduledTasksMap::const_iterator it = scheduledTasks.begin(); - while(it != scheduledTasks.end()) { - if (it->second->getSASTreeID() == sas_tree_id) return it->second; - ++it; - } - - inActiveTasksMap::const_iterator iit = inactiveTasks.begin(); - while(iit != inactiveTasks.end()) { - if (iit->second->getSASTreeID() == sas_tree_id) return iit->second; - ++iit; - } - - reservationsMap::const_iterator rit = itsReservations.begin(); - while(rit != itsReservations.end()) { - if (rit->second->getSASTreeID() == sas_tree_id) return rit->second; - ++rit; - } - - unscheduledTasksDeque::const_iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getSASTreeID() == sas_tree_id) return *uit; - ++uit; - } - - pipelinesMap::const_iterator pit = itsPipelines.begin(); - while(pit != itsPipelines.end()) { - if (pit->second->getSASTreeID() == sas_tree_id) return pit->second; - ++pit; - } - - return 0; -} - -Task *SchedulerDataBlock::getTaskForChangeByMomID(quint32 momID) const { - scheduledTasksMap::const_iterator it = scheduledTasks.begin(); - while(it != scheduledTasks.end()) { - if (it->second->getMomID() == momID) return it->second; - ++it; - } - - inActiveTasksMap::const_iterator iit = inactiveTasks.begin(); - while(iit != inactiveTasks.end()) { - if (iit->second->getMomID() == momID) return iit->second; - ++iit; - } - - reservationsMap::const_iterator rit = itsReservations.begin(); - while(rit != itsReservations.end()) { - if (rit->second->getMomID() == momID) return rit->second; - ++rit; - } - - unscheduledTasksDeque::const_iterator uit = unscheduledTasks.begin(); - while(uit != unscheduledTasks.end()) { - if ((*uit)->getMomID() == momID) return *uit; - ++uit; - } - - pipelinesMap::const_iterator pit = itsPipelines.begin(); - while(pit != itsPipelines.end()) { - if (pit->second->getMomID() == momID) return pit->second; - ++pit; - } - - return 0; -} - - -// goes by all scheduler tasks and checks for status changes (for instance because the task has been downloaded again and overwritten) -// then it takes appropriate action to unschedule/move the task to the correct map (unscheduled/scheduled/inactive) -void SchedulerDataBlock::checkStatusChanges(void) { - // check all tasks in the scheduled tasks map - vector<unsigned> doUnscheduleTasks, doScheduleTasks, doInactivateTasks; - Task::task_status status; - for (scheduledTasksMap::const_iterator sit = scheduledTasks.begin(); sit != scheduledTasks.end(); ++sit) { - if (sit->second) { - status = sit->second->getStatus(); - if (status < Task::PRESCHEDULED || status > Task::COMPLETING) { -// if ((status != Task::PRESCHEDULED) && (status != Task::SCHEDULED) && (status != Task::STARTING) && (status != Task::ACTIVE)) { - // add to tasks to be unscheduled - doUnscheduleTasks.push_back(sit->first); - } - } - } - // do the actual unscheduling / moving - Task *pTask; - for (vector<unsigned>::const_iterator uit = doUnscheduleTasks.begin(); uit != doUnscheduleTasks.end(); ++uit) { - status = getScheduledTask(*uit)->getStatus(); // remember the current status of the task before taking action - unscheduleTask(*uit); - pTask = getUnscheduledTaskForChange(*uit); - if (pTask) { - pTask->setStatus(status); - // now check if the previously unscheduled task needs to be moved to inactive map (they do not need to be moved to scheduled map because that's where they came from) - if (status >= Task::FINISHED) { - moveTaskToInactive(*uit); - } - } - } - - - // check all tasks in the inactive tasks map - doScheduleTasks.clear(); - doUnscheduleTasks.clear(); - for (inActiveTasksMap::const_iterator iit = inactiveTasks.begin(); iit != inactiveTasks.end(); ++iit) { - if (iit->second) { - status = iit->second->getStatus(); // remember the current status of the task before taking action - if (status < Task::FINISHED) { // not inactive anymore? - // where does it need to go? unscheduled or scheduled map? - if (status >= Task::PRESCHEDULED && status <= Task::COMPLETING) { -// if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED) || (status == Task::STARTING) || (status == Task::ACTIVE)) { - doScheduleTasks.push_back(iit->first); - } - else { - doUnscheduleTasks.push_back(iit->first); - } - } - } - } - // do the actual unscheduling / scheduling - for (vector<unsigned>::const_iterator uit = doUnscheduleTasks.begin(); uit != doUnscheduleTasks.end(); ++uit) { - moveTaskFromInactive(*uit); - } - for (vector<unsigned>::const_iterator sit = doScheduleTasks.begin(); sit != doScheduleTasks.end(); ++sit) { - status = getInactiveTask(*sit)->getStatus(); // remember the current status of the task before taking action - pTask = getInactiveTaskForChange(*sit); - scheduleTask(pTask); // this also takes care of removing the task from the inactive map - pTask = getScheduledTask(*sit); - if (pTask) { - pTask->setStatus(status); // set the previous status after scheduling - } - } - - - // check all tasks in the unscheduled tasks map - doScheduleTasks.clear(); - doInactivateTasks.clear(); - for (unscheduledTasksDeque::const_iterator usit = unscheduledTasks.begin(); usit != unscheduledTasks.end(); ++usit) { - if (*usit) { - status = (*usit)->getStatus(); // remember the current status of the task before taking action - // does it need to be moved? where to? unscheduled or scheduled map? - if (status >= Task::PRESCHEDULED && status <= Task::COMPLETING) { -// if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED) || (status == Task::STARTING) || (status == Task::ACTIVE)) { - doScheduleTasks.push_back((*usit)->getID()); - } - else { - doInactivateTasks.push_back((*usit)->getID()); - } - } - } - // schedule the tasks that need to be scheduled - for (vector<unsigned>::const_iterator sit = doScheduleTasks.begin(); sit != doScheduleTasks.end(); ++sit) { - status = getUnscheduledTask(*sit)->getStatus(); // remember the current status of the task before taking action - pTask = getUnscheduledTaskForChange(*sit); - scheduleTask(pTask); // this also takes care of removing the task from the unscheduled deque - pTask = getScheduledTask(*sit); - if (pTask) { - pTask->setStatus(status); // set the previous status after scheduling - } - } - // move the tasks that need to be moved to the inactivemap - for (vector<unsigned>::const_iterator iit = doInactivateTasks.begin(); iit != doInactivateTasks.end(); ++iit) { - moveTaskToInactive(*iit); - } -} - -Task * SchedulerDataBlock::moveTaskFromInactive(unsigned task_id) { - inActiveTasksMap::iterator it = inactiveTasks.find(task_id); - if (it != inactiveTasks.end()) { - Task *pTask(it->second); - if (pTask->isPipeline()) { - itsPipelines[it->first] = static_cast<Pipeline *>(pTask); - } - else { - unscheduledTasks.push_back(pTask); - } - inactiveTasks.erase(it); - return pTask; - } - return 0; -} - -const Station *SchedulerDataBlock::getStation(unsigned station_id) const { - stationsMap::const_iterator it = itsStations.find(station_id); - if (it != itsStations.end()) { - return &(it->second); - } - return 0; -} - -Station *SchedulerDataBlock::getStationForChange(unsigned station_id) { - stationsMap::iterator it = itsStations.find(station_id); - if (it != itsStations.end()) { - return &(it->second); - } - return 0; -} - -bool SchedulerDataBlock::getNextTask(Task &task) const { - if (!unscheduledTasks.empty()) { - task = *(unscheduledTasks.front()); - return true; - } else { - debugErr("s", - "SchedulerDataBlock::getNextTask: There are no unscheduled tasks."); - return false; - } -} - -bool SchedulerDataBlock::scheduleNextTask(const AstroDateTime &schedule_time) { - if (!unscheduledTasks.empty()) { - Task * utp = unscheduledTasks.front(); - // debugInfo("siss", "scheduling task: ", utp->getID(), " at: ", schedule_time.toString().c_str()); - utp->setScheduledStart(schedule_time); - scheduleTask(utp); - return true; - } else { - debugErr("s", - "SchedulerDataBlock: There are no unscheduled tasks to schedule!"); - return false; - } -} - -bool SchedulerDataBlock::checkStationConflicts(StationTask *pTask) { - const taskStationsMap &task_stations = pTask->getStations(); - std::vector<unsigned> overlappingTasks; - for (taskStationsMap::const_iterator sit = task_stations.begin(); sit != task_stations.end(); ++sit) { - for (stationsMap::const_iterator statit = itsStations.begin(); statit != itsStations.end(); ++statit) { - if (sit->second == statit->first) { // found station - // check conflicting overlapping tasks for this station. If conflicts then set the conflict in the checked task - overlappingTasks = statit->second.getTaskswithinTimeSpan(pTask->getScheduledStart(), pTask->getScheduledEnd()); - // check parallel task constraints - for (std::vector<unsigned>::const_iterator parTaskIDit = overlappingTasks.begin(); parTaskIDit != overlappingTasks.end(); ++parTaskIDit) { - if (*parTaskIDit != pTask->getID()) { // Station::getOverlappingTasks also returns the current task which obviously always overlaps with itself (exclude this task) - const Task *parallelTask = getScheduledTask(*parTaskIDit); // the next overlapping task on this station - if (parallelTask) { - if (parallelTask->isMaintenance()) { - pTask->setConflict(CONFLICT_MAINTENANCE); - pTask->setReason("Station " + sit->first + " is in maintenance. No tasks can be scheduled on that station during the maintenance period"); - return false; - } - else if (pTask->isObservation() && parallelTask->isReservation()) { - if (static_cast<const Observation *>(pTask)->getReservation() != *parTaskIDit) { - pTask->setConflict(CONFLICT_RESERVATION); - pTask->setReason("Station " + sit->first + " is reserved. This observation is not part of that reservation and can therefore not be scheduled on that station during the reservation period"); - return false; - } - } - else if (pTask->isReservation() && parallelTask->isObservation()) { - if (static_cast<const Observation *>(parallelTask)->getReservation() != pTask->getID()) { - pTask->setConflict(CONFLICT_RESERVATION); - pTask->setReason("Reservation conflicts with scheduled observation:" + int2String(parallelTask->getID()) + " on station:" + sit->first); - return false; - } - } - else if (pTask->isMaintenance()) { - pTask->setConflict(CONFLICT_MAINTENANCE); - pTask->setReason("Maintenance conflicts with scheduled task:" + int2String(parallelTask->getID()) + " on station:" + sit->first); - return false; - } - else { - pTask->setConflict(CONFLICT_STATIONS); - pTask->setReason("Observation conflicts with scheduled task:" + int2String(parallelTask->getID()) + " on station:" + sit->first); - return false; - } - } - } - } - } - } - } - pTask->clearConflict(CONFLICT_STATIONS); - pTask->clearConflict(CONFLICT_OUT_OF_DATASLOTS); - pTask->clearConflict(CONFLICT_BITMODE); - pTask->clearConflict(CONFLICT_RESERVATION); - pTask->clearConflict(CONFLICT_MAINTENANCE); - return true; -} - -/* -bool SchedulerDataBlock::checkStationConflicts(Task *pTask) { - const taskStationsMap &task_stations = pTask->getStations(); - std::vector<unsigned> overlappingTasks; - int NrDataSlotsLeft(0); - unsigned short bitMode(pTask->getBitMode()); - switch (bitMode) { - default: - case 16: - NrDataSlotsLeft = (MAX_DATASLOT_PER_RSP_16_BITS + 1) * 4; // 4 RSP boards - break; - case 8: - NrDataSlotsLeft = (MAX_DATASLOT_PER_RSP_8_BITS + 1) * 4; - break; - case 4: - NrDataSlotsLeft = (MAX_DATASLOT_PER_RSP_4_BITS + 1) * 4; - break; - } - NrDataSlotsLeft -= pTask->getNrOfSubbands(); - Task::task_type otherType; - std::vector<unsigned int> countedTasks; - for (taskStationsMap::const_iterator sit = task_stations.begin(); sit != task_stations.end(); ++sit) { - for (stationsMap::const_iterator statit = itsStations.begin(); statit != itsStations.end(); ++statit) { - if (sit->second == statit->first) { // found station - // check conflicting overlapping tasks for this station. If conflicts then set the conflict in the checked task - overlappingTasks = statit->second.getTaskswithinTimeSpan(pTask->getScheduledStart(), pTask->getScheduledEnd()); - // check parallel task constraints - for (std::vector<unsigned>::const_iterator parTaskIDit = overlappingTasks.begin(); parTaskIDit != overlappingTasks.end(); ++parTaskIDit) { - if (*parTaskIDit != pTask->getID()) { // Station::getOverlappingTasks also returns the current task which obviously always overlaps with itself (exclude this task) - const Task *parallelTask = getScheduledTask(*parTaskIDit); // the next overlapping task on this station - if (parallelTask) { - otherType = parallelTask->getType(); - if (otherType == Task::MAINTENANCE) { - pTask->setConflict(CONFLICT_MAINTENANCE); - pTask->setReason("Station " + sit->first + " is in maintenance. No tasks can be scheduled on that station during the maintenance period"); - return false; - } - else if (otherType == Task::RESERVATION) { - if (pTask->getReservation() != *parTaskIDit) { - pTask->setConflict(CONFLICT_RESERVATION); - pTask->setReason("Station " + sit->first + " is reserved. This task is not coupled to that reservation and can therefore not be scheduled on that station during the reservation period"); - return false; - } - } - else if (pTask->isReservation()) { - if (parallelTask->getReservation() != pTask->getID()) { - pTask->setConflict(CONFLICT_RESERVATION); - pTask->setReason("Reservation conflicts with scheduled task:" + int2String(parallelTask->getID()) + " on station:" + sit->first); - return false; - } - } - else if (pTask->isMaintenance()) { - pTask->setConflict(CONFLICT_MAINTENANCE); - pTask->setReason("Maintenance conflicts with scheduled task:" + int2String(parallelTask->getID()) + " on station:" + sit->first); - return false; - } - // check that bit mode is the same for parallel tasks - else if (parallelTask->getBitMode() == bitMode) { - // check the number of subbands - if (find(countedTasks.begin(), countedTasks.end(), *parTaskIDit) == countedTasks.end()) { // did we count the dataslots of this parallel task already? - countedTasks.push_back(*parTaskIDit); - NrDataSlotsLeft -= parallelTask->getNrOfSubbands(); - if (NrDataSlotsLeft < 0) { - // too many dataslots required, set conflict - pTask->setConflict(CONFLICT_OUT_OF_DATASLOTS); - pTask->setReason(string("Too many subbands on station:") + sit->first - + "\nConflicting task:" + int2String(parallelTask->getID()) + " - " + parallelTask->getTaskName() + " (" + int2String(parallelTask->getSASTreeID()) - + ")\nThe tasks are either overlapping or too close to each other"); - return false; - } - } - } - else { // there is a bit mode conflict for this task and the parallel task - pTask->setConflict(CONFLICT_BITMODE); - pTask->setReason("Bit mode conflict with task:" + int2String(parallelTask->getID()) + " on station " + sit->first); - return false; - } - } - } - } - } - } - } - pTask->clearConflict(CONFLICT_OUT_OF_DATASLOTS); - pTask->clearConflict(CONFLICT_BITMODE); - pTask->clearConflict(CONFLICT_RESERVATION); - pTask->clearConflict(CONFLICT_MAINTENANCE); - return true; -} -*/ - -bool SchedulerDataBlock::scheduleTask(Task * pTask) { - unsigned taskID = pTask->getID(); - bool scheduledCorrect(false); - if (pTask->isReservation() || pTask->isMaintenance()) { - reservationsMap::iterator it = itsReservations.find(taskID); - if (it != itsReservations.end()) { - it->second->setStatus(Task::PRESCHEDULED); // sets the reservation's state to PRESCHEDULED - it->second->setReason(NO_ERROR); - scheduledCorrect = true; - } - } - else if (pTask->isObservation()) { - std::pair<scheduledTasksMap::iterator, bool> ret = scheduledTasks.insert(scheduledTasksMap::value_type(taskID, static_cast<Observation *>(pTask))); - ret.first->second->setStatus(Task::SCHEDULED); // sets the task state to SCHEDULED - ret.first->second->setReason(NO_ERROR); - scheduledCorrect = ret.second; - } - else if (pTask->isPipeline()) { - pTask->setStatus(Task::SCHEDULED); // sets the task state to SCHEDULED - pTask->setReason(NO_ERROR); - scheduledCorrect = true; - } - if (scheduledCorrect) { // if inserted correctly - if (pTask->isStationTask()) { - stationsMap::iterator sit; - // go by all stations to schedule the task in the stations their task lists - const taskStationsMap &stations = static_cast<Observation *>(pTask)->getStations(); - for (taskStationsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - sit = itsStations.find(it->second); - if (sit != itsStations.end()) { - sit->second.addTasktoStation(taskID, pTask->getScheduledStart(), pTask->getScheduledEnd()); - } - } - } - - if (!pTask->isReservation() && !pTask->isMaintenance() && !pTask->isPipeline()) { - // remove from unscheduled tasks or inactive tasks (in case of aborted task that is rescheduled) - bool foundInUnscheduledTasks(false); - for (unscheduledTasksDeque::iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - if ((*it)->getID() == taskID) { - unscheduledTasks.erase(it); - foundInUnscheduledTasks = true; - break; - } - } - if (!foundInUnscheduledTasks) { - inactiveTasks.erase(taskID); - } - } - return true; - } else { - debugErr("si", "SchedulerDataBlock: Could not schedule task: ", taskID); - return false; - } -} - -const AstroDateTime & SchedulerDataBlock::getTaskStartTime(unsigned taskID) const { - return getTask(taskID)->getScheduledStart(); -} - -const AstroDateTime & SchedulerDataBlock::getTaskEndTime(unsigned taskID) const { - return getTask(taskID)->getScheduledEnd(); -} - -AstroDateTime SchedulerDataBlock::getTaskFirstPossibleDate(unsigned taskID) const { - return getTask(taskID)->getFirstPossibleDateTime(); -} - -const AstroTime & SchedulerDataBlock::getTaskPredecessorMaxTimeDif( - unsigned taskID) const { - return getTask(taskID)->getPredecessorMaxTimeDif(); -} - -Task::task_status SchedulerDataBlock::getTaskStatus(unsigned taskID) const { - return getTask(taskID)->getStatus(); -} - -void SchedulerDataBlock::holdNextTask(const std::string &reason) { - if (!unscheduledTasks.empty()) { - Task *pt = unscheduledTasks.front(); - -// if (reason != UNSCHEDULED_REASON_END) { - pt->setReason(reason); -// } - - unscheduledTasks.pop_front(); - unscheduledTasks.push_back(pt); // put at the end - if (pt->getStatus() == Task::SCHEDULED) { - pt->setStatus(Task::UNSCHEDULED); - } - } -} - -void SchedulerDataBlock::holdNextTask(unscheduled_reasons reason) { - if (!unscheduledTasks.empty()) { - Task *pt = unscheduledTasks.front(); - - if (reason != UNSCHEDULED_REASON_END) { - pt->setReason(unscheduled_reason_str[reason]); - } - - unscheduledTasks.pop_front(); - unscheduledTasks.push_back(pt); // put at the end - if (pt->getStatus() == Task::SCHEDULED) { - pt->setStatus(Task::UNSCHEDULED); - } - } -} - - -void SchedulerDataBlock::updateStations(void) { - const stationNameIDMapping & stations = Controller::theSchedulerSettings.getStations(); - stationsMap stationsCopy = itsStations; - itsStations.clear(); - - unsigned station_id; - stationsMap::iterator sit; - for (stationNameIDMapping::const_iterator it = stations.begin(); it != stations.end(); ++it) { - station_id = it->second; - sit = stationsCopy.find(station_id); - if (sit == stationsCopy.end()) { // new station - Station newStation(it->first, station_id); - std::pair<stationsMap::iterator, bool> ret = itsStations.insert( stationsMap::value_type(station_id, newStation) ); - if (!ret.second) { - debugWarn("sssi", "SchedulerDataBlock::updateStations, Warning, could not insert new station: ", newStation.getName().c_str(), " with ID:", newStation.getStationID()); - } - } else { - itsStations.insert(stationsMap::value_type(sit->first, sit->second)); - } - } -} - -bool SchedulerDataBlock::addStation(unsigned station_id, const std::string &name) { - if (itsStations.find(station_id) == itsStations.end()) { - Station newStation(name, station_id); - /*std::pair<stationsMap::iterator, bool> ret = */ - itsStations.insert( stationsMap::value_type(station_id, newStation) ); - return true; - } else { - debugWarn("sis","SchedulerDataBlock::addStation: Trying to add station with ID: ", station_id, " that already exist."); - return false; - } -} - -std::vector<Task *> SchedulerDataBlock::getReservationsVector(void) const { - std::vector<Task *> tasks; - for (reservationsMap::const_iterator it = itsReservations.begin(); it != itsReservations.end(); ++it) { - if (it->second->isReservation()) { - tasks.push_back(it->second); - } - } - return tasks; -} - -std::vector<Task *> SchedulerDataBlock::getMaintenanceVector(void) const { - std::vector<Task *> tasks; - for (reservationsMap::const_iterator it = itsReservations.begin(); it != itsReservations.end(); ++it) { - if (it->second->isMaintenance()) { - tasks.push_back(it->second); - } - } - return tasks; -} - -std::vector<Task *> SchedulerDataBlock::getScheduledTasksVector(void) const { - std::vector<Task *> tasks; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - tasks.push_back(it->second); - } - return tasks; -} - -std::vector<Task *> SchedulerDataBlock::getInactiveTaskVector(void) const { - std::vector<Task *> tasks; - for (inActiveTasksMap::const_iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++it) { - tasks.push_back(it->second); - } - return tasks; -} - -std::vector<Task *> SchedulerDataBlock::getUnScheduledTasksVector(void) const { - std::vector<Task *> tasks; - - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - tasks.push_back(*it); - } - return tasks; -} - -std::vector<Task *> SchedulerDataBlock::getPipelinesVector(void) const { - std::vector<Task *> pipelines; - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - pipelines.push_back(it->second); - } - // sort according to start time - sort(pipelines.begin(), pipelines.end(), cmp_taskScheduledStart()); - return pipelines; -} - -std::vector<Pipeline *> SchedulerDataBlock::getScheduledPipelinesVector(void) const { - std::vector<Pipeline *> pipelines; - Task::task_status status; - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - status = it->second->getStatus(); - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - pipelines.push_back(it->second); - } - } - // sort according to start time - sort(pipelines.begin(), pipelines.end(), cmp_taskScheduledStart()); - return pipelines; -} - -std::vector<Task *> SchedulerDataBlock::getTasksInScheduleSortStartTime(void) const { - std::vector<Task *> sortedTasks; - Task::task_status status; - //scheduledTasksMap & scheduled_tasks = data.getScheduledTasks(); - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - sortedTasks.push_back(it->second); - } - for (reservationsMap::const_iterator it = itsReservations.begin(); it != itsReservations.end(); ++it) { - status = it->second->getStatus(); - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - sortedTasks.push_back(it->second); - } - } - for (inActiveTasksMap::const_iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++it) { - sortedTasks.push_back(it->second); - } - - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - return sortedTasks; -} - -std::map<unsigned, std::vector<Task *> > SchedulerDataBlock::getGroupedObservations(Task::task_status state) const { - std::map<unsigned, std::vector<Task *> > tasks; - unsigned groupID; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - groupID = it->second->getGroupID(); - if (groupID != 0) { - if ((state != Task::TASK_STATUS_END) && (it->second->getStatus() == state)) { - tasks[groupID].push_back(it->second); - } - } - } - if (state < Task::PRESCHEDULED) { - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - groupID = (*it)->getGroupID(); - if (groupID != 0) { - if ((state != Task::TASK_STATUS_END) && ((*it)->getStatus() == state)) { - tasks[groupID].push_back(*it); - } - } - } - } - for (std::map<unsigned, std::vector<Task *> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - std::sort(it->second.begin(), it->second.end(), cmp_taskScheduledStart()); - } - return tasks; -} - -std::vector<unsigned> SchedulerDataBlock::tasksInGroup(unsigned groupID, selector_types type) const { - std::vector<unsigned> groupTasks; - unsigned taskGroup; - bool add(true); - - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - taskGroup = it->second->getGroupID(); - if (taskGroup == groupID) { - switch (type) { - case SEL_OBSERVATIONS: - add = (it->second->getType() == Task::OBSERVATION) ? true : false; - break; - case SEL_CALIBRATOR_PIPELINES: - case SEL_TARGET_PIPELINES: - case SEL_IMAGING_PIPELINES: - case SEL_PREPROCESSING_PIPELINES: - case SEL_PULSAR_PIPELINES: - case SEL_LONGBASELINE_PIPELINES: - add = false; // pipelines are not in scheduledTasks map - break; - default: // all tasks - add = true; - break; - } - if (add) { - groupTasks.push_back(it->first); - } - } - } - - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - taskGroup = (*it)->getGroupID(); - if (taskGroup == groupID) { - switch (type) { - case SEL_OBSERVATIONS: - add = ((*it)->getType() == Task::OBSERVATION) ? true : false; - break; - case SEL_CALIBRATOR_PIPELINES: - case SEL_TARGET_PIPELINES: - case SEL_IMAGING_PIPELINES: - case SEL_PREPROCESSING_PIPELINES: - case SEL_PULSAR_PIPELINES: - case SEL_LONGBASELINE_PIPELINES: - add = false; // pipelines are not in scheduledTasks map - break; - default: // all tasks - add = true; - break; - } - if (add) { - groupTasks.push_back((*it)->getID()); - } - } - } - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - taskGroup = it->second->getGroupID(); - if (taskGroup == groupID) { - switch (type) { - case SEL_OBSERVATIONS: - add = false; - break; - case SEL_CALIBRATOR_PIPELINES: - add = ((it->second->getType() == Task::PIPELINE) && (it->second->getStrategy().contains("calibrator", Qt::CaseInsensitive))) ? true : false; - break; - case SEL_TARGET_PIPELINES: - add = ((it->second->getType() == Task::PIPELINE) && (it->second->getStrategy().contains("target", Qt::CaseInsensitive))) ? true : false; - break; - case SEL_IMAGING_PIPELINES: - add = (it->second->getProcessSubtype() == PST_IMAGING_PIPELINE || it->second->getProcessSubtype() == PST_MSSS_IMAGING_PIPELINE) ? true : false; - break; - case SEL_LONGBASELINE_PIPELINES: - add = (it->second->getProcessSubtype() == PST_LONG_BASELINE_PIPELINE) ? true : false; - break; - case SEL_PREPROCESSING_PIPELINES: - add = (it->second->getProcessSubtype() == PST_AVERAGING_PIPELINE) ? true : false; - break; - case SEL_PULSAR_PIPELINES: - add = (it->second->getProcessSubtype() == PST_PULSAR_PIPELINE) ? true : false; - break; - default: // all tasks - add = true; - break; - } - if (add) { - groupTasks.push_back(it->first); - } - } - } - for (inActiveTasksMap::const_iterator it = inactiveTasks.begin(); it != inactiveTasks.end(); ++ it) { - taskGroup = it->second->getGroupID(); - if (taskGroup == groupID) { - switch (type) { - case SEL_OBSERVATIONS: - add = (it->second->getType() == Task::OBSERVATION) ? true : false; - break; - case SEL_CALIBRATOR_PIPELINES: - add = ((it->second->getType() == Task::PIPELINE) && (it->second->getStrategy().contains("calibrator", Qt::CaseInsensitive))) ? true : false; - break; - case SEL_TARGET_PIPELINES: - add = ((it->second->getType() == Task::PIPELINE) && (it->second->getStrategy().contains("target", Qt::CaseInsensitive))) ? true : false; - break; - case SEL_IMAGING_PIPELINES: - add = (it->second->getProcessSubtype() == PST_IMAGING_PIPELINE || it->second->getProcessSubtype() == PST_MSSS_IMAGING_PIPELINE) ? true : false; - break; - case SEL_LONGBASELINE_PIPELINES: - add = (it->second->getProcessSubtype() == PST_LONG_BASELINE_PIPELINE) ? true : false; - break; - case SEL_PREPROCESSING_PIPELINES: - add = (it->second->getProcessSubtype() == PST_AVERAGING_PIPELINE) ? true : false; - break; - case SEL_PULSAR_PIPELINES: - add = (it->second->getProcessSubtype() == PST_PULSAR_PIPELINE) ? true : false; - break; - default: // all tasks - add = true; - break; - } - if (add) { - groupTasks.push_back(it->first); - } - } - } - - return groupTasks; -} - -std::map<unsigned, std::vector<Task *> > SchedulerDataBlock::getGroupedTasks(Task::task_status state) const { - std::map<unsigned, std::vector<Task *> > tasks; - unsigned groupID; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - groupID = it->second->getGroupID(); - if (groupID != 0) { - if (it->second->getStatus() == state) { - tasks[groupID].push_back(it->second); - } - } - } - if (state < Task::PRESCHEDULED) { - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - groupID = (*it)->getGroupID(); - if (groupID != 0) { - if ((*it)->getStatus() == state) { - tasks[groupID].push_back(*it); - } - } - } - } - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - groupID = it->second->getGroupID(); - if (groupID != 0) { - if (it->second->getStatus() == state) { - tasks[groupID].push_back(it->second); - } - } - } - - for (std::map<unsigned, std::vector<Task *> >::iterator it = tasks.begin(); it != tasks.end(); ++it) { - std::sort(it->second.begin(), it->second.end(), cmp_taskScheduledStart()); - } - return tasks; -} - -std::vector<Task *> SchedulerDataBlock::getPreScheduledTasksSortStartTime(void) const { - std::vector<Task *> sortedTasks; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if (it->second->getStatus() == Task::PRESCHEDULED) - sortedTasks.push_back(it->second); - } - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - if (it->second->getStatus() == Task::PRESCHEDULED) - sortedTasks.push_back(it->second); - } - - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - return sortedTasks; -} - -std::vector<Task *> SchedulerDataBlock::getScheduledTasksSortStartTime(void) const { - std::vector<Task *> sortedTasks; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if (it->second->getStatus() == Task::SCHEDULED) - sortedTasks.push_back(it->second); - } - for (pipelinesMap::const_iterator it = itsPipelines.begin(); it != itsPipelines.end(); ++it) { - if (it->second->getStatus() == Task::SCHEDULED) - sortedTasks.push_back(it->second); - } - - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - return sortedTasks; -} - -std::vector<Task *> SchedulerDataBlock::getScheduledObservationsSortStartTime(void) const { - std::vector<Task *> sortedTasks; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if ((it->second->getType() == Task::OBSERVATION) && (it->second->getStatus() == Task::SCHEDULED)) - sortedTasks.push_back(it->second); - } - - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - return sortedTasks; -} - -std::vector<Task *> SchedulerDataBlock::getPreScheduledObservationsSortStartTime(void) const { - std::vector<Task *> sortedTasks; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if ((it->second->getType() == Task::OBSERVATION) && (it->second->getStatus() == Task::PRESCHEDULED)) - sortedTasks.push_back(it->second); - } - - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - return sortedTasks; -} - - -std::vector<Observation *> SchedulerDataBlock::getFutureObservationsSortStartTime(void) const { - QDateTime cT = QDateTime::currentDateTimeUtc(); - AstroDateTime now(cT.date().day(), cT.date().month(), cT.date().year(), - cT.time().hour(), cT.time().minute(), cT.time().second()); - std::vector<Observation *> sortedTasks; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if ((it->second->isObservation()) && (it->second->getScheduledStart() >= now)) { - sortedTasks.push_back(static_cast<Observation *>(it->second)); - } - } - - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskScheduledStart()); - return sortedTasks; -} - - -std::vector<Task *> SchedulerDataBlock::getUnScheduledTasksSortFirstDate(void) const { - //unscheduledTasksDeque &unscheduledTasks = data.getUnscheduledTasks(); - std::vector<Task *> sortedTasks; - - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - sortedTasks.push_back(*it); - } - sort(sortedTasks.begin(), sortedTasks.end(), cmp_taskFirstPossibleDateTime()); - return sortedTasks; -} - -std::map<std::string, std::vector<Task *> > SchedulerDataBlock::getPublishTasks(const AstroDateTime &start, const AstroDateTime &end) const { - const std::vector<Task *> &sortedTasks = getTasksInScheduleSortStartTime(); - std::map<std::string, std::vector<Task *> > tasks; - std::string projectID; - for (std::vector<Task *>::const_iterator it = sortedTasks.begin(); it != sortedTasks.end(); ++it) { - const AstroDateTime &taskStart = (*it)->getScheduledStart(); - const AstroDateTime &taskEnd = (*it)->getScheduledEnd(); - if ((taskEnd >= start) && (taskStart <= end)) { - const std::string &projectID((*it)->getProjectID()); - tasks[projectID].push_back(*it); - } - } - return tasks; -} - -unsigned SchedulerDataBlock::calculatePenalty(void) { - itsPenalty = 0; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - itsPenalty += it->second->calculatePenalty(); - } - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - if ((*it)->getStatus() != Task::ERROR) { - itsPenalty += UNSCHEDULED_TASK_PENALTY; - } - } - return itsPenalty; -} - -void SchedulerDataBlock::cleanup(void) { - // free memory pointed taken by all vector elements for unscheduledTasks - for (unscheduledTasksDeque::iterator i = unscheduledTasks.begin(); i != unscheduledTasks.end(); ++i) { - delete *i; - } - unscheduledTasks.clear(); // clear the vector itself - - // do the same for scheduledTasks - for (scheduledTasksMap::iterator i = scheduledTasks.begin(); i != scheduledTasks.end(); ++i) { - delete i->second; - } - scheduledTasks.clear(); // clear the map itself - - // and for reservations - for (reservationsMap::iterator i = itsReservations.begin(); i != itsReservations.end(); ++i) { - delete i->second; - } - itsReservations.clear(); - - // pipelines - for (pipelinesMap::iterator i = itsPipelines.begin(); i != itsPipelines.end(); ++i) { - delete i->second; - } - itsPipelines.clear(); - - // and for inactive tasks - for (inActiveTasksMap::iterator i = inactiveTasks.begin(); i != inactiveTasks.end(); ++i) { - delete i->second; - } - inactiveTasks.clear(); - - errorTasks.clear(); - itsStations.clear(); - itsUsedTaskIDs.clear(); - itsPenalty = -1; - itsSaveRequired = false; - itsUploadRequired = false; -} - - -unscheduled_reasons SchedulerDataBlock::checkTaskStations(StationTask *pTask) { - // check for forbidden station combinations - const map<string, unsigned> &stations = pTask->getStations(); - if (!stations.empty()) { - // check for non-existing stations - for (map<string, unsigned>::const_iterator sit = stations.begin(); sit != stations.end(); ++sit) { - if (!(Controller::theSchedulerSettings.stationExist(sit->first))) { - errorTasks[pTask->getID()].push_back(STATION_ID); - pTask->setReason(std::string("non existing station ") + sit->first); - if (pTask->isScheduled()) { - unscheduleTask(pTask->getID()); - } - pTask->setStatus(Task::ERROR); - return NON_EXISTING_STATION;// only one station error for this task is enough to have it reported as error - } - } - } - else { // empty station list - errorTasks[pTask->getID()].push_back(STATION_ID); - pTask->setReason(NO_STATIONS_DEFINED); - pTask->setStatus(Task::ERROR); - return NO_STATIONS_DEFINED; - } - return NO_ERROR; -} - -bool SchedulerDataBlock::checkTasksForErrors(void) { - Task *task; - for (errorTasksMap::iterator tit = errorTasks.begin(); tit != errorTasks.end(); ++tit) { - task = getTaskForChange(tit->first); - if (task) { - if (task->getStatus() == Task::ERROR) { - task->setStatus(Task::UNSCHEDULED); - } - task->setReason(NO_ERROR); - } - } - - errorTasks.clear(); - - for (unscheduledTasksDeque::const_iterator it = unscheduledTasks.begin(); it != unscheduledTasks.end(); ++it) { - checkTask(*it); - } - - std::vector<unsigned> scheduledTasksWithErrors; - for (scheduledTasksMap::const_iterator it = scheduledTasks.begin(); it != scheduledTasks.end(); ++it) { - if (!checkTask(it->second)) scheduledTasksWithErrors.push_back(it->first); - } - - Task *pTask(0); - for (std::vector<unsigned>::const_iterator it = scheduledTasksWithErrors.begin(); it != scheduledTasksWithErrors.end(); ++it) { - unscheduleTask(*it); - pTask = getUnscheduledTaskForChange(*it); - if (pTask) { - pTask->setStatus(Task::ERROR); - } - } - - if (errorTasks.empty()) return true; - else return false; -} - -bool SchedulerDataBlock::checkTask(Task *pTask) { // do a 'manual' check for errors on a single task - Task::task_status status(pTask->getStatus()); - if (status != Task::ON_HOLD) { // ON_HOLD tasks should not be checked for errors. They are typically set to ON_HOLD manually because they have an error that needs fixing - unsigned taskID = pTask->getID(); - - // check predecessors - const IDvector &predecessors(pTask->getPredecessors()); - for (IDvector::const_iterator it = predecessors.begin(); it != predecessors.end(); ++it) { - if (getTask(it->second, it->first) == 0) { - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - unscheduleTask(taskID); - pTask->setStatus(Task::ERROR); - } - pTask->setReason(PREDECESSOR_NOT_FOUND); - return false; - } - } - - // check times - if (pTask->getScheduledStart() > pTask->getScheduledEnd()) { - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - unscheduleTask(taskID); - pTask->setStatus(Task::ERROR); - } - errorTasks[pTask->getID()].push_back(PLANNED_START); - errorTasks[pTask->getID()].push_back(PLANNED_END); - pTask->setReason(START_LATER_THEN_END); - return false; - } - - // check stations - if (pTask->isStationTask()) { - if (checkTaskStations(static_cast<StationTask *>(pTask)) != NO_ERROR) { - return false; - } - - // check if required fields are specified (only for observations) - if (pTask->isObservation()) { - Observation *pObs(static_cast<Observation *>(pTask)); - if (pObs->getAntennaMode() == 0) { - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - unscheduleTask(taskID); - pObs->setStatus(Task::ERROR); - } - errorTasks[pObs->getID()].push_back(ANTENNA_MODE); - pTask->setReason(ANTENNA_MODE_UNSPECIFIED); - return false; - } - if (pObs->getStationClock() == UNSPECIFIED_CLOCK) { - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - unscheduleTask(taskID); - pObs->setStatus(Task::ERROR); - } - errorTasks[pObs->getID()].push_back(CLOCK_FREQUENCY); - pObs->setReason(CLOCK_FREQUENCY_UNSPECIFIED); - return false; - } - if (pObs->getFilterType() == 0) { - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - unscheduleTask(taskID); - pObs->setStatus(Task::ERROR); - } - errorTasks[pObs->getID()].push_back(FILTER_TYPE); - pObs->setReason(FILTER_TYPE_UNSPECIFIED); - return false; - } - - const Observation::RTCPsettings rtcp(pObs->getRTCPsettings()); - const TaskStorage::enableDataProdukts odp(pObs->storage()->getOutputDataProductsEnabled()); - if ((odp.coherentStokes || odp.incoherentStokes) && !rtcp.flysEye && (pObs->totalNrTABs() == 0)) { - pObs->setReason(unscheduled_reason_str[NO_TABS_DEFINED]); - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - unscheduleTask(taskID); - pObs->setStatus(Task::ERROR); - } - return false; - } - } - } - - - // everything ok, no more errors - if (status == Task::ERROR) { // if the task previously was in the ERROR state then set it to UNSCHEDULED if no errors are detected anymore - pTask->setStatus(Task::UNSCHEDULED); - } - pTask->setReason(NO_ERROR); - return true; - } - else return true; -} - -bool SchedulerDataBlock::newErrorTasks(void) { - Task *pTask = 0; - for (errorTasksMap::const_iterator it = errorTasks.begin(); it != errorTasks.end(); ++it) { - if ((pTask = getTaskForChange(it->first))) { - if (pTask->getStatus() != Task::ERROR) // only one task that didn't have ERROR status set is required - return true; - } - } - return false; -} - -void SchedulerDataBlock::markErrorTasksStatus(void) { - Task * pTask = 0; - for (errorTasksMap::iterator it = errorTasks.begin(); it != errorTasks.end(); ++it) { - if ((pTask = getTaskForChange(it->first))) - pTask->setStatus(Task::ERROR); - } -} - -void SchedulerDataBlock::clearError(unsigned taskID, data_headers header) { - errorTasksMap::iterator it = errorTasks.find(taskID); - if (it != errorTasks.end()) { - std::vector<data_headers>::iterator dit = find(it->second.begin(), it->second.end(), header); - if (dit != it->second.end()) { - it->second.erase(dit); - if (it->second.empty()) { - errorTasks.erase(it); - } - } - } -} - -unsigned SchedulerDataBlock::getRandomScheduledTaskID(void) { - scheduledTasksMap::iterator it = scheduledTasks.begin(); - int rndIdx; - float rnd; - if (!scheduledTasks.empty()) { - rnd = static_cast<float> (rand()) / static_cast<float> (RAND_MAX); - rndIdx = static_cast<int> (rnd * static_cast<float> (scheduledTasks.size())); - while (--rndIdx >= 0) { - ++it; - } - return it->first; - } - else return 0; -} - diff --git a/SAS/Scheduler/src/schedulerdatablock.h b/SAS/Scheduler/src/schedulerdatablock.h deleted file mode 100644 index bad28149bd55f38f1aebf4a6e813531ee347d831..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulerdatablock.h +++ /dev/null @@ -1,261 +0,0 @@ -/* - * schedulerdatablock.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 12, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulerdatablock.h $ - * - */ - -#ifndef SCHEDULERDATABLOCK_H_ -#define SCHEDULERDATABLOCK_H_ - -#include <fstream> -#include <map> -#include <deque> -#include <vector> -#include <string> -#include <algorithm> -#include "lofar_scheduler.h" -#include "station.h" -#include "Storage.h" - -// TODO: Why not include the headerfiles? -class Observation; -class Pipeline; -class CalibrationPipeline; -class ImagingPipeline; -class PulsarPipeline; -class LongBaselinePipeline; -class StationTask; - -#define FORCE_UNSCHEDULE true -#define OVERRIDE_SAS_TASKIDS true -#define DONT_CHECK_FREE_ID true - -typedef std::map <unsigned, Station> stationsMap; -typedef std::deque <Task *> unscheduledTasksDeque; -typedef std::map <unsigned, StationTask *> scheduledTasksMap; -typedef std::map <unsigned, StationTask *> reservationsMap; -typedef std::map <unsigned, Pipeline *> pipelinesMap; -typedef std::map <unsigned, Task *> inActiveTasksMap; // tasks that have status equal or above finished - -#include "task.h" -#include "schedulergui.h" - -class SchedulerDataBlock -{ -public: - SchedulerDataBlock(); - SchedulerDataBlock(const SchedulerDataBlock &); - virtual ~SchedulerDataBlock(); - - SchedulerDataBlock & operator=(const SchedulerDataBlock &rhs); - friend QDataStream& operator<< (QDataStream &out, const SchedulerDataBlock &data); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, SchedulerDataBlock &data); // used for reading data from binary file - - void cleanup(void); // clean up data objects - void addUsedTaskID(unsigned taskID); - void addUsedTaskIDs(const std::vector<unsigned> &taskIDs); - const std::vector<unsigned> &getSASUsedTaskIDs(void) const {return itsExistingSASTaskIDs;} - void setSASUsedTaskIDs(const std::vector<unsigned> &task_ids) {itsExistingSASTaskIDs = task_ids;} - void updateUsedTaskIDs(void); - void removeUsedTaskID(unsigned task_id); - inline bool isTaskIDFree(unsigned taskID) const {return (find(itsUsedTaskIDs.begin(), itsUsedTaskIDs.end(), taskID) == itsUsedTaskIDs.end());} - inline bool isTaskIDFreeInSAS(unsigned taskID) const {return (find(itsExistingSASTaskIDs.begin(), itsExistingSASTaskIDs.end(), taskID) == itsExistingSASTaskIDs.end());} - bool addTask(Task *task, bool check_ID_free = true);// adds the (already created) task to scheduler - unsigned getNewTaskID(bool override_SAS_taskIDs = false) const; - StationTask *newReservation(unsigned reservation_id, bool override_SAS_taskIDs = false); // create a new reseravation with task ID equal to task_id, return pointer to task object or 0 when reservation_id already exists - Observation *newObservation(unsigned task_id, bool override_SAS_taskIDs = false); // create a new task with task ID equal to task_id, return pointer to task or 0 when task_id already exists - Pipeline *newPipeline(unsigned task_id, pipelineType type, bool override_SAS_taskIDs = false); // create a new task with task ID equal to task_id, return pointer to task or 0 when task_id already exists - Task *newTask(unsigned task_id, bool override_SAS_taskIDs = false); - Task *newTask(unsigned task_id, const OTDBtree &SAS_tree, bool override_SAS_taskIDs = false); -// void deleteTask(unsigned taskID); - Task *deleteTask(unsigned id, id_type IDtype = ID_SCHEDULER, bool erase = true); - bool scheduleNextTask(const AstroDateTime &schedule_time); // schedules the next unscheduled task (which can be obtained with getNextTask - bool scheduleTask(Task * pTask); // schedule the unscheduled task pointed to by pTask - bool moveTaskToInactive(unsigned taskID); // puts the task in the inactive map if its state is one of the inactive states - bool rescheduleTask(unsigned task_id, const AstroDateTime & new_start); // tries to reschedule the task at the first opportunity from the given start time onwards (does not always succeed) - bool rescheduleAbortedTask(unsigned task_id, const AstroDateTime & new_start); - void tryScheduleUnscheduledTasks(void); // iterates over all unscheduled tasks to try and schedule them - // the following change.. functions change a task's schedule times without checking conflicts with other tasks - bool changeTaskStartTime(unsigned task_id, const AstroDateTime &new_start); - bool changeTaskEndTime(unsigned task_id, const AstroDateTime &new_end); - bool changeTaskDuration(unsigned task_id, const AstroTime &new_duration); - bool changeTaskSchedule(unsigned task_id, const AstroDateTime &new_start, const AstroDateTime &new_end); - void scheduleFixedTasks(void); // schedules tasks marked with fixed day or fixed time - void holdNextTask(const std::string &reason); // puts the next unscheduled task at the end of the unscheduled task list - void holdNextTask(unscheduled_reasons reason = NO_ERROR); // puts the next unscheduled task at the end of the unscheduled task list - bool unscheduleTask(unsigned task_id); // un-schedule the task with ID equal to task_id, returns true if un-schedule was successful - bool unscheduleReservation(unsigned reservation_id); // unschedule a reservation (putting it ON HOLD and removing it from the stations - bool addStation(unsigned station_id, const std::string &name); // add a new station (group) to the list of stations - void setChangesMadeFlag(void) {itsSaveRequired = true; itsUploadRequired = true;} - void clearChangesMadeFlag(void) {itsSaveRequired = false;} - void clearUploadRequiredFlag(void) {itsUploadRequired = false;} - unsigned calculatePenalty(void); // calculates the current total penalty (and stores it in totalPenalty) - void moveUnscheduledTask(unsigned from, unsigned to); -// void commitChanges(const tableChanges &); // used to commit the changes from the GUI's table view into the data structure of this schedulerDataBlock - // unscheduleAll: unschedules all tasks and put them in the unscheduled list. - void unscheduleAll(void); - void checkStatusChanges(void); -// void setConflictsTask(unsigned taskID, std::vector<unsigned> & conflicting_tasks) {itsConflicts[taskID] = conflicting_tasks;} -// void clearConflictsTask(unsigned taskID) {itsConflicts.erase(taskID);} -// unsigned getRandomScheduledTaskID(bool includeFixedTasks); - unsigned getRandomScheduledTaskID(void); - bool taskExists(unsigned task_id) const; - // updates all tasks to use the new station IDs from schedulerSettings - void updateTasksStationIDs(void); - // calculate the dataslots for all scheduled tasks -// bool calculateDataSlots(void); - - std::vector<unsigned> moveTask(Task *pTask, const AstroDateTime &new_start, bool unschedule_conflicting_tasks); // returns a vector of conflicting tasks when not successful - bool shiftTask(unsigned task_id, bool unschedule_conflicting_tasks); // shift the task to the left or right, returns false if the task was not yet scheduled - bool tryMoveTaskToAdjacentDay(unsigned task_id, bool unschedule_conflicting_tasks); // returns conflicting tasks - bool tryShiftTaskWithinDay(unsigned task_id, bool unschedule_conflicting_tasks); -// bool tryShiftTask(unsigned task_id, bool unschedule_conflicting_tasks); - -// void alignLeft(void); // aligns all task as much as possible to the left - - //sorting functions -// void sortScheduledTask2StartTime(void); -// void sortUnscheduledTasks2StartTime(void); - void sortUnscheduledTasks2Priority(void); - - // get methods - size_t getNrTasks() const {return unscheduledTasks.size() + scheduledTasks.size() + inactiveTasks.size() + itsReservations.size() + itsPipelines.size();} - bool getNextTask(Task &task) const; // returns true if the next unscheduled task was found. parameter task contains the task - bool SaveRequired(void) const { return itsSaveRequired; } // controls if data changes need to be saved - size_t getNrUnscheduled(void) const {return unscheduledTasks.size();} - size_t getNrScheduled(void) const { return scheduledTasks.size(); } - size_t getNrReservations(void) const { return itsReservations.size(); } - size_t getNrInactive(void) const { return inactiveTasks.size(); } - size_t getNrPipelines(void) const { return itsPipelines.size(); } - const unscheduledTasksDeque &getUnscheduledTasks(void) const { return unscheduledTasks; } - const scheduledTasksMap &getScheduledTasks(void) const {return scheduledTasks;} - const reservationsMap &getReservations(void) const {return itsReservations;} - const pipelinesMap &getPipelineTasks(void) const {return itsPipelines;} - const inActiveTasksMap &getInactiveTasks(void) const {return inactiveTasks;} - std::vector<Task *> getReservationsVector(void) const; - std::vector<Task *> getMaintenanceVector(void) const; - std::vector<Task *> getScheduledTasksVector(void) const; // no pipelines - std::vector<Task *> getInactiveTaskVector(void) const; - std::vector<Task *> getUnScheduledTasksVector(void) const; - std::vector<Task *> getPipelinesVector(void) const; - std::vector<Pipeline *> getScheduledPipelinesVector(void) const; - Task *getTaskForChange(unsigned task_id, id_type = ID_SCHEDULER); // returns the task with id equal to task_id so the caller can edit its properties - Pipeline *getPipelineForChange(unsigned task_id); // returns the task with id equal to task_id so the caller can edit its properties - StationTask *getReservationForChange(unsigned task_id); // returns the task with id equal to task_id so the caller can edit its properties - std::vector<unsigned> tasksInGroup(unsigned groupID, selector_types type = SEL_ALL_TASKS) const; - std::map<unsigned, std::vector<Task *> > getGroupedTasks(Task::task_status state) const; // key = groupID - std::map<unsigned, std::vector<Task *> > getGroupedObservations(Task::task_status state = Task::TASK_STATUS_END) const; // key = groupID - std::vector<Task *> getTasksInScheduleSortStartTime(void) const; - std::vector<Task *> getScheduledTasksSortStartTime(void) const; - std::vector<Task *> getScheduledObservationsSortStartTime(void) const; - std::vector<Task *> getPreScheduledObservationsSortStartTime(void) const; - std::vector<Task *> getPreScheduledTasksSortStartTime(void) const; - std::vector<Observation *> getFutureObservationsSortStartTime(void) const; // get all observations (no maintenance and reservations) with status SCHEDULED and PRESCHEDULED in the future - std::vector<Task *> getUnScheduledTasksSortFirstDate(void) const; - std::map<std::string, std::vector<Task *> > getPublishTasks(const AstroDateTime &start, const AstroDateTime &end) const; - const Task *getTask(unsigned task_id, id_type IDtype = ID_SCHEDULER) const; - const StationTask *getStationTask(unsigned task_id, id_type IDtype = ID_SCHEDULER) const; - const Observation *getObservation(unsigned taskID, id_type IDtype = ID_SCHEDULER) const; - const Pipeline *getPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const; - const CalibrationPipeline *getCalibrationPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const; - const ImagingPipeline *getImagingPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const; - const PulsarPipeline *getPulsarPipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const; - const LongBaselinePipeline *getLongBaselinePipeline(unsigned taskID, id_type IDtype = ID_SCHEDULER) const; - const StationTask *getScheduledTask(unsigned task_id) const; - StationTask *getScheduledTask(unsigned task_id); - const Observation *getScheduledObservation(unsigned task_id) const; - const Pipeline *getPipelineTask(unsigned task_id) const; - const StationTask *getReservation(unsigned reservation_id) const; - const Task *getUnscheduledTask(unsigned task_id) const; - const Task *getInactiveTask(unsigned task_id) const; - Task *getUnscheduledTaskForChange(unsigned task_id) const; - Task *getInactiveTaskForChange(unsigned task_id) const; - const Station *getStation(unsigned station_id) const; - Station *getStationForChange(unsigned station_id); - void updateStations(void); // creates the stations which are defined in theSchedulerSettings - unsigned getPenalty(void) const {return itsPenalty;} - const stationsMap &getStations(void) const {return itsStations;} - const AstroDateTime & getTaskStartTime(unsigned taskID) const; - const AstroDateTime & getTaskEndTime(unsigned taskID) const; - AstroDateTime getTaskFirstPossibleDate(unsigned taskID) const; - const AstroTime & getTaskPredecessorMaxTimeDif(unsigned taskID) const; - Task::task_status getTaskStatus(unsigned taskID) const; - bool getSaveRequired(void) const {return itsSaveRequired;} - bool getUploadRequired(void) const {return itsUploadRequired;} - const errorTasksMap &getErrorTasks(void) const {return errorTasks;} - bool newErrorTasks(void); - void clearError(unsigned taskID, data_headers header); - void markErrorTasksStatus(void); // sets the status of task with errors to state ERROR - unsigned nrOfErrorTasks(void) const {return errorTasks.size();} - const Storage &getStorage(void) const {return itsStorage;} - - // checking tasks - bool checkStationConflicts(StationTask *pTask); - bool checkTasksForErrors(void); // check for all errors, returns 1 if no-errors or errors were fixed - bool predecessorExists(unsigned predecessorID) const {return taskExists(predecessorID);} - unscheduled_reasons checkTaskStations(StationTask *pTask); // check stations of the given task - // do a 'manual' check for errors on a single task - bool checkTask(Task *pTask); - // checks if the specified task time window is within the schedule - bool checkTaskBoundaries(const Task &task) const; - const std::vector<unsigned> &getUsedTaskIDs(void) const {return itsUsedTaskIDs;} - void setUsedTaskIDs(const std::vector<unsigned> &usedIDs) {itsUsedTaskIDs = usedIDs;} - bool findFirstOpportunity(const Task *pTask, AstroDateTime &start_time, unsigned reservation_id = 0); - void initStorage(void) {itsStorage.initStorage();} - - void clearStorageClaims(void) {itsStorage.clearStorageClaims();} - std::vector<storageResult> checkAssignedTaskStorage(Task *pTask, dataProductTypes dataProduct) {return itsStorage.checkAssignedTaskStorage(pTask, dataProduct);} - storageLocationOptions getStorageLocationOptions(dataProductTypes dataProduct, const AstroDateTime &startTime, const AstroDateTime &endTime, const double &fileSize, const double &bandWidth, unsigned minNrFiles, sortMode sort_mode = SORT_NONE, const std::vector<int> &nodes = std::vector<int>()) { - return itsStorage.getStorageLocationOptions(dataProduct, startTime, endTime, fileSize, bandWidth, minNrFiles, sort_mode, nodes); - } - const std::vector<storageResult> &getLastStorageCheckResult(void) const {return itsStorage.getLastStorageCheckResult();} - void setAllowedStorageHosts(const std::vector<int> &allowedStorageHosts) {itsStorage.setAllowedStorageHosts(allowedStorageHosts);} - Task * moveTaskFromInactive(unsigned task_id); - -private: - unsigned getTaskID(unsigned task_id, bool override_SAS_taskIDs); - void printUsedTaskIDs(void) const; - // remove a task is inactive (finished, aborted, etc) from the stations - void removeTaskFromStations(StationTask *task); - const Task *getTaskByTaskID(unsigned task_id) const; - const Task *getTaskBySASTreeID(quint32 sas_tree_id) const; // returns the task with the specified SAS id so the caller can edit its properties - const Task *getTaskByMomID(quint32 momID) const; - Task *getTaskForChangeByTaskID(unsigned task_id) const; - Task *getTaskForChangeBySASTreeID(quint32 sas_tree_id) const; - Task *getTaskForChangeByMomID(quint32 momID) const; - Task *readTaskFromStream(QDataStream &in); - void writeTaskToStream(QDataStream &out, Task *pTask) const; - // withinPredecessorsRange: check if the task is still within predecessor range - // return value: - // -1: both the lower limit and upper limit have been reached (no movement possible) - // 0: clear of both limits can move left (earlier) or right (later) - // 1: lower limit reached, can move right (later) - // 2: upper limit reached, can move left (earlier) - short int withinPredecessorsRange(const Task *task, const AstroDateTime &new_start) const; - -protected: - // scheduler data objects - // map conflicts will hold for every unscheduled task the possible conflicting (scheduled) task IDs. - unscheduledTasksDeque unscheduledTasks; // contains pointers to the tasks that have not yet been scheduled - scheduledTasksMap scheduledTasks; // contains the already scheduled tasks. Key = TaskId, Value = pointer to task - reservationsMap itsReservations; // contains all reservations - pipelinesMap itsPipelines; // contains all pipelines - errorTasksMap errorTasks; // contains the tasks that have erroneous parameters. The second part contains the specific field which has errors - inActiveTasksMap inactiveTasks; // contains 'unscheduleable' tasks with status: idle, described, prepared, aborted, finished, obsolete - stationsMap itsStations; // contains the existing stations - Storage itsStorage; // contains the existing storage nodes - std::vector<unsigned> itsUsedTaskIDs; // keep a record of the used task IDs - std::vector<unsigned> itsExistingSASTaskIDs; // keep a record of the task IDs that exist already in SAS - unsigned itsPenalty; // the total penalty for this schedule - bool itsSaveRequired, itsUploadRequired; - Task nullTask; -}; - -#endif /* SCHEDULERDATABLOCK_H_ */ diff --git a/SAS/Scheduler/src/schedulergui.cpp b/SAS/Scheduler/src/schedulergui.cpp deleted file mode 100644 index f13885ee16df483140c5b6ffe2c3a106678b65f4..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulergui.cpp +++ /dev/null @@ -1,2269 +0,0 @@ -/* - * schedulergui.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulergui.cpp $ - * - */ - -#include <QtGui> -#include <QBoxLayout> -#include "qlofardatamodel.h" -#include <QTableView> -#include <QDesktopWidget> -#include <QDockWidget> -#include <QStatusBar> -#include <QLCDNumber> -#include <QFileDialog> -#include <sstream> -#include <vector> -#include <algorithm> -#include <fstream> -#include <cstdlib> // needed for system() call in publish() -#include "lofar_scheduler.h" -#include "schedulergui.h" -#include "schedulerdata.h" -#include "Controller.h" -#include "GraphicResourceScene.h" -#include "graphicstoragescene.h" -#include "GraphicTask.h" -#include "FileUtils.h" -#include "parsettreeviewer.h" -#include "shifttasksdialog.h" - -using std::ofstream; -using std::string; -using std::endl; - -const char * DATA_HEADERS[NR_DATA_HEADERS] = { "task ID", "SAS ID", "MoM ID", "group ID", "project ID", "task name", "planned start (UTC)", "planned end (UTC)", "duration", - "task type", "task status" , "cluster", "error reason", "task description", "stations", "reservation", "priority", "fix day", "fix time", - "first possible date", "last possible date", "window min time", "window max time", "antenna mode", "clock", "filter", "# subbands", - "contact name", "phone", "e-mail", "predecessors", "pred. min time dif", "pred. max time dif", "night wf.", "data size"}; - -extern QString currentUser; - - -SchedulerGUI::SchedulerGUI(Controller *controller) - : QMainWindow(0), itsSortColumn(PLANNED_START), itsSortOrder(Qt::DescendingOrder), itsModel(0), itsDelegate(0), itsSearchBar(0), - itsSearchLineEdit(0), itsSearchNextButton(0), itsSearchPreviousButton(0), itsSearchColumnOnlyCheckBox(0), - itsIsTestMode(false), itsIsSaveRequired(false), itsEnablePublish(false), - itsController(controller) - - { - ui.setupUi(this); - -#if defined Q_OS_WINDOWS || _DEBUG_ - itsEnablePublish = true; -#endif - - if (currentUser == "lofarsys") { - itsEnablePublish = true; - } - - itsEnablePublish = true; - - createMainToolbar(); - createGraphicDock(); - createTableDock(); -// createGraphicStorageDock(); - createStatusBar(); - createSearchBar(); - - itsTaskDialog = new TaskDialog(this, itsController); - itsTreeViewer = new ParsetTreeViewer(); - - connectInternalSignals(); - - - // center the GUI in the middle of the current screen - QRect geometry = this->geometry(); - QDesktopWidget * pDesktop = QApplication::desktop(); - QRect screenGeometry = pDesktop->screenGeometry(pDesktop->screenNumber()); - int xpos = (screenGeometry.width() - geometry.width()) / 2; - int ypos = (screenGeometry.height() - geometry.height()) / 2; - this->setGeometry(xpos, ypos, geometry.width(), geometry.height()); - clearCurrentFileName(); - itsWindowTitle = "LOFAR Scheduler"; - updateWindowTitle(); - - // the timer to update the current time - line - itsTimer = new QTimer(this); - itsTimer->setSingleShot(false); - connect(itsTimer, SIGNAL(timeout()), this, SLOT(updateCurrentTime())); - itsTimer->setInterval(1000); // update every minute - itsTimer->start(); -} - -SchedulerGUI::~SchedulerGUI() -{ - delete itsModel; - delete itsSearchLineEdit; - delete itsSearchNextButton; - delete itsSearchPreviousButton; - delete itsSearchColumnOnlyCheckBox; - delete itsSearchBar; - // status bar components - delete itsStatusBarUsedDatabase; - delete itsStatusBarProgress; - delete itsStatusBarTaskStatus; - delete itsStatusBarStatusText; - delete itsStatusBar; - // main toolbar - delete itsLCDtimer; - delete itsMainToolBar; - //graphic view components - delete itsZoomOutAction; - delete itsZoomInAction; - delete itsGraphicViewToolbar; - delete itsGraphicView; - delete itsGraphicResourceScene; - delete itsGraphicDockMainLayout; - delete itsGraphicDockWidgetContents; - delete itsGraphicDock; - // table view components - delete itsTableView; - delete closeSearchBarAct; - delete itsSearchPreviousAct; - delete itsSearchNextAct; - delete itsSearchColumnOnlyCheckBoxAct; - delete closeIcon; - delete itsTaskDialog; -} - -void SchedulerGUI::updateCurrentTime(void) { - const QDateTime &UTC(QDateTime::currentDateTime().toUTC()); - itsGraphicResourceScene->updateCurrentTime(UTC); - itsLCDtimer->display(UTC.toString("hh:mm:ss")); -} - -void SchedulerGUI::createMainToolbar(void) { - itsMainToolBar = new QToolBar(tr("Main")); - addToolBar(Qt::TopToolBarArea, itsMainToolBar); - itsMainToolBar->setMovable(false); - - // new schedule - ui.action_New_schedule->setIcon(QIcon(tr(":/icons/new_schedule.png"))); - ui.action_New_schedule->setText(tr("New schedule")); - itsMainToolBar->addAction(ui.action_New_schedule); - // open schedule - ui.action_Open_Schedule->setIcon(QIcon(tr(":/icons/open.png"))); - ui.action_Open_Schedule->setText(tr("Open schedule")); - itsMainToolBar->addAction(ui.action_Open_Schedule); - // save schedule - ui.action_Save_schedule->setIcon(QIcon(tr(":/icons/save.png"))); - ui.action_Save_schedule->setText(tr("Save schedule")); - itsMainToolBar->addAction(ui.action_Save_schedule); - - // undo - itsMainToolBar->addSeparator(); - ui.action_Undo->setIcon(QIcon(tr(":/icons/undo.png"))); - ui.action_Undo->setText(tr("Undo")); - itsMainToolBar->addAction(ui.action_Undo); - //redo - ui.action_Redo->setIcon(QIcon(tr(":/icons/redo.png"))); - ui.action_Redo->setText(tr("Redo")); - itsMainToolBar->addAction(ui.action_Redo); - // add - ui.action_Add_task->setIcon(QIcon(tr(":/icons/add_task.png"))); - ui.action_Add_task->setText(tr("Add task")); - itsMainToolBar->addAction(ui.action_Add_task); - // delete - ui.action_Delete_task->setIcon(QIcon(tr(":/icons/delete_task.png"))); - ui.action_Delete_task->setText(tr("Delete task")); - itsMainToolBar->addAction(ui.action_Delete_task); - //thrashcan - ui.action_Thrashcan->setIcon(QIcon(tr(":/icons/empty_trash.png"))); - ui.action_Thrashcan->setText(tr("Show thrashcan")); - itsMainToolBar->addAction(ui.action_Thrashcan); - // find - ui.action_Find->setIcon(QIcon(tr(":/icons/find.png"))); - ui.action_Find->setText(tr("Find")); - itsMainToolBar->addAction(ui.action_Find); - - itsMainToolBar->addSeparator(); - // download schedule - ui.action_DownloadSASSchedule->setIcon(QIcon(tr(":/icons/download.png"))); - ui.action_DownloadSASSchedule->setText(tr("Download current schedule")); - itsMainToolBar->addAction(ui.action_DownloadSASSchedule); - // synchronize with SAS - ui.action_SyncSASSchedule->setIcon(QIcon(tr(":/icons/synchronize.png"))); - ui.action_SyncSASSchedule->setText(tr("Synchronize with SAS")); - itsMainToolBar->addAction(ui.action_SyncSASSchedule); - - itsMainToolBar->addSeparator(); - // create initial schedule create_initial_schedule.png - ui.action_Create_initial_schedule->setIcon(QIcon(tr(":/icons/create_initial_schedule.png"))); - ui.action_Create_initial_schedule->setText(tr("Create initial schedule")); - itsMainToolBar->addAction(ui.action_Create_initial_schedule); - // optimize schedule - ui.action_Optimize_schedule->setIcon(QIcon(tr(":/icons/optimize.png"))); - ui.action_Optimize_schedule->setText(tr("Optimize schedule")); - itsMainToolBar->addAction(ui.action_Optimize_schedule); - // equalize schedule - ui.action_Balance_schedule->setIcon(QIcon(tr(":/icons/load-balancing.png"))); - ui.action_Balance_schedule->setText(tr("Balance schedule")); - itsMainToolBar->addAction(ui.action_Balance_schedule); - // assign resources - itsMainToolBar->addAction(ui.action_Assign_resources); - - itsMainToolBar->addSeparator(); - ui.actionPublish_schedule->setIcon(QIcon(tr(":/icons/publish.png"))); - ui.actionPublish_schedule->setText(tr("Publish schedule")); - itsMainToolBar->addAction(ui.actionPublish_schedule); - - ui.actionPublish_schedule->setEnabled(itsEnablePublish); - if (!itsEnablePublish) { - ui.actionPublish_schedule->setToolTip("Publishing is only enabled when you are lofarsys"); - } - - itsMainToolBar->addSeparator(); - ui.action_Schedule_Settings->setIcon(QIcon(tr(":/icons/settings.png"))); - ui.action_Schedule_Settings->setText(tr("Schedule settings")); - itsMainToolBar->addAction(ui.action_Schedule_Settings); - itsMainToolBar->addSeparator(); - ui.actionConnect_to_Data_monitor->setIcon(QIcon(tr(":/icons/connect_datamonitor.png"))); - ui.actionConnect_to_Data_monitor->setCheckable(true); - itsMainToolBar->addAction(ui.actionConnect_to_Data_monitor); - itsMainToolBar->addSeparator(); - // add empty space by using an empty widget with automatic stretch - QWidget* empty = new QWidget(); - empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); - itsMainToolBar->addWidget(empty); - itsLCDtimer = new QLCDNumber(itsMainToolBar); - itsLCDtimer->setSegmentStyle(QLCDNumber::Flat); - itsLCDtimer->setFrameStyle(QLCDNumber::Sunken); - itsLCDtimer->setFrameShape(QLCDNumber::WinPanel); - itsLCDtimer->setDigitCount(8); - itsLCDtimer->setToolTip("current UTC"); - itsLCDtimer->display("00:00:00"); - itsMainToolBar->addWidget(itsLCDtimer); -} - -void SchedulerGUI::setExistingProjects(const campaignMap &projects) { - itsTaskDialog->setExistingProjects(projects); - updateProjectsFilter(projects); -} - -void SchedulerGUI::updateDataMonitorConnectionStatus(void) { - ui.actionConnect_to_Data_monitor->setChecked(itsController->isDataMonitorConnected()); -} - - -void SchedulerGUI::setSaveRequired(bool save_required) { - if (save_required != itsIsSaveRequired) { - itsIsSaveRequired = save_required; - updateWindowTitle(); - if (save_required) { - ui.action_Save_schedule->setEnabled(true); - } - else { - ui.action_Save_schedule->setEnabled(false); - } - } -} - -/* -void SchedulerGUI::setTestMode(bool enable_test_mode) { - if (enable_test_mode) { - gui->setWindowTitle("LOFAR Scheduler (" + itsCurrentFileName + ")"); - } - else { - gui->setWindowTitle("** TEST MODE ** LOFAR Scheduler (" + itsCurrentFileName + ")"); - } -} -*/ - -void SchedulerGUI::updateWindowTitle(void) { - QString fullTitle(itsWindowTitle + " (" + itsCurrentFileName); - if (itsIsSaveRequired) { - fullTitle += "*)"; - } - else { - fullTitle += ")"; - } - if (itsIsTestMode) { - fullTitle += " ### TEST MODE ###"; - } - setWindowTitle(fullTitle); -} - -void SchedulerGUI::showTaskDialog(const Task *task, tabIndex tab) { - itsTaskDialog->show(task, tab); -} - -void SchedulerGUI::multiEditTasks(std::vector<Task *> &tasks) { - itsTaskDialog->showMultiEdit(tasks); -} - -void SchedulerGUI::updateTaskDialogStations(void) { - itsTaskDialog->loadAvailableStations(); -} - -void SchedulerGUI::setShortcutKeys(void) { -} - -void SchedulerGUI::horizontalView(void) { - ui.actionVertical_view->setChecked(false); - ui.actionHorizontal_view->setChecked(true); -// itsTableDock->setAllowedAreas(Qt::LeftDockWidgetArea); -// itsGraphicDock->setAllowedAreas(Qt::LeftDockWidgetArea); - splitDockWidget(itsGraphicDock, itsTableDock, Qt::Vertical); -} - -void SchedulerGUI::verticalView(void) { - ui.actionVertical_view->setChecked(true); - ui.actionHorizontal_view->setChecked(false); -// itsTableDock->setAllowedAreas(Qt::TopDockWidgetArea); -// itsGraphicDock->setAllowedAreas(Qt::TopDockWidgetArea); - splitDockWidget(itsTableDock, itsGraphicDock, Qt::Horizontal); -} - -void SchedulerGUI::updateGraphicStations() { - itsGraphicResourceScene->updateStationTimeLines(); -} - -void SchedulerGUI::updateSceneTimeSpan(void) { - itsGraphicResourceScene->setNewTimeSpan(); -} - -void SchedulerGUI::addTask(const Task *pTask) { - if (pTask->isStationTask()) { - itsGraphicResourceScene->addTask(pTask); - } - unsigned rows = itsModel->rowCount() + 1; - itsModel->setRowCount(rows); - updateTableTask(pTask, rows-1); -} - -void SchedulerGUI::deleteTaskFromGUI(unsigned int taskID, Task::task_type type) { - if (type != Task::PIPELINE) { - itsGraphicResourceScene->removeTaskFromScene(taskID); - } - // delete task from table - QList<QStandardItem *> results = itsModel->findItems(QString(int2String(taskID).c_str()),Qt::MatchExactly, TASK_ID); - if (!results.empty()) { - itsModel->removeRows(itsModel->indexFromItem(results.first()).row(), 1); - } -} - -void SchedulerGUI::updateGraphicTask(unsigned task_id) { - const Task *pTask(itsController->getTask(task_id)); - if (pTask) { - itsGraphicResourceScene->updateTask(pTask); - } -} - -void SchedulerGUI::updateGraphicTasks(const scheduledTasksMap &scheduledTasks, const reservationsMap &reservations, const inActiveTasksMap & inactiveTasks) { - itsGraphicResourceScene->updateTasks(scheduledTasks, reservations, inactiveTasks); -} - -void SchedulerGUI::createTableDock(void) { - // create table dock and its layout - itsTableDock = new QDockWidget("Table schedule view", this); - itsTableDockWidgetContents = new QWidget(); - itsTableDockMainLayout = new QGridLayout(itsTableDockWidgetContents); - itsTableDockMainLayout->setMargin(5); - // create the table view - itsTableView = new TableView(itsTableDockWidgetContents); - itsTableView->setWordWrap(false); -#if QT_VERSION >= 0x050000 - itsTableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); - itsTableView->horizontalHeader()->setSectionsMovable(true); -#else - itsTableView->verticalHeader()->setResizeMode(QHeaderView::Fixed); - itsTableView->horizontalHeader()->setMovable(true); -#endif - itsTableView->setDragEnabled(false); - itsTableView->setDropIndicatorShown(true); - itsTableView->setAcceptDrops(false); - itsTableView->setAlternatingRowColors(true); - itsTableView->sortByColumn(itsSortColumn, itsSortOrder); - // create two table filtering checkboxes for observations and pipelines - itsTableObsEnabled = new QCheckBox("Observations"); - itsTableObsEnabled->setToolTip("Hide/show Observations in table"); - itsTableObsEnabled->setChecked(true); - itsTableDockMainLayout->addWidget(itsTableObsEnabled, 0, 0, 1, 1); - itsTablePipesEnabled = new QCheckBox("Pipelines"); - itsTablePipesEnabled->setChecked(true); - itsTablePipesEnabled->setToolTip("Hide/show Pipelines in table"); - itsTableDockMainLayout->addWidget(itsTablePipesEnabled, 0, 1, 1, 1); - itsTableProjectFilter = new QComboBox(); - itsTableProjectFilter->setToolTip("Filter on specific project"); - itsTableProjectFilter->setMinimumWidth(175); // Magix number - itsTableDockMainLayout->addWidget(itsTableProjectFilter, 0, 2, 1, 1); - itsTableSpacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - itsTableDockMainLayout->addItem(itsTableSpacerItem, 0, 3, 1, 1); - itsTableDockMainLayout->addWidget(itsTableView, 1, 0, 1, 4); - - itsTableDock->setWidget(itsTableDockWidgetContents); - itsTableDock->setAllowedAreas(Qt::LeftDockWidgetArea); // change all LeftDockWidgetArea in TopDockWidgetArea for vertical view - - addDockWidget(Qt::LeftDockWidgetArea, itsTableDock); -} - -void SchedulerGUI::createGraphicDock(void) { - // create docking widget for graphical area - itsGraphicDock = new QDockWidget(tr("Graphic schedule view"), this); - itsGraphicDockWidgetContents = new QWidget(); - itsGraphicDockMainLayout = new QVBoxLayout(itsGraphicDockWidgetContents); - itsGraphicDockMainLayout->setMargin(0); - itsGraphicDock->setAllowedAreas(Qt::LeftDockWidgetArea); - itsGraphicResourceScene = new GraphicResourceScene(itsController); - itsGraphicView = new QGraphicsView(itsGraphicResourceScene); - itsGraphicView->setDragMode(QGraphicsView::RubberBandDrag); - itsGraphicResourceScene->setViewPort(itsGraphicView); - itsGraphicViewToolbar = new QToolBar(itsGraphicDockWidgetContents); - // zoom in/zoom out buttons - itsZoomInAction = new QAction(QIcon(":/icons/zoomin.png"), tr("Zoom in"), this); - itsZoomOutAction = new QAction(QIcon(":/icons/zoomout.png"), tr("Zoom out"), this); - itsGraphicViewToolbar->addAction(itsZoomInAction); - itsGraphicViewToolbar->addAction(itsZoomOutAction); - // Now button - itsCenterOnNow = new QAction(QIcon(":/icons/clock.png"), tr("Now"), this); - itsGraphicViewToolbar->addAction(itsCenterOnNow); - // Color mode button - itsTaskTypeColorModeAction = new QAction(QIcon(":/icons/taskcolormode.png"), tr("Toggle task color mode"), this); - itsTaskTypeColorModeAction->setIconText("Status color mode"); - itsGraphicViewToolbar->addAction(itsTaskTypeColorModeAction); - - itsGraphicViewToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); -// itsZoomInAction->setMaximumSize(20,20); -// itsZoomOutAction->setMaximumSize(20,20); -// itsGraphicViewToolbar->addAction(itsZoomOutButton); -// itsGraphicViewToolbar->addWidget(itsZoomInButton); - itsGraphicDockMainLayout->addWidget(itsGraphicViewToolbar); - itsGraphicDockMainLayout->addWidget(itsGraphicView); - itsGraphicDock->setWidget(itsGraphicDockWidgetContents); - itsGraphicView->centerOn(0,0); - itsGraphicView->show(); - addDockWidget(Qt::LeftDockWidgetArea, itsGraphicDock); -} - -void SchedulerGUI::updateProjectsFilter(const campaignMap &campaigns) { - bool projectFilterApplied(itsTableProjectFilter->currentIndex() != 0); - QString curSelProject(itsTableProjectFilter->currentText()); - QStringList projects; - projects.append("All projects"); - for (campaignMap::const_iterator it = campaigns.begin(); it != campaigns.end(); ++it) { - if (itsActiveProjects.contains(it->second.name.c_str())) { // only show projects that are in the table - projects << it->second.name.c_str(); - } - } - itsTableProjectFilter->blockSignals(true); - itsTableProjectFilter->clear(); - itsTableProjectFilter->addItems(projects); - itsTableProjectFilter->blockSignals(false); - - // re-select the previously selected project if any - if (projectFilterApplied) { - int cnt(itsTableProjectFilter->count()); - for (int i = 0; i < cnt; ++i) { - if (itsTableProjectFilter->itemText(i) == curSelProject) { - itsTableProjectFilter->setCurrentIndex(i); - break; - } - } - } -} - - - -void SchedulerGUI::updateTimeLinePosAfterScroll(void) { - itsGraphicResourceScene->updateTimeLineYPos(); -} - -void SchedulerGUI::updateStationTimeLinesAfterScroll(void) { - itsGraphicResourceScene->updateStationNamesXPos(); -} - -void SchedulerGUI::createStatusBar(void) { - itsStatusBar = new QStatusBar(this); - this->setStatusBar(itsStatusBar); - itsStatusBarStatusText = new QLabel(tr("Ready"), itsStatusBar); - itsStatusBarStatusText->setMinimumWidth(300); - itsStatusBar->addWidget(itsStatusBarStatusText); - - itsStatusBarTaskStatus = new QLabel("#S:0, #US:0, #INACT:0, #RES:0, #ERR:0", itsStatusBar); - itsStatusBar->addWidget(itsStatusBarTaskStatus, 1); - - itsStatusBarUsedDatabase = new QLabel("SAS DB:" + itsController->getSasDatabaseName(), itsStatusBar); - itsStatusBarUsedDatabase->setMinimumWidth(150); - itsStatusBar->addWidget(itsStatusBarUsedDatabase); - - itsStatusBarProgress = new QProgressBar(); - itsStatusBarProgress->setMaximumHeight(15); - itsStatusBarProgress->setMinimumWidth(150); - itsStatusBarProgress->setMaximumWidth(150); - itsStatusBar->addPermanentWidget(itsStatusBarProgress); - - itsStatusBar->show(); -} - -void SchedulerGUI::updateSasDatabaseName(void) { - itsStatusBarUsedDatabase->setText("SAS DB:" + itsController->getSasDatabaseName()); -} - -void SchedulerGUI::updateProgressBar(int progress) { - itsStatusBarProgress->setValue(progress); -} - -void SchedulerGUI::setProgressBarMaximum(int maxValue) { - itsStatusBarProgress->setEnabled(true); - itsStatusBarProgress->setMaximum(maxValue); -} - -void SchedulerGUI::updateStatusBar(unsigned nr_scheduled, unsigned nr_unscheduled, unsigned nr_inactive, unsigned nr_reservations, unsigned nr_errortasks, unsigned nr_pipelines, int progress) { - QString statusStr = "#S:" + QString::number(nr_scheduled) + ", #US:" + QString::number(nr_unscheduled) + - ", #INACT:" + QString::number(nr_inactive) + ", #RES:" + QString::number(nr_reservations) + - ", #ERR:" + QString::number(nr_errortasks) + ", #PL:" + QString::number(nr_pipelines); - itsStatusBarTaskStatus->setText(statusStr); - itsStatusBarProgress->setValue(progress); -} - -void SchedulerGUI::disableProgressBar(void) { - itsStatusBarProgress->setValue(0); - itsStatusBarProgress->setEnabled(false); -} - -void SchedulerGUI::createSearchBar(void) { - itsSearchBar = new QToolBar(this); - addToolBar(Qt::BottomToolBarArea, itsSearchBar); - itsSearchBar->setAccessibleName(QString("Search")); - itsSearchBar->setWindowTitle(tr("Search")); - itsSearchBar->setAllowedAreas(Qt::BottomToolBarArea|Qt::TopToolBarArea); - - //showSearchBarAct = new QAction(this); -// this->addAction(showSearchBarAct); - - // create search widgets - - // close button - closeSearchBarAct = new QAction(this); - closeSearchBarAct->setObjectName(QString::fromUtf8("close")); - closeIcon = new QIcon; -//#ifdef Q_OS_UNIX - closeIcon->addPixmap(QPixmap(QString::fromUtf8(":/icons/close16x16.png")), QIcon::Normal, QIcon::Off); -//#elif defined(Q_OS_WIN) -// closeIcon->addPixmap(QPixmap(QString::fromUtf8(":/icons\\close16x16.png")), QIcon::Normal, QIcon::Off); -//#endif - closeSearchBarAct->setIcon(*closeIcon); - itsSearchBar->addAction(closeSearchBarAct); - - // search line edit - itsSearchLineEdit = new QLineEdit(this); - itsSearchLineEdit->setObjectName(QString::fromUtf8("itsSearchLineEdit")); - - // previous button - itsSearchPreviousButton = new QPushButton(itsSearchBar); - itsSearchPreviousButton->setText(tr("&Previous")); - itsSearchPreviousAct = new QAction(this); - itsSearchPreviousAct->setObjectName(QString::fromUtf8("searchPreviousAct")); - itsSearchPreviousButton->addAction(itsSearchPreviousAct); - - // next button - itsSearchNextButton = new QPushButton(itsSearchBar); - itsSearchNextButton->setText(tr("&Next")); - itsSearchNextAct = new QAction(this); - itsSearchNextAct->setObjectName(QString::fromUtf8("searchNextAct")); - itsSearchNextButton->addAction(itsSearchNextAct); - - //current column - itsSearchColumnOnlyCheckBox = new QCheckBox(itsSearchBar); -// itsSearchColumnOnlyCheckBox->setChecked(true); - itsSearchColumnOnlyCheckBox->setText(tr("Search current &column")); - itsSearchColumnOnlyCheckBoxAct = new QAction(this); - itsSearchColumnOnlyCheckBoxAct->setObjectName(QString::fromUtf8("columnOnlyAct")); - itsSearchColumnOnlyCheckBox->addAction(itsSearchColumnOnlyCheckBoxAct); - -// //current row -// itsSearchRowOnlyCheckBox = new QCheckBox(itsSearchBar); -// itsSearchRowOnlyCheckBox->setText(tr("Search &row")); - - //current row - -// // match case checkbox -// itsSearchMatchCaseCheckBox = new QCheckBox(itsSearchBar); -// itsSearchMatchCaseCheckBox->setText(tr("&Match case")); - - // add widgets to search bar - itsSearchBar->addWidget(itsSearchLineEdit); - itsSearchBar->addWidget(itsSearchPreviousButton); - itsSearchBar->addWidget(itsSearchNextButton); - itsSearchBar->addWidget(itsSearchColumnOnlyCheckBox); -// itsSearchBar->addWidget(itsSearchRowOnlyCheckBox); -// itsSearchBar->addWidget(itsSearchMatchCaseCheckBox); - - itsSearchBar->hide(); - -} - -/* -void SchedulerGUI::keyPressEvent ( QKeyEvent * event ) { - std::cout << "keypressed event" << std::endl; - //if (event->key() == Qt::Key_Escape) -} -*/ - -void SchedulerGUI::doSearch(const QString& term) { - search(term); -} - -void SchedulerGUI::searchAgain(void) { - itsSearchLineEdit->setFocus(); // directly set focus to the line edit box again after user checks the column only checkbox - itsSearchLineEdit->selectAll();// scheduler.createStartSchedule(); - // gui->updateGraphicTasks(data.getScheduledTasks()); - - QString searchTerm = itsSearchLineEdit->text(); // fetch the changed search term directly from the line edit box - if (!searchTerm.isEmpty()) { - search(searchTerm); - } -} - -void SchedulerGUI::search(const QString& term) { - clearSearch(); - if (itsModel && !term.isEmpty()) { - if (itsSearchColumnOnlyCheckBox->isChecked()) { - columnSearched = itsTableView->currentIndex().column(); - searchResult = itsModel->findItems(term,Qt::MatchContains, columnSearched); - } - else { - for (unsigned short col = 0; col < NR_DATA_HEADERS; ++col) { - searchResult += itsModel->findItems(term,Qt::MatchContains, col); - } - } - - if (!searchResult.isEmpty()) { -// QColor color("white"); - QPalette palet = ( itsSearchLineEdit->palette() ); - palet.setColor( QPalette::Base, Qt::white ); - itsSearchLineEdit->setPalette(palet); - search_iterator = searchResult.begin(); - - itsTableView->setCurrentIndex(itsModel->indexFromItem(*search_iterator)); -// itsSearchPreviousButton->setEnabled(false); -// if (searchResult.size() == 1) { -// itsSearchNextButton->setEnabled(false); -// } -// else if (searchResult.size() > 1) { -// itsSearchNextButton->setEnabled(true); -// } - } - else { -// QColor color("red");// = QColorDialog::getColor( Qt::red, this); - QPalette palet = ( itsSearchLineEdit->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - itsSearchLineEdit->setPalette(palet); -// itsSearchPreviousButton->setEnabled(false); -// itsSearchNextButton->setEnabled(false); - } - } -} - -void SchedulerGUI::searchPrevious() { - if (!searchResult.isEmpty()) { - if (search_iterator != searchResult.begin()) { -// itsSearchNextButton->setEnabled(true);// scheduler.createStartSchedule(); - // gui->updateGraphicTasks(data.getScheduledTasks()); - - --search_iterator; - } - else if (searchResult.size() > 1) { - if (QMessageBox::question(0, tr("Beginning of search results"), - tr("This is the first search result?\n Do you want to jump to the last?"), - QMessageBox::Ok | QMessageBox::Default, - QMessageBox::Cancel) == QMessageBox::Ok) { - search_iterator = searchResult.end()-1; - } - else return; - } - itsTableView->setCurrentIndex(itsModel->indexFromItem(*search_iterator)); -// if (search_iterator == searchResult.begin()) { -// itsSearchPreviousButton->setEnabled(false); -// } - } - else { - doSearch(itsSearchLineEdit->text()); - } -} - -void SchedulerGUI::searchNext() { - if (!searchResult.isEmpty()) { - if (search_iterator != searchResult.end()-1) { -// itsSearchPreviousButton->setEnabled(true); - ++search_iterator; - } - else if (searchResult.size() > 1) { - if (QMessageBox::question(0, tr("End of search results"), - tr("This is the last search result?\n Do you want to jump to the first?"), - QMessageBox::Ok | QMessageBox::Default, - QMessageBox::Cancel) == QMessageBox::Ok) { - search_iterator = searchResult.begin(); - } - else return; - } - itsTableView->setCurrentIndex(itsModel->indexFromItem(*search_iterator)); - } - else { - doSearch(itsSearchLineEdit->text()); - } -} - -void SchedulerGUI::newTable(SchedulerData const &data) { - delete itsModel; - itsModel = 0; - itsModel = new QLofarDataModel(data.getNrTasks(), NR_DATA_HEADERS, 0); - - QStringList headerList; - for (std::vector<std::string>::const_iterator it=data.getDataHeaders().begin(); it != data.getDataHeaders().end(); ++it) { - headerList << it->c_str(); - } - itsModel->setHorizontalHeaderLabels(headerList); - - itsModel->setSortRole(Qt::UserRole); // to get proper sorting make sure the userRole has the correct data (that sorts correctly) for every column - - itsTableView->setModel(itsModel); - itsTableView->setItemDelegate(&itsDelegate); - itsTableView->horizontalHeader()->setStretchLastSection(true); -#if QT_VERSION >= 0x050000 - itsTableView->horizontalHeader()->setSectionsClickable(true); -#else - itsTableView->horizontalHeader()->setClickable(true); -#endif - itsTableView->horizontalHeader()->setSortIndicatorShown(true); - writeTableData(data); -} -/* -void SchedulerGUI::loadNewTable(SchedulerData const &data) { - newTable(data); - size_t startRow(0); - std::vector<Task *> tasks; - // write scheduled tasks to table - tasks = data.getScheduledTasksVector(); - writeTasksToTable(tasks,0); - startRow += tasks.size(); - // write the unscheduled tasks to the table - tasks = data.getUnScheduledTasksVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // write the reservations to the table - tasks = data.getReservationsVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // maintenance - tasks = data.getMaintenanceVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // write the inactive tasks to the table - tasks = data.getInactiveTaskVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // write pipeline tasks to table - tasks = data.getPipelinesVector(); - writeTasksToTable(tasks,startRow); - - itsTableView->sortByColumn(itsSortColumn, itsSortOrder); - setDefaultColumnWidths(); - itsTableView->resizeRowsToContents(); -} -*/ - -void SchedulerGUI::setDefaultColumnWidths(void) { - itsTableView->resizeColumnsToContents(); - itsTableView->setColumnWidth(PROJECT_ID,150); // - itsTableView->setColumnWidth(TASK_NAME,150); // - itsTableView->setColumnWidth(CONTACT_NAME,100); // - itsTableView->setColumnWidth(CONTACT_PHONE,100); // - itsTableView->setColumnWidth(CONTACT_EMAIL,100); // - itsTableView->setColumnWidth(STATION_ID,200); // - itsTableView->setColumnWidth(FILTER_TYPE,150); // Antenna mode - itsTableView->setColumnWidth(ANTENNA_MODE,205); // Antenna mode -// itsTableView->setColumnWidth(SOURCES,100); // sources -// itsTableView->setColumnWidth(RIGHT_ASCENSION,100); // RA - itsTableView->setColumnWidth(PLANNED_START,155); // declination - itsTableView->setColumnWidth(PLANNED_END,155); // declination - itsTableView->setColumnWidth(TASK_STATUS,100); - itsTableView->setColumnWidth(UNSCHEDULED_REASON,280); // unscheduled reason - itsTableView->setColumnWidth(FIXED_DAY,50); - itsTableView->setColumnWidth(FIXED_TIME,50); - itsTableView->setColumnWidth(PRIORITY,50); - itsTableView->setColumnWidth(CLUSTER_NAME,50); -} - -void SchedulerGUI::writeTableData(SchedulerData const &data) { - // clear table search results to avoid referencing altered items in table - if (itsModel) { - clearSearch(); - itsModel->removeRows(0, itsModel->rowCount()); - itsModel->insertRows(0, data.getNrTasks()); - } - if (data.getNrTasks() > 0) { - size_t startRow(0); - std::vector<Task *> tasks; - // write scheduled tasks to table - tasks = data.getScheduledTasksVector(); - writeTasksToTable(tasks,0); - startRow += tasks.size(); - // write the unscheduled tasks to the table - tasks = data.getUnScheduledTasksVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // write the reservations to the table - tasks = data.getReservationsVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // maintenance - tasks = data.getMaintenanceVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // write the inactive tasks to the table - tasks = data.getInactiveTaskVector(); - writeTasksToTable(tasks, startRow); - startRow += tasks.size(); - // write pipeline tasks to table - tasks = data.getPipelinesVector(); - writeTasksToTable(tasks,startRow); - - itsTableView->sortByColumn(itsSortColumn, itsSortOrder); - // writeTasksToTable(data.getUnScheduledTasksSortFirstDate(),data.getNrScheduled()); - itsTableView->resizeRowsToContents(); - setDefaultColumnWidths(); - setErrorCells(data.getErrorTasks()); - itsTableView->repaint(); - } -} - -void SchedulerGUI::updateTableTasksScheduleTimes(const std::vector<const Task *> &tasks) { - int row; - for (std::vector<const Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - row = itsModel->findTaskRow((*it)->getID()); - if (row != -1) { - itsModel->setData(itsModel->index(row, PLANNED_START), (*it)->getScheduledStart().toQDateTime().toString("yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PLANNED_START), (*it)->getScheduledStart().toQDateTime(), Qt::UserRole); // used for sorting - itsModel->setData(itsModel->index(row, PLANNED_END), (*it)->getScheduledEnd().toQDateTime().toString("yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PLANNED_END), (*it)->getScheduledEnd().toQDateTime(), Qt::UserRole); // used for sorting - } - } - itsTableView->repaint(); -} - -void SchedulerGUI::updateTableTaskScheduleTimes(const Task &task) { - int row(itsModel->findTaskRow(task.getID())); - if (row != -1) { - itsModel->setData(itsModel->index(row, PLANNED_START), task.getScheduledStart().toQDateTime().toString("yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PLANNED_START), task.getScheduledStart().toQDateTime(), Qt::UserRole); // used for sorting - itsModel->setData(itsModel->index(row, PLANNED_END), task.getScheduledEnd().toQDateTime().toString("yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PLANNED_END), task.getScheduledEnd().toQDateTime(), Qt::UserRole); // used for sorting - itsTableView->repaint(); - } -} - -void SchedulerGUI::updateTask(const Task *pTask) { - updateTableTask(pTask); - if (pTask->isStationTask()) { - itsGraphicResourceScene->updateTask(pTask); - } -} - -std::vector<unsigned> SchedulerGUI::getSelectedRowsTaskIDs(void) const { - std::vector<unsigned> taskIDs; - QList<int> list(itsTableView->selectedRows().toList()); - qSort(list); - - for (QList<int>::const_iterator rit = list.begin(); rit != list.end(); ++rit) { - taskIDs.push_back(itsModel->data(itsModel->index(*rit, (int)TASK_ID)).toUInt()); - } - return taskIDs; -} - -std::vector<unsigned> SchedulerGUI::getShownTaskIDs(void) const { - std::vector<unsigned> taskIDs; - - for (int row = 0; row < itsModel->rowCount(); ++row) { - taskIDs.push_back(itsModel->data(itsModel->index(row, (int)TASK_ID)).toUInt()); - } - return taskIDs; -} - -int SchedulerGUI::findTableTaskByID(unsigned ID, id_type IDtype) const { - int nrRows = itsModel->rowCount(); - int col; - if (IDtype == ID_SCHEDULER) col = TASK_ID; - else if (IDtype == ID_SAS) col = SAS_ID; - else col = MOM_ID; - - for (int row = 0; row <= nrRows; ++row) { - if (itsModel->data(itsModel->index(row, col), Qt::UserRole).toUInt() == ID) return row; // if this is the row with the right task ID - } - return -1; -} - -void SchedulerGUI::updateTableTask(const Task *pTask, int row) { - if (pTask) { - if (row == -1) { - row = findTableTaskByID(pTask->getID(), ID_SCHEDULER); - if (row == -1) { // task not found in table, add it - unsigned rows = itsModel->rowCount() + 1; - itsModel->setRowCount(rows); - row = rows-1; - } - } - // store the task type (int) at index (row,0) to be used to determine if a row needs to be treated specially - // i.e. some cells need to be read only for task type RESERVATION and MAINTENANCE - itsModel->setData(itsModel->index(row, TASK_TYPE), QVariant(static_cast<int>(pTask->getType())), USERDATA_ROLE); - // store task status also as userdata - itsModel->setData(itsModel->index(row, TASK_STATUS), QVariant(static_cast<int>(pTask->getStatus())), USERDATA_ROLE); - - QModelIndex idx(itsModel->index(row, TASK_ID)); - itsModel->setData(idx, pTask->getID()); - itsModel->setData(idx, pTask->getID(), Qt::UserRole); - idx = itsModel->index(row, SAS_ID); - itsModel->setData(idx, pTask->getSASTreeID()); - itsModel->setData(idx, pTask->getSASTreeID(), Qt::UserRole); - idx = itsModel->index(row, MOM_ID); - itsModel->setData(idx, pTask->getMomID()); - itsModel->setData(idx, pTask->getMomID(), Qt::UserRole); - itsModel->setData(itsModel->index(row, GROUP_ID), pTask->getGroupID()); - itsModel->setData(itsModel->index(row, GROUP_ID), pTask->getGroupID(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, PROJECT_ID), pTask->getProjectID()); - itsModel->setData(itsModel->index(row, PROJECT_ID), pTask->getProjectID(), Qt::UserRole); // for sorting - itsActiveProjects.insert(pTask->getProjectID()); - itsModel->setData(itsModel->index(row, TASK_NAME), pTask->getTaskName()); - itsModel->setData(itsModel->index(row, TASK_NAME), pTask->getTaskName(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, TASK_DESCRIPTION), pTask->SASTree().description().c_str()); - itsModel->setData(itsModel->index(row, TASK_DESCRIPTION), pTask->SASTree().description().c_str(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, CONTACT_NAME), pTask->getContactName()); - itsModel->setData(itsModel->index(row, CONTACT_NAME), pTask->getContactName(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, CONTACT_PHONE), pTask->getContactPhone()); - itsModel->setData(itsModel->index(row, CONTACT_PHONE), pTask->getContactPhone(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, CONTACT_EMAIL), pTask->getContactEmail()); - itsModel->setData(itsModel->index(row, CONTACT_EMAIL), pTask->getContactEmail(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, TASK_TYPE), pTask->getTypeStr()); - itsModel->setData(itsModel->index(row, TASK_TYPE), pTask->getTypeStr(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, CLUSTER_NAME), pTask->getOutputDataproductCluster()); - itsModel->setData(itsModel->index(row, CLUSTER_NAME), pTask->getOutputDataproductCluster(), Qt::UserRole); // for sorting - - const StationTask *pStationTask = dynamic_cast<const StationTask *>(pTask); - if (pStationTask) { // is this a stationTask? - // stations - QStringList stationList; - std::map<std::string, unsigned int> const &stations = pStationTask->getStations(); - for (std::map<std::string, unsigned int>::const_iterator stit = stations.begin(); stit != stations.end(); ++stit) { - stationList.append(QString(stit->first.c_str())); - } - itsModel->setData(itsModel->index(row, STATION_ID), stationList); - itsModel->setData(itsModel->index(row, STATION_ID), stationList, Qt::UserRole); - // mode - itsModel->setData(itsModel->index(row, ANTENNA_MODE), pStationTask->getAntennaModeStr()); - itsModel->setData(itsModel->index(row, ANTENNA_MODE), pStationTask->getAntennaModeStr(), Qt::UserRole); - // filter type - itsModel->setData(itsModel->index(row, FILTER_TYPE), pStationTask->getFilterTypeStr()); - itsModel->setData(itsModel->index(row, FILTER_TYPE), pStationTask->getFilterTypeStr(), Qt::UserRole); - // clock frequency - itsModel->setData(itsModel->index(row, CLOCK_FREQUENCY), pStationTask->getStationClockStr()); - itsModel->setData(itsModel->index(row, CLOCK_FREQUENCY), pStationTask->getStationClockStr(), Qt::UserRole); - - const Observation *pObs = dynamic_cast<const Observation *>(pTask); - if (pObs) { // is this an observation? - itsModel->setData(itsModel->index(row, RESERVATION_NAME), itsController->getReservationName(pObs->getReservation())); - itsModel->setData(itsModel->index(row, RESERVATION_NAME), itsController->getReservationName(pObs->getReservation()), Qt::UserRole); // for sorting - // Nr of subbands - itsModel->setData(itsModel->index(row, NR_OF_SUBBANDS), pObs->getNrOfSubbands()); - itsModel->setData(itsModel->index(row, NR_OF_SUBBANDS), pObs->getNrOfSubbands(), Qt::UserRole); // for sorting - // Night time weight - itsModel->setData(itsModel->index(row, NIGHT_TIME_WEIGHT_FACTOR), pObs->getNightTimeWeightFactor()); - itsModel->setData(itsModel->index(row, NIGHT_TIME_WEIGHT_FACTOR), pObs->getNightTimeWeightFactor(), Qt::UserRole); // for sorting - // for observations show real end time which could differ from scheduled end time - const AstroDateTime &realEnd(pTask->getRealEnd()); - Task::task_status state(pTask->getStatus()); - if (state >= Task::FINISHED && realEnd.isSet()) { - if (realEnd <= pTask->getScheduledEnd().subtractMinutes(1)) { - string afs = state == Task::ABORTED ? "Aborted early at:" : "Finished early at:"; - afs += realEnd.toString(); - itsModel->setData(itsModel->index(row, PLANNED_END), afs.c_str(), Qt::ToolTipRole); - itsModel->setData(itsModel->index(row, PLANNED_END), (int)Qt::darkGreen, Qt::UserRole+1); - } - else if (realEnd >= pTask->getScheduledEnd().addMinutes(50)) { - string afs = state == Task::ABORTED ? "Aborted late at:" : "Finish late at:"; - afs += realEnd.toString() + "\nCheck for missing MetaData!"; - itsModel->setData(itsModel->index(row, PLANNED_END), afs.c_str(), Qt::ToolTipRole); - itsModel->setData(itsModel->index(row, PLANNED_END), (int)Qt::red, Qt::UserRole+1); - } - } - - } - - // check if observations are currently hidden in the table - if (!itsTableObsEnabled->isChecked()) { - itsTableView->hideRow(row); - } - } - else if (pTask->isPipeline() && !itsTablePipesEnabled->isChecked()) { // check if pipelines are currently hidden in the table - itsTableView->hideRow(row); - } - - if (itsTableProjectFilter->currentIndex() != 0) { // project Filter enabled? - if (pTask->getProjectID() != itsTableProjectFilter->currentText()) { - itsTableView->hideRow(row); - } - } - - if (pTask->hasPredecessors()) { - // predecessor min and max time difference - itsModel->setData(itsModel->index(row, PREDECESSORS), pTask->getPredecessorsString()); - itsModel->setData(itsModel->index(row, PREDECESSORS), pTask->getPredecessorsString(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, PRED_MIN_TIME_DIF), QDateTime::fromString(QString(pTask->getPredecessorMinTimeDif().toString().c_str()),"yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PRED_MIN_TIME_DIF), pTask->getPredecessorMinTimeDif().toQTime(), Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, PRED_MAX_TIME_DIF), QDateTime::fromString(QString(pTask->getPredecessorMaxTimeDif().toString().c_str()),"yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PRED_MAX_TIME_DIF), pTask->getPredecessorMaxTimeDif().toQTime(), Qt::UserRole); // for sorting - } - - // priority - itsModel->setData(itsModel->index(row, PRIORITY), pTask->getPriority()); - itsModel->setData(itsModel->index(row, PRIORITY), pTask->getPriority(), Qt::UserRole); - // duration - itsModel->setData(itsModel->index(row, TASK_DURATION), pTask->getDuration().toString().c_str()); - itsModel->setData(itsModel->index(row, TASK_DURATION), pTask->getDuration().totalSeconds(), Qt::UserRole); - // planned start - itsModel->setData(itsModel->index(row, PLANNED_START), QDateTime::fromString(QString(pTask->getScheduledStart().toString().c_str()),"yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PLANNED_START), pTask->getScheduledStart().toQDateTime(), Qt::UserRole); - // planned end - itsModel->setData(itsModel->index(row, PLANNED_END), QDateTime::fromString(QString(pTask->getScheduledEnd().toString().c_str()),"yyyy-MM-dd hh:mm:ss")); - itsModel->setData(itsModel->index(row, PLANNED_END), pTask->getScheduledEnd().toQDateTime(), Qt::UserRole); - // fixed day - itsModel->setData(itsModel->index(row, FIXED_DAY), static_cast<unsigned short>(pTask->getFixedDay())); - itsModel->setData(itsModel->index(row, FIXED_DAY), static_cast<unsigned short>(pTask->getFixedDay()), Qt::UserRole); // for sorting - // fixed time - itsModel->setData(itsModel->index(row, FIXED_TIME), static_cast<unsigned short>(pTask->getFixedTime())); - itsModel->setData(itsModel->index(row, FIXED_TIME), static_cast<unsigned short>(pTask->getFixedTime()), Qt::UserRole); // for sorting - // task status - itsModel->setData(itsModel->index(row, TASK_STATUS), pTask->getStatusStr()); - itsModel->setData(itsModel->index(row, TASK_STATUS), pTask->getStatusStr(), Qt::UserRole); // for sorting - // Reason if unscheduled - QString reason(pTask->getReason().c_str()); - reason = reason.replace('$','\n'); - itsModel->setData(itsModel->index(row, UNSCHEDULED_REASON), reason); - itsModel->setData(itsModel->index(row, UNSCHEDULED_REASON), reason, Qt::UserRole); // for sorting - itsModel->setData(itsModel->index(row, UNSCHEDULED_REASON), reason, Qt::ToolTipRole); - - const TaskStorage *task_storage(pTask->storage()); - if (task_storage) { - itsModel->setData(itsModel->index(row, STORAGE_SIZE), humanReadableUnits((long double)task_storage->getTotalStoragekBytes(), SIZE_UNITS).c_str()); - itsModel->setData(itsModel->index(row, STORAGE_SIZE), task_storage->getTotalStoragekBytes(), Qt::UserRole); // for sorting - } - } -} - -void SchedulerGUI::writeTasksToTable(const std::vector<Task *> &tasks, unsigned int startRow) { - for (std::vector<Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - updateTableTask(*it, startRow++); - } -} - - -void SchedulerGUI::showSearchBar() { - itsSearchBar->show(); - itsSearchLineEdit->selectAll(); - itsSearchLineEdit->setFocus(); -} - -void SchedulerGUI::cleanup(void) { - updateStatusBar(0,0,0,0,0,0,0); - columnSearched = 0; - itsSortColumn = PLANNED_START; - itsSortOrder = Qt::DescendingOrder; - clearSearch(); - delete itsModel; - itsModel = 0; - ui.action_Undo->setEnabled(false); - ui.action_Redo->setEnabled(false); -} - -void SchedulerGUI::clearTasks(void) { - itsGraphicResourceScene->clearTasks(); -} - -void SchedulerGUI::connectInternalSignals(void) -{ - connect(ui.action_About, SIGNAL(triggered()), this, SLOT(about())); - connect(ui.action_Find, SIGNAL(triggered()), this, SLOT(showSearchBar())); - connect(closeSearchBarAct, SIGNAL(triggered()), this, SLOT(closeSearchBar())); - connect(itsSearchLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(doSearch(const QString&)) ); - connect(itsSearchNextButton, SIGNAL(clicked()), this, SLOT(searchNext())); - connect(itsSearchPreviousButton, SIGNAL(clicked()), this, SLOT(searchPrevious())); - connect(itsSearchColumnOnlyCheckBox, SIGNAL(clicked()), this, SLOT(searchAgain())); - connect(itsSearchLineEdit, SIGNAL(returnPressed()), this, SLOT(searchNext())); - connect(itsTableView->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(toggleTableSort(int))); - - connect(ui.action_Move_task, SIGNAL(triggered()), this, SLOT(openMoveTasksDialog())); - - connect(ui.actionHorizontal_view, SIGNAL(triggered()), this, SLOT(horizontalView())); - connect(ui.actionVertical_view, SIGNAL(triggered()), this, SLOT(verticalView())); - connect(ui.actionGraphicalViewShow, SIGNAL(toggled(bool)), this, SLOT(graphicalViewEnable(bool))); - connect(ui.actionTableViewShow, SIGNAL(toggled(bool)), this, SLOT(tableViewEnable(bool))); - connect(ui.actionSelect_colums_to_view, SIGNAL(triggered()), this, SLOT(viewColumns())); - connect(ui.actionConnect_to_Data_monitor, SIGNAL(triggered()), this, SLOT(connectToDataMonitor())); - - // Graphic scene signals - connect(itsController, SIGNAL(schedulerSettingsChanged()), this, SLOT(applyGraphicSceneChanges())); - connect(itsZoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn())); - connect(itsZoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut())); - connect(itsTaskTypeColorModeAction, SIGNAL(triggered()), this, SLOT(toggleTaskColorMode())); - connect(itsCenterOnNow, SIGNAL(triggered()), this, SLOT(scrollToNow())); - connect(itsGraphicResourceScene, SIGNAL(setEnableZoomIn(bool)), this, SLOT(setZoomInEnable(bool))); - connect(itsGraphicResourceScene, SIGNAL(setEnableZoomOut(bool)), this, SLOT(setZoomOutEnable(bool))); - connect(itsGraphicResourceScene, SIGNAL(clickedGraphicTask(unsigned)), this, SLOT(handleGraphicViewClick(unsigned))); - connect(itsGraphicResourceScene, SIGNAL(showTaskDialog(const Task *)), this, SLOT(showTaskDialog(const Task *))); - connect(itsTableView, SIGNAL(mouseClick(const QModelIndex &, QMouseEvent *)), this, SLOT(handleTableClick(const QModelIndex &, QMouseEvent *))); - connect(itsTableView, SIGNAL(tableContextMenuRequest(const QModelIndex &, QContextMenuEvent *)), this, SLOT(showTableContextMenu(const QModelIndex &, QContextMenuEvent *))); - connect(itsTableView->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(handleTableHorHeaderClick(int))); - connect(itsTableObsEnabled, SIGNAL(stateChanged(int)), this, SLOT(filterTable(void))); - connect(itsTablePipesEnabled, SIGNAL(stateChanged(int)), this, SLOT(filterTable(void))); - connect(itsTableProjectFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(filterTable(void))); - - connect(ui.actionPublish_schedule, SIGNAL(triggered()), this, SLOT(openPublishDialog())); - connect(&itsPublishDialog, SIGNAL(goPublish(const scheduleWeekVector &)), this, SLOT(doPublish(const scheduleWeekVector &))); - connect(&itsViewColumnsDialog, SIGNAL(viewColumns(const std::vector<unsigned int> &)), this, SLOT(setViewColumns(const std::vector<unsigned int> &))); - connect(itsGraphicView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateTimeLinePosAfterScroll(void))); // signal to repaint time line at the top of the view - connect(itsGraphicView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateStationTimeLinesAfterScroll(void))); // signal to keep station names visible -} - -void SchedulerGUI::connectToDataMonitor(void) { - if (itsController->isDataMonitorConnected()) { - itsController->disconnectDataMonitor(); - } - else { - if (!itsController->connectToDataMonitor()) { // Controller will update the connection icon - QMessageBox::critical(0, tr("No connection to Data Monitor"), - tr("Could not connect to the Data Monitor.\n Please check Data Monitor connection settings.")); - } - } -} - -void SchedulerGUI::openMoveTasksDialog(void) { - ShiftTasksDialog shiftDlg(this, itsController); -} - -void SchedulerGUI::viewColumns(void) { - itsViewColumnsDialog.show(); -} - -void SchedulerGUI::setViewColumns(const std::vector<unsigned int> &columns) { - for (int i = 0; i < itsModel->columnCount(); ++i) { - itsTableView->hideColumn(i); - } - for (std::vector<unsigned int>::const_iterator it = columns.begin(); it != columns.end(); ++it) { - itsTableView->showColumn(*it); - } - itsTableView->resizeColumnsToContents(); -// setDefaultColumnWidths(); -} - -void SchedulerGUI::zoomIn(void) const { - itsGraphicResourceScene->zoomIn(); -} - -void SchedulerGUI::zoomOut(void) const { - itsGraphicResourceScene->zoomOut(); -} - -void SchedulerGUI::setTaskColorMode(Task::task_color_mode color_mode) const { - itsGraphicResourceScene->setTaskColorMode(color_mode); -} - -void SchedulerGUI::toggleTaskColorMode(void) const { - if (itsGraphicResourceScene->getTaskColorMode() == Task::TASK_STATUS_COLOR_MODE) { - itsGraphicResourceScene->setTaskColorMode(Task::TASK_TYPE_COLOR_MODE); - itsTaskTypeColorModeAction->setIconText("Type color mode"); - - } - else { - itsGraphicResourceScene->setTaskColorMode(Task::TASK_STATUS_COLOR_MODE); - itsTaskTypeColorModeAction->setIconText("Status color mode"); - } - -} - -void SchedulerGUI::scrollToNow(void) const { - itsGraphicResourceScene->scrollToNow(); -} - -void SchedulerGUI::setEnableScheduleMenuItems(bool enabled) { - //ui.action_Save_schedule->setEnabled(enabled); - ui.action_Save_schedule_as->setEnabled(enabled); - ui.action_Save_task_list->setEnabled(enabled); - ui.action_Close_schedule->setEnabled(enabled); - ui.action_Optimize_schedule->setEnabled(enabled); - ui.action_Create_initial_schedule->setEnabled(enabled); - ui.action_Balance_schedule->setEnabled(enabled); - ui.action_Add_task->setEnabled(enabled); - ui.action_Delete_task->setEnabled(enabled); - ui.actionPublish_schedule->setEnabled(itsEnablePublish); -} - -void SchedulerGUI::setEnableTaskListMenuItems(bool enabled) { - ui.action_Close_schedule->setEnabled(enabled); - ui.action_Save_task_list->setEnabled(enabled); - ui.action_Optimize_schedule->setEnabled(enabled); - ui.action_Create_initial_schedule->setEnabled(enabled); - ui.action_Balance_schedule->setEnabled(enabled); - ui.action_Find->setEnabled(enabled); -} - -// focusOnTaskInTable is called when user clicks on a task in the graphic view -void SchedulerGUI::handleGraphicViewClick(unsigned taskID) { - QList<QStandardItem *> items = itsModel->findItems(QString::number(taskID), Qt::MatchExactly, TASK_ID); - if (!items.empty()) { - QModelIndex idx = itsModel->indexFromItem(items.first()); - int h = itsTableView->horizontalScrollBar()->value(); - itsTableView->scrollTo(idx); - itsTableView->horizontalScrollBar()->setValue(h); - itsTableView->selectRow(idx.row()); - } -} - -// focusOnTaskInGraphicView is called when user clicks on a task in the table -void SchedulerGUI::handleTableClick(const QModelIndex &index, QMouseEvent *event) { // const Qt::KeyboardModifiers &modifier_keys - this->blockSignals(true); - itsTableView->blockSignals(true); - if (event->button() == Qt::LeftButton) { - Qt::KeyboardModifiers modifier_keys = event->modifiers(); - QSet<int> selectedRows(itsTableView->selectedRows()); - - // reset search if user selected different column and checkbox this column only is checked - if (itsSearchColumnOnlyCheckBox->isChecked() && (columnSearched != itsTableView->currentIndex().column())) { - searchResult.clear(); - } - - if ((modifier_keys == Qt::ControlModifier) || (modifier_keys == Qt::ShiftModifier)) { - itsTableView->setSelectionMode(QAbstractItemView::MultiSelection); - itsSelectedTableTasks.clear(); - int row; - foreach (row, selectedRows) { - itsSelectedTableTasks.push_back(itsModel->index(row, TASK_ID).data().toUInt()); - } - itsController->setSelectedTasks(itsSelectedTableTasks); - - itsGraphicResourceScene->deselectAllGraphicTasks(); - - for (std::vector<unsigned>::const_iterator it = itsSelectedTableTasks.begin(); it != itsSelectedTableTasks.end(); ++it) { - itsGraphicResourceScene->selectGraphicTask(*it); - } - } - else { // single selection - itsTableView->setSelectionMode(QAbstractItemView::SingleSelection); - itsSelectedTaskID = itsModel->index(index.row(), TASK_ID).data().toUInt(); - itsGraphicResourceScene->deselectAllGraphicTasks(); - itsGraphicResourceScene->selectGraphicTask(itsSelectedTaskID); - itsController->setSelectedTask(itsSelectedTaskID); -// itsController->selectTask(itsSelectedTaskID, true, false); - } - - itsGraphicResourceScene->ensureTaskIsVisible(itsModel->data(itsModel->index(index.row(), 0), TASK_ID).toUInt()); - } - else if (event->button() == Qt::RightButton) { - itsSelectedTaskID = itsModel->index(index.row(), TASK_ID).data().toUInt(); - if (!itsController->isSelected(itsSelectedTaskID)) { - itsSelectedTaskID = itsModel->index(index.row(), TASK_ID).data().toUInt(); - itsGraphicResourceScene->deselectAllGraphicTasks(); - itsGraphicResourceScene->selectGraphicTask(itsSelectedTaskID); - itsController->setSelectedTask(itsSelectedTaskID); - itsTableView->setSelectionMode(QAbstractItemView::SingleSelection); - } - } - itsTableView->blockSignals(false); - this->blockSignals(false); -} - -void SchedulerGUI::showTableContextMenu(const QModelIndex &index, QContextMenuEvent *event) { - itsSelectedTaskID = itsModel->data(itsModel->index(index.row(), TASK_ID)).toUInt(); - if (itsController->multipleSelected()) { - QMenu menu,submenu("Select tasks within these groups"); - QAction *action = menu.addAction("Unschedule multiple tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(unscheduleSelectedTasks(void))); - action = menu.addAction("set PRESCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(preScheduleSelectedTasks())); - action = menu.addAction("set SCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(scheduleSelectedTasks())); - action = menu.addAction("Put on hold now!"); - connect(action, SIGNAL(triggered()), this, SLOT(setSelectedTasksOnHold(void))); - action = menu.addAction("Move/Redistribute tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(moveSelectedTasks(void))); - submenu.setTitle("Select tasks within these groups"); - menu.addMenu(&submenu); - action = submenu.addAction("All tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsAll(void))); - action = submenu.addAction("Observations"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsObservation(void))); - action = submenu.addAction("Calibration Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsCalibrator(void))); - action = submenu.addAction("Target Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsTarget(void))); - action = submenu.addAction("Pre-processing Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsPreProcessing(void))); - action = submenu.addAction("Long-Baseline Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsLongBaseline(void))); - action = submenu.addAction("Imaging Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsImaging(void))); - action = submenu.addAction("Pulsar Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsPulsar(void))); - action = menu.addAction("Copy tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(copySelectedTasks(void))); - action = menu.addAction("Delete tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(deleteSelectedTasks(void))); - action = menu.addAction("multi-edit"); - connect(action, SIGNAL(triggered()), this, SLOT(showSelectedTasksProperties(void))); - menu.exec(event->globalPos()); - } - else { - const Task *pTask(itsController->getTask(itsSelectedTaskID)); - - if (pTask) { - Task::task_status status = pTask->getStatus(); - QMenu menu, submenu; - QAction *action(0); - if ((status == Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - action = menu.addAction("Unschedule task"); - connect(action, SIGNAL(triggered()), this, SLOT(unscheduleTask(void))); - } - if ((status < Task::PRESCHEDULED) || (status == Task::SCHEDULED)) { - action = menu.addAction("set PRESCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(preScheduleTask())); - } - if (status == Task::PRESCHEDULED) { - action = menu.addAction("set SCHEDULED"); - connect(action, SIGNAL(triggered()), this, SLOT(scheduleTask())); - } - if (status <= Task::SCHEDULED) { - if (status != Task::ON_HOLD) { - action = menu.addAction("Put on hold now!"); - connect(action, SIGNAL(triggered()), this, SLOT(setTaskOnHold(void))); - } - action = menu.addAction("Move task"); - connect(action, SIGNAL(triggered()), this, SLOT(moveSelectedTasks(void))); - } - if (pTask->getGroupID() != 0) { - submenu.setTitle("Select tasks within this group"); - menu.addMenu(&submenu); - action = submenu.addAction("All tasks"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsAll(void))); - action = submenu.addAction("Observations"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsObservation(void))); - action = submenu.addAction("Calibration Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsCalibrator(void))); - action = submenu.addAction("Target Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsTarget(void))); - action = submenu.addAction("Pre-processing Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsPreProcessing(void))); - action = submenu.addAction("Long-Baseline Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsLongBaseline(void))); - action = submenu.addAction("Imaging Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsImaging(void))); - action = submenu.addAction("Pulsar Pipelines"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCurrentTaskGroupsPulsar(void))); - } - - action = menu.addAction("Copy task"); - connect(action, SIGNAL(triggered()), this, SLOT(copySelectedTask(void))); - if (status == Task::ABORTED) { - action = menu.addAction("Reschedule aborted task"); - connect(action, SIGNAL(triggered()), this, SLOT(rescheduleAbortedTask(void))); - } - action = menu.addAction("Delete task"); - connect(action, SIGNAL(triggered()), this, SLOT(deleteSelectedTasks(void))); - - action = menu.addAction("Properties"); - connect(action, SIGNAL(triggered()), this, SLOT(showTaskProperties(void))); - - action = menu.addAction("SAS state history"); - connect(action, SIGNAL(triggered()), this, SLOT(showStateHistory(void))); - - int sasTreeID(pTask->getSASTreeID()); - if (sasTreeID) { - action = menu.addAction("SAS tree viewer"); - connect(action, SIGNAL(triggered()), this, SLOT(openSASTreeViewer(void))); - action = menu.addAction("View meta-data"); - connect(action, SIGNAL(triggered()), this, SLOT(openMetaDataViewer(void))); - } - - menu.exec(event->globalPos()); - } - } -} - -void SchedulerGUI::filterTable(void) { - int nrRows(itsModel->rowCount()); - bool obsEnabled(itsTableObsEnabled->isChecked()); - bool pipesEnabled(itsTablePipesEnabled->isChecked()); - bool projectFilterEnabled(itsTableProjectFilter->currentIndex() != 0); - for (int row = 0; row < nrRows; ++row) { - if (obsEnabled && pipesEnabled) { - if (projectFilterEnabled) { - if (itsTableProjectFilter->currentText() == itsModel->data(itsModel->index(row, PROJECT_ID)).toString()) { - itsTableView->showRow(row); - } - else itsTableView->hideRow(row); - } - else itsTableView->showRow(row); - } - else { - Task::task_type type = static_cast<Task::task_type>(itsModel->data(itsModel->index(row, TASK_TYPE), USERDATA_ROLE).toInt()); - if (type == Task::OBSERVATION || type == Task::RESERVATION || type == Task::MAINTENANCE) { - if (obsEnabled) { - if (projectFilterEnabled) { - if (itsTableProjectFilter->currentText() == itsModel->data(itsModel->index(row, PROJECT_ID)).toString()) { - itsTableView->showRow(row); - } - else itsTableView->hideRow(row); - } - else itsTableView->showRow(row); - } - else itsTableView->hideRow(row); - } - else if (type == Task::PIPELINE) { - if (pipesEnabled) { - if (projectFilterEnabled) { - if (itsTableProjectFilter->currentText() == itsModel->data(itsModel->index(row, PROJECT_ID)).toString()) { - itsTableView->showRow(row); - } - else itsTableView->hideRow(row); - } - else itsTableView->showRow(row); - } - else itsTableView->hideRow(row); - } - } - } -} - -void SchedulerGUI::unscheduleTask(void) { - itsController->unscheduleTask(itsSelectedTaskID); -} - -void SchedulerGUI::unscheduleSelectedTasks(void) { - itsController->unscheduleSelectedTasks(); -} - -void SchedulerGUI::preScheduleTask(void) { - itsController->scheduleTask(itsSelectedTaskID, Task::PRESCHEDULED); -} - -void SchedulerGUI::scheduleTask(void) { - itsController->scheduleTask(itsSelectedTaskID, Task::SCHEDULED); -} - -void SchedulerGUI::preScheduleSelectedTasks(void) { - itsController->scheduleSelectedTasks(Task::PRESCHEDULED); -} - -void SchedulerGUI::scheduleSelectedTasks(void) { - itsController->scheduleSelectedTasks(Task::SCHEDULED); -} - -void SchedulerGUI::setTaskOnHold(void) { - itsController->setTaskOnHold(itsSelectedTaskID); -} - -void SchedulerGUI::selectCurrentTaskGroupsAll(void) { - itsController->selectCurrentTaskGroups(); -} - -void SchedulerGUI::selectCurrentTaskGroupsObservation(void) { - itsController->selectCurrentTaskGroups(SEL_OBSERVATIONS); -} - -void SchedulerGUI::selectCurrentTaskGroupsCalibrator(void) { - itsController->selectCurrentTaskGroups(SEL_CALIBRATOR_PIPELINES); -} - -void SchedulerGUI::selectCurrentTaskGroupsTarget(void) { - itsController->selectCurrentTaskGroups(SEL_TARGET_PIPELINES); -} - -void SchedulerGUI::selectCurrentTaskGroupsImaging(void) { - itsController->selectCurrentTaskGroups(SEL_IMAGING_PIPELINES); -} - -void SchedulerGUI::selectCurrentTaskGroupsPreProcessing(void) { - itsController->selectCurrentTaskGroups(SEL_PREPROCESSING_PIPELINES); -} - -void SchedulerGUI::selectCurrentTaskGroupsLongBaseline(void) { - itsController->selectCurrentTaskGroups(SEL_LONGBASELINE_PIPELINES); -} - -void SchedulerGUI::selectCurrentTaskGroupsPulsar(void) { - itsController->selectCurrentTaskGroups(SEL_PULSAR_PIPELINES); -} - -void SchedulerGUI::copySelectedTask(void) { - itsController->copyTask(itsSelectedTaskID); -} - -void SchedulerGUI::setSelectedTasksOnHold(void) { - itsController->setSelectedTasksOnHold(); -} - -void SchedulerGUI::rescheduleAbortedTask(void) { - itsController->rescheduleAbortedTask(itsSelectedTaskID); -} - -void SchedulerGUI::deleteSelectedTasks(void) { - itsController->deleteSelectedTasks(); -} - -void SchedulerGUI::moveSelectedTasks(void) { - itsController->openMoveTasksDialog(); -} - -void SchedulerGUI::copySelectedTasks(void) { - itsController->copySelectedTasks(); -} - -void SchedulerGUI::showTaskProperties(void) { - const Task *pTask = itsController->getTask(itsSelectedTaskID); - if (pTask) { - showTaskDialog(pTask); - } -} - -void SchedulerGUI::showSelectedTasksProperties(void) { - itsController->multiEditSelectedTasks(); -} - -void SchedulerGUI::showStateHistory(void) { - itsController->showTaskStateHistory(itsSelectedTaskID); -} - -void SchedulerGUI::openSASTreeViewer(void) const { - const Task *pTask(itsController->getTask(itsSelectedTaskID)); - if (pTask) { - itsController->openSASTreeViewer(pTask->getSASTreeID()); - } -} - -void SchedulerGUI::openMetaDataViewer(void) const { - const Task *pTask(itsController->getTask(itsSelectedTaskID)); - if (pTask) { - itsController->openMetaDataViewer(pTask->getSASTreeID()); - } -} - -void SchedulerGUI::handleTableHorHeaderClick(int row) { -// itsTableView->setSelectionMode(QAbstractItemView::SelectRows); - QModelIndex idx = itsModel->index(row, TASK_ID); - unsigned int taskID = itsModel->data(idx).toUInt(); - if (itsController->isSelected(taskID)) { // task is currently selected - itsController->deselectTask(taskID, false, true); - } - else { // task is not currently selected - itsController->selectTask(taskID, false, true); - } -} - -void SchedulerGUI::selectRows(const std::vector<unsigned> &selectedTasks) { - itsTableView->clearSelection(); - for (std::vector<unsigned>::const_iterator it = selectedTasks.begin(); it != selectedTasks.end(); ++it) { - QList<QStandardItem *> items = itsModel->findItems(QString::number(*it), Qt::MatchExactly, TASK_ID); - if (!items.isEmpty()) { - itsTableView->selectRow(itsModel->indexFromItem(items.first()).row()); - } - } -} - -void SchedulerGUI::clearSelection(void) { - itsSelectedTableTasks.clear(); - itsTableView->clearSelection(); - itsGraphicResourceScene->deselectAllGraphicTasks(); -} - -void SchedulerGUI::selectTableTask(unsigned taskID, bool tableclicked) { - std::vector<unsigned>::const_iterator it = std::find(itsSelectedTableTasks.begin(), itsSelectedTableTasks.end(), taskID); - if (it == itsSelectedTableTasks.end()) { // if not yet selected - itsSelectedTableTasks.push_back(taskID); - itsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); - if (tableclicked) { // when table was clicked we have to re-select all selected rows otherwise the clicked row will not be selected - itsTableView->clearSelection(); - for (int row = 0; row < itsModel->rowCount(); ++row) { - if (std::find(itsSelectedTableTasks.begin(), itsSelectedTableTasks.end(), itsModel->data(itsModel->index(row, TASK_ID)).toUInt()) != itsSelectedTableTasks.end()) { - itsTableView->selectRow(row); - } - } - } - else { // this function call was not caused by a table click, in this case we only have to select the row of the newly selected task without having to re-select all other selected tasks - for (int row = 0; row < itsModel->rowCount(); ++row) { - if (itsModel->data(itsModel->index(row, TASK_ID)).toUInt() == taskID) { - itsTableView->selectRow(row); - break; - } - } - } - itsTableView->setSelectionBehavior(QAbstractItemView::SelectItems); - } -} - - -void SchedulerGUI::deselectTableTask(unsigned taskID) { - std::vector<unsigned>::iterator it = std::find(itsSelectedTableTasks.begin(), itsSelectedTableTasks.end(), taskID); - if (it != itsSelectedTableTasks.end()) { - itsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); - itsSelectedTableTasks.erase(it); - itsTableView->clearSelection(); - for (std::vector<unsigned>::const_iterator it = itsSelectedTableTasks.begin(); it != itsSelectedTableTasks.end(); ++it) { - QList<QStandardItem *> items = itsModel->findItems(QString::number(*it), Qt::MatchExactly, TASK_ID); - if (!items.isEmpty()) { - itsTableView->selectRow(items.first()->row()); // select/deselect the row depending on its current selection state - } - } - itsTableView->setSelectionBehavior(QAbstractItemView::SelectItems); - } -} - - -void SchedulerGUI::selectTasks(const std::vector<unsigned> &tasks) { - this->blockSignals(true); - QAbstractItemView::SelectionBehavior prevBehaviour(itsTableView->selectionBehavior()); - itsGraphicResourceScene->deselectAllGraphicTasks(); - itsTableView->clearSelection(); - itsSelectedTableTasks.clear(); - if (tasks.size() > 1) { - itsTableView->setSelectionMode(QAbstractItemView::MultiSelection); - } - else { - itsTableView->setSelectionMode(QAbstractItemView::SingleSelection); - } - itsTableView->setSelectionBehavior(QAbstractItemView::SelectRows); - for (std::vector<unsigned>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - itsGraphicResourceScene->selectGraphicTask(*it); - itsSelectedTableTasks.push_back(*it); - QList<QStandardItem *> items = itsModel->findItems(QString::number(*it), Qt::MatchExactly, TASK_ID); - if (!items.isEmpty()) { - itsTableView->selectRow(itsModel->indexFromItem(items.first()).row()); - } - } - itsTableView->setSelectionBehavior(prevBehaviour); - this->blockSignals(false); -} - -void SchedulerGUI::selectTask(unsigned taskID, bool singleSelection, bool selectRows, bool tableClick) { // should be used by the controller only - if (singleSelection) { - itsTableView->setSelectionMode(QAbstractItemView::SingleSelection); - itsGraphicResourceScene->deselectAllGraphicTasks(); - itsSelectedTableTasks.clear(); - } - else { - itsTableView->setSelectionMode(QAbstractItemView::MultiSelection); - } - itsGraphicResourceScene->selectGraphicTask(taskID); - if (selectRows) { - selectTableTask(taskID, tableClick); - } - else { - std::vector<unsigned>::iterator it = std::find(itsSelectedTableTasks.begin(), itsSelectedTableTasks.end(), taskID); - if (it == itsSelectedTableTasks.end()) { - itsSelectedTableTasks.push_back(taskID); - } - } -} - -void SchedulerGUI::deselectTask(unsigned taskID, bool singleSelection, bool selectRows) { // should be used by the controller only - if (singleSelection) { - itsTableView->setSelectionMode(QAbstractItemView::SingleSelection); - } - else { - itsTableView->setSelectionMode(QAbstractItemView::MultiSelection); - } - itsGraphicResourceScene->deselectGraphicTask(taskID); - if (selectRows) { - deselectTableTask(taskID); - } - else { - std::vector<unsigned>::iterator it = std::find(itsSelectedTableTasks.begin(), itsSelectedTableTasks.end(), taskID); - if (it == itsSelectedTableTasks.end()) { - itsSelectedTableTasks.erase(it); - } - } -} - -bool SchedulerGUI::checkPublishSettings(void) { - QString path; - if (Controller::theSchedulerSettings.publishLocal()) { - path = Controller::theSchedulerSettings.getLocalPublishPath(); - if (path.isEmpty()) { - // publish path not set - QMessageBox::warning(this, tr("Local publish path not set"), - tr("The local publish path is not defined. Please set the path.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } -#ifdef Q_OS_UNIX - if (path.right(1).compare("/") != 0) { - path += '/'; - Controller::theSchedulerSettings.setLocalPublishPath(path); - } -#elif defined(Q_OS_WIN) - if (path.right(1).compare("\\") != 0) { - path += "\\"; - Controller::theSchedulerSettings.setLocalPublishPath(path); - } -#endif - QFileInfo publishPath(path); - if (!publishPath.isDir()) { - itsPublishDialog.hide(); - QMessageBox::warning(this, tr("Publish path not valid"), - tr("The Publish path does not point to an existing directory.\nPlease enter a correct directory path.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } - } - else { // REMOTE PUBLISHING - if (Controller::theSchedulerSettings.getSchedulerAccountName().isEmpty()) { - QMessageBox::warning(this, tr("Scheduler account name not set"), - tr("The scheduler account name is not set.\n Please specify the account used for uploading the schedule to the web server.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } -#ifdef Q_OS_WIN - if (Controller::theSchedulerSettings.getPrivateKeyFile().isEmpty()) { - QMessageBox::warning(this, tr("Private key filename not specified"), - tr("The private key filename is not set.\n Please specify the private key file for automated logon to the web server.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } - else if (!QFileInfo(Controller::theSchedulerSettings.getPrivateKeyFile()).exists()) { - QMessageBox::warning(this, tr("Private key file not found"), - tr("The specified private key file could not be found.\n Please specify the private key file for automated logon to the web server.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } -#endif - if (Controller::theSchedulerSettings.getWebServerName().isEmpty()) { - QMessageBox::warning(this, tr("Web server name not set"), - tr("The web server name is not set.\n Please specify the name of the web server.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } - path = Controller::theSchedulerSettings.getWebServerPublishPath(); - if (path.isEmpty()) { // publish path not set - QMessageBox::warning(this, tr("Web server publish path not set"), - tr("The web server publish path is not defined. Please set the path.\n" - "menu Settings -> Schedule settings -> Publishing"), - QMessageBox::Ok, QMessageBox::Ok); - setStatusText("Publishing aborted"); - return false; - } - } - return true; -} - - - -void SchedulerGUI::openPublishDialog(void) { -// bool publish_local = Controller::theSchedulerSettings.getLocalPublishPath(); - if (checkPublishSettings()) { - itsPublishDialog.show(); - } -} - -void SchedulerGUI::doPublish(const scheduleWeekVector &publish_weeks) { - if (publish(publish_weeks)) { - QStringList wkl; - for (scheduleWeekVector::const_iterator it = publish_weeks.begin(); it != publish_weeks.end(); ++it) { - wkl.append(QString::number(it->first)); - } - QMessageBox::information(this, tr("Publishing successful"), - tr("Publishing finished successfully.\nThe following week numbers have been uploaded to the web-schedule:\n") + - wkl.join(QChar(','))); - } - else { - QMessageBox::critical(this, tr("Publishing finished with errors"), - tr("Publishing finished with errors.\nThe schedule could not correctly be uploaded to the webserver \n")); - } -} - -bool SchedulerGUI::publish(const scheduleWeekVector &publish_weeks) { - setStatusText("Publishing in progress..."); - bool publish_local = Controller::theSchedulerSettings.publishLocal(); - QString local_path, web_server_name, account_name, server_path, privateKeyFileName, working_dir, systemCmd; - QDir localPublishDir; - working_dir = QDir::toNativeSeparators(QDir::currentPath()); - local_path = QDir::toNativeSeparators(Controller::theSchedulerSettings.getLocalPublishPath()); - localPublishDir.setPath(local_path); - - if (!publish_local) { - // delete tmp directory if it exists already - if (localPublishDir.exists("publish_tmp")) { - FileUtils filemanip; - localPublishDir.cd("publish_tmp"); - filemanip.removeDir(localPublishDir.canonicalPath()); - localPublishDir.cdUp(); - } - // recreate the tmp dir in local publish directory, because we are going to delete this local directory structure after upload to web server - localPublishDir.mkdir("publish_tmp"); - localPublishDir.cd("publish_tmp"); -// local_path = QDir::toNativeSeparators(localPublishDir.absolutePath()); - account_name = Controller::theSchedulerSettings.getSchedulerAccountName(); - web_server_name = Controller::theSchedulerSettings.getWebServerName(); - server_path = Controller::theSchedulerSettings.getWebServerPublishPath(); - privateKeyFileName = Controller::theSchedulerSettings.getPrivateKeyFile(); - } - - // remember current graphic view zoom factor and position - zoom_level prevZoom = itsGraphicResourceScene->getZoomLevel(); - int xPrevScrollPos = itsGraphicView->horizontalScrollBar()->value(); - int yPrevScrollPos = itsGraphicView->verticalScrollBar()->value(); - - setProgressBarMaximum(publish_weeks.size()); - itsGraphicResourceScene->setZoomLevel(ZM_DAY); - Task::task_color_mode prevColorMode = itsGraphicResourceScene->getTaskColorMode(); - itsGraphicResourceScene->setTaskColorMode(Task::TASK_TYPE_COLOR_MODE); - itsGraphicResourceScene->hideCurrentTimeLine(); - itsController->deselectAllTasks(); - itsGraphicView->repaint(); - - int startPos, endPos; - int height = static_cast<int>(itsGraphicResourceScene->sceneRect().height()); - std::string stations; - int progress(0), imgWidth; - QString weekName, weekNrStr, prevWeek, nextWeek, htmlFileName; // stationsPicStr - QDateTime date = QDateTime::currentDateTime().toUTC(); - QLocale lc(QLocale::English, QLocale::UnitedStates); - string dateStr = lc.toString(date,"dddd dd MMM yyyy hh:mm").toStdString(); - - AstroDate startDate, endDate, nextWeekMonday; - - QString fullPath, yearStr, stationImgPath, stationsPicStr, weekImg; - std::vector<QString> yearDirsToPublish; - - // generate the station picture - stationImgPath = localPublishDir.canonicalPath() + QDir::toNativeSeparators("/stations.png"); - - itsGraphicView->horizontalScrollBar()->setValue(0); - itsGraphicView->verticalScrollBar()->setValue(0); - - QImage *img = new QImage(QSize(70, height), QImage::Format_ARGB32_Premultiplied); - img->fill(0); - QPainter *paint = new QPainter(img); - itsGraphicResourceScene->render(paint, QRectF(), QRectF(0, 0, 70, height)); - paint->end(); - img->save(stationImgPath, "png"); // "/2009/stations_week_52.png" - delete paint; - delete img; - - QFile stationImgFile(stationImgPath); // necessary later on - - const campaignMap &projects(itsController->getCampaignList()); - campaignMap::const_iterator plocit; - - // *** loop through the published weeks and upload the weeks - for (scheduleWeekVector::const_iterator it = publish_weeks.begin(); it != publish_weeks.end(); ++it) { - // step 1 generate the week schedule pictures - startDate = it->second; - endDate = it->second.addDays(6); - nextWeekMonday = it->second.addDays(7); - yearStr = QString::number(startDate.addDays(3).getYear()); - if (!localPublishDir.exists(yearStr)) { // create the year directory for the current week if it doesn't exist yet - localPublishDir.mkdir(yearStr); - // create remote directory even if it already exists - // we have to do this with separate script because if the remote directory already exists then this script will return with error - // and thus abort the uploading of the actual publish files -#if defined(Q_OS_WIN) - QFile scriptFile("create_dir.txt"); - scriptFile.remove(); - if (!scriptFile.open(QIODevice::ReadWrite | QIODevice::Text)) { - setStatusText("Publishing failed"); - disableProgressBar(); - return false; - } - QString scriptText = "option batch abort\noption confirm off\nopen " + account_name + "@" + web_server_name + "\n"; - scriptText += "mkdir " + server_path + "/" + yearStr + "\n"; - scriptText += "exit\n"; - scriptFile.write(scriptText.toStdString().c_str()); - scriptFile.close(); - systemCmd = working_dir + "\\WinSCP\\WinSCP.com /privatekey=\"" + privateKeyFileName + "\" /script=" + working_dir + "\\create_dir.txt"; - std::system(systemCmd.toStdString().c_str()); // creates the remote 'year' directory - yearDirsToPublish.push_back(yearStr); -#endif -#ifdef Q_OS_UNIX - systemCmd = "ssh " + account_name + "@" + web_server_name + " mkdir " + server_path + "/" + yearStr; - std::system(systemCmd.toStdString().c_str()); // creates the remote 'year' directory - yearDirsToPublish.push_back(yearStr); -#endif - } - - fullPath = localPublishDir.absolutePath() + QDir::toNativeSeparators("/" + yearStr + "/"); - - weekNrStr = QString::number(it->first); - weekName = "week_" + weekNrStr; // "week_52" - stationsPicStr = "stations_" + weekName + ".png"; - weekImg = fullPath + weekName + ".png"; - - // copy the station picture to the year directory with a week specific name (to prevent overwriting other weeks on the webserver) - stationImgFile.copy(fullPath + stationsPicStr); - - // generate the week picture - startPos = itsGraphicResourceScene->time2xPos(startDate); - endPos = itsGraphicResourceScene->time2xPos(nextWeekMonday) + 1; - imgWidth = endPos - startPos; - img = new QImage(QSize(imgWidth, height), QImage::Format_ARGB32_Premultiplied); - img->fill(0); - paint = new QPainter(img); - itsGraphicResourceScene->render(paint, QRectF(), QRectF(startPos, 0, imgWidth, height)); - paint->end(); - img->save(weekImg, "png"); - delete paint; - delete img; - - prevWeek = QString("week_") + QString::number(startDate.subtractDays(7).getWeek()) + ".html"; - nextWeek = QString("week_") + QString::number(nextWeekMonday.getWeek()) + ".html"; - - // step 2 generate the HTML pages - const std::map<std::string, std::vector<Task *> > tasks = itsController->getPublishTasks(startDate, nextWeekMonday); - ofstream file; - htmlFileName = fullPath + weekName + ".html"; // "/2009/week_52.html" - file.open(htmlFileName.toStdString().c_str(), std::ios::out); - if (file.is_open()) { - file << " <!-- " << endl << "created by the LOFAR Scheduler" << endl - << "created on: " << dateStr << "<BR>" << endl << endl - << "LOFAR Scheduler version: " << SCHEDULER_VERSION << endl << "-->" << endl << endl - << "<SUB>Change date (UTC): " << dateStr << "</SUB><BR>" << endl - << "<TABLE BORDER='0' WIDTH=1100><TR><TD>" << endl - << "<IMG SRC='" << yearStr.toStdString() << "/" << stationsPicStr.toStdString() << "' WIDTH=70 HEIGHT=" << int2String(height) - << " STYLE='float: left; padding-right: 0px; border-style: none;' BORDER='0' ALT='LOFAR Schedule of week " << weekNrStr.toStdString() << "' TITLE='LOFAR Schedule of week " << weekNrStr.toStdString() << "'>" << endl - << "<IMG SRC='" << yearStr.toStdString() << "/" << weekName.toStdString() << ".png' WIDTH=" << imgWidth << " HEIGHT=" << int2String(height) - << " STYLE='border-style: none;' ALT='LOFAR Schedule of week " << weekNrStr.toStdString() << "' BORDER='0'"; - if (!tasks.empty()) { - file << " USEMAP='#tasks'" << endl; - } - file << "></TD></TR></TABLE><BR>" << endl - << "<TABLE id='report'><TR class='fixed'><TD colspan='10'>LOFAR schedule tasks for week " << weekNrStr.toStdString() << ", " << yearStr.toStdString() << " (click on a project to see its tasks)</TD></TR>\n" - << "<TR class='fixed'><TD WIDTH='50px'>ID</TD><TD WIDTH='200px'>Task</TD><TD WIDTH='100px'>Type</TD><TD WIDTH='100px'>Mode</TD><TD WIDTH='100px'>Stations</TD><TD WIDTH='150px'>Start (UTC)</TD><TD WIDTH='150px'>Stop (UTC)</TD><TD WIDTH='50px'>Duration</TD><TD WIDTH='200px'>Description</TD><td width='16px'></TR>" << endl; - - // insert task properties into project table - //const std::vector<Task *> tasks = itsController->getScheduledTasksWithinPeriod(startDate, nextWeekMonday); - - for (std::map<std::string, std::vector<Task *> >::const_iterator pit = tasks.begin(); pit != tasks.end(); ++pit) { - plocit = projects.find(pit->first); - file << "<TR class='project'><TD colspan='9'><strong>" << pit->first; - if (plocit != projects.end()) { - file << " - " << plocit->second.title; - } - file << "</strong></TD><td><div class='arrow'></div></TR>" << endl; - for (std::vector<Task *>::const_iterator tit = pit->second.begin(); tit != pit->second.end(); ++tit) { - if ((*tit)->isStationTask()) { - stations = static_cast<StationTask *>(*tit)->getStationNamesStr(',', 5, "<br>"); // <br> ipv \n werkt ook met ddrivetip - } - file << "<TR><TD>" << (*tit)->getSASTreeID() - << "</TD><TD>" << (*tit)->getTaskName() - << "</TD><TD>" << (*tit)->getTypeStr() - << "</TD><TD>" << (*tit)->getProcessSubtypeStr() - << "</TD><TD onmouseover=\"ddrivetip('" << stations << "', 'yellow', 260)\" onmouseout=\"hideddrivetip()\">" << stations.substr(0,17); - if (stations.length() > 17) { - file << "..."; - } - file << "</TD><TD>" - << (*tit)->getScheduledStart().toString() << "</TD><TD>" - << (*tit)->getScheduledEnd().toString() << "</TD><TD>" - << (*tit)->getDuration().toString(3) << "</TD><TD colspan='2'>" - << (*tit)->SASTree().description() << "</TD></TR>" << endl; - } - } - - file << "</TABLE>" << endl; - - // create the image maps - if (!tasks.empty()) { - file << "<MAP NAME='tasks'>\n"; - const tasksMap &graphicTasks = itsGraphicResourceScene->getGraphicTasks(); - unsigned int taskID; - tasksMap::const_iterator gtit; - for (std::map<std::string, std::vector<Task *> >::const_iterator pit = tasks.begin(); pit != tasks.end(); ++pit) { - for (std::vector<Task *>::const_iterator tit = pit->second.begin(); tit != pit->second.end(); ++tit) { - taskID = (*tit)->getID(); - gtit = graphicTasks.find(taskID); - if (gtit != graphicTasks.end()) { - for (std::vector<GraphicTask *>::const_iterator git = gtit->second.begin(); git != gtit->second.end(); ++git) { - // COORDS are left, top, right, bottom - file << "<AREA SHAPE='rect' COORDS='" << (*git)->left() - startPos << "," << (*git)->top() << "," - << (*git)->right() - startPos << "," << (*git)->bottom() - << "' NOHREF onMouseOver=\"ddrivetip('" << (*git)->toolTipHTML() << "', 'yellow', 250)\"; onMouseout=\"hideddrivetip()\">\n"; - } - } - } - } - file << "</MAP>\n"; - } - - file.close(); - } - - // update the progress bar after each created week - updateProgressBar(progress++); - } - - // we're done rendering now restore previous view settings - itsGraphicResourceScene->setZoomLevel(prevZoom); - itsGraphicResourceScene->setTaskColorMode(prevColorMode); - itsGraphicResourceScene->showCurrentTimeLine(); - itsGraphicView->horizontalScrollBar()->setValue(xPrevScrollPos); - itsGraphicView->verticalScrollBar()->setValue(yPrevScrollPos); - itsGraphicView->repaint(); - - // delete original station picture that is in the root publish directory - QFile::remove(stationImgPath); - - // step 3 (optional publish to web) transfer files to web server and delete local copy - if (!publish_local) { - - setStatusText((std::string("Uploading files to web server ") + web_server_name.toStdString()).c_str()); - // scp YYYY lofarsched@dop40:/www/astron.nl/lofar-schedule/ (where YYYY is the four digit year number) -#ifdef Q_OS_UNIX - systemCmd = "cd " + localPublishDir.canonicalPath() + "; scp -r " + yearStr + " " + account_name + "@" + web_server_name + ":" + server_path; -#endif - - if (std::system(systemCmd.toStdString().c_str()) != 0) { - disableProgressBar(); - setStatusText("Publishing failed"); - return false; - } - } - - setStatusText("Publishing successfull"); - disableProgressBar(); - return true; -} - -void SchedulerGUI::tableViewEnable(bool checked) { - if (checked) { - itsTableView->show(); - itsTableDock->show(); - } - else { - itsTableView->hide(); - itsTableDock->hide(); - } -} - -void SchedulerGUI::graphicalViewEnable(bool checked) { - if (checked) { - itsGraphicView->show(); - itsGraphicDock->show(); - } - else { - itsGraphicView->hide(); - itsGraphicDock->hide(); - } -} - -void SchedulerGUI::applyGraphicSceneChanges(void) { - itsGraphicResourceScene->applyNewScheduleTimeSpan(); -// itsGraphicView->repaint(); -} - -void SchedulerGUI::toggleTableSort(int column) { - itsSortColumn = static_cast<data_headers>(column); - if (itsSortOrder == Qt::AscendingOrder) - itsSortOrder = Qt::DescendingOrder; - else - itsSortOrder = Qt::AscendingOrder; - itsTableView->sortByColumn(itsSortColumn, itsSortOrder); - emit tableSortChanged(); -} - -void SchedulerGUI::closeEvent(QCloseEvent *event) -{ - event->ignore(); - emit quitApp(); -} - -QString SchedulerGUI::openTaskFileDialog() -{ - return fileDialog(tr("Open Task list file"), "csv", tr("Task list files (*.csv)")); -} - -QString SchedulerGUI::saveTaskFileDialog() -{ - return fileDialog(tr("Save Task list file"), "csv", tr("Task list files (*.csv)"), 1); -} - -QString SchedulerGUI::openProjectDialog() -{ - return fileDialog(tr("Open Schedule project file"), "pro", tr("Scheduling project files (*.pro)")); -} - -QString SchedulerGUI::saveProjectDialog() -{ - return fileDialog(tr("Save Schedule project file"), "pro", tr("Scheduling project files (*.pro)"), 1); -} - -QString SchedulerGUI::fileDialog(const QString &title, const QString &def_suffix, const QString &filter, int save_load) { - QFileDialog dialog; - QFileInfo fi; - QString path=""; - dialog.setNameFilters(filter.split('\n')); - dialog.setWindowTitle(title); - - - if (lastPath == "") { - char *home = getenv("HOME"); - if (home) lastPath = home; - else lastPath = "."; - } else if (QFileInfo(lastPath).isDir()) { - lastPath = QFileInfo(lastPath).canonicalPath(); - } else { - lastPath = QFileInfo(lastPath).absoluteDir().canonicalPath(); - } - - dialog.setDirectory(lastPath); - - if (save_load == 0) - dialog.setAcceptMode(QFileDialog::AcceptOpen); - else - dialog.setAcceptMode(QFileDialog::AcceptSave); - - dialog.setFileMode(QFileDialog::AnyFile); - dialog.setConfirmOverwrite(false); // we'll do that - - dialog.setDefaultSuffix(def_suffix); - - bool good = false; - - while (!good) { - - path = ""; - - if (!dialog.exec()) break; - - QStringList files = dialog.selectedFiles(); - if (files.empty()) break; - path = *files.begin(); -// std::cout << "path:" << path.toStdString() << std::endl; - - fi = path; - - if (fi.isDir()) { - QMessageBox::critical(0, tr("Directory selected"), - tr("File \"%1\" is a directory").arg(path)); - continue; - } - if (save_load == 1) { - if (fi.exists()) { - if (QMessageBox::question(0, tr("File exists"), - tr("The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path), - QMessageBox::Ok, - QMessageBox::Cancel) != QMessageBox::Ok) { - continue; - } - } - } - good = true; - } - lastPath = path; - return path; -} - - -void SchedulerGUI::addUndo(const QString &undo_action) { - itsUndoList.append(undo_action); - setUndoText(QString("Undo ") + undo_action); - ui.action_Undo->setEnabled(true); -} - -void SchedulerGUI::removeUndo(const QString &undo_info) { - for (QStringList::iterator it = itsUndoList.begin(); it != itsUndoList.end(); ++it) { - if (undo_info.compare(*it) == 0) { - itsUndoList.erase(it); - if (!itsUndoList.isEmpty()) { - setUndoText(QString("Undo ") + itsUndoList.back()); - } - else { - ui.action_Undo->setEnabled(false); - setUndoText("Undo"); - } - return; - } - } -} - -void SchedulerGUI::undo(bool store_redo) { - if (!itsUndoList.isEmpty()) { - if (store_redo) { - itsRedoList.append(itsUndoList.back()); - ui.action_Redo->setEnabled(true); - setRedoText(QString("Redo ") + itsRedoList.back()); - } - itsUndoList.pop_back(); - if (!itsUndoList.isEmpty()) { // still undo's left ? - setUndoText(QString("Undo ") + itsUndoList.back()); - } - else { - setUndoText("Undo"); - ui.action_Undo->setEnabled(false); - } - } -} - -void SchedulerGUI::redo(void) { - if (!itsRedoList.isEmpty()) { - itsUndoList.append(itsRedoList.back()); - ui.action_Undo->setEnabled(true); - setUndoText(QString("Undo ") + itsUndoList.back()); - itsRedoList.pop_back(); - if (!itsRedoList.isEmpty()) { // still redo's left ? - setRedoText(QString("Redo ") + itsRedoList.back()); - } - else { - setRedoText("Redo"); - ui.action_Redo->setEnabled(false); - } - } -} - - -void SchedulerGUI::removeLastUndo(void) { - if (!itsUndoList.isEmpty()) { - itsUndoList.pop_back(); - if (!itsUndoList.isEmpty()) { // still undo's left ? - setUndoText(QString("Undo ") + itsUndoList.back()); - } - else { - setUndoText("Undo"); - ui.action_Undo->setEnabled(false); - } - } -} - - -void SchedulerGUI::removeTaskFromScene(unsigned taskID) { - itsGraphicResourceScene->removeTaskFromScene(taskID); -} - - -void SchedulerGUI::parsetTreeView(const QString &parset, const OTDBtree &otdb_tree) { - itsTreeViewer->view(parset, otdb_tree); -} - -void SchedulerGUI::about() -{ - QString msg = "<b>LOFAR Scheduler</b><br>Version:"; - msg += SCHEDULER_VERSION; - msg += "<br>Copyright: ASTRON 2009"; - - QMessageBox::about(this, "About LOFAR Scheduler", msg); -} diff --git a/SAS/Scheduler/src/schedulergui.h b/SAS/Scheduler/src/schedulergui.h deleted file mode 100644 index ead8a6eb64c5f047e349ef65c4b7a05ec127c374..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulergui.h +++ /dev/null @@ -1,357 +0,0 @@ -/* - * schedulergui.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Feb 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulergui.h $ - * - */ - -#ifndef SCHEDULERGUI_H -#define SCHEDULERGUI_H - -#include <string> -#include <vector> -#include <map> -#include <QMainWindow> -#include <QFileInfo> -#include <QToolBar> -#include <QGraphicsView> -#include <QScrollBar> -#include "lofar_scheduler.h" -#include "ui_schedulergui.h" -#include "taskdialog.h" -#include "publishdialog.h" -#include "tablecolumnselectdialog.h" -#include "tableview.h" -#include "scheduletabledelegate.h" -#include "schedulerdatablock.h" -#include "qlofardatamodel.h" - -class GraphicResourceScene; -class GraphicStorageScene; -class QBoxLayout; -class SchedulerData; -class QPushButton; -class QCheckBox; -class QTableWidgetItem; -//class QGraphicsView; -class QWidget; -class QDockWidget; -class QStatusBar; -class QProgressBar; -class QLabel; -class QVBoxLayout; -class QHBoxLayout; -class QSpacerItem; -class QAction; -class Task; -class Controller; -class ParsetTreeViewer; -class QLCDNumber; - -class SchedulerGUI : public QMainWindow -{ - Q_OBJECT - -public: - SchedulerGUI(Controller *controller); - ~SchedulerGUI(); - - void connectInternalSignals(void); // for handling of internal signals - const Ui::SchedulerGUIClass &getSchedulerGUIClass(void) const {return ui;} - - QString openTaskFileDialog(); // opens a file open dialog to select a task file to open - QString saveTaskFileDialog(); // opens a save file dialog to save the task file - QString openProjectDialog(); - QString saveProjectDialog(); - - // handle to the scene for the controller to be able to connect signals - GraphicResourceScene * scene(void) const {return itsGraphicResourceScene;} - - // Scheduler table methods - void newTable(SchedulerData const & data); -// void loadNewTable(SchedulerData const &data); - void writeTableData(SchedulerData const &data); // updates the table data (to be used after the data has been changed) - void updateTableTaskScheduleTimes(const Task &task); - void updateTableTasksScheduleTimes(const std::vector<const Task *> &tasks); - void updateGraphicTask(unsigned task_id); - void updateTableTask(const Task *, int row=-1); - void updateTask(const Task *); // updates a task in the GUI -// void addRow(); -// void deleteRow(); - const ScheduleTableDelegate *getTableDelegate(void) const {return &itsDelegate;} - void setErrorCells(const errorTasksMap & errorTasks) {itsModel->setErrorCells(errorTasks); } - void repaintTable(void) {itsTableView->repaint();} - bool isErrorIndex(const QModelIndex &index) const {return itsModel->isErrorIndex(index);} - void clearErrorIndex(const QModelIndex &index) {itsModel->clearErrorIndex(index);} - void addErrorIndex(const QModelIndex &index) {itsModel->addErrorIndex(index);} - void clearErrorCell(unsigned int taskID, data_headers column) {itsModel->clearErrorCell(taskID, column);} - void cleanup(void); // clean up gui and its data to initial settings - void setSortCol(data_headers sortCol) {itsSortColumn = sortCol;} - data_headers sortCol(void) const {return itsSortColumn;} - void setSortOrd(Qt::SortOrder sort_order) {itsSortOrder = sort_order;} - Qt::SortOrder sortOrd(void) const {return itsSortOrder;} - QString fileDialog (const QString &title, const QString &def_suffix, const QString &filter, int save_load = 0); - std::vector<unsigned> getSelectedRowsTaskIDs(void) const; - std::vector<unsigned> getShownTaskIDs(void) const; - - void updateGraphicStations(); // updates all stations in the graphical view - void updateGraphicTasks(const scheduledTasksMap &scheduledTasks, const reservationsMap &reservations, const inActiveTasksMap & inactiveTasks); - void updateSceneTimeSpan(void); - void clearTasks(void); - void setProgressBarMaximum(int maxValue); - void setStatusText(const char *status) {itsStatusBarStatusText->setText(status);} - void clearStatusText(void) {itsStatusBarStatusText->clear();} - void setStatusText(const QString &status) {setStatusText(status.toStdString().c_str());} - void updateStatusBar(unsigned nr_scheduled, unsigned nr_unscheduled, unsigned nr_inactive, unsigned nr_reservations, unsigned nr_errortasks, unsigned nr_pipelines, int progress = 0); - void updateProgressBar(int progress);// {itsStatusBarProgress->setValue(progress);} - - void disableProgressBar(void); - - //enable/disable menu items -// void setSaveTaskListEnable(bool); - void setDataMonitorConnectionButton(bool enable) {ui.actionConnect_to_Data_monitor->setChecked(enable);} - void setEnableTaskListMenuItems(bool); // call after task list was loaded - void setEnableScheduleMenuItems(bool); // call after a schedule was created - void addUndo(const QString &undo_action); - void removeUndo(const QString &undo_info); - void removeLastUndo(void); - void undo(bool store_redo = true); - void redo(void); - void clearUndo(void) { itsUndoList.clear(); ui.action_Undo->setText("Undo"); ui.action_Undo->setEnabled(false); } - void clearRedo(void) { itsRedoList.clear(); ui.action_Redo->setText("Redo"); ui.action_Redo->setEnabled(false); } - void clearUndoRedo(void) { clearUndo(); clearRedo();} - void setUndoMenuItemEnabled(bool enabled) {ui.action_Undo->setEnabled(enabled);} - void setRedoMenuItemEnabled(bool enabled) {ui.action_Redo->setEnabled(enabled);} - TaskDialog *taskDialog(void) const {return itsTaskDialog;} - void updateTaskDialogStations(void); - void updateTaskDialog(const Task *task=0) {itsTaskDialog->update(task);} - void addTaskDialog(unsigned int taskID) {itsTaskDialog->addTask(taskID);} -// void addReservationDialog(unsigned int taskID) {itsTaskDialog->addReservation(taskID);} - void addTask(const Task *pTask); - void deleteTaskFromGUI(unsigned taskID, Task::task_type type = Task::OBSERVATION); - - void selectRows(const std::vector<unsigned> &selectedTasks); - void selectTask(unsigned taskID, bool singleSelection, bool selectRows = true, bool tableClick = false); // should be used by the controller only - void selectTasks(const std::vector<unsigned> &tasks); // clears current selection and selects the supplied tasks - void deselectTask(unsigned taskID, bool singleSelection, bool selectRows = true); // should be used by the controller only -// void selectRow(int row); -// void deselectRow(int row); - void clearSelection(void); - void multiEditTasks(std::vector<Task *> &tasks); - // put the correct week numbers and dates in the publish week selection dialog - void initPublishDialog(void) {itsPublishDialog.initPublishDialog();} - void setSaveRequired(bool save_required); - void setTestMode(bool enable_test_mode) {itsIsTestMode = enable_test_mode; updateWindowTitle(); } - void setApplicationName(const QString &title) {itsWindowTitle = title; updateWindowTitle(); } - void setCurrentFileName(const QString &fileName) {itsCurrentFileName = fileName; updateWindowTitle();} - void clearCurrentFileName(void) {itsCurrentFileName = "no name"; updateWindowTitle();} - void updateWindowTitle(void); - void setTaskColorMode(Task::task_color_mode color_mode) const; -// Task::task_color_mode getTaskColorMode(void) const {return itsGraphicResourceScene->getTaskColorMode();} - void setEmptyThrashIcon(void) {ui.action_Thrashcan->setIcon(QIcon(tr(":/icons/empty_trash.png")));} - void setFullThrashIcon(void) {ui.action_Thrashcan->setIcon(QIcon(tr(":/icons/full_trash.png")));} - void updateDataMonitorConnectionStatus(void); // updates the data monitor connection icon according to current connection status - void setExistingProjects(const campaignMap &projects); - void removeTaskFromScene(unsigned taskID); - void parsetTreeView(const QString &parset, const OTDBtree &otdb_tree = OTDBtree()); - void sortTable(void) {itsTableView->sortByColumn(itsSortColumn, itsSortOrder);} - void loadProcessTypes(void) {itsTaskDialog->loadProcessTypes();} - void updateSasDatabaseName(void); - bool publish(const scheduleWeekVector &); - void updateProjectsFilter(const campaignMap &); - -private: - void writeTasksToTable(const std::vector<Task *> &tasks, unsigned int startRow); - inline void setUndoText(const QString &txt) {ui.action_Undo->setText(txt); ui.action_Undo->setToolTip(txt);} - inline void setRedoText(const QString &txt) {ui.action_Redo->setText(txt); ui.action_Redo->setToolTip(txt);} - -signals: - void quitApp(void) const; - void tableSortChanged(void) const; - -private: - int findTableTaskByID(unsigned ID, id_type IDtype) const; - void closeEvent(QCloseEvent *event); // when user closes the main window - void setShortcutKeys(void); - void createSearchBar(void); - void createStatusBar(void); - void createTableDock(void); - void createGraphicDock(void); - void search(const QString& term); - void clearSearch(void) {searchResult.clear(); search_iterator = 0;} - void setDefaultColumnWidths(void); - bool checkPublishSettings(void); - void createMainToolbar(void); - void selectTableTask(unsigned taskID, bool tableclicked = false); - void deselectTableTask(unsigned taskID); - -public slots: - void doPublish(const scheduleWeekVector &); - -private slots: - void applyGraphicSceneChanges(void); - void about(void); // shows about dialog - void closeSearchBar(void) {itsSearchBar->hide();} // closes the search bar - void showSearchBar(void); // shows the search bar - void doSearch(const QString& term); // do a search on term - void searchNext(void); - void searchPrevious(void); - void searchAgain(void); - void toggleTableSort(int column); - void horizontalView(void); - void verticalView(void); - void zoomIn(void) const; - void zoomOut(void) const; - void setZoomInEnable(bool enable) {itsZoomInAction->setEnabled(enable);} - void setZoomOutEnable(bool enable) {itsZoomOutAction->setEnabled(enable);} - void toggleTaskColorMode(void) const; - void scrollToNow(void) const; - - void handleGraphicViewClick(unsigned taskID); - void handleTableHorHeaderClick(int); - void handleTableClick(const QModelIndex &index, QMouseEvent *event); - void showTableContextMenu(const QModelIndex &index, QContextMenuEvent *event); - void tableViewEnable(bool); - void graphicalViewEnable(bool); - void openPublishDialog(void); - void viewColumns(void); - void setViewColumns(const std::vector<unsigned int> &columns); - void filterTable(void); - void connectToDataMonitor(void); - - void updateTimeLinePosAfterScroll(void); - void updateStationTimeLinesAfterScroll(void); - - void unscheduleTask(void); - void unscheduleSelectedTasks(void); - void preScheduleTask(void); - void scheduleTask(void); - void preScheduleSelectedTasks(void); - void scheduleSelectedTasks(void); - void setTaskOnHold(void); - void copySelectedTask(void); - void selectCurrentTaskGroupsAll(void); - void selectCurrentTaskGroupsObservation(void); - void selectCurrentTaskGroupsCalibrator(void); - void selectCurrentTaskGroupsTarget(void); - void selectCurrentTaskGroupsPulsar(void); - void selectCurrentTaskGroupsPreProcessing(void); - void selectCurrentTaskGroupsLongBaseline(void); - void selectCurrentTaskGroupsImaging(void); - void setSelectedTasksOnHold(void); - void rescheduleAbortedTask(void); - void deleteSelectedTasks(void); - void moveSelectedTasks(void); - void copySelectedTasks(void); - void showTaskProperties(void); - void showSelectedTasksProperties(void); - void showStateHistory(void); - void openSASTreeViewer(void) const; - void openMetaDataViewer(void) const; - -public slots: - void openMoveTasksDialog(void); - void showTaskDialog(const Task *task, tabIndex tab = TAB_SCHEDULE); - -private slots: - void updateCurrentTime(void); - -private: - data_headers itsSortColumn; - Qt::SortOrder itsSortOrder; - QLofarDataModel * itsModel; - ScheduleTableDelegate itsDelegate; - QToolBar * itsMainToolBar; - QLCDNumber *itsLCDtimer; - QToolBar * itsSearchBar; - QLineEdit * itsSearchLineEdit; - QPushButton * itsSearchNextButton; - QPushButton * itsSearchPreviousButton; - QCheckBox * itsSearchColumnOnlyCheckBox; - // timer for displaying current UTC - QTimer *itsTimer; - // search result - QList<QStandardItem *>::const_iterator search_iterator; - QList<QStandardItem *> searchResult; - int columnSearched; - bool itsIsTestMode, itsIsSaveRequired, itsEnablePublish; - QSet<QString> itsActiveProjects; - - // the GUI - Ui::SchedulerGUIClass ui; - - QStringList itsUndoList, itsRedoList; - QString itsWindowTitle, itsCurrentFileName; - - // graphic schedule view dock - QDockWidget *itsGraphicDock; - QWidget *itsGraphicDockWidgetContents; - QToolBar *itsGraphicViewToolbar; - QAction *itsZoomInAction; - QAction *itsZoomOutAction; - QAction *itsTaskTypeColorModeAction; - QAction *itsCenterOnNow; - QGraphicsView *itsGraphicView; - GraphicResourceScene *itsGraphicResourceScene; - QVBoxLayout *itsGraphicDockMainLayout; - - // graphic storage resource use view dock - QDockWidget *itsGraphicStorageDock; - QWidget *itsStorageDockWidgetContents; - QVBoxLayout *itsStorageDockLayout; - GraphicStorageScene *itsGraphicStorageScene; - - // table view dock - QDockWidget *itsTableDock; - QWidget *itsTableDockWidgetContents; - QGridLayout *itsTableDockMainLayout; - QSpacerItem *itsTableSpacerItem; - TableView *itsTableView; - QCheckBox *itsTableObsEnabled, *itsTablePipesEnabled; - QComboBox *itsTableProjectFilter; - QPushButton *pb_Cancel, *pb_Apply; - std::vector<unsigned> itsSelectedTableTasks; - unsigned int itsSelectedTaskID; - - //status bar - QStatusBar *itsStatusBar; - QLabel *itsStatusBarStatusText; - QLabel *itsStatusBarTaskStatus; - QLabel *itsStatusBarUsedDatabase; - QProgressBar *itsStatusBarProgress; - - // controller - Controller *itsController; - - // task dialog - TaskDialog *itsTaskDialog; - - // Parset Tree View Dialog; - ParsetTreeViewer *itsTreeViewer; - - // publish dialog - PublishDialog itsPublishDialog; - - //column view dialog - tableColumnSelectDialog itsViewColumnsDialog; - -// Actions - QAction *showSearchBarAct; - QAction *closeSearchBarAct; - QAction *itsSearchPreviousAct; - QAction *itsSearchNextAct; - QAction *itsSearchColumnOnlyCheckBoxAct; - - QString lastPath; - -// Icons - QIcon *closeIcon; -}; - -#endif // SCHEDULERGUI_H diff --git a/SAS/Scheduler/src/schedulergui.ui b/SAS/Scheduler/src/schedulergui.ui deleted file mode 100644 index 4f5dec69a7be69b55bf8e46f1799d2c529679453..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulergui.ui +++ /dev/null @@ -1,461 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SchedulerGUIClass</class> - <widget class="QMainWindow" name="SchedulerGUIClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>1100</width> - <height>800</height> - </rect> - </property> - <property name="baseSize"> - <size> - <width>800</width> - <height>600</height> - </size> - </property> - <property name="windowTitle"> - <string>MainWindow</string> - </property> - <widget class="QMenuBar" name="menubar"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>1100</width> - <height>23</height> - </rect> - </property> - <widget class="QMenu" name="menu_File"> - <property name="title"> - <string>&File</string> - </property> - <addaction name="action_New_schedule"/> - <addaction name="action_Open_Schedule"/> - <addaction name="action_Save_schedule"/> - <addaction name="action_Save_schedule_as"/> - <addaction name="action_Close_schedule"/> - <addaction name="action_Save_task_list"/> - <addaction name="action_Quit"/> - </widget> - <widget class="QMenu" name="menu_Settings"> - <property name="title"> - <string>&Settings</string> - </property> - <addaction name="action_Schedule_Settings"/> - <addaction name="action_Load_settings"/> - <addaction name="actionLoad_default_settings"/> - <addaction name="action_Save_settings"/> - <addaction name="action_Save_default_settings"/> - </widget> - <widget class="QMenu" name="menu_Help"> - <property name="title"> - <string>&Help</string> - </property> - <addaction name="action_About"/> - </widget> - <widget class="QMenu" name="menu_Actions"> - <property name="title"> - <string>&Actions</string> - </property> - <addaction name="action_Create_initial_schedule"/> - <addaction name="action_Optimize_schedule"/> - <addaction name="action_Balance_schedule"/> - <addaction name="action_Assign_resources"/> - <addaction name="action_Align_left"/> - <addaction name="actionPublish_schedule"/> - </widget> - <widget class="QMenu" name="menu_Edit"> - <property name="title"> - <string>&Edit</string> - </property> - <addaction name="action_Add_task"/> - <addaction name="action_Delete_task"/> - <addaction name="action_Undo"/> - <addaction name="action_Redo"/> - <addaction name="action_Find"/> - <addaction name="action_Thrashcan"/> - <addaction name="action_Move_task"/> - </widget> - <widget class="QMenu" name="menu_View"> - <property name="title"> - <string>&View</string> - </property> - <widget class="QMenu" name="menuGraphical_schedule_view"> - <property name="title"> - <string>&Graphical schedule view</string> - </property> - <addaction name="actionGraphicalViewShow"/> - <addaction name="actionResource_view"/> - <addaction name="actionTask_view"/> - </widget> - <widget class="QMenu" name="menuTable_view"> - <property name="title"> - <string>&Table view</string> - </property> - <addaction name="actionTableViewShow"/> - <addaction name="actionSelect_colums_to_view"/> - </widget> - <addaction name="menuGraphical_schedule_view"/> - <addaction name="menuTable_view"/> - <addaction name="actionHorizontal_view"/> - <addaction name="actionVertical_view"/> - <addaction name="action_Statistics"/> - </widget> - <widget class="QMenu" name="menuSAS"> - <property name="title"> - <string>SAS</string> - </property> - <addaction name="action_DownloadSASSchedule"/> - <addaction name="action_SyncSASSchedule"/> - <addaction name="action_Compare_differences"/> - <addaction name="actionCheck_SAS_status"/> - </widget> - <widget class="QMenu" name="menuConnect"> - <property name="title"> - <string>Connect</string> - </property> - <addaction name="actionConnect_to_Data_monitor"/> - </widget> - <addaction name="menu_File"/> - <addaction name="menu_Edit"/> - <addaction name="menu_Actions"/> - <addaction name="menuSAS"/> - <addaction name="menuConnect"/> - <addaction name="menu_Settings"/> - <addaction name="menu_View"/> - <addaction name="menu_Help"/> - </widget> - <action name="action_Close_schedule"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Close schedule</string> - </property> - </action> - <action name="action_About"> - <property name="text"> - <string>&About</string> - </property> - </action> - <action name="action_Optimize_schedule"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Optimize schedule</string> - </property> - <property name="toolTip"> - <string>Optimize schedule (Ctrl + O)</string> - </property> - <property name="shortcut"> - <string>Ctrl+O</string> - </property> - </action> - <action name="action_Balance_schedule"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Balance schedule</string> - </property> - <property name="toolTip"> - <string>Balance schedule</string> - </property> - </action> - <action name="action_Open_task_list"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="text"> - <string>Open task list</string> - </property> - </action> - <action name="action_Create_initial_schedule"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Create initial schedule</string> - </property> - <property name="toolTip"> - <string>Create initial schedule</string> - </property> - </action> - <action name="action_Quit"> - <property name="text"> - <string>&Quit</string> - </property> - <property name="toolTip"> - <string>Quit (Ctrl + Q)</string> - </property> - <property name="shortcut"> - <string>Ctrl+Q</string> - </property> - </action> - <action name="action_Save_task_list"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Export task list</string> - </property> - </action> - <action name="action_Undo"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Undo</string> - </property> - <property name="toolTip"> - <string>Undo (Ctrl + Z)</string> - </property> - <property name="shortcut"> - <string>Ctrl+Z</string> - </property> - </action> - <action name="action_Redo"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Redo</string> - </property> - <property name="toolTip"> - <string>Redo (Ctrl + Y)</string> - </property> - <property name="shortcut"> - <string>Ctrl+Y</string> - </property> - </action> - <action name="action_Save_schedule_as"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Save schedule as</string> - </property> - </action> - <action name="action_Open_Schedule"> - <property name="text"> - <string>&Open schedule</string> - </property> - </action> - <action name="action_Save_schedule"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Save schedule</string> - </property> - <property name="toolTip"> - <string>Save schedule (Ctrl + S)</string> - </property> - <property name="shortcut"> - <string>Ctrl+S</string> - </property> - </action> - <action name="close"> - <property name="icon"> - <iconset> - <normaloff>images/close16x16.png</normaloff>images/close16x16.png</iconset> - </property> - <property name="text"> - <string>Close</string> - </property> - </action> - <action name="action_Schedule_Settings"> - <property name="text"> - <string>&Schedule settings</string> - </property> - </action> - <action name="action_Save_settings"> - <property name="text"> - <string>S&ave settings</string> - </property> - </action> - <action name="action_Load_settings"> - <property name="text"> - <string>&Load settings</string> - </property> - </action> - <action name="action_Save_default_settings"> - <property name="text"> - <string>Save as &default settings</string> - </property> - </action> - <action name="action_Find"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Find</string> - </property> - <property name="shortcut"> - <string>Ctrl+F</string> - </property> - </action> - <action name="action_New_schedule"> - <property name="text"> - <string>&New schedule</string> - </property> - </action> - <action name="actionLoad_default_settings"> - <property name="text"> - <string>Load default settings</string> - </property> - </action> - <action name="actionShow_Status_Bar"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="text"> - <string>Status bar</string> - </property> - </action> - <action name="actionSelect_colums_to_view"> - <property name="text"> - <string>Select colums to view</string> - </property> - </action> - <action name="actionResource_view"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>Resource view</string> - </property> - </action> - <action name="actionTask_view"> - <property name="text"> - <string>Task view</string> - </property> - </action> - <action name="actionGraphicalViewShow"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>Show</string> - </property> - </action> - <action name="actionTableViewShow"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>Show</string> - </property> - </action> - <action name="actionHorizontal_view"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="checked"> - <bool>true</bool> - </property> - <property name="text"> - <string>&Horizontal view</string> - </property> - </action> - <action name="actionVertical_view"> - <property name="checkable"> - <bool>true</bool> - </property> - <property name="text"> - <string>&Vertical view</string> - </property> - </action> - <action name="action_Align_left"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>&Align left</string> - </property> - </action> - <action name="action_Add_task"> - <property name="text"> - <string>&Add task</string> - </property> - </action> - <action name="action_Delete_task"> - <property name="text"> - <string>&Delete task(s)</string> - </property> - <property name="shortcut"> - <string>Ctrl+Del</string> - </property> - </action> - <action name="action_DownloadSASSchedule"> - <property name="text"> - <string>&Download running schedule from SAS</string> - </property> - </action> - <action name="action_SyncSASSchedule"> - <property name="text"> - <string>&Synchronize schedule with SAS</string> - </property> - </action> - <action name="action_Compare_differences"> - <property name="text"> - <string>&Compare differences</string> - </property> - </action> - <action name="action_Statistics"> - <property name="text"> - <string>&Statistics</string> - </property> - </action> - <action name="actionPublish_schedule"> - <property name="text"> - <string>&Publish schedule</string> - </property> - </action> - <action name="action_Thrashcan"> - <property name="text"> - <string>&Thrashcan</string> - </property> - </action> - <action name="actionCheck_SAS_status"> - <property name="text"> - <string>Check SAS status</string> - </property> - </action> - <action name="action_Assign_resources"> - <property name="text"> - <string>Assign resources</string> - </property> - </action> - <action name="actionConnect_to_Data_monitor"> - <property name="text"> - <string>Connect to Data Monitor</string> - </property> - </action> - <action name="actionCleanup_Storage"> - <property name="text"> - <string>Cleanup &Storage</string> - </property> - </action> - <action name="action_Move_task"> - <property name="text"> - <string>&Move task(s)</string> - </property> - </action> - </widget> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/schedulersettings.cpp b/SAS/Scheduler/src/schedulersettings.cpp deleted file mode 100644 index 7560cc78f4f09f63d58d7c1edf0adbf9c6f0520e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulersettings.cpp +++ /dev/null @@ -1,712 +0,0 @@ -/* - * schedulersettings.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Aug 6, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulersettings.cpp $ - * - */ - -#include "schedulersettings.h" -#include "astrodatetime.h" -#include "Controller.h" -#include <cmath> -#include <QDate> - -SchedulerSettings::SchedulerSettings() - : itsMinTimeBetweenTasks(MIN_TIME_BETWEEN_TASKS_GREGORIAN), uniqueStationID(1), itsAllowMultipleRaidPerNode(false), itsStorageNodeBandWidth(STORAGE_NODE_kbps), itsRaidMaxWriteSpeed(STORAGE_RAID_WRITE_KBS), - itsStorageFillPercentage(STORAGE_FILL_PECENTAGE), itsUserAcceptedPenaltyEnabled(false), itsMaxNrOptimizationsEnabled(true), itsAllowUnscheduleFixedTasks(false), - itsLoadDefaultSettings(true), itsfocusTaskAtClick(true), itsIsTestEnvironment(false), itsUserAcceptedPenalty(0), itsMaxNrOptimizations(MAX_OPTIMIZE_ITERATIONS), itsMaxNrOfFilesPerStorageNode(MAX_FILES_PER_STORAGE_NODE), - itsPublishLocal(false) -{ - QDate day = QDate::currentDate(); - day = day.addDays(-day.dayOfWeek() + 1); // start on monday - itsEarliestDay = AstroDate(day.day(), day.month(), day.year()); - day = day.addMonths(6); - day = day.addDays(7 - day.dayOfWeek()); // end on Sunday - itsLatestDay = AstroDate(day.day(), day.month(), day.year()); - itsNrOfDaysInSchedule = itsLatestDay.toJulian() - itsEarliestDay.toJulian(); - wrongSunRiseSetValue = std::pair<double, double>(-1,-1); - itsObservationIDprefix= "L"; -} - -SchedulerSettings::~SchedulerSettings() { -} - -QDataStream& operator<< (QDataStream &out, const SchedulerSettings &settings) { - out << (quint16) settings.uniqueStationID - << (quint16) settings.itsUserAcceptedPenalty - << (quint16) settings.itsMaxNrOptimizations - << (quint16) settings.itsNrOfDaysInSchedule - << (quint16) settings.itsShortTermScheduleDuration - << (quint16) settings.itsScheduleDuration - << (quint16) settings.itsMaxNrOfFilesPerStorageNode - << settings.itsUserAcceptedPenaltyEnabled - << settings.itsMaxNrOptimizationsEnabled - << settings.itsAllowUnscheduleFixedTasks - << settings.itsPublishLocal - << settings.itsLoadDefaultSettings - << settings.itsIsTestEnvironment - << settings.itsObservationIDprefix - << settings.itsStorageNodeBandWidth - << settings.itsRaidMaxWriteSpeed - << (quint8) settings.itsStorageFillPercentage - << settings.itsSASUserName - << settings.itsSASPassword - << settings.itsSASDatabase - << settings.itsSASHostName - << settings.itsDMUserName - << settings.itsDMPassword - << settings.itsDMDatabase - << settings.itsDMHostName - << settings.itsLocalPublishPath - << settings.itsSchedulerAccountName - << settings.itssWebServerName - << settings.itsPrivateKeyFile - << settings.itsWebServerPublishPath - << settings.itsMinTimeBetweenTasks - << settings.itsDemixSources - - // save default template information - << (quint32) settings.itsDefaultTemplates.size(); - for (std::map<quint32, DefaultTemplate>::const_iterator it = settings.itsDefaultTemplates.begin(); it != settings.itsDefaultTemplates.end(); ++it) { - out << it->first - << it->second.treeID - << it->second.name - << (quint16) it->second.status - << it->second.processType - << it->second.processSubtype - << it->second.strategy - << it->second.description; - } - - // write campaigns from settings - out << (quint32) settings.itsCampaigns.size(); - for (campaignMap::const_iterator it = settings.itsCampaigns.begin(); it != settings.itsCampaigns.end(); ++it) { - out << it->second.id // id - << it->second.name - << it->second.title - << it->second.PriInvestigator - << it->second.CoInvestigator - << it->second.contact; - } - - out << (quint32) settings.itsStationList.size(); - for (stationDefinitionsMap::const_iterator it = settings.itsStationList.begin(); it != settings.itsStationList.end(); ++it) { - out << it->first - << it->second.first - << it->second.second; - } - out << (quint32) settings.itsStationNameIDMapping.size(); - for (stationNameIDMapping::const_iterator it = settings.itsStationNameIDMapping.begin(); it != settings.itsStationNameIDMapping.end(); ++it) { - out << it->first - << (quint16)it->second; - } - out << (quint32) settings.itsStationPositions.size(); - for (stationPositionsMap::const_iterator it = settings.itsStationPositions.begin(); it != settings.itsStationPositions.end(); ++it) { - out << (quint16)it->first - << it->second.first - << it->second.second; - } - - // write storage nodes name->ID mapping - const storageHostsMap &storagenodes = settings.itsController->getStorageNodes(); - out << (quint32)storagenodes.size(); - for (storageHostsMap::const_iterator it = storagenodes.begin(); it != storagenodes.end(); ++it) { - out << (quint16) it->second.itsID // storage node ID - << it->second.itsName // storage node name - << it->second.itsMayBeUsed; // may this storage node be used? - } - - // write storage nodes definitions - const hostPartitionsMap &partitions = settings.itsController->getStoragePartitions(); - out << (quint32)partitions.size(); - for (hostPartitionsMap::const_iterator it = partitions.begin(); it != partitions.end(); ++it) { - out << it->first // storage node ID - << (quint32)it->second.size(); // size of storagePartitionsMap - for (dataPathsMap::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { - out << (quint16) sit->first // partition ID - << sit->second.first // partition name - << (quint64) sit->second.second[0] // total size of partition - << (quint64) sit->second.second[1] // used space on partition - << (quint64) sit->second.second[2] // claimed space on partition - << (quint64) sit->second.second[3]; // free space on partition - } - } - - // data distribution scheme - out << (quint8) settings.itsDataDistributionScheme; - - // preferred storage nodes per data product type - out << (quint32) settings.itsPreferredDataProductStorage.size(); - for (preferredDataProductStorageMap::const_iterator it = settings.itsPreferredDataProductStorage.begin(); it != settings.itsPreferredDataProductStorage.end(); ++it) { - out << (quint16) it->first - << (quint32) it->second.size(); - for (std::vector<int>::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { - out << *sit; - } - } - - // preferred storage nodes per project - out << (quint32) settings.itsPreferredProjectStorage.size(); - for (preferredProjectStorageMap::const_iterator it = settings.itsPreferredProjectStorage.begin(); it != settings.itsPreferredProjectStorage.end(); ++it) { - out << (quint16)it->first - << (quint32) it->second.size(); - for (std::vector<int>::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { - out << *sit; - } - } - - return out; -} - -QDataStream& operator>> (QDataStream &in, SchedulerSettings &settings) { - quint32 size, size2; - quint8 uint8; - quint16 uint16; - std::string str; - std::vector<std::pair<double, double> > vec; - std::pair<double, double> dPair; - settings.itsStationList.clear(); - settings.itsStationNameIDMapping.clear(); - settings.itsStationPositions.clear(); - settings.itsStationSunMap.clear(); - - in >> settings.uniqueStationID - >> settings.itsUserAcceptedPenalty - >> settings.itsMaxNrOptimizations - >> settings.itsNrOfDaysInSchedule - >> settings.itsShortTermScheduleDuration - >> settings.itsScheduleDuration - >> settings.itsMaxNrOfFilesPerStorageNode - >> settings.itsUserAcceptedPenaltyEnabled - >> settings.itsMaxNrOptimizationsEnabled - >> settings.itsAllowUnscheduleFixedTasks - >> settings.itsPublishLocal - >> settings.itsLoadDefaultSettings - >> settings.itsIsTestEnvironment - >> settings.itsObservationIDprefix -// >> dummy - >> settings.itsStorageNodeBandWidth - >> settings.itsRaidMaxWriteSpeed - >> settings.itsStorageFillPercentage - >> settings.itsSASUserName - >> settings.itsSASPassword - >> settings.itsSASDatabase - >> settings.itsSASHostName - >> settings.itsDMUserName - >> settings.itsDMPassword - >> settings.itsDMDatabase - >> settings.itsDMHostName - >> settings.itsLocalPublishPath - >> settings.itsSchedulerAccountName - >> settings.itssWebServerName - >> settings.itsPrivateKeyFile - >> settings.itsWebServerPublishPath - >> settings.itsMinTimeBetweenTasks - >> settings.itsDemixSources; - - // read default template information - settings.itsDefaultTemplates.clear(); - DefaultTemplate t; - quint32 key; - in >> size; - while (size--) { - in >> key >> t.treeID >> t.name >> t.status >> t.processType >> t.processSubtype >> t.strategy >> t.description; - settings.itsDefaultTemplates.insert(std::map<quint32, DefaultTemplate>::value_type(key,t)); - } - - settings.itsController->defaultTemplatesUpdated(); - - // read campaigns from settings - campaignInfo campaign; - settings.clearCampaigns(); - in >> size; - while (size--) { - in >> campaign.id // id - >> campaign.name - >> campaign.title - >> campaign.PriInvestigator - >> campaign.CoInvestigator - >> campaign.contact; - settings.addCampaign(campaign); - } - - in >> size; - while (size--) { - in >> str >> dPair.first >> dPair.second; - settings.itsStationList.insert(stationDefinitionsMap::value_type (str, dPair)); - } - in >> size; - while (size--) { - in >> str >> uint16; - settings.itsStationNameIDMapping.push_back(stationNameIDMapping::value_type (str, uint16)); - } - in >> size; - while (size--) { - in >> uint16 >> dPair.first >> dPair.second; - settings.itsStationPositions.insert(stationPositionsMap::value_type (uint16, dPair)); - } - - // storage nodes - storageHostsMap storagenodes; - // read storage nodes name->ID mapping - StorageHost newStorageHost; - newStorageHost.itsStatus = -1; // unknown status - - in >> size; - while (size--) { - in >> newStorageHost.itsID // storage node ID - >> newStorageHost.itsName // storage node name - >> newStorageHost.itsMayBeUsed; // may this storage node be used? - storagenodes[newStorageHost.itsID] = newStorageHost; - } - settings.itsController->setStorageNodes(storagenodes); - - // read storage nodes definitions - hostPartitionsMap partitions; - quint16 partitionID; - dataPathsMap dataPaths; - quint64 space; - int nodeID; - std::vector<quint64> sizeVec; - std::pair<std::string, std::vector<quint64> > partitionPair; - in >> size; - while (size--) { // iterate over itsStorageNodesPartitions - in >> nodeID // storage node ID - >> size2; // size of dataPathsMap - while (size2--) { - in >> partitionID // partition ID - >> partitionPair.first // partition name - >> space; // total size of partition - sizeVec.push_back(space); - in >> space; // used space on partition - sizeVec.push_back(space); - in >> space; // claimed space on partition - sizeVec.push_back(space); - in >> space; // free space on partition - sizeVec.push_back(space); - partitionPair.second = sizeVec; - dataPaths[partitionID] = partitionPair; - sizeVec.clear(); - } - partitions[nodeID] = dataPaths; - dataPaths.clear(); - } - settings.itsController->setStoragePartitions(partitions); - - // data distribution scheme - - in >> uint8; - settings.itsDataDistributionScheme = static_cast<storageNodeDistribution>(uint8); - - // preferred storage nodes per data product type - preferredDataProductStorageMap newDPSMap; - std::vector<int> nodes; - quint16 dataProduct; - in >> size; - while (size--) { - in >> dataProduct >> size2; - while (size2--) { - in >> nodeID; - nodes.push_back(nodeID); - } - newDPSMap[static_cast<dataProductTypes>(dataProduct)] = nodes; - nodes.clear(); - } - settings.itsPreferredDataProductStorage = newDPSMap; - - // preferred storage nodes per project - preferredProjectStorageMap newPSMap; - quint16 projectID; - in >> size; - while (size--) { - in >> projectID >> size2; - while (size2--) { - in >> nodeID; - nodes.push_back(nodeID); - } - newPSMap[projectID] = nodes; - nodes.clear(); - } - settings.itsPreferredProjectStorage = newPSMap; - - // also recalculate sunrises and sundowns again - for (stationPositionsMap::const_iterator it = settings.itsStationPositions.begin(); it != settings.itsStationPositions.end(); ++it) { - settings.calculateSunRisesAndSunDowns(it->first); - } - settings.calculateScheduleWeeks(); - - return in; -} - -void SchedulerSettings::updateSettings(const ScheduleSettingsDialog *settingsDialog) { - setUserAcceptedPenalty(settingsDialog->getUserAcceptedPenalty()); - setUserAcceptedPenaltyEnabled(settingsDialog->getUserAcceptedPenaltyEnabled()); - setMaxNrOptimizations(settingsDialog->getMaxNrOptimizeIterations()); - setmaxNrOptimizationsEnabled(settingsDialog->getmaxNrOptimizationsEnabled()); - setAllowUnscheduleFixedTasks(settingsDialog->getAllowUnscheduleFixedTasks()); - setMinTimeBetweenTasks(settingsDialog->getMinimumTimeBetweenObservations()); - setLoadDefaultSettingsOnStartup(settingsDialog->getLoadDefaultSettingsOnStartUp()); - setShortTermScheduleDurationWeeks(settingsDialog->getShortTermScheduleDurationWeeks()); - setScheduleDurationMonths(settingsDialog->getScheduleDurationMonths()); - setMaxNrOfFilesPerStorageNode(settingsDialog->getMaxNrOfFilesPerStorageNode()); - setSASDatabase(settingsDialog->getSASDatabase()); - setSASHostName(settingsDialog->getSASHostName()); - setSASUserName(settingsDialog->getSASUserName()); - setSASPassword(settingsDialog->getSASPassword()); - setDMDatabase(settingsDialog->getDMDatabase()); - setDMHostName(settingsDialog->getDMHostName()); - setDMUserName(settingsDialog->getDMUserName()); - setDMPassword(settingsDialog->getDMPassword()); - setLocalPublishPath(settingsDialog->getLocalPublishPath()); - setAutoPublish(settingsDialog->getAutoPublish()); - setSchedulerAccountName(settingsDialog->getSchedulerAccountName()); - setPrivateKeyFile(settingsDialog->getPrivateKeyFile()); - setWebServerName(settingsDialog->getWebServerName()); - setWebServerPublishPath(settingsDialog->getWebServerPublishPath()); - setPublishLocal(settingsDialog->publishLocal()); - setStorageNodeBandWidth(settingsDialog->getStorageNodeBandWidth()); - setRaidMaxWriteSpeed(settingsDialog->getRaidMaxWriteSpeed()); - setDemixSources(settingsDialog->getDemixSources()); - // test environment mode? - setTestEnvironmentMode(settingsDialog->getIsTestEnvironment()); -} - -void SchedulerSettings::setTestEnvironmentMode(bool enableTestMode) { - itsIsTestEnvironment = enableTestMode; - itsObservationIDprefix = enableTestMode ? "T" : "L"; -} - -quint32 SchedulerSettings::getSASDefaultTreeID(const QString &ptype, const QString & pstype, const QString &strategy) const { - for (std::map<quint32, DefaultTemplate>::const_iterator it = itsDefaultTemplates.begin(); it != itsDefaultTemplates.end(); ++it) { - if ((it->second.processType == ptype) && (it->second.processSubtype == pstype) && (it->second.strategy == strategy)) return it->first; - } - return 0; -} - -quint32 SchedulerSettings::getSASDefaultTreeID(const Task *pTask) const { - for (std::map<quint32, DefaultTemplate>::const_iterator it = itsDefaultTemplates.begin(); it != itsDefaultTemplates.end(); ++it) { - if ((it->second.processType == pTask->getProcessType()) && (it->second.processSubtype == pTask->getProcessSubtypeStr()) && (it->second.strategy == pTask->getStrategy())) return it->first; - } - return 0; -} - - -QStringList SchedulerSettings::getAllProcessTypes(void) const { - QStringList ptypes; - for (std::map<quint32, DefaultTemplate>::const_iterator it = itsDefaultTemplates.begin(); it != itsDefaultTemplates.end(); ++it) { - if (it->second.status != SAS_STATE_OBSOLETE) { - if (!ptypes.contains(it->second.processType)) ptypes.append(it->second.processType); - } - } - ptypes.sort(); - return ptypes; -} - - -QStringList SchedulerSettings::getAllProcessSubTypes(const QString &processType) const { - QStringList pstypes; - for (std::map<quint32, DefaultTemplate>::const_iterator it = itsDefaultTemplates.begin(); it != itsDefaultTemplates.end(); ++it) { - if (it->second.status != SAS_STATE_OBSOLETE) { - if (it->second.processType == processType) { - if (!pstypes.contains(it->second.processSubtype)) pstypes.append(it->second.processSubtype); - } - } - } - pstypes.sort(); - return pstypes; -} - - -QStringList SchedulerSettings::getAllStrategies(const QString &processType, const QString &processSubtype) const { - QStringList strategies; - for (std::map<quint32, DefaultTemplate>::const_iterator it = itsDefaultTemplates.begin(); it != itsDefaultTemplates.end(); ++it) { - if (it->second.status != SAS_STATE_OBSOLETE) { - if ((it->second.processType == processType) & (it->second.processSubtype == processSubtype)) { - if (!strategies.contains(it->second.strategy)) strategies.append(it->second.strategy); - } - } - } - strategies.sort(); - return strategies; -} - -const std::map<quint32, DefaultTemplate> &SchedulerSettings::updateDefaultTemplates(void) { - clearDefaultTemplates(); - itsSchedulerDefaultTemplate = 0; - itsDefaultTemplates.clear(); - std::vector<DefaultTemplate> defaultTemplates = itsController->getDefaultTemplatesFromSAS(); - for (std::vector<DefaultTemplate>::const_iterator it = defaultTemplates.begin(); it != defaultTemplates.end(); ++it) { - itsDefaultTemplates.insert(std::map<quint32, DefaultTemplate>::value_type(it->treeID, *it)); - if (it->name == "Scheduler default template") { - itsSchedulerDefaultTemplate = it->treeID; - } - } - if (itsSchedulerDefaultTemplate == 0) { - debugErr("s","Warning: Scheduler default template does not exist in SAS database!"); - } - itsController->defaultTemplatesUpdated(); - return itsDefaultTemplates; -} - -void SchedulerSettings::defineScheduleAndStations(const stationDefinitionsMap &stations, const AstroDate &start_day, const AstroDate &end_day) { - if (end_day > start_day) { - if ((start_day != itsEarliestDay) || (end_day != itsLatestDay)) { - itsEarliestDay = start_day; - itsLatestDay = end_day; - itsNrOfDaysInSchedule = end_day.toJulian() - start_day.toJulian(); - itsStationSunMap.clear(); - } - defineStations(stations, true); - calculateScheduleWeeks(); - } else { - itsEarliestDay.set_MJDay(0); - itsNrOfDaysInSchedule = 0; - std::cerr << "ERROR: last scheduling day is earlier than first scheduling day" << std::endl; - } -} - -void SchedulerSettings::setStationPosition(unsigned int stationID, const double &latitude, const double &longitude) { - itsStationPositions[stationID] = std::pair<double, double>(latitude, longitude); -} - -unsigned int SchedulerSettings::getStationID(const std::string &station_name) const { - for (stationNameIDMapping::const_iterator it = itsStationNameIDMapping.begin(); it != itsStationNameIDMapping.end(); ++it) { - if (it->first.compare(station_name) == 0) return it->second; - } - return 0; -} - -std::string SchedulerSettings::getStationName(unsigned int station_id) const { - for (stationNameIDMapping::const_iterator it = itsStationNameIDMapping.begin(); it != itsStationNameIDMapping.end(); ++it) { - if (it->second == station_id) { - return it->first; - } - } - return ""; -} - -bool SchedulerSettings::getStationPosition(unsigned int stationID, std::pair<double, double> &position) { - stationPositionsMap::const_iterator it = itsStationPositions.find(stationID); - if (it != itsStationPositions.end()) { - position = it->second; - return true; - } - else { - position.first = 0; - position.second = 0; - return false; - } -} - -const std::pair<double, double> & SchedulerSettings::getStationSunRiseAndSet(unsigned int stationID, const AstroDate & day) const { - if ((day >= itsEarliestDay) & (day < itsEarliestDay + itsNrOfDaysInSchedule) ) { - stationSunMap::const_iterator cit = itsStationSunMap.find(stationID); - if (cit != itsStationSunMap.end()) { - return (cit->second)[(day - itsEarliestDay).toJulian()]; - } - } - return wrongSunRiseSetValue; //itsStationSunMap.begin()->second.front(); // return 'wrong' value -} - -const std::vector<std::pair<double, double> > &SchedulerSettings::getStationSunVector(unsigned int stationID) const { - stationSunMap::const_iterator cit = itsStationSunMap.find(stationID); - return cit->second; -} - -void SchedulerSettings::defineStations(const stationDefinitionsMap &stations, bool recalculateExistingStations) { - itsStationList = stations; - // clean up no longer existing stations from itsStationPositions, itsStationSunMap - // and itsStationNameIDMapping - if (recalculateExistingStations) { - itsStationSunMap.clear(); - } - // check which stations to keep and which to delete - std::vector<std::pair<std::string, unsigned int> > deleteStations; - bool keep; - for (stationNameIDMapping::const_iterator it = itsStationNameIDMapping.begin(); it != itsStationNameIDMapping.end(); ++it) { - keep = false; - for (stationDefinitionsMap::const_iterator sit = itsStationList.begin(); sit != itsStationList.end(); ++sit) { // check if existing station name is still in the new list (itsStationList) - if (sit->first.compare(it->first) == 0) { - keep = true; - break; - } - } - if (!keep) { - deleteStations.push_back(*it); - } - } - - // now delete references for the 'stations to delete' in the other station maps - if (!deleteStations.empty()) { - stationPositionsMap::iterator spit; - stationSunMap::iterator ssit; - for (std::vector<std::pair<std::string, unsigned int> >::const_iterator it = deleteStations.begin(); it != deleteStations.end(); ++it) { - for (stationNameIDMapping::iterator snit = itsStationNameIDMapping.begin(); snit != itsStationNameIDMapping.end(); ++snit) { - if (snit->second == it->second) { // same station ID? - itsStationNameIDMapping.erase(snit); - break; - } - } - if ((spit = itsStationPositions.find(it->second)) != itsStationPositions.end()) - itsStationPositions.erase(spit); - if ((ssit = itsStationSunMap.find(it->second)) != itsStationSunMap.end()) - itsStationSunMap.erase(ssit); - } - } - // at last we create the stations that have been newly added and we possibly update the stations that existed but might have different coordinates - stationNameIDMapping::const_iterator sit; - if (!(stations.empty())) { - for (stationDefinitionsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - for (sit = itsStationNameIDMapping.begin(); sit != itsStationNameIDMapping.end(); ++sit) { - if (sit->first.compare(it->first) == 0) break; // found - } - if (sit == itsStationNameIDMapping.end()) { // new station name - itsStationNameIDMapping.push_back(stationNameIDMapping::value_type(it->first, uniqueStationID)); - itsStationPositions[uniqueStationID] = it->second; - calculateSunRisesAndSunDowns(uniqueStationID++); - } - else { // existing station, see if position was changed by user or we need to recalc because e.g. schedule time span has changed - if ((fabs(itsStationPositions[sit->second].first - it->second.first) > 1e-15) || - (fabs(itsStationPositions[sit->second].second - it->second.second) > 1e-15) || - recalculateExistingStations) { - itsStationPositions[sit->second] = it->second; - calculateSunRisesAndSunDowns(sit->second); - } - } - } - // now sort the stations in itsStationNameIDMapping according to the - // sorting sequence: CSxxx, RSxxx and then all other stations alphabetically - // currently they are sorted alphabetically by the map functionality itself - stationNameIDMapping sortedMappingCS, sortedMappingRS, sortedMappingOther; - for (stationNameIDMapping::const_iterator snit = itsStationNameIDMapping.begin(); snit != itsStationNameIDMapping.end(); ++snit) { - if (snit->first[0] == 'C') { - sortedMappingCS.push_back(*snit); - } - } - for (stationNameIDMapping::const_iterator snit = itsStationNameIDMapping.begin(); snit != itsStationNameIDMapping.end(); ++snit) { - if (snit->first[0] == 'R') { - sortedMappingRS.push_back(*snit); - } - } - for (stationNameIDMapping::const_iterator snit = itsStationNameIDMapping.begin(); snit != itsStationNameIDMapping.end(); ++snit) { - if ((snit->first[0] != 'R') & (snit->first[0] != 'C')) { - sortedMappingOther.push_back(*snit); - } - } - sort(sortedMappingCS.begin(), sortedMappingCS.end()); - sort(sortedMappingRS.begin(), sortedMappingRS.end()); - sort(sortedMappingOther.begin(), sortedMappingOther.end()); - itsStationNameIDMapping = sortedMappingCS; - itsStationNameIDMapping.insert(itsStationNameIDMapping.end(), sortedMappingRS.begin(), sortedMappingRS.end()); - itsStationNameIDMapping.insert(itsStationNameIDMapping.end(), sortedMappingOther.begin(), sortedMappingOther.end()); - } -} - -void SchedulerSettings::calculateSunRisesAndSunDowns(unsigned int stationID) { - // algorithm taken from: - // The Astronomical Almanac for the year 2008, chapter C24 - // low precision formulas for the Sun's coordinates and the equation of time - double sunrise, sunset; - double n, L, g, lambda, eps, ra, dec, lst_rise, lst_set, ha, fday, lam_quadrant, RA_quadrant; -/* -#ifdef DEBUG_SCHEDULER - for (stationNameIDMapping::const_iterator it = itsStationNameIDMapping.begin(); it != itsStationNameIDMapping.end(); ++it) { - if (it->second == stationID) { - std::cout << "Calculating sun rise and set times for station: " << it->first << std::endl; - std::cout << "Station latitude: " << itsStationPositions[stationID].first << ", longitude: " - << itsStationPositions[stationID].second << std::endl; - break; - } - } -#endif -*/ - for (int day = itsEarliestDay.toJulian(); day != itsLatestDay.toJulian(); ++day) { - // day is the integer day number at noon counted from 0, where 0 equals the day set in julianStartDay - // returns sunrise and sunset in UTC. To local time add +2 hours - n = static_cast<double>(day); - // mean longitude of the sun L, put into range of 0 - 360 degrees - L = fmod((280.46 + 0.9856474 * n), 360) * GRAD2RAD; - // Mean anomaly g, put into range of 0 - 360 degrees - g = fmod((357.528 + 0.9856003 * n), 360) * GRAD2RAD; - // Ecliptic longitude lambda, put into the range of 0 - 2PI - lambda = fmod(L + (1.915 * sin(g) + 0.02 * sin(2 * g)) * GRAD2RAD, TWO_PI); - // Obliquity of ecliptic epsilon - eps = (23.439 - 0.0000004 * n) * GRAD2RAD; - ra = fmod(atan(cos(eps) * tan(lambda)), TWO_PI); - // put ra in the same quadrant as lambda - lam_quadrant = floor(lambda / PI_DIV2) * PI_DIV2; - RA_quadrant = floor(ra / PI_DIV2) * PI_DIV2; - ra = ra + (lam_quadrant - RA_quadrant); - - //Declination - dec = asin(sin(eps) * sin(lambda)); - ha = fmod(acos(SINSUNRISESETEL - tan(itsStationPositions[stationID].first * GRAD2RAD) * tan(dec)), TWO_PI); - lst_rise = fmod((ra - ha) * 12 / PI, 24); - lst_set = fmod((ra + ha) * 12 / PI, 24); - - fday = fmod((n - 0.5) * DU_LST_LINEAR + DU_LST_CONST + itsStationPositions[stationID].second / 15, 24); - if (fday > lst_rise) { - sunrise = n + (lst_rise - (fday - 24)) * LST_DU_LINEAR; - } else { - sunrise = n + (lst_rise - fday) * LST_DU_LINEAR; - } - if (fday > lst_set) { - sunset = n + (lst_set - (fday - 24)) * LST_DU_LINEAR; - } else { - sunset = n + (lst_set - fday) * LST_DU_LINEAR; - } - itsStationSunMap[stationID].push_back(std::pair<double, double>(sunrise, sunset)); - } -} - -bool SchedulerSettings::stationExist(const std::string &stationName) const { - for (stationNameIDMapping::const_iterator it = itsStationNameIDMapping.begin(); it != itsStationNameIDMapping.end(); ++it) { - if (it->first.compare(stationName) == 0) { - return true; - } - } - return false; -} - -bool SchedulerSettings::addCampaign(const campaignInfo &campaign) { - std::pair<campaignMap::iterator, bool> retValue; - retValue = itsCampaigns.insert(campaignMap::value_type(campaign.name, campaign)); - return retValue.second; -} - -const campaignInfo & SchedulerSettings::getCampaignInfo(const std::string &campaign_name) { - campaignMap::const_iterator it = itsCampaigns.find(campaign_name); - if (it != itsCampaigns.end()) return it->second; - else return itsCampaigns[""]; -} - - -int SchedulerSettings::getStorageNodeID(const std::string &name) const {return itsController->getStorageNodeID(name);} -std::string SchedulerSettings::getStorageNodeName(int node_id) const {return itsController->getStorageNodeName(node_id);} -std::string SchedulerSettings::getStorageRaidName(int node_id, int raid_id) const {return itsController->getStorageRaidName(node_id, raid_id);} -const storageHostsMap &SchedulerSettings::getStorageNodes(void) const {return itsController->getStorageNodes();} -const statesMap &SchedulerSettings::getStorageNodesStates(void) const {return itsController->getStorageNodesStates();} -size_t SchedulerSettings::getNrOfStorageNodesAvailable(void) const {return itsController->getNrOfStorageNodesAvailable();} -const hostPartitionsMap &SchedulerSettings::getStoragePartitions(void) const {return itsController->getStoragePartitions();} -int SchedulerSettings::getStorageRaidID(int node_id, const std::string &raidName) const {return itsController->getStorageRaidID(node_id,raidName);} - - -void SchedulerSettings::calculateScheduleWeeks(void) { - itsScheduleWeeks.clear(); - // first week of schedule - unsigned day = itsEarliestDay.getDayOfTheWeek(); - AstroDate monday = itsEarliestDay.subtractDays(day); - // last week of schedule - day = itsLatestDay.getDayOfTheWeek(); - AstroDate lastMonday = itsLatestDay.subtractDays(day); - while (monday <= lastMonday) { - itsScheduleWeeks.push_back(std::pair<unsigned, AstroDate>(monday.getWeek(), monday)); - monday = monday.addDays(7); - } -} diff --git a/SAS/Scheduler/src/schedulersettings.h b/SAS/Scheduler/src/schedulersettings.h deleted file mode 100644 index 84c67fe4ac26bd36c857493f504c89392470e547..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulersettings.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * schedulersettings.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Aug 6, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulersettings.h $ - * - */ - -#ifndef SCHEDULERSETTINGS_H_ -#define SCHEDULERSETTINGS_H_ - -#include <map> -#include <vector> -#include <string> -#include <fstream> - -// preferredProjectStorageMap: preferred storage nodes based on projects (key = project ID) -typedef std::map<int, std::vector<int> > preferredProjectStorageMap; - -enum sortMode { - SORT_NONE, - SORT_USAGE, - SORT_SIZE -}; - -#include "task.h" - -// preferredDataProductStorageMap: preferred storage nodes based on product data type -typedef std::map<dataProductTypes, std::vector<int> > preferredDataProductStorageMap; -// the sun rises and sun sets of every defined station specified as a pair of double (julian day) values -typedef std::map <unsigned int, std::vector<std::pair<double, double> > > stationSunMap; -// latitude and longitude of all defined stations -// the map's key is the unique station ID and the pair of doubles contain the latitude and longitude angles in radians -typedef std::map <unsigned int, std::pair<double, double> > stationPositionsMap; - -typedef std::map<int, std::string> storageNodeNameIDmap; -typedef std::map<std::string, std::pair<double, double> > stationDefinitionsMap; -typedef std::vector <std::pair<std::string, unsigned int> > stationNameIDMapping; - -enum storageNodeDistribution { - STORAGE_DISTRIBUTION_FLAT_USAGE, - STORAGE_DISTIBUTION_LEAST_FRAGMENTED, - END_STORAGE_DISTRIBUTION -}; -#define NR_STORAGE_DISTRIBUTIONS END_STORAGE_DISTRIBUTION - -#include "lofar_utils.h" -#include "lofar_scheduler.h" -#include "astrodate.h" -#include "astrotime.h" -#include "schedulesettingsdialog.h" -#include "StorageNode.h" - - -class DefaultTemplate { -public: - quint32 treeID; - QString name; - quint16 status; - QString processType, processSubtype; - QString strategy; - QString description; -}; - -class Controller; -class ScheduleSettingsDialog; - -typedef std::vector<std::pair<unsigned int, AstroDate> > scheduleWeekVector; // contains the week number and the monday of all the schedule weeks - -class SchedulerSettings { -public: - SchedulerSettings(); - virtual ~SchedulerSettings(); - - friend QDataStream & operator<<(QDataStream &out, const SchedulerSettings &settings); - friend QDataStream & operator>>(QDataStream &in, SchedulerSettings &settings); - - //getters - const std::map<quint32, DefaultTemplate> &getDefaultTemplates(void) const {return itsDefaultTemplates;} - const stationDefinitionsMap &getStationList(void) const {return itsStationList;} - bool getUserAcceptedPenaltyEnabled(void) const {return itsUserAcceptedPenaltyEnabled;} - unsigned int getUserAcceptedPenalty(void) const {return itsUserAcceptedPenalty;} - bool stationExist(const std::string &stationName) const; - const stationNameIDMapping & getStations(void) const {return itsStationNameIDMapping;} - unsigned int getStationID(const std::string &station_name) const; - std::string getStationName(unsigned int station_id) const; - bool getStationPosition(unsigned int stationID, std::pair<double, double> &position); - const std::vector<std::pair<double, double> > &getStationSunVector(unsigned int stationID) const; - double getStationSunRise(unsigned int stationID, const AstroDate & day) const {return getStationSunRiseAndSet(stationID, day).first;} - double getStationSunSet(unsigned int stationID, const AstroDate & day) const {return getStationSunRiseAndSet(stationID, day).second;} - const std::pair<double, double> & getStationSunRiseAndSet(unsigned int stationID, const AstroDate & day) const; - const AstroDate & getEarliestSchedulingDay(void) const {return itsEarliestDay;} - const AstroDate & getLatestSchedulingDay(void) const {return itsLatestDay;} - bool getMaxNrOptimizationsEnabled(void) const {return itsMaxNrOptimizationsEnabled;} - unsigned getMaxNrOptimizations(void) const {return itsMaxNrOptimizations;} - const AstroTime & getMinimumTimeBetweenTasks(void) const {return itsMinTimeBetweenTasks;} - bool getLoadDefaultSettingsOnStartUp(void) const {return itsLoadDefaultSettings;} - bool getIsTestEnvironment(void) const {return itsIsTestEnvironment;} - const QString &getObservationIDprefix(void) const {return itsObservationIDprefix;} - unsigned getShortTermScheduleDurationWeeks(void) const {return itsShortTermScheduleDuration;} - unsigned getScheduleDurationMonths(void) const {return itsScheduleDuration;} - quint16 getMaxNrOfFilesPerStorageNode(void) const {return itsMaxNrOfFilesPerStorageNode;} - bool getAllowUnscheduleFixedTasks(void) const {return itsAllowUnscheduleFixedTasks;} - bool getFocusTaskAtClick(void) const {return itsfocusTaskAtClick;} - const QString &getSASUserName(void) const {return itsSASUserName;} - const QString &getSASPassword(void) const {return itsSASPassword;} - const QString &getSASDatabase(void) const {return itsSASDatabase;} - const QString &getSASHostName(void) const {return itsSASHostName;} - quint32 getSchedulerDefaultTemplate(void) const {return itsSchedulerDefaultTemplate;} - quint32 getSASDefaultTreeID(const QString &ptype = "", const QString &pstype = "", const QString &strategy = "") const;// {return itsSASDefaultTree;} - quint32 getSASDefaultTreeID(const Task *pTask) const; - QStringList getAllProcessTypes(void) const; - QStringList getAllProcessSubTypes(const QString &processType) const; - QStringList getAllStrategies(const QString &processType, const QString &processSubtype) const; - const QString &getDMUserName(void) const {return itsDMUserName;} - const QString &getDMPassword(void) const {return itsDMPassword;} - const QString &getDMDatabase(void) const {return itsDMDatabase;} - const QString &getDMHostName(void) const {return itsDMHostName;} - const QString &getLocalPublishPath(void) const {return itsLocalPublishPath;} - const QString &getWebServerPublishPath(void) const {return itsWebServerPublishPath;} - const QString &getSchedulerAccountName(void) const {return itsSchedulerAccountName;} - const QString &getWebServerName(void) const {return itssWebServerName;} - const QString &getPrivateKeyFile(void) const {return itsPrivateKeyFile;} - bool getAutoPublish(void) const {return itsAutoPublish;} - bool publishLocal(void) const {return itsPublishLocal;} - const scheduleWeekVector &getScheduleWeeks(void) const {return itsScheduleWeeks;} - int getStorageNodeID(const std::string &name) const; - std::string getStorageNodeName(int node_id) const; - std::string getStorageRaidName(int node_id, int raid_id) const; - int getStorageRaidID(int node_id, const std::string &raidName) const; - const storageHostsMap &getStorageNodes(void) const; - const statesMap &getStorageNodesStates(void) const; - size_t getNrOfStorageNodesAvailable(void) const; - const hostPartitionsMap &getStoragePartitions(void) const; - const double &getStorageNodeBandWidth(void) const {return itsStorageNodeBandWidth;} - short int getStorageFillPercentage(void) const {return itsStorageFillPercentage;} - double getRaidMaxWriteSpeed(void) const {return itsRaidMaxWriteSpeed;} - const storageNodeDistribution &getStorageDistribution(void) const {return itsDataDistributionScheme;} - bool getAllowMultipleRaidPerStorageNode(void) const {return itsAllowMultipleRaidPerNode;} - const preferredProjectStorageMap &getPreferredProjectStorage(void) const {return itsPreferredProjectStorage;} - const preferredDataProductStorageMap &getPreferredDataProductStorage(void) const {return itsPreferredDataProductStorage;} - const QStringList &getDemixSources(void) const {return itsDemixSources;} - - //setters - void setController(Controller *controller) {itsController = controller;} - void updateSettings(const ScheduleSettingsDialog *settingsDialog); - void setEarliestSchedulingDay(const AstroDate &date) {itsEarliestDay = date;} - void setLatestSchedulingDay(const AstroDate &date) {itsLatestDay = date;} - void setMinTimeBetweenTasks(const AstroTime &min_time) {itsMinTimeBetweenTasks = min_time;} - void defineScheduleAndStations(const stationDefinitionsMap &stations, const AstroDate &start_day, const AstroDate &end_day); - void setStationList(const stationDefinitionsMap &stationList) {itsStationList = stationList;} - void setStationPosition(unsigned int stationID, const double &latitude, const double &longitude); - void setUserAcceptedPenaltyEnabled(bool endis) {itsUserAcceptedPenaltyEnabled = endis;} - void setUserAcceptedPenalty(unsigned int user_penalty) {itsUserAcceptedPenalty = user_penalty;} - void setmaxNrOptimizationsEnabled(bool endis) {itsMaxNrOptimizationsEnabled = endis;} - void setMaxNrOptimizations(unsigned maxNrOpt) {itsMaxNrOptimizations = maxNrOpt;} - void setLoadDefaultSettingsOnStartup(bool load_defaults) {itsLoadDefaultSettings = load_defaults;} - void setIsTestEnvironment(bool is_test_environment) {itsIsTestEnvironment = is_test_environment;} - void setShortTermScheduleDurationWeeks(unsigned weeks) {itsShortTermScheduleDuration = weeks;} - void setScheduleDurationMonths(unsigned months) {itsScheduleDuration = months;} - void setMaxNrOfFilesPerStorageNode(quint16 nr_files) {itsMaxNrOfFilesPerStorageNode = nr_files;} - void setAllowUnscheduleFixedTasks(bool allow) {itsAllowUnscheduleFixedTasks = allow;} - void setFocusTaskAtClick(bool focus) {itsfocusTaskAtClick = focus;} - void setSASConnectionSettings(const QString &username, const QString &password, const QString &DBname, const QString &hostname) { - itsSASUserName = username; - itsSASPassword = password; - itsSASDatabase = DBname; - itsSASHostName = hostname; - } - void setSASUserName(const QString &SAS_username) {itsSASUserName = SAS_username;} - void setSASPassword(const QString &SAS_password) {itsSASPassword = SAS_password;} - void setSASDatabase(const QString &SAS_database) {itsSASDatabase = SAS_database;} - void setSASHostName(const QString &SAS_hostname) {itsSASHostName = SAS_hostname;} - void setDMUserName(const QString &DM_username) {itsDMUserName = DM_username;} - void setDMPassword(const QString &DM_password) {itsDMPassword = DM_password;} - void setDMDatabase(const QString &DM_database) {itsDMDatabase = DM_database;} - void setDMHostName(const QString &DM_hostname) {itsDMHostName = DM_hostname;} - void setAutoPublish(bool enabled) {itsAutoPublish = enabled;} - void setLocalPublishPath(const QString &publish_path) {itsLocalPublishPath = publish_path;} - void setSchedulerAccountName(const QString &account_name) {itsSchedulerAccountName = account_name;} - void setWebServerPublishPath(const QString &publish_path) {itsWebServerPublishPath = publish_path;} - void setWebServerName(const QString &server_name) {itssWebServerName = server_name;} - void setPrivateKeyFile(const QString &private_key_file) {itsPrivateKeyFile = private_key_file;} - void setPublishLocal(bool local) {itsPublishLocal = local;} - void setStorageNodeBandWidth(const double &bandwidth) {itsStorageNodeBandWidth = bandwidth;} - void setStorageFillPercentage(short int percentage) {itsStorageFillPercentage = percentage;} - void setRaidMaxWriteSpeed(const double &write_speed) {itsRaidMaxWriteSpeed = write_speed;} - void setStorageDistribution(const storageNodeDistribution &distribution) {itsDataDistributionScheme = distribution;} - void setAllowMultipleRaidPerStorageNode(bool allow) {itsAllowMultipleRaidPerNode = allow;} - // return the campaign list containing the existing projects - const campaignMap &getCampaignList(void) const {return itsCampaigns;} // returns the campaign (project) list - const campaignInfo &getCampaignInfo(const std::string &campaign_name); - void clearCampaigns(void) {itsCampaigns.clear();} - bool addCampaign(const campaignInfo &campaign); - void setCampaigns(const campaignMap &campaigns) {itsCampaigns = campaigns;} - const std::map<quint32, DefaultTemplate> &updateDefaultTemplates(void); - void clearDefaultTemplates(void) {itsDefaultTemplates.clear();} - void setPreferredProjectStorage(const preferredProjectStorageMap &map) {itsPreferredProjectStorage = map;} - void setPreferredDataProductStorage(const preferredDataProductStorageMap &map) {itsPreferredDataProductStorage = map;} - void setTestEnvironmentMode(bool enableTestMode); // set the scheduler to test environment mode - void setDemixSources(const QStringList &demix_sources) {itsDemixSources = demix_sources;} - -private: - void defineStations(const stationDefinitionsMap &stations, bool recalculateExistingStations); - void calculateScheduleWeeks(void); - void calculateSunRisesAndSunDowns(unsigned int stationID); - -private: - Controller *itsController; - std::pair<double, double> wrongSunRiseSetValue; - quint32 itsSchedulerDefaultTemplate; - std::map<quint32, DefaultTemplate> itsDefaultTemplates; - stationDefinitionsMap itsStationList; - AstroDate itsEarliestDay, itsLatestDay; - scheduleWeekVector itsScheduleWeeks; - AstroTime itsMinTimeBetweenTasks; - quint16 uniqueStationID; //, itsMinNrOfStorageNodes; - preferredDataProductStorageMap itsPreferredDataProductStorage; - preferredProjectStorageMap itsPreferredProjectStorage; - storageNodeDistribution itsDataDistributionScheme; - bool itsAllowMultipleRaidPerNode; - stationNameIDMapping itsStationNameIDMapping; - stationPositionsMap itsStationPositions; - stationSunMap itsStationSunMap; - double itsStorageNodeBandWidth, itsRaidMaxWriteSpeed; // bandwidth in kbit/s, raid write speed in kbyte/sec - quint8 itsStorageFillPercentage; - bool itsUserAcceptedPenaltyEnabled, itsMaxNrOptimizationsEnabled, itsAllowUnscheduleFixedTasks; - bool itsLoadDefaultSettings, itsfocusTaskAtClick, itsIsTestEnvironment; - quint16 itsUserAcceptedPenalty, itsMaxNrOptimizations; - quint16 itsShortTermScheduleDuration, itsScheduleDuration; - quint16 itsNrOfDaysInSchedule, itsMaxNrOfFilesPerStorageNode; - // SAS database connection attributes - QString itsSASUserName, itsSASPassword, itsSASDatabase, itsSASHostName, itsObservationIDprefix, - itsDMUserName, itsDMPassword, itsDMDatabase, itsDMHostName; - QStringList itsDemixSources; - bool itsPublishLocal, itsAutoPublish; - QString itsLocalPublishPath, itsWebServerPublishPath, itssWebServerName, itsSchedulerAccountName, itsPrivateKeyFile; - campaignMap itsCampaigns; -}; - -#endif /* SCHEDULERSETTINGS_H_ */ diff --git a/SAS/Scheduler/src/schedulesettingsdialog.cpp b/SAS/Scheduler/src/schedulesettingsdialog.cpp deleted file mode 100644 index 1d8b4d75a8d8c05255997a2cc6a9cda5aa4a1820..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulesettingsdialog.cpp +++ /dev/null @@ -1,1206 +0,0 @@ -/* - * schedulesettingsdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 5-march-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulesettingsdialog.cpp $ - * - */ - -#include "schedulesettingsdialog.h" -#include "Controller.h" -#include "astrodate.h" -#include "astrotime.h" -#include "SASConnection.h" -#include <iostream> -#include <sstream> -#include <QMessageBox> -#include <QFileDialog> - -const char *storage_distributions_str[NR_STORAGE_DISTRIBUTIONS] = {"Spread (flat usage)","Least fragmented (fill up nodes)"}; - -ScheduleSettingsDialog::ScheduleSettingsDialog(Controller * controller) : - itsController(controller) { - ui.setupUi(this); - createActions(); - ui.lineEdit_StationName->setInputMask(">nnnnn;_"); - ui.pb_ClearStationList->setEnabled(false); - ui.pb_DeleteStation->setEnabled(false); - ui.lineEdit_Latitude->setInputMask("#09.0000000"); - ui.lineEdit_Latitude->setText("+0.0"); - ui.lineEdit_Longitude->setInputMask("#099.0000000"); - ui.lineEdit_Longitude->setText("+0.0"); - - AstroDate day(Controller::theSchedulerSettings.getEarliestSchedulingDay()); - itsEarliestDay.setDate(day.getYear(), day.getMonth(), day.getDay()); - ui.dateEdit_Earliest->setDate(itsEarliestDay); -// ui.dateEdit_Earliest->setMinimumDate(itsEarliestDay); - - day = Controller::theSchedulerSettings.getLatestSchedulingDay(); - itsLatestDay.setDate(day.getYear(), day.getMonth(), day.getDay()); - ui.dateEdit_Latest->setDate(itsLatestDay); -// ui.dateEdit_Latest->setMinimumDate(itsEarliestDay.addDays(1)); - - AstroTime ti(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); - itsMinTimeBetweenTasks.setHMS(ti.getHours(), ti.getMinutes(), ti.getSeconds()); - ui.timeEdit_MinTimeBetweenObservations->setTime(itsMinTimeBetweenTasks); - - itsMaxNrOptimizeIterations = Controller::theSchedulerSettings.getMaxNrOptimizations(); - ui.sbMaxNrOptimizations->setValue(itsMaxNrOptimizeIterations); - itsUserAcceptedPenalty = Controller::theSchedulerSettings.getUserAcceptedPenalty(); - ui.sbUserAcceptedPenalty->setValue(itsUserAcceptedPenalty); - itsAllowUnscheduleFixedTasks = Controller::theSchedulerSettings.getAllowUnscheduleFixedTasks(); - -// ui.cbUnscheduleFixedTasksAllowed->setChecked(itsAllowUnscheduleFixedTasks); - itsIsTestEnvironment = Controller::theSchedulerSettings.getIsTestEnvironment(); - ui.checkBoxTestEnvironment->setChecked(itsIsTestEnvironment); - - itsShortTermScheduleDuration = Controller::theSchedulerSettings.getShortTermScheduleDurationWeeks(); - ui.sp_ShortTermDurationWeeks->setValue(itsShortTermScheduleDuration); - itsScheduleDuration = Controller::theSchedulerSettings.getScheduleDurationMonths(); - ui.sb_ScheduleDurationMonths->setValue(itsScheduleDuration); - - // storage nodes header - ui.treeWidgetStorageNodes->setColumnCount(5); - QStringList header; - header << "Storage node" << "Partition" << "Total Size" << "Free Space" << "Percentage full"; - ui.treeWidgetStorageNodes->setHeaderLabels(header); -// ui.treeWidgetStorageNodes->header()->setResizeMode(QHeaderView::ResizeToContents); - ui.treeWidgetStorageNodes->header()->resizeSection(0,230); - ui.treeWidgetStorageNodes->header()->resizeSection(1,80); - ui.treeWidgetStorageNodes->header()->resizeSection(2,80); - ui.treeWidgetStorageNodes->header()->resizeSection(3,80); - // add the storage nodes itself - /* - QList<QTreeWidgetItem *> items; - const storageNodeNameIDmap &storagenodes = Controller::theSchedulerSettings.getStorageNodesNameIDmapping(); - const std::map<int, storagePartitionsMap> &partitions = Controller::theSchedulerSettings.getStoragePartitionsMap(); - std::map<int, storagePartitionsMap>::const_iterator pit; - QTreeWidgetItem *nodeItem; - QStringList itemValues; - for (storageNodeNameIDmap::const_iterator stit = storagenodes.begin(); stit != storagenodes.end(); ++stit) { - nodeItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(stit->second.c_str())); - pit = partitions.find(stit->first); - for (storagePartitionsMap::const_iterator ppit = pit->second.begin(); ppit != pit->second.end(); ++ppit) { - itemValues << "" << ppit->second.first.c_str() << "online" << QString::number(ppit->second.second) << "100"; - new QTreeWidgetItem(nodeItem, itemValues); - itemValues.clear(); - } - items.append(nodeItem); - } - ui.treeWidgetStorageNodes->insertTopLevelItems(0, items); - */ - - // Storage distribution - for (int i = 0; i < NR_STORAGE_DISTRIBUTIONS; ++i) { - ui.comboBoxDataDistribution->addItem(storage_distributions_str[i]); - } - - // init product data type storage preferences table - ui.tableWidgetDataProductStorage->setRowCount(DP_UNKNOWN_TYPE); - ui.tableWidgetDataProductStorage->setColumnCount(1); -// ui.tableWidgetDataProductStorage->setSelectionMode(QAbstractItemView::MultiSelection); - ui.tableWidgetDataProductStorage->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui.tableWidgetDataProductStorage->horizontalHeader()->hide(); - ui.tableWidgetDataProductStorage->verticalHeader()->hide(); - QTableWidgetItem *item; - for (int row = 0; row < DP_UNKNOWN_TYPE; ++row) { - item = new QTableWidgetItem(DATA_PRODUCTS[row]); - item->setFlags(Qt::ItemIsEnabled); - ui.tableWidgetDataProductStorage->setItem(row,0,item); - } - ui.tableWidgetDataProductStorage->resizeColumnsToContents(); - - ui.tableWidgetProjectStorage->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui.tableWidgetProjectStorage->horizontalHeader()->hide(); - ui.tableWidgetProjectStorage->verticalHeader()->hide(); - - ui.edit_SAShostname->setText(Controller::theSchedulerSettings.getSASHostName()); - ui.edit_SASdatabase->setText(Controller::theSchedulerSettings.getSASDatabase()); - ui.edit_SASusername->setText(Controller::theSchedulerSettings.getSASUserName()); - ui.edit_SASpassword->setText(Controller::theSchedulerSettings.getSASPassword()); -// ui.spinBox_DefaultTemplateTreeID->setValue(Controller::theSchedulerSettings.getSASDefaultTreeID()); - - ui.tableWidgetDefaultTemplates->setColumnCount(7); - header.clear(); - header << "ID" << "Name" << "Process type" << "Process subtype" << "Strategy" << "Status" << "Description"; - ui.tableWidgetDefaultTemplates->setHorizontalHeaderLabels(header); - ui.tableWidgetDefaultTemplates->horizontalHeader()->setStretchLastSection(true); -#if QT_VERSION >= 0x050000 - ui.tableWidgetDefaultTemplates->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); -#else - ui.tableWidgetDefaultTemplates->horizontalHeader()->setResizeMode(QHeaderView::Interactive); -#endif - - ui.checkBoxAutoPublish->setChecked(Controller::theSchedulerSettings.getAutoPublish()); - itsPublishLocal = Controller::theSchedulerSettings.publishLocal(); - itsLocalPublishPath = Controller::theSchedulerSettings.getLocalPublishPath(); - itsSchedulerAccountName = Controller::theSchedulerSettings.getSchedulerAccountName(); - itsPrivateKeyFile = Controller::theSchedulerSettings.getPrivateKeyFile(); - itsWebServerName = Controller::theSchedulerSettings.getWebServerName(); - itsWebServerPublishPath = Controller::theSchedulerSettings.getWebServerPublishPath(); - - ui.radioButton_PublishLocal->setChecked(itsPublishLocal); - ui.radioButton_PublishToWeb->setChecked(!itsPublishLocal); - ui.lineEdit_PublishAccountName->setText(itsSchedulerAccountName); - ui.lineEdit_PublishPrivateKeyFile->setText(itsPrivateKeyFile); - ui.lineEdit_PublishWebServerName->setText(itsWebServerName); - ui.lineEdit_PublishWebServerDirectory->setText(itsWebServerPublishPath); - - ui.lineEditStorageNodeBandwidth->setText(QString::number(Controller::theSchedulerSettings.getStorageNodeBandWidth())); - ui.radioButtonGbs->setChecked(true); - - itsPublishLocal = Controller::theSchedulerSettings.publishLocal(); - if (itsPublishLocal) { - ui.radioButton_PublishLocal->setChecked(true); - } - else { - ui.radioButton_PublishToWeb->setChecked(true); - } - enablePublishField(); - // allow auto publish? - if (itsController->autoPublishAllowed()) { - ui.checkBoxAutoPublish->setEnabled(true); - ui.checkBoxAutoPublish->setChecked(true); - } - else { - ui.checkBoxAutoPublish->setEnabled(false); - ui.checkBoxAutoPublish->setChecked(false); - ui.checkBoxAutoPublish->setToolTip("Auto publishing is only allowed for user lofarsys"); - } -} - -ScheduleSettingsDialog::~ScheduleSettingsDialog() { - -} - -void ScheduleSettingsDialog::doubleClickedStation(const QModelIndex &index) { - QStringList stationInfo(index.data(Qt::UserRole).toStringList()); - if (stationInfo.size() == 3) { - ui.lineEdit_StationName->setText(stationInfo.at(0)); - ui.lineEdit_Latitude->setText(stationInfo.at(1)); - ui.lineEdit_Longitude->setText(stationInfo.at(2)); - } -} - -void ScheduleSettingsDialog::show() { - // load the settings from the program settings into this dialog - itsStations = Controller::theSchedulerSettings.getStationList(); - - setEarliestSchedulingDay(Controller::theSchedulerSettings.getEarliestSchedulingDay()); - setLatestSchedulingDay(Controller::theSchedulerSettings.getLatestSchedulingDay()); - itsUserAcceptedPenalty = Controller::theSchedulerSettings.getUserAcceptedPenalty(); - itsUserAcceptedPenaltyEnabled = Controller::theSchedulerSettings.getUserAcceptedPenaltyEnabled(); - itsMaxNrOptimizeIterations = Controller::theSchedulerSettings.getMaxNrOptimizations(); - itsMaxNrOptimizationsEnabled = Controller::theSchedulerSettings.getMaxNrOptimizationsEnabled(); - setMinimumTimeBetweenTasks(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); - itsLoadDefaultSettings = Controller::theSchedulerSettings.getLoadDefaultSettingsOnStartUp(); - itsIsTestEnvironment = Controller::theSchedulerSettings.getIsTestEnvironment(); - itsShortTermScheduleDuration = Controller::theSchedulerSettings.getShortTermScheduleDurationWeeks(); - itsScheduleDuration = Controller::theSchedulerSettings.getScheduleDurationMonths(); - itsAllowUnscheduleFixedTasks = Controller::theSchedulerSettings.getAllowUnscheduleFixedTasks(); - itsSASHostName = Controller::theSchedulerSettings.getSASHostName(); - itsSASDatabase = Controller::theSchedulerSettings.getSASDatabase(); - itsSASUserName = Controller::theSchedulerSettings.getSASUserName(); - itsSASPassword = Controller::theSchedulerSettings.getSASPassword(); - itsDMHostName = Controller::theSchedulerSettings.getDMHostName(); - itsDMDatabase = Controller::theSchedulerSettings.getDMDatabase(); - itsDMUserName = Controller::theSchedulerSettings.getDMUserName(); - itsDMPassword = Controller::theSchedulerSettings.getDMPassword(); - itsPublishLocal = Controller::theSchedulerSettings.publishLocal(); - itsLocalPublishPath = Controller::theSchedulerSettings.getLocalPublishPath(); - itsSchedulerAccountName = Controller::theSchedulerSettings.getSchedulerAccountName(); - itsWebServerName = Controller::theSchedulerSettings.getWebServerName(); - itsPrivateKeyFile = Controller::theSchedulerSettings.getPrivateKeyFile(); - itsWebServerPublishPath = Controller::theSchedulerSettings.getWebServerPublishPath(); - itsMaxNrOfFilesPerStorageNode = Controller::theSchedulerSettings.getMaxNrOfFilesPerStorageNode(); - itsDemixSources = Controller::theSchedulerSettings.getDemixSources(); - -// if ((!ui.edit_SASdatabase->text().isEmpty()) & (!ui.edit_SAShostname->text().isEmpty())) { -// updateDefaultTemplates(true); -// } - writeDefaultTemplatesToDialog(); - - // general tab - ui.cb_LoadDefaultSettings->setChecked(itsLoadDefaultSettings); - ui.checkBoxTestEnvironment->setChecked(itsIsTestEnvironment); - - // scheduler tab - ui.dateEdit_Earliest->setDate(itsEarliestDay); - ui.dateEdit_Latest->setDate(itsLatestDay); - ui.timeEdit_MinTimeBetweenObservations->setTime(itsMinTimeBetweenTasks); - ui.sp_ShortTermDurationWeeks->setValue(itsShortTermScheduleDuration); - ui.sb_ScheduleDurationMonths->setValue(itsScheduleDuration); - - //storage tab - itsStorageRaidWriteSpeed = Controller::theSchedulerSettings.getRaidMaxWriteSpeed(); // in kByte/sec - ui.lineEditStorageRaidWriteSpeed->setText(QString::number(itsStorageRaidWriteSpeed/1000)); - ui.spinBoxStorageFillPercentage->setValue(Controller::theSchedulerSettings.getStorageFillPercentage()); - - itsStorageNodeBandWidth = Controller::theSchedulerSettings.getStorageNodeBandWidth(); // in kb/s - if (itsStorageNodeBandWidth > 999999) { - ui.lineEditStorageNodeBandwidth->setText(QString::number(itsStorageNodeBandWidth / 1000000)); - ui.radioButtonGbs->setChecked(true); - } - else { - ui.lineEditStorageNodeBandwidth->setText(QString::number(itsStorageNodeBandWidth / 1000)); - ui.radioButtonMbs->setChecked(true); - } - - // add the storage nodes info - ui.treeWidgetStorageNodes->clear(); - if (itsController) { // if the controller is set - const storageHostsMap &nodes = itsController->getStorageNodes(); - const hostPartitionsMap &partitions = itsController->getStoragePartitions(); - const statesMap & states = itsController->getStorageNodesStates(); - updateStorageNodeInfoTree(nodes,states,partitions); - updatePreferredStorageLists(nodes); - } - - ui.tableWidgetDataProductStorage->clearSelection(); - ui.tableWidgetDataProductStorage->scrollTo(ui.tableWidgetDataProductStorage->model()->index(0,0)); - ui.tableWidgetProjectStorage->clearSelection(); - ui.tableWidgetProjectStorage->scrollTo(ui.tableWidgetProjectStorage->model()->index(0,0)); - - int storage_dist(Controller::theSchedulerSettings.getStorageDistribution()); - if ((storage_dist >= 0) & (storage_dist < ui.comboBoxDataDistribution->count())) { - ui.comboBoxDataDistribution->setCurrentIndex(storage_dist); - } - - ui.spinBoxMaxNrFilesToNode->setValue(itsMaxNrOfFilesPerStorageNode); - - // optimization tab - ui.cbMaxNrOptimizations->setChecked(itsMaxNrOptimizationsEnabled); - ui.cbUserAcceptedPenalty->setChecked(itsUserAcceptedPenaltyEnabled); - ui.sbMaxNrOptimizations->setValue(itsMaxNrOptimizeIterations); - ui.sbMaxNrOptimizations->setEnabled(itsMaxNrOptimizationsEnabled); - ui.sbUserAcceptedPenalty->setValue(itsUserAcceptedPenalty); - ui.sbUserAcceptedPenalty->setEnabled(itsUserAcceptedPenaltyEnabled); - - // stations tab - //populate the list of stations - ui.listStations->clear(); - const stationDefinitionsMap &stations(Controller::theSchedulerSettings.getStationList()); - if (!stations.empty()) { - QString name, latitude, longitude; - QStringList itemInfo; - for (stationDefinitionsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - latitude.setNum(it->second.first, 'f', 7); - longitude.setNum(it->second.second, 'f', 7); - name = it->first.c_str(); - itemInfo << name << latitude << longitude; - QListWidgetItem *newStation = new QListWidgetItem(name + " (" + latitude + ", " + longitude + ")"); - newStation->setData(Qt::UserRole,itemInfo); - ui.listStations->addItem(newStation); - itemInfo.clear(); - } - ui.lineEdit_Latitude->setText("+0.0"); - ui.lineEdit_Longitude->setText("+0.0"); - ui.lineEdit_StationName->setText(""); - ui.pb_ClearStationList->setEnabled(true); - ui.pb_DeleteStation->setEnabled(true); - } else { - ui.pb_ClearStationList->setEnabled(false); - ui.pb_DeleteStation->setEnabled(false); - } - - // SAS tab - ui.edit_SAShostname->setText(itsSASHostName); - ui.edit_SASdatabase->setText(itsSASDatabase); - ui.edit_SASusername->setText(itsSASUserName); - ui.edit_SASpassword->setText(itsSASPassword); - - // pipelines tab - ui.tableWidgetDemixSources->blockSignals(true); - ui.tableWidgetDemixSources->setRowCount(itsDemixSources.count()); - for (int row = 0; row < itsDemixSources.count(); ++row) { - ui.tableWidgetDemixSources->setItem(row, 0, new QTableWidgetItem(itsDemixSources.at(row))); - } - ui.tableWidgetDemixSources->blockSignals(false); - - // Data Monitor tab - ui.edit_DMhostname->setText(itsDMHostName); - ui.edit_DMdatabase->setText(itsDMDatabase); - ui.edit_DMusername->setText(itsDMUserName); - ui.edit_DMpassword->setText(itsDMPassword); - - // publish tab - ui.checkBoxAutoPublish->setChecked(Controller::theSchedulerSettings.getAutoPublish()); - ui.radioButton_PublishLocal->setChecked(itsPublishLocal); - ui.radioButton_PublishToWeb->setChecked(!itsPublishLocal); - ui.lineEdit_PublishLocalPath->setText(itsLocalPublishPath); - ui.lineEdit_PublishAccountName->setText(itsSchedulerAccountName); - ui.lineEdit_PublishWebServerName->setText(itsWebServerName); - ui.lineEdit_PublishPrivateKeyFile->setText(itsPrivateKeyFile); - ui.lineEdit_PublishWebServerDirectory->setText(itsWebServerPublishPath); - - enablePublishField(); - ui.pb_Ok->setDefault(true); - - this->setVisible(true); -} - -void ScheduleSettingsDialog::enablePublishField(void) { - if (ui.radioButton_PublishLocal->isChecked()) { // local - ui.label_PublishLocalPath->setEnabled(true); - ui.label_PublishSCPCommand->setEnabled(false); - ui.label_PublishWebServerPath->setEnabled(false); - ui.label_PublishPrivateKeyFile->setEnabled(false); - ui.pushButton_BrowseLocalPath->setEnabled(true); - ui.pushButton_BrowsePrivateKeyFile->setEnabled(false); - ui.lineEdit_PublishAccountName->setEnabled(false); - ui.lineEdit_PublishPrivateKeyFile->setEnabled(false); - ui.lineEdit_PublishWebServerName->setEnabled(false); - ui.lineEdit_PublishWebServerDirectory->setEnabled(false); - ui.lineEdit_PublishLocalPath->setEnabled(true); - } - else { // web - ui.label_PublishLocalPath->setEnabled(false); - ui.label_PublishSCPCommand->setEnabled(true); - ui.label_PublishWebServerPath->setEnabled(true); - ui.label_PublishPrivateKeyFile->setEnabled(true); - ui.pushButton_BrowseLocalPath->setEnabled(false); - ui.pushButton_BrowsePrivateKeyFile->setEnabled(true); - ui.lineEdit_PublishAccountName->setEnabled(true); - ui.lineEdit_PublishPrivateKeyFile->setEnabled(true); - ui.lineEdit_PublishWebServerName->setEnabled(true); - ui.lineEdit_PublishWebServerDirectory->setEnabled(true); - ui.lineEdit_PublishLocalPath->setEnabled(false); - } -} - - -AstroDate ScheduleSettingsDialog::getEarliestSchedulingDay(void) const { - AstroDate dt(itsEarliestDay.day(), itsEarliestDay.month(), itsEarliestDay.year()); - return dt; -} - -AstroDate ScheduleSettingsDialog::getLatestSchedulingDay(void) const { - AstroDate dt(itsLatestDay.day(), itsLatestDay.month(), itsLatestDay.year()); - return dt; -} - -AstroTime ScheduleSettingsDialog::getMinimumTimeBetweenObservations(void) const { - AstroTime t(itsMinTimeBetweenTasks.hour(), itsMinTimeBetweenTasks.minute(), itsMinTimeBetweenTasks.second()); - return t; - -} - -void ScheduleSettingsDialog::okClicked(void) { - // general tab - itsLoadDefaultSettings = ui.cb_LoadDefaultSettings->isChecked(); - itsIsTestEnvironment = ui.checkBoxTestEnvironment->isChecked(); - - // schedule tab - itsEarliestDay = ui.dateEdit_Earliest->date(); // always on a monday - itsLatestDay = ui.dateEdit_Latest->date(); - itsMinTimeBetweenTasks = ui.timeEdit_MinTimeBetweenObservations->time(); - itsShortTermScheduleDuration = ui.sp_ShortTermDurationWeeks->value(); - itsScheduleDuration = ui.sb_ScheduleDurationMonths->value(); - - //stations tab - - //storage tab - // first get the list of allowed storage nodes (user could have changed them) - std::vector<int> allowedStorageHosts; - QTreeWidgetItemIterator treeit(ui.treeWidgetStorageNodes); - while (*treeit) { - if ((*treeit)->checkState(0)) - allowedStorageHosts.push_back((*treeit)->data(0,Qt::UserRole).toInt()); // push the storage host id in allowedStorageHosts - ++treeit; - } - itsController->setAllowedStorageHosts(allowedStorageHosts); // updates the itsMayBeUsed fields of the storage nodes in the DM connection - itsMaxNrOfFilesPerStorageNode = ui.spinBoxMaxNrFilesToNode->value(); - - if (ui.radioButtonGbs->isChecked()) { - itsStorageNodeBandWidth = ui.lineEditStorageNodeBandwidth->text().toDouble() * 1000000; - } - else { - itsStorageNodeBandWidth = ui.lineEditStorageNodeBandwidth->text().toDouble() * 1000; - } - itsStorageRaidWriteSpeed = ui.lineEditStorageRaidWriteSpeed->text().toDouble() * 1000; - - Controller::theSchedulerSettings.setStorageFillPercentage(ui.spinBoxStorageFillPercentage->value()); - - // pipelines - - itsDemixSources.clear(); - for (int row = 0; row < ui.tableWidgetDemixSources->rowCount(); ++row) { - itsDemixSources.append(ui.tableWidgetDemixSources->item(row,0)->text()); - } - itsDemixSources.removeDuplicates(); - itsDemixSources.sort(); - ui.tableWidgetDemixSources->blockSignals(true); - ui.tableWidgetDemixSources->clearContents(); - ui.tableWidgetDemixSources->setRowCount(itsDemixSources.size()); - for (int i = 0; i < itsDemixSources.size(); ++i) { - ui.tableWidgetDemixSources->setItem(i,0,new QTableWidgetItem(itsDemixSources.at(i))); - } - ui.tableWidgetDemixSources->blockSignals(false); - - // optimization tab - itsUserAcceptedPenaltyEnabled = ui.cbUserAcceptedPenalty->isChecked(); - itsMaxNrOptimizationsEnabled = ui.cbMaxNrOptimizations->isChecked(); - itsUserAcceptedPenalty = ui.sbUserAcceptedPenalty->value(); - itsMaxNrOptimizeIterations = ui.sbMaxNrOptimizations->value(); - - // SAS tab - if ((itsSASHostName != ui.edit_SAShostname->text()) || - (itsSASDatabase != ui.edit_SASdatabase->text()) || - (itsSASUserName != ui.edit_SASusername->text()) || - (itsSASPassword != ui.edit_SASpassword->text())) { - updateSASConnectionSettings(); - updateDefaultTemplates(true); - } - - // Data Monitor tab - itsDMHostName = ui.edit_DMhostname->text(); - itsDMDatabase = ui.edit_DMdatabase->text(); - itsDMUserName = ui.edit_DMusername->text(); - itsDMPassword = ui.edit_DMpassword->text(); - - // publish tab - itsPublishLocal = ui.radioButton_PublishLocal->isChecked(); - itsLocalPublishPath = ui.lineEdit_PublishLocalPath->text(); - itsSchedulerAccountName = ui.lineEdit_PublishAccountName->text(); - itsWebServerName = ui.lineEdit_PublishWebServerName->text(); - itsPrivateKeyFile = ui.lineEdit_PublishPrivateKeyFile->text(); - itsWebServerPublishPath = ui.lineEdit_PublishWebServerDirectory->text(); - - Controller::theSchedulerSettings.defineScheduleAndStations(itsStations,getEarliestSchedulingDay(),getLatestSchedulingDay()); - - // save the preferred storage node per data produkt type and per project - Controller::theSchedulerSettings.setPreferredDataProductStorage(getPreferredDataProductStorage()); - Controller::theSchedulerSettings.setPreferredProjectStorage(getPreferredProjectStorage()); - // save the type of storage distribution - Controller::theSchedulerSettings.setStorageDistribution(static_cast<storageNodeDistribution>(ui.comboBoxDataDistribution->currentIndex())); - - emit actionSaveSettings(); -} - -void ScheduleSettingsDialog::updateSASConnectionSettings(void) { - itsSASHostName = ui.edit_SAShostname->text(); - itsSASDatabase = ui.edit_SASdatabase->text(); - itsSASUserName = ui.edit_SASusername->text(); - itsSASPassword = ui.edit_SASpassword->text(); - itsController->setSASConnectionSettings(itsSASUserName, itsSASPassword, itsSASDatabase, itsSASHostName); -} - -void ScheduleSettingsDialog::cancelClicked(void) { - this->close(); -} - -void ScheduleSettingsDialog::createActions(void) { - connect(ui.pb_Ok, SIGNAL(clicked()), this, SLOT(okClicked())); - connect(ui.pb_Cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); - connect(ui.pb_ClearStationList, SIGNAL(clicked()), this, - SLOT(clearStationList())); - connect(ui.pb_AddStation, SIGNAL(clicked()), this, SLOT(addStation())); - connect(ui.pb_DeleteStation, SIGNAL(clicked()), this, SLOT(removeStation())); - connect(ui.pushButton_BrowseLocalPath, SIGNAL(clicked()), this, SLOT(openLocalPathBrowseDialog())); - connect(ui.pushButton_BrowsePrivateKeyFile, SIGNAL(clicked()), this, SLOT(privateKeyBrowseDialog())); - connect(ui.radioButton_PublishLocal,SIGNAL(toggled(bool)), this, SLOT(enablePublishField())); - connect(ui.pb_RefreshStorageNodesInfo, SIGNAL(clicked()), this, SLOT(doRefreshStorageNodesInfo())); - connect(ui.pushButtonUpdateDefaultTemplates, SIGNAL(clicked()), this, SLOT(updateDefaultTemplates())); - connect(ui.listStations, SIGNAL(doubleClicked(const QModelIndex &)),this, SLOT(doubleClickedStation(const QModelIndex &))); - connect(ui.tableWidgetDataProductStorage, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(updateDataProductStorageItem(QTableWidgetItem *))); - connect(ui.tableWidgetProjectStorage, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(updateProjectsStorageItem(QTableWidgetItem *))); - connect(ui.pushButtonSelectDataProductStorage, SIGNAL(clicked()), this, SLOT(selectDataProductStorageNodes())); - connect(ui.pushButtonDeselectDataProductStorage, SIGNAL(clicked()), this, SLOT(deselectDataProductStorageNodes())); - connect(ui.pushButtonSelectProjectStorage, SIGNAL(clicked()), this, SLOT(selectProjectsStorageNodes())); - connect(ui.pushButtonDeselectProjectStorage, SIGNAL(clicked()), this, SLOT(deselectProjectsStorageNodes())); - connect(ui.treeWidgetStorageNodes, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(countStorageSelection(QTreeWidgetItem *, int))); - connect(ui.pushButtonAddDemixSource, SIGNAL(clicked()), this, SLOT(addRowToDemixSourceTable())); - connect(ui.pushButtonDeleteDemixSource, SIGNAL(clicked()), this, SLOT(deleteDemixSourceFromTable())); - connect(ui.tableWidgetDemixSources, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(checkDemixSourceItem())); -} - -void ScheduleSettingsDialog::checkDemixSourceItem(void) { - itsDemixSources.clear(); - QTableWidgetItem * item; - for (int row = 0; row < ui.tableWidgetDemixSources->rowCount(); ++row) { - item = ui.tableWidgetDemixSources->item(row,0); - if (itsDemixSources.contains(item->text())) { - QMessageBox::warning(this,"patch already exist","the demix source patch already exist"); - ui.tableWidgetDemixSources->setCurrentItem(item); - ui.tableWidgetDemixSources->editItem(item); - break; - } - else { - itsDemixSources.append(item->text()); - } - } -} - - -void ScheduleSettingsDialog::addRowToDemixSourceTable(void) { - int row(ui.tableWidgetDemixSources->rowCount()); - QTableWidgetItem *item(0); - if ((row == 0) || (!ui.tableWidgetDemixSources->item(row-1,0)->text().isEmpty())) { - ui.tableWidgetDemixSources->insertRow(ui.tableWidgetDemixSources->rowCount()); - item = new QTableWidgetItem(""); - ui.tableWidgetDemixSources->setItem(row, 0, item); - } - else { - item = ui.tableWidgetDemixSources->item(row-1,0); - } - ui.tableWidgetDemixSources->editItem(item); -} - -void ScheduleSettingsDialog::deleteDemixSourceFromTable(void) { - QList<QTableWidgetItem*> items(ui.tableWidgetDemixSources->selectedItems()); - for (QList<QTableWidgetItem*>::iterator it = items.begin(); it != items.end(); ++ it) { - ui.tableWidgetDemixSources->removeRow((*it)->row()); - } -} - - -void ScheduleSettingsDialog::countStorageSelection(QTreeWidgetItem */*item*/, int col) { - int count(0); - if (col == 0) { - QTreeWidgetItemIterator it(ui.treeWidgetStorageNodes, QTreeWidgetItemIterator::Checked); - while (*it++) { - ++count; - } - } - ui.lineEditNrOfSelectedNodes->setText(QString::number(count)); -} - -void ScheduleSettingsDialog::writeDefaultTemplatesToDialog(void) { - const std::map<quint32, DefaultTemplate> &templates(Controller::theSchedulerSettings.getDefaultTemplates()); - ui.tableWidgetDefaultTemplates->setRowCount(templates.size()); - QTableWidgetItem *item; - int row(0); - for (std::map<quint32, DefaultTemplate>::const_iterator it = templates.begin(); it != templates.end(); ++it) { - item = new QTableWidgetItem(QString::number(it->second.treeID)); - ui.tableWidgetDefaultTemplates->setItem(row, 0, item); - item = new QTableWidgetItem(it->second.name); - ui.tableWidgetDefaultTemplates->setItem(row, 1, item); - item = new QTableWidgetItem(it->second.processType); - ui.tableWidgetDefaultTemplates->setItem(row, 2, item); - item = new QTableWidgetItem(it->second.processSubtype); - ui.tableWidgetDefaultTemplates->setItem(row, 3, item); - item = new QTableWidgetItem(it->second.strategy); - ui.tableWidgetDefaultTemplates->setItem(row, 4, item); - item = new QTableWidgetItem(getSasTextState(it->second.status).c_str()); - ui.tableWidgetDefaultTemplates->setItem(row, 5, item); - item = new QTableWidgetItem(it->second.description); - ui.tableWidgetDefaultTemplates->setItem(row++, 6, item); - } - ui.tableWidgetDefaultTemplates->resizeColumnsToContents(); -} - -void ScheduleSettingsDialog::updateDefaultTemplates(bool quiet) { - updateSASConnectionSettings(); // get the possibly altered connection settings from the dialog - ui.tableWidgetDefaultTemplates->clearContents(); - ui.tableWidgetDefaultTemplates->setRowCount(0); - int result(itsController->checkSASconnection(ui.edit_SASusername->text(), ui.edit_SASpassword->text(), ui.edit_SASdatabase->text(), ui.edit_SAShostname->text())); - if ((result == 0) || (result == -2)) { - Controller::theSchedulerSettings.updateDefaultTemplates(); - writeDefaultTemplatesToDialog(); - if (result == -2) { - QApplication::beep(); - QMessageBox::warning(this, tr("No write permissions to SAS database"), - tr("Although the default templates have been successfully updated\nit appears that you don't have write permissions to the SAS database.\nPlease check the SAS user name and password")); - } - else if (!quiet) { - if (Controller::theSchedulerSettings.getSchedulerDefaultTemplate() == 0) { - QMessageBox::warning(this, tr("Scheduler default template does not exist"), - tr("Although the default templates have been successfully updated\nthe 'Scheduler default template' could not be found in the SAS database.\n\nPlease create this default template and name it:\n'Scheduler default template'")); - } - else { - QMessageBox::information(this, tr("Default templates updated"), - tr("Default templates have been successfully updated")); - } - } - } - else if (!quiet && (result == -1)) { - QApplication::beep(); - QMessageBox::critical(this, tr("No connection to SAS"), - tr("Could not connect to SAS database.\n Please check SAS connection settings.\n\nError:\n") + - itsController->lastSASError()); - } -} - -void ScheduleSettingsDialog::doRefreshStorageNodesInfo(void) { - // first get the list of allowed storage nodes (user could have changed them) - ui.pb_RefreshStorageNodesInfo->setEnabled(false); - - bool isConnected(itsController->isDataMonitorConnected()); - - std::vector<int> allowedStorageHosts; - QTreeWidgetItemIterator treeit(ui.treeWidgetStorageNodes); - while (*treeit) { - if ((*treeit)->checkState(0)) - allowedStorageHosts.push_back((*treeit)->data(0,Qt::UserRole).toInt()); // push the storage host id in allowedStorageHosts - ++treeit; - } - itsController->setAllowedStorageHosts(allowedStorageHosts); // updates the itsMayBeUsed fields of the storage nodes in the DM connection - - if (isConnected) { - ui.treeWidgetStorageNodes->clear(); - QApplication::setOverrideCursor(Qt::WaitCursor); - QCoreApplication::processEvents(); - itsController->refreshStorageNodesInfo(); - } - else { - itsController->disconnectDataMonitor(); // connection might have been lost, make sure the old connection is removed - QApplication::beep(); - if (QMessageBox::question(this, tr("Connect to Data Monitor"), tr( - "You are currently not connected to the Data Monitor. Do you want to connect now?"), - QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) { - if (itsController->connectToDataMonitor()) { - ui.treeWidgetStorageNodes->clear(); - QApplication::setOverrideCursor(Qt::WaitCursor); - QCoreApplication::processEvents(); - itsController->refreshStorageNodesInfo(); - } - else { - QApplication::restoreOverrideCursor(); - QMessageBox::critical(this, tr("No connection to Data Monitor"), - tr("Could not connect to the Data Monitor.\n Please check Data Monitor connection settings.")); - QCoreApplication::processEvents(); - } - } - else { // user doesn't want to connect to data monitor - ui.treeWidgetStorageNodes->clear(); -// QApplication::setOverrideCursor(Qt::WaitCursor); -// QCoreApplication::processEvents(); - itsController->refreshStorageNodesInfo(false); - } - } - ui.pb_RefreshStorageNodesInfo->setEnabled(true); -} - - -bool ScheduleSettingsDialog::checkLocalPublishPath(void) { - QString path = ui.lineEdit_PublishLocalPath->text(); - if (!path.isEmpty()) { - -#ifdef Q_OS_UNIX - if (path.right(1).compare("/") != 0) { - path += '/'; - } -#elif defined(Q_OS_WIN) - if (path.right(1).compare("\\") != 0) { - path += "\\"; - } -#endif - - } - else { - QMessageBox::warning(this, tr("Publish path not valid"), - tr("The local publish path cannot be left empty.\nPlease enter a local publish path.\n"), - QMessageBox::Ok, QMessageBox::Ok); - ui.tabWidget->setCurrentWidget(ui.tab_Publishing); - ui.lineEdit_PublishLocalPath->setFocus(); - return false; - } - - QFileInfo fi(path); - if (!fi.isDir()) { - QMessageBox::warning(this, tr("Publish path not valid"), - tr("The publish path does not point to an existing directory.\nPlease enter a correct directory path.\n"), - QMessageBox::Ok, QMessageBox::Ok); - ui.tabWidget->setCurrentWidget(ui.tab_Publishing); - ui.lineEdit_PublishLocalPath->setFocus(); - return false; - } - ui.lineEdit_PublishLocalPath->setText(path); - itsLocalPublishPath = path; - return true; -} - -void ScheduleSettingsDialog::openLocalPathBrowseDialog(void) { - QFileDialog dialog; - dialog.setFileMode(QFileDialog::Directory); - if (!itsLocalPublishPath.isEmpty()) { - QFileInfo prevPath(itsLocalPublishPath); - if (prevPath.exists() & prevPath.isDir()) { - dialog.setDirectory(itsLocalPublishPath); - } - } - dialog.exec(); - if (dialog.result() == QDialog::Accepted) { - QStringList files = dialog.selectedFiles(); - itsLocalPublishPath = *files.begin(); -#ifdef Q_OS_UNIX - itsLocalPublishPath += '/'; -#elif defined(Q_OS_WIN) - itsLocalPublishPath += "\\"; -#endif - ui.lineEdit_PublishLocalPath->setText(QDir::toNativeSeparators(itsLocalPublishPath)); - } -} - -void ScheduleSettingsDialog::privateKeyBrowseDialog(void) { - QFileDialog dialog; - if (!itsPrivateKeyFile.isEmpty()) { - QFileInfo prevFile(itsPrivateKeyFile); - if (prevFile.exists() & prevFile.isFile()) { - dialog.setDirectory(prevFile.absoluteDir()); - } - } - dialog.setNameFilter("private key files (*.ppk)"); - dialog.exec(); - if (dialog.result() == QDialog::Accepted) { - QStringList files = dialog.selectedFiles(); - itsPrivateKeyFile = *files.begin(); - ui.lineEdit_PublishPrivateKeyFile->setText(QDir::toNativeSeparators(itsPrivateKeyFile)); - } -} - -void ScheduleSettingsDialog::addStation(void) { - QString name = ui.lineEdit_StationName->text(); - QString longitude = ui.lineEdit_Longitude->text(); - QString latitude = ui.lineEdit_Latitude->text(); - double flat = latitude.toDouble(); - double flon = longitude.toDouble(); - if (ui.lineEdit_StationName->text().length() < 3) { - QMessageBox::warning(this, tr("Wrong station name"), tr( - "Station name should be at least 3 characters"), - QMessageBox::Ok); - ui.lineEdit_StationName->setFocus(); - } else if ((flat < -90.0) | (flat > 90)) { - QMessageBox::warning(this, tr("Wrong latitude"), tr( - "Latitude should be within the [-90,+90] range"), - QMessageBox::Ok); - ui.lineEdit_Latitude->setFocus(); - } else if ((flon < -180) | (flon > 180)) { - QMessageBox::warning(this, tr("Wrong longitude"), tr( - "Longitude should be within the [-180,+180] range"), - QMessageBox::Ok); - ui.lineEdit_Longitude->setFocus(); - } else { - std::pair<stationDefinitionsMap::iterator, bool> ret = - itsStations.insert(stationDefinitionsMap::value_type( - ui.lineEdit_StationName->text().toStdString(), - std::pair<double, double>(flat, flon))); - QStringList itemInfo; - itemInfo << name << latitude << longitude; - if (ret.second) { - QListWidgetItem *newStation = new QListWidgetItem(name + " (" + latitude + ", " + longitude + ")"); - newStation->setData(Qt::UserRole,itemInfo); - ui.listStations->addItem(newStation); - ui.pb_ClearStationList->setEnabled(true); - ui.pb_DeleteStation->setEnabled(true); - } else { - stationDefinitionsMap::iterator it = itsStations.find(ui.lineEdit_StationName->text().toStdString()); - it->second.first = flat; - it->second.second= flon; - QList<QListWidgetItem*> items = ui.listStations->findItems(ui.lineEdit_StationName->text(), Qt::MatchStartsWith); - if (!items.isEmpty()) { - items.front()->setText(ui.lineEdit_StationName->text() + " (" + latitude + ", " + longitude + ")"); - items.front()->setData(Qt::UserRole,itemInfo); - } -// QMessageBox::warning(this, tr("Station name exists"), tr( -// "Station name already exists"), QMessageBox::Ok); -// ui.lineEdit_StationName->setFocus(); - } - } -} - -void ScheduleSettingsDialog::removeStation(void) { - int idx(0); - QListWidgetItem * item2Delete; - std::string stationName; - - while (ui.listStations->item(idx)) { - if (ui.listStations->item(idx)->isSelected()) { - item2Delete = ui.listStations->takeItem(idx); - stationName = item2Delete->text().toStdString(); - stationName = stationName.substr(0, stationName.find_first_of(' ')); - itsStations.erase(stationName); - } - else ++idx; - } - - if (ui.listStations->count() == 0) { - ui.pb_ClearStationList->setEnabled(false); - ui.pb_DeleteStation->setEnabled(false); - } -} - -void ScheduleSettingsDialog::clearStationList(void) { - if (ui.listStations->count() > 0) { - if (QMessageBox::question(this, tr("Clear station list"), tr( - "Are you sure you want to clear the station list?"), - QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) { - ui.listStations->clear(); - itsStations.clear(); - ui.pb_ClearStationList->setEnabled(false); - ui.pb_DeleteStation->setEnabled(false); - } - } -} - -void ScheduleSettingsDialog::today(void) { - QDate day(QDate::currentDate()); - ui.dateEdit_Earliest->setDate(day); - int dur_months = ui.sb_ScheduleDurationMonths->value(); - ui.dateEdit_Latest->setMinimumDate(day.addDays(1)); - ui.dateEdit_Latest->setDate(day.addMonths(dur_months)); -} - -void ScheduleSettingsDialog::scheduleStartDateChanged(QDate start) { - ui.dateEdit_Earliest->blockSignals(true); - int dur_months = ui.sb_ScheduleDurationMonths->value(); - ui.dateEdit_Latest->setMinimumDate(start.addDays(1)); - // always set to first day of the week (monday) - ui.dateEdit_Earliest->setDate(ui.dateEdit_Earliest->date()); - // Removed restriction for mondays (next line) [AS] - // .addDays(-ui.dateEdit_Earliest->date().dayOfWeek() + 1)); - QDate endDate(start.addMonths(dur_months)); - endDate = endDate.addDays(7-endDate.dayOfWeek()); - ui.dateEdit_Latest->setDate(endDate); - ui.dateEdit_Earliest->blockSignals(false); -} - -void ScheduleSettingsDialog::scheduleEndDateChanged(QDate endDate) { - ui.dateEdit_Latest->blockSignals(true); - // always set to last day of the week (sunday) - endDate = endDate.addDays(7-endDate.dayOfWeek()); - ui.dateEdit_Latest->setDate(endDate); - ui.dateEdit_Latest->blockSignals(false); -} - -void ScheduleSettingsDialog::scheduleDurationChanged(int months) { - QDate start(ui.dateEdit_Earliest->date()); - ui.dateEdit_Latest->setDate(start.addMonths(months)); -} - -bool ScheduleSettingsDialog::checkSASsettings(void) { - if (ui.edit_SASusername->text().isEmpty()) { - QMessageBox::critical(this, tr("SAS user name not specified"), - tr("SAS user name is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - else if (ui.edit_SASpassword->text().isEmpty()) { - QMessageBox::critical(this, tr("SAS password not set"), - tr("SAS password is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - else if (ui.edit_SASdatabase->text().isEmpty()) { - QMessageBox::critical(this, tr("SAS database name not specified"), - tr("SAS database name is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - else if (ui.edit_SAShostname->text().isEmpty()) { - QMessageBox::critical(this, tr("SAS host name not specified"), - tr("SAS host name is not specified.\n Please specify this via menu 'Settings' -> menu option 'Schedule settings' -> 'SAS' tab")); - return false; - } - return true; -} - -int ScheduleSettingsDialog::testSASconnection(bool quietWhenOk) { - int result(-3); - if (checkSASsettings()) { - result = itsController->checkSASconnection(ui.edit_SASusername->text(), ui.edit_SASpassword->text(), ui.edit_SASdatabase->text(), ui.edit_SAShostname->text()); - if ((result == 0) & !quietWhenOk) { - QMessageBox::information(this, tr("Connection to SAS OK"), - tr("Connection tests successful. Connection to SAS is OK.")); - } - else if (result == -1) { - QApplication::beep(); - QMessageBox::critical(this, tr("No connection to SAS"), - tr("Could not connect to SAS database.\n Please check SAS connection settings.\n\nError:\n") + - itsController->lastSASError()); - } - else if (result == -2) { - QApplication::beep(); - QMessageBox::warning(this, tr("No write permissions to SAS database"), - tr("You don't have write permissions to the SAS database.\n Please check the SAS user name and password")); - } - } - return result; -} - - -void ScheduleSettingsDialog::updateStorageNodeInfoTree(const storageHostsMap &nodes, const statesMap &states, const hostPartitionsMap &hostPartitions) { - // Storage Node, Partition, Node Status, Total Size (kb), Free Space (kb) - QTreeWidgetItem *nodeItem, *childItem; - QList<QTreeWidgetItem *> items; - std::string hostName, hostStatus(" (Status unknown)"); - statesMap::const_iterator sit; - hostPartitionsMap::const_iterator pit; - QStringList itemValues; - int nodeStatus, total, free; - std::vector<std::pair<QTreeWidgetItem *, QProgressBar *> > progressBarVector; - int checkCount(0); - for (storageHostsMap::const_iterator hit = nodes.begin(); hit != nodes.end(); ++hit) { - hostName = hit->second.itsName; - nodeStatus = hit->second.itsStatus; - sit = states.find(nodeStatus); - if (sit != states.end()) - hostStatus = " (" + sit->second + ")"; - // node name and status - hostName += hostStatus; - nodeItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(hostName.c_str())); - nodeItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); - nodeItem->setData(0,Qt::UserRole,hit->second.itsID); // store the storage node ID in the treewidget item for later identification of allowed storage nodes - if (hit->second.itsMayBeUsed) { - nodeItem->setCheckState(0,Qt::Checked); - ++checkCount; - } - else { - nodeItem->setCheckState(0,Qt::Unchecked); - } - if (nodeStatus == 0) { // inactive status - nodeItem->setTextColor(0,Qt::red); - } - // see which partition IDs belong to this host - pit = hostPartitions.find(hit->second.itsID); - if (pit != hostPartitions.end()) { - for (dataPathsMap::const_iterator dpit = pit->second.begin(); dpit != pit->second.end(); ++dpit) { // iterate over all partitions for this host - itemValues << "" << dpit->second.first.c_str() /*partition name */ - << humanReadableUnits(dpit->second.second[0], SIZE_UNITS).c_str() /*total space*/ << humanReadableUnits(dpit->second.second[3], SIZE_UNITS).c_str() /*free space*/; - childItem = new QTreeWidgetItem(nodeItem, itemValues); - if (nodeStatus == 0) { // inactive status - childItem->setTextColor(1,Qt::red); - childItem->setTextColor(2,Qt::red); - childItem->setTextColor(3,Qt::red); - } - // create a progress bar showing the percentage of free space - QProgressBar *pBar = new QProgressBar(); - pBar->setMaximum(100); - - total = dpit->second.second[0] / 1000; - free = dpit->second.second[3] / 1000; - - if (total != 0) { - pBar->setValue((int)((float)(total-free) / total * 100)); - } - - progressBarVector.push_back(std::pair<QTreeWidgetItem *, QProgressBar *>(childItem, pBar)); - - itemValues.clear(); -// } - } - } - items.append(nodeItem); - } - ui.treeWidgetStorageNodes->insertTopLevelItems(0, items); - // add the progress bars, this can only be done now because the childitems have to be added to the treewidget before setItemWidget can be called - for (std::vector<std::pair<QTreeWidgetItem *, QProgressBar *> >::iterator pbit = progressBarVector.begin();pbit!=progressBarVector.end(); ++pbit) { - ui.treeWidgetStorageNodes->setItemWidget(pbit->first, 4, pbit->second); - } - - ui.treeWidgetStorageNodes->expandAll(); - ui.pb_RefreshStorageNodesInfo->setEnabled(true); - ui.lineEditNrOfSelectedNodes->setText(QString::number(checkCount)); - QApplication::restoreOverrideCursor(); -} - -void ScheduleSettingsDialog::updatePreferredStorageLists(const storageHostsMap &nodes) { - ui.tableWidgetDataProductStorage->blockSignals(true); - QTableWidgetItem *item; - preferredDataProductStorageMap::const_iterator pit; - const preferredDataProductStorageMap &preferredDataProductStorage(Controller::theSchedulerSettings.getPreferredDataProductStorage()); - int col(1); - ui.tableWidgetDataProductStorage->setColumnCount(nodes.size()+1); - for (int r = 0; r < NR_DATA_PRODUCT_TYPES; ++r) { - for (storageHostsMap::const_iterator hit = nodes.begin(); hit != nodes.end(); ++hit) { - item = new QTableWidgetItem(hit->second.itsName.c_str()); // storage node name - item->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsSelectable|Qt::ItemIsEnabled); - item->setData(Qt::UserRole,hit->second.itsID); // storage node ID - pit = preferredDataProductStorage.find(static_cast<dataProductTypes>(r)); - if (pit != preferredDataProductStorage.end()) { - if (std::find(pit->second.begin(), pit->second.end(), hit->second.itsID) != pit->second.end()) { - item->setCheckState(Qt::Checked); - item->setBackground(Qt::blue); - item->setForeground(Qt::white); - } - else { - item->setCheckState(Qt::Unchecked); - item->setBackground(Qt::white); - item->setForeground(Qt::black); - } - } - else { - item->setCheckState(Qt::Unchecked); - item->setBackground(Qt::white); - item->setForeground(Qt::black); - } - ui.tableWidgetDataProductStorage->setItem(r,col++,item); - } - col = 1; - } - ui.tableWidgetDataProductStorage->resizeColumnsToContents(); - ui.tableWidgetDataProductStorage->blockSignals(false); - - // project based preferred storage - ui.tableWidgetProjectStorage->blockSignals(true); - col = 1; - int row(0); - QString tooltip; - const campaignMap &projects(Controller::theSchedulerSettings.getCampaignList()); - const preferredProjectStorageMap &preferredProjectStorage(Controller::theSchedulerSettings.getPreferredProjectStorage()); - preferredProjectStorageMap::const_iterator prit; - ui.tableWidgetProjectStorage->setRowCount(projects.size()); - ui.tableWidgetProjectStorage->setColumnCount(nodes.size()+1); - bool project_found; - for (campaignMap::const_iterator projectIt = projects.begin(); projectIt != projects.end(); ++projectIt) { - item = new QTableWidgetItem(projectIt->first.c_str()); // project name - item->setData(Qt::UserRole,projectIt->second.id); // project ID - tooltip = QString(projectIt->first.c_str()) + "\n" + // project name - projectIt->second.title.c_str() + "\n" + - + "PI: " + projectIt->second.PriInvestigator.c_str() + "\n" + - + "CoI: " + projectIt->second.CoInvestigator.c_str() + "\n" + - + "contact: " + projectIt->second.contact.c_str(); - item->setToolTip(tooltip); - item->setFlags(Qt::ItemIsEnabled); - ui.tableWidgetProjectStorage->setItem(row,0,item); - prit = preferredProjectStorage.find(projectIt->second.id); - if (prit == preferredProjectStorage.end()) { - project_found = false; - } - else { - project_found = true; - } - for (storageHostsMap::const_iterator hit = nodes.begin(); hit != nodes.end(); ++hit) { - item = new QTableWidgetItem(hit->second.itsName.c_str()); // storage node name - item->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsSelectable|Qt::ItemIsEnabled); - item->setData(Qt::UserRole,hit->second.itsID); // storage node ID - item->setToolTip(tooltip); - if (project_found) { - if (std::find(prit->second.begin(), prit->second.end(), hit->first) != prit->second.end()) { - item->setCheckState(Qt::Checked); - item->setBackground(Qt::blue); - item->setForeground(Qt::white); - } - else { - item->setCheckState(Qt::Unchecked); - item->setBackground(Qt::white); - item->setForeground(Qt::black); - } - } - else { - item->setCheckState(Qt::Unchecked); - item->setBackground(Qt::white); - item->setForeground(Qt::black); - } - ui.tableWidgetProjectStorage->setItem(row,col++,item); - } - col = 1; - ++row; - } - ui.tableWidgetProjectStorage->resizeColumnsToContents(); - ui.tableWidgetProjectStorage->blockSignals(false); -} - -// get the preferred storage nodes for each data product from the dialog -preferredDataProductStorageMap ScheduleSettingsDialog::getPreferredDataProductStorage(void) const { - preferredDataProductStorageMap storageMap; - std::vector<int> nodeIDs; - for (int row = 0; row < ui.tableWidgetDataProductStorage->rowCount(); ++row) { // row number corresponds to the data product type enum value - for (int col = 1; col < ui.tableWidgetDataProductStorage->columnCount(); ++col) { - if (ui.tableWidgetDataProductStorage->item(row,col)->checkState() == Qt::Checked) { - nodeIDs.push_back(ui.tableWidgetDataProductStorage->model()->data(ui.tableWidgetDataProductStorage->model()->index(row,col),Qt::UserRole).toInt()); - } - } - storageMap[static_cast<dataProductTypes>(row)] = nodeIDs; - nodeIDs.clear(); - } - return storageMap; -} - -// get the preferred storage nodes for each project from the dialog -preferredProjectStorageMap ScheduleSettingsDialog::getPreferredProjectStorage(void) const { - preferredProjectStorageMap storageMap; - std::vector<int> nodeIDs; - int project_id; - for (int row = 0; row < ui.tableWidgetProjectStorage->rowCount(); ++row) { - project_id = ui.tableWidgetProjectStorage->model()->data(ui.tableWidgetProjectStorage->model()->index(row,0),Qt::UserRole).toInt(); - for (int col = 1; col < ui.tableWidgetProjectStorage->columnCount(); ++col) { - if (ui.tableWidgetProjectStorage->item(row,col)->checkState() == Qt::Checked) { - nodeIDs.push_back(ui.tableWidgetProjectStorage->model()->data(ui.tableWidgetProjectStorage->model()->index(row,col),Qt::UserRole).toInt()); - } - } - storageMap[project_id] = nodeIDs; - nodeIDs.clear(); - } - return storageMap; -} - -void ScheduleSettingsDialog::updateDataProductStorageItem(QTableWidgetItem *item) { - if (item->checkState() == Qt::Checked) { - item->setBackground(Qt::blue); - item->setForeground(Qt::white); - } - else { - item->setBackground(Qt::white); - item->setForeground(Qt::black); - } -} - -void ScheduleSettingsDialog::updateProjectsStorageItem(QTableWidgetItem *item) { - if (item->checkState() == Qt::Checked) { - item->setBackground(Qt::blue); - item->setForeground(Qt::white); - } - else { - item->setBackground(Qt::white); - item->setForeground(Qt::black); - } -} - -void ScheduleSettingsDialog::selectDataProductStorageNodes(void) { - QList<QTableWidgetItem*> items(ui.tableWidgetDataProductStorage->selectedItems()); - for (QList<QTableWidgetItem*>::iterator it = items.begin(); it != items.end(); ++it) { - (*it)->setCheckState(Qt::Checked); - (*it)->setBackground(Qt::blue); - (*it)->setForeground(Qt::white); - } -} - -void ScheduleSettingsDialog::deselectDataProductStorageNodes(void) { - QList<QTableWidgetItem*> items(ui.tableWidgetDataProductStorage->selectedItems()); - for (QList<QTableWidgetItem*>::iterator it = items.begin(); it != items.end(); ++it) { - (*it)->setCheckState(Qt::Unchecked); - (*it)->setBackground(Qt::white); - (*it)->setForeground(Qt::black); - } -} -void ScheduleSettingsDialog::selectProjectsStorageNodes(void) { - QList<QTableWidgetItem*> items(ui.tableWidgetProjectStorage->selectedItems()); - for (QList<QTableWidgetItem*>::iterator it = items.begin(); it != items.end(); ++it) { - (*it)->setCheckState(Qt::Checked); - (*it)->setBackground(Qt::blue); - (*it)->setForeground(Qt::white); - } -} - -void ScheduleSettingsDialog::deselectProjectsStorageNodes(void) { - QList<QTableWidgetItem*> items(ui.tableWidgetProjectStorage->selectedItems()); - for (QList<QTableWidgetItem*>::iterator it = items.begin(); it != items.end(); ++it) { - (*it)->setCheckState(Qt::Unchecked); - (*it)->setBackground(Qt::white); - (*it)->setForeground(Qt::black); - } -} - -/* - const storageNodeNameIDmap &storagenodes = Controller::theSchedulerSettings.getStorageNodesNameIDmapping(); - const std::map<int, storagePartitionsMap> &partitions = Controller::theSchedulerSettings.getStoragePartitionsMap(); - std::map<int, storagePartitionsMap>::const_iterator pit; - QTreeWidgetItem *nodeItem; - QStringList itemValues; - for (storageNodeNameIDmap::const_iterator stit = storagenodes.begin(); stit != storagenodes.end(); ++stit) { - nodeItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(stit->second.c_str())); - pit = partitions.find(stit->first); - for (storagePartitionsMap::const_iterator ppit = pit->second.begin(); ppit != pit->second.end(); ++ppit) { - // Storage Node, Partition, Node Status, Total Size (kb), Free Space (kb) - itemValues << "" << ppit->second.first << itsController->getStorageNodeStatusStr(stit->first) - << QString::number(ppit->second.second) << itsController->getStorageNodeSpaceRemaining(stit->first, pit->first); - new QTreeWidgetItem(nodeItem, itemValues); - itemValues.clear(); - } - items.append(nodeItem); - } - ui.treeWidgetStorageNodes->insertTopLevelItems(0, items); -*/ diff --git a/SAS/Scheduler/src/schedulesettingsdialog.h b/SAS/Scheduler/src/schedulesettingsdialog.h deleted file mode 100644 index f75bb572ada3ccfd07ca6fb73b38ff9266dd8763..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulesettingsdialog.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * schedulesettingsdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 5-march-2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/schedulesettingsdialog.h $ - * - */ - -#ifndef SCHEDULESETTINGSDIALOG_H -#define SCHEDULESETTINGSDIALOG_H - -#include <QDialog> -#include "ui_schedulesettingsdialog.h" -#include "lofar_scheduler.h" -#include "astrodate.h" -#include "astrotime.h" -#include "DataMonitorConnection.h" -#include "schedulersettings.h" -class QString; -class Controller; - -extern const char *storage_distributions_str[NR_STORAGE_DISTRIBUTIONS]; - -class ScheduleSettingsDialog : public QDialog -{ - Q_OBJECT - -public: - ScheduleSettingsDialog(Controller *controller); - ~ScheduleSettingsDialog(); - - const stationDefinitionsMap & getStationsList(void) const {return itsStations;} - AstroDate getEarliestSchedulingDay(void) const; //{return itsEarliestDay;} - AstroDate getLatestSchedulingDay(void) const; // {return itsLatestDay;} - unsigned getMaxNrOptimizeIterations(void) const {return itsMaxNrOptimizeIterations;} - AstroTime getMinimumTimeBetweenObservations(void) const; // const {return itsMinTimeBetweenObservations;} - bool getUserAcceptedPenaltyEnabled(void) const {return itsUserAcceptedPenaltyEnabled;} - unsigned int getUserAcceptedPenalty(void) const {return itsUserAcceptedPenalty;} - bool getmaxNrOptimizationsEnabled(void) const {return itsMaxNrOptimizationsEnabled;} - unsigned getMaxNrOptimizations(void) const {return itsMaxNrOptimizeIterations;} - bool getLoadDefaultSettingsOnStartUp(void) const {return itsLoadDefaultSettings;} - bool getIsTestEnvironment(void) const {return itsIsTestEnvironment;} - unsigned getShortTermScheduleDurationWeeks(void) const {return itsShortTermScheduleDuration;} - unsigned getScheduleDurationMonths(void) const {return itsScheduleDuration;} - bool getAllowUnscheduleFixedTasks(void) const {return itsAllowUnscheduleFixedTasks;} - quint16 getMaxNrOfFilesPerStorageNode(void) const {return itsMaxNrOfFilesPerStorageNode;} - const QString &getSASDatabase(void) const {return itsSASDatabase;} - const QString &getSASHostName(void) const {return itsSASHostName;} - const QString &getSASUserName(void) const {return itsSASUserName;} - const QString &getSASPassword(void) const {return itsSASPassword;} - int getSASDefaultTreeID(void) const {return itsSASDefaultTree;} - const QString &getDMDatabase(void) const {return itsDMDatabase;} - const QString &getDMHostName(void) const {return itsDMHostName;} - const QString &getDMUserName(void) const {return itsDMUserName;} - const QString &getDMPassword(void) const {return itsDMPassword;} - bool getAutoPublish(void) const {return ui.checkBoxAutoPublish->isChecked();} - const QString &getLocalPublishPath(void) const {return itsLocalPublishPath;} - const QString &getSchedulerAccountName(void) const {return itsSchedulerAccountName;} - const QString &getPrivateKeyFile(void) const {return itsPrivateKeyFile;} - const QString &getWebServerName(void) const {return itsWebServerName;} - const QString &getWebServerPublishPath(void) const {return itsWebServerPublishPath;} -// const QString &getFileNameMask(void) const {return itsFileNameMask;} - bool publishLocal(void) const {return itsPublishLocal;} - unsigned getMinimumNrOfStorageNodes(void) const {return itsMinNrOfStorageNodes;} - const double &getStorageNodeBandWidth(void) const {return itsStorageNodeBandWidth;} - const double &getRaidMaxWriteSpeed(void) const {return itsStorageRaidWriteSpeed;} - const QStringList &getDemixSources(void) const {return itsDemixSources;} - - //update the storage nodes capacity info box - void updateStorageNodeInfoTree(const storageHostsMap &nodes, const statesMap &states, const hostPartitionsMap &hostPartitions); - void updatePreferredStorageLists(const storageHostsMap &nodes); -// const Ui::ScheduleSettingsDialogClass &getSettingsGUIClass(void) const {return ui;}; - - void setStationList(const stationDefinitionsMap &stations) {itsStations = stations;} - void setEarliestSchedulingDay(const AstroDate &day) {itsEarliestDay.setDate(day.getYear(), day.getMonth(), day.getDay());} - void setLatestSchedulingDay(const AstroDate &day) {itsLatestDay.setDate(day.getYear(), day.getMonth(), day.getDay());} - void setMinimumTimeBetweenTasks(const AstroTime &t) {itsMinTimeBetweenTasks.setHMS(t.getHours(), t.getMinutes(), t.getSeconds());} - void setUserAcceptedPenalty(unsigned int penalty) {itsUserAcceptedPenalty = penalty;} - void setUserAcceptedPenaltyEnabled(bool userPenaltyEnabled) {itsUserAcceptedPenaltyEnabled = userPenaltyEnabled;} - void setMaxNrOptimizations(unsigned int maxOptimations) {itsMaxNrOptimizeIterations = maxOptimations;} - void setmaxNrOptimizationsEnabled(bool maxOptEnabled) {itsMaxNrOptimizationsEnabled = maxOptEnabled;} - void setLoadDefaultSettingsOnStartUp(bool loadDefault) {itsLoadDefaultSettings = loadDefault;} - void setIsTestEnvironemnt(bool is_test_environment) {itsIsTestEnvironment = is_test_environment;} - void setShortTermScheduleDurationWeeks(unsigned weeks) {itsShortTermScheduleDuration = weeks;} - void setScheduleDurationMonths(unsigned months) {itsScheduleDuration = months;} - void setAllowUnscheduleFixedTasks(bool allow) {itsAllowUnscheduleFixedTasks = allow;} - void setMaxNrOfFilesPerStorageNode(quint16 nr_files) {itsMaxNrOfFilesPerStorageNode = nr_files;} - void setSASUserName(const std::string &SAS_username) {itsSASUserName = SAS_username.c_str();} - void setSASPassword(const std::string &SAS_password) {itsSASPassword = SAS_password.c_str();} - void setSASDatabase(const std::string &SAS_database) {itsSASDatabase = SAS_database.c_str();} - void setSASHostName(const std::string &SAS_hostname) {itsSASHostName = SAS_hostname.c_str();} - void setSASDefaultTreeID(int treeID) {itsSASDefaultTree = treeID;} - void setDMUserName(const std::string &DM_username) {itsDMUserName = DM_username.c_str();} - void setDMPassword(const std::string &DM_password) {itsDMPassword = DM_password.c_str();} - void setDMDatabase(const std::string &DM_database) {itsDMDatabase = DM_database.c_str();} - void setDMHostName(const std::string &DM_hostname) {itsDMHostName = DM_hostname.c_str();} - void setAutoPublish(bool enabled) {ui.checkBoxAutoPublish->setChecked(enabled);} - void setLocalPublishPath(const std::string &publish_path) {itsLocalPublishPath = publish_path.c_str();} - void setSchedulerAccountName(const std::string &account_name) {itsSchedulerAccountName = account_name.c_str();} - void setPrivateKeyFile(const std::string &private_key_file) {itsPrivateKeyFile = private_key_file.c_str();} - void setWebServerName(const std::string &server_name) {itsWebServerName = server_name.c_str();} - void setWebServerPublishPath(const std::string &publish_path) {itsWebServerPublishPath = publish_path.c_str();} -// void setFileNameMask(const std::string &file_name_mask) {itsFileNameMask = file_name_mask.c_str();} - void setPublishLocal(bool local) {itsPublishLocal = local;} - void setMinimumNrOfStorageNodes(unsigned min_storage_nodes) {itsMinNrOfStorageNodes = min_storage_nodes;} - void setStorageNodeBandwidth(const double &bandwidth) {itsStorageNodeBandWidth = bandwidth;} - void setRaidMaxWriteSpeed(const double &write_speed_kBs) {itsStorageRaidWriteSpeed = write_speed_kBs;} - void stopStorageWaitCursor(void) { - ui.pb_RefreshStorageNodesInfo->setEnabled(true); - QApplication::restoreOverrideCursor(); - } - -private: - void createActions(void); -// std::pair<std::string, std::pair<double, double> > getStationData(const QString &s) const; - bool checkLocalPublishPath(void); - bool checkSASsettings(void); - int checkSASconnection(void); - void updateSASConnectionSettings(void); // gets the sas connection settings from the dialog - void writeDefaultTemplatesToDialog(void); - preferredDataProductStorageMap getPreferredDataProductStorage(void) const; - preferredProjectStorageMap getPreferredProjectStorage(void) const; - -signals: - void actionSaveSettings(void) const; - -public slots: - void show(void); - void enablePublishField(void); - -private slots: - void addRowToDemixSourceTable(void); - void deleteDemixSourceFromTable(void); - void checkDemixSourceItem(void); - void openLocalPathBrowseDialog(void); - void privateKeyBrowseDialog(void); - void okClicked(void); - void cancelClicked(void); - void addStation(void); - void removeStation(void); - void clearStationList(void); - void today(void); - void scheduleStartDateChanged(QDate); - void scheduleEndDateChanged(QDate endDate); - void scheduleDurationChanged(int); - int testSASconnection(bool quietWhenOk = false); - void doRefreshStorageNodesInfo(void); - void updateDefaultTemplates(bool quiet = false); - void doubleClickedStation(const QModelIndex &); - void updateDataProductStorageItem(QTableWidgetItem *); - void updateProjectsStorageItem(QTableWidgetItem *); - void selectDataProductStorageNodes(void); - void deselectDataProductStorageNodes(void); - void selectProjectsStorageNodes(void); - void deselectProjectsStorageNodes(void); - void countStorageSelection(QTreeWidgetItem *, int); - -private: - Ui::ScheduleSettingsDialogClass ui; - Controller *itsController; - stationDefinitionsMap itsStations; - QDate itsEarliestDay, itsLatestDay; - QTime itsMinTimeBetweenTasks; - QStringList itsDemixSources; - unsigned itsUserAcceptedPenalty, itsMaxNrOptimizeIterations; - unsigned itsShortTermScheduleDuration, itsScheduleDuration, itsMinNrOfStorageNodes; - double itsStorageNodeBandWidth, itsStorageRaidWriteSpeed; - bool itsUserAcceptedPenaltyEnabled, itsMaxNrOptimizationsEnabled; - bool itsAllowUnscheduleFixedTasks, itsLoadDefaultSettings, itsIsTestEnvironment; - QString itsSASDatabase, itsSASHostName, itsSASUserName, itsSASPassword; - QString itsDMDatabase, itsDMHostName, itsDMUserName, itsDMPassword; - quint16 itsMaxNrOfFilesPerStorageNode; - int itsSASDefaultTree; - // publish settings - QString itsLocalPublishPath, itsWebServerPublishPath, itsWebServerName, itsSchedulerAccountName, - itsPrivateKeyFile; - bool itsPublishLocal; - storageNodeDistribution itsDataDistributionScheme; - -}; - -#endif // SCHEDULESETTINGSDIALOG_H diff --git a/SAS/Scheduler/src/schedulesettingsdialog.ui b/SAS/Scheduler/src/schedulesettingsdialog.ui deleted file mode 100644 index 96a4301304e94af75875f60ca6c7fba56780c5c0..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/schedulesettingsdialog.ui +++ /dev/null @@ -1,1604 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>ScheduleSettingsDialogClass</class> - <widget class="QDialog" name="ScheduleSettingsDialogClass"> - <property name="windowModality"> - <enum>Qt::NonModal</enum> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>830</width> - <height>638</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>610</width> - <height>530</height> - </size> - </property> - <property name="windowTitle"> - <string>Settings</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <property name="modal"> - <bool>true</bool> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QTabWidget" name="tabWidget"> - <property name="tabShape"> - <enum>QTabWidget::Rounded</enum> - </property> - <property name="currentIndex"> - <number>1</number> - </property> - <widget class="QWidget" name="tab_General"> - <attribute name="title"> - <string>General</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_7"> - <item row="0" column="0"> - <widget class="QCheckBox" name="cb_LoadDefaultSettings"> - <property name="toolTip"> - <string>when selected the default scheduler settings will be loaded at startup</string> - </property> - <property name="text"> - <string>Load previously saved default settings on start up</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QCheckBox" name="cb_LoadSASscheduleOnStartUp"> - <property name="toolTip"> - <string>when selected downloads the current schedule from SAS at startup</string> - </property> - <property name="text"> - <string>Load current schedule from SAS on start up</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <spacer name="verticalSpacer_5"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="cb_LoadStorageNodesOnStartUp"> - <property name="toolTip"> - <string>when selected updates the storage nodes information from the data monitor at startup</string> - </property> - <property name="text"> - <string>Load storage nodes from Data Monitor on start up</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QCheckBox" name="checkBoxTestEnvironment"> - <property name="toolTip"> - <string>Switch to test environment settings. -When enabled the observation id 'Lxxxxx' and the file names will start with a 'T' in stead of a 'L' -to make it easy to recognise files and directories written by the test system.</string> - </property> - <property name="text"> - <string>Test Environment Mode settings</string> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Schedule"> - <attribute name="title"> - <string>Schedule</string> - </attribute> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Schedule earliest date</string><!--Used to be Mondays only [AS]--> - </property> - </widget> - </item> - <item row="6" column="0" colspan="2"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Schedule latest date (sunday)</string> - </property> - </widget> - </item> - <item row="6" column="3"> - <widget class="QDateEdit" name="dateEdit_Latest"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the last day of the schedule</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="7" column="0" colspan="3"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Minimum time between observations</string> - </property> - </widget> - </item> - <item row="7" column="3" colspan="2"> - <widget class="QTimeEdit" name="timeEdit_MinTimeBetweenObservations"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the minimum distance (time) to keep between tasks</string> - </property> - <property name="locale"> - <locale language="English" country="UnitedStates"/> - </property> - <property name="buttonSymbols"> - <enum>QAbstractSpinBox::UpDownArrows</enum> - </property> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - <item row="0" column="3" colspan="2"> - <widget class="QDateEdit" name="dateEdit_Earliest"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>The first day of the schedule. -Will automatically select the monday of the week you select.</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QPushButton" name="pb_Today"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>30</height> - </size> - </property> - <property name="toolTip"> - <string>set the start day of the schedule to the monday of the current week</string> - </property> - <property name="text"> - <string>Current week</string> - </property> - </widget> - </item> - <item row="3" column="0" colspan="3"> - <widget class="QLabel" name="label_10"> - <property name="text"> - <string>Short term schedule duration (weeks)</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QSpinBox" name="sp_ShortTermDurationWeeks"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>the short term schedule duration</string> - </property> - <property name="maximum"> - <number>12</number> - </property> - <property name="value"> - <number>2</number> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Schedule duration (months)</string> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="QSpinBox" name="sb_ScheduleDurationMonths"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>the schedule duration in months</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="value"> - <number>6</number> - </property> - </widget> - </item> - <item row="8" column="0"> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="4"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Stations"> - <attribute name="title"> - <string>Stations</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="0" rowspan="3" colspan="3"> - <widget class="QListWidget" name="listStations"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>154</height> - </size> - </property> - <property name="focusPolicy"> - <enum>Qt::NoFocus</enum> - </property> - <property name="toolTip"> - <string>the list of known stations. -double click a station to edit its coordinates</string> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> - <property name="resizeMode"> - <enum>QListView::Adjust</enum> - </property> - <property name="sortingEnabled"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="QPushButton" name="pb_ClearStationList"> - <property name="maximumSize"> - <size> - <width>80</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>delete all stations</string> - </property> - <property name="text"> - <string>Clear list</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_6"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>10</height> - </size> - </property> - <property name="text"> - <string>Name</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLabel" name="label_7"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>10</height> - </size> - </property> - <property name="text"> - <string>Latitude</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QLabel" name="label_8"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>10</height> - </size> - </property> - <property name="text"> - <string>Longitude</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLineEdit" name="lineEdit_StationName"> - <property name="toolTip"> - <string>designation of the station</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QLineEdit" name="lineEdit_Latitude"> - <property name="toolTip"> - <string>latitude coordinate of the station</string> - </property> - </widget> - </item> - <item row="4" column="2"> - <widget class="QLineEdit" name="lineEdit_Longitude"> - <property name="toolTip"> - <string>longitude coordinate of the station</string> - </property> - </widget> - </item> - <item row="4" column="3"> - <widget class="QPushButton" name="pb_AddStation"> - <property name="maximumSize"> - <size> - <width>80</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Add/Update</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QPushButton" name="pb_DeleteStation"> - <property name="maximumSize"> - <size> - <width>80</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>delete the selected station(s)</string> - </property> - <property name="text"> - <string>Delete</string> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Pipelines"> - <attribute name="title"> - <string>Pipelines</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_10"> - <item row="0" column="0"> - <widget class="QLabel" name="label_27"> - <property name="text"> - <string>Sources that can be demixed:</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <spacer name="horizontalSpacer_8"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="1" column="0" rowspan="3"> - <widget class="QTableWidget" name="tableWidgetDemixSources"> - <property name="toolTip"> - <string>Source patches that can be demixed and which are defined in the existing sky models</string> - </property> - <property name="rowCount"> - <number>0</number> - </property> - <property name="columnCount"> - <number>1</number> - </property> - <attribute name="horizontalHeaderVisible"> - <bool>false</bool> - </attribute> - <attribute name="horizontalHeaderDefaultSectionSize"> - <number>100</number> - </attribute> - <attribute name="horizontalHeaderStretchLastSection"> - <bool>true</bool> - </attribute> - <attribute name="verticalHeaderVisible"> - <bool>false</bool> - </attribute> - <column/> - </widget> - </item> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButtonAddDemixSource"> - <property name="text"> - <string>Add</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QPushButton" name="pushButtonDeleteDemixSource"> - <property name="text"> - <string>Delete</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <spacer name="verticalSpacer_4"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_StorageNodes"> - <attribute name="title"> - <string>Storage</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_8"> - <item row="1" column="0" colspan="6"> - <widget class="QTreeWidget" name="treeWidgetStorageNodes"> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_20"> - <property name="text"> - <string>Raid set write speed (MB/sec)</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_21"> - <property name="text"> - <string>Network bandwidth to single node:</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="QLineEdit" name="lineEditStorageNodeBandwidth"> - <property name="minimumSize"> - <size> - <width>50</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the network bandwidth limit to a single storage node</string> - </property> - </widget> - </item> - <item row="5" column="2"> - <widget class="QRadioButton" name="radioButtonMbs"> - <property name="text"> - <string>Mb/s</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QLineEdit" name="lineEditStorageRaidWriteSpeed"> - <property name="toolTip"> - <string>the write speed limit for a single raid set (MB/sec)</string> - </property> - </widget> - </item> - <item row="4" column="4"> - <widget class="QLabel" name="label_26"> - <property name="text"> - <string>Maximum fill percentage:</string> - </property> - </widget> - </item> - <item row="5" column="4"> - <widget class="QLabel" name="label_9"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Maximum files to single node:</string> - </property> - </widget> - </item> - <item row="5" column="5"> - <widget class="QSpinBox" name="spinBoxMaxNrFilesToNode"> - <property name="toolTip"> - <string>the maximum number of files to write to a single storage node (per task)</string> - </property> - <property name="maximum"> - <number>999</number> - </property> - </widget> - </item> - <item row="2" column="5"> - <widget class="QPushButton" name="pb_RefreshStorageNodesInfo"> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>updates the storage nodes info (disk space and status) from the data monitor</string> - </property> - <property name="text"> - <string>Refresh</string> - </property> - </widget> - </item> - <item row="5" column="3"> - <widget class="QRadioButton" name="radioButtonGbs"> - <property name="text"> - <string>Gb/s</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="4" column="5"> - <widget class="QSpinBox" name="spinBoxStorageFillPercentage"> - <property name="toolTip"> - <string>the maximum fill percentage of each storage node (as a percentage of total space)</string> - </property> - <property name="maximum"> - <number>100</number> - </property> - <property name="value"> - <number>90</number> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_25"> - <property name="text"> - <string>Selected nr. of nodes:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="lineEditNrOfSelectedNodes"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab"> - <attribute name="title"> - <string>Data distribution</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_9"> - <item row="6" column="0" colspan="7"> - <widget class="QTableWidget" name="tableWidgetDataProductStorage"/> - </item> - <item row="7" column="0" colspan="2"> - <widget class="QLabel" name="label_23"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Preferred storage nodes based on project</string> - </property> - </widget> - </item> - <item row="8" column="0" colspan="7"> - <widget class="QTableWidget" name="tableWidgetProjectStorage"/> - </item> - <item row="3" column="0" colspan="3"> - <widget class="QLabel" name="label_24"> - <property name="minimumSize"> - <size> - <width>250</width> - <height>0</height> - </size> - </property> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Preferred storage nodes based on data product</string> - </property> - </widget> - </item> - <item row="3" column="6"> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="7" column="6"> - <widget class="QPushButton" name="pushButtonUpdateProjects"> - <property name="maximumSize"> - <size> - <width>110</width> - <height>90</height> - </size> - </property> - <property name="text"> - <string>Update projects</string> - </property> - </widget> - </item> - <item row="7" column="5"> - <widget class="QPushButton" name="pushButtonDeselectProjectStorage"> - <property name="maximumSize"> - <size> - <width>65</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>deselect</string> - </property> - </widget> - </item> - <item row="7" column="3"> - <widget class="QPushButton" name="pushButtonSelectProjectStorage"> - <property name="maximumSize"> - <size> - <width>65</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>select</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QPushButton" name="pushButtonSelectDataProductStorage"> - <property name="maximumSize"> - <size> - <width>65</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>select</string> - </property> - </widget> - </item> - <item row="3" column="5"> - <widget class="QPushButton" name="pushButtonDeselectDataProductStorage"> - <property name="maximumSize"> - <size> - <width>65</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>deselect</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_22"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Distribution scheme:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="0"> - <spacer name="horizontalSpacer_5"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>1</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="1"> - <spacer name="horizontalSpacer_6"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>1</height> - </size> - </property> - </spacer> - </item> - <item row="1" column="1" colspan="3"> - <widget class="QComboBox" name="comboBoxDataDistribution"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - </widget> - </item> - <item row="0" column="2"> - <spacer name="horizontalSpacer_7"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>1</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Optimize"> - <attribute name="title"> - <string>Optimize</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="0" column="0"> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Optimization stop criteria</string> - </property> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="0" column="0"> - <widget class="QCheckBox" name="cbMaxNrOptimizations"> - <property name="toolTip"> - <string>the maximum number of optimization iterations after which the optimization stops. -Uncheck this box to disable the maximum number of optimizations. -Optimization will then stop after one of the other stopping criteria -have been met or when user interrupts the optimization. -The best schedule thus far will be used.</string> - </property> - <property name="text"> - <string>Maximum number of optimization iterations</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="cbUserAcceptedPenalty"> - <property name="toolTip"> - <string>Stop optimization when total penalty falls below the given value. Best schedule thus far will be used. -Uncheck to disable the user accepted penalty</string> - </property> - <property name="text"> - <string>User accepted penalty</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="sbMaxNrOptimizations"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>60</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the maximum number of iterations when optimizing the schedule</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>5000</number> - </property> - <property name="value"> - <number>1000</number> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QSpinBox" name="sbUserAcceptedPenalty"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>60</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>specifies a good enough penalty value for optimizing the schedule</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Publishing"> - <attribute name="title"> - <string>Publishing</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_6"> - <item row="3" column="0"> - <widget class="QLabel" name="label_PublishLocalPath"> - <property name="text"> - <string>Publish local path:</string> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QLineEdit" name="lineEdit_PublishLocalPath"> - <property name="toolTip"> - <string>the local path to save the published html files</string> - </property> - </widget> - </item> - <item row="7" column="2" colspan="2"> - <widget class="QLineEdit" name="lineEdit_PublishWebServerDirectory"> - <property name="statusTip"> - <string>the directory on the web server to store the published schedule</string> - </property> - </widget> - </item> - <item row="7" column="0"> - <widget class="QLabel" name="label_PublishSCPCommand"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> - </property> - <property name="text"> - <string>Publish directory on server:</string> - </property> - </widget> - </item> - <item row="9" column="0"> - <spacer name="verticalSpacer_3"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0"> - <widget class="QRadioButton" name="radioButton_PublishLocal"> - <property name="text"> - <string>Publish locally</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_PublishWebServerPath"> - <property name="text"> - <string>Publish web server:</string> - </property> - </widget> - </item> - <item row="6" column="2" colspan="2"> - <widget class="QLineEdit" name="lineEdit_PublishWebServerName"> - <property name="statusTip"> - <string>the web server to upload the published schedule</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QRadioButton" name="radioButton_PublishToWeb"> - <property name="text"> - <string>Publish to webserver</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_14"> - <property name="text"> - <string>Scheduler account name:</string> - </property> - </widget> - </item> - <item row="4" column="2" colspan="2"> - <widget class="QLineEdit" name="lineEdit_PublishAccountName"> - <property name="toolTip"> - <string>the account name to use for uploading the schedule</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QPushButton" name="pushButton_BrowseLocalPath"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Browse</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_PublishPrivateKeyFile"> - <property name="text"> - <string>Private key file</string> - </property> - </widget> - </item> - <item row="5" column="2"> - <widget class="QLineEdit" name="lineEdit_PublishPrivateKeyFile"/> - </item> - <item row="5" column="3"> - <widget class="QPushButton" name="pushButton_BrowsePrivateKeyFile"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Browse</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="checkBoxAutoPublish"> - <property name="toolTip"> - <string>Auto publish to webserver. -(This setting is not saved to the default settings)</string> - </property> - <property name="text"> - <string>Auto publish with every SAS synchronize</string> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_SAS"> - <attribute name="title"> - <string>SAS</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_5"> - <item row="0" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>SAS host name:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="edit_SAShostname"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the host that holds the SAS database</string> - </property> - <property name="whatsThis"> - <string>The name or IP-address of the host on which the SAS database is running.</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_11"> - <property name="text"> - <string>Database name:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="edit_SASdatabase"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the name of the database</string> - </property> - <property name="whatsThis"> - <string>The name of the SAS database itself.</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_12"> - <property name="text"> - <string>SAS user name:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="edit_SASusername"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the internal database user that has write rights </string> - </property> - <property name="whatsThis"> - <string>The user name to get access to the database.</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_13"> - <property name="text"> - <string>SAS password:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLineEdit" name="edit_SASpassword"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>password for the internal user of the database</string> - </property> - <property name="whatsThis"> - <string>The password belonging to the SAS database account.</string> - </property> - <property name="echoMode"> - <enum>QLineEdit::Password</enum> - </property> - </widget> - </item> - <item row="7" column="0" colspan="2"> - <widget class="QTableWidget" name="tableWidgetDefaultTemplates"> - <property name="toolTip"> - <string>Shows the existing default templates in the SAS database</string> - </property> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - <property name="sortingEnabled"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="5" column="0" colspan="2"> - <widget class="QLabel" name="label_15"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Default templates:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="8" column="0"> - <widget class="QPushButton" name="pushButtonUpdateDefaultTemplates"> - <property name="text"> - <string>Update</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QPushButton" name="pushButtonTestSASConnection"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Test connection</string> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_DataMonitor"> - <attribute name="title"> - <string>Data Monitor</string> - </attribute> - <layout class="QFormLayout" name="formLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label_18"> - <property name="text"> - <string>DM host name:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="edit_DMhostname"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the host name of the machine that holds the data monitor database</string> - </property> - <property name="whatsThis"> - <string>The name or IP-address of the host on which the Data Monitor database is running.</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_19"> - <property name="text"> - <string>Database name:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="edit_DMdatabase"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the database name of the data monitor</string> - </property> - <property name="whatsThis"> - <string>The name of the Data Monitor database itself.</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_16"> - <property name="text"> - <string>DM user name:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="edit_DMusername"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the data monitor user name</string> - </property> - <property name="whatsThis"> - <string>The user name to get access to the database.</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_17"> - <property name="text"> - <string>DM password:</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLineEdit" name="edit_DMpassword"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>22</height> - </size> - </property> - <property name="statusTip"> - <string>the data monitor user password</string> - </property> - <property name="whatsThis"> - <string>The password belonging to the Data Monitor database account.</string> - </property> - <property name="echoMode"> - <enum>QLineEdit::Password</enum> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QPushButton" name="pushButtonTestDataMonitorConnection"> - <property name="text"> - <string>Test connection</string> - </property> - </widget> - </item> - </layout> - </widget> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pb_Cancel"> - <property name="maximumSize"> - <size> - <width>70</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pb_Ok"> - <property name="maximumSize"> - <size> - <width>70</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>OK</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <tabstops> - <tabstop>cb_LoadDefaultSettings</tabstop> - <tabstop>pb_Today</tabstop> - <tabstop>dateEdit_Earliest</tabstop> - <tabstop>sb_ScheduleDurationMonths</tabstop> - <tabstop>sp_ShortTermDurationWeeks</tabstop> - <tabstop>dateEdit_Latest</tabstop> - <tabstop>timeEdit_MinTimeBetweenObservations</tabstop> - <tabstop>lineEdit_StationName</tabstop> - <tabstop>lineEdit_Latitude</tabstop> - <tabstop>lineEdit_Longitude</tabstop> - <tabstop>pb_AddStation</tabstop> - <tabstop>pb_DeleteStation</tabstop> - <tabstop>pb_ClearStationList</tabstop> - <tabstop>cbMaxNrOptimizations</tabstop> - <tabstop>cbUserAcceptedPenalty</tabstop> - <tabstop>pb_Cancel</tabstop> - <tabstop>pb_Ok</tabstop> - <tabstop>tabWidget</tabstop> - </tabstops> - <resources/> - <connections> - <connection> - <sender>cbMaxNrOptimizations</sender> - <signal>clicked(bool)</signal> - <receiver>sbMaxNrOptimizations</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>206</x> - <y>95</y> - </hint> - <hint type="destinationlabel"> - <x>400</x> - <y>98</y> - </hint> - </hints> - </connection> - <connection> - <sender>cbUserAcceptedPenalty</sender> - <signal>clicked(bool)</signal> - <receiver>sbUserAcceptedPenalty</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>206</x> - <y>127</y> - </hint> - <hint type="destinationlabel"> - <x>400</x> - <y>130</y> - </hint> - </hints> - </connection> - <connection> - <sender>pb_Today</sender> - <signal>clicked()</signal> - <receiver>ScheduleSettingsDialogClass</receiver> - <slot>today()</slot> - <hints> - <hint type="sourcelabel"> - <x>231</x> - <y>74</y> - </hint> - <hint type="destinationlabel"> - <x>168</x> - <y>259</y> - </hint> - </hints> - </connection> - <connection> - <sender>dateEdit_Earliest</sender> - <signal>dateChanged(QDate)</signal> - <receiver>ScheduleSettingsDialogClass</receiver> - <slot>scheduleStartDateChanged(QDate)</slot> - <hints> - <hint type="sourcelabel"> - <x>339</x> - <y>73</y> - </hint> - <hint type="destinationlabel"> - <x>136</x> - <y>278</y> - </hint> - </hints> - </connection> - <connection> - <sender>sb_ScheduleDurationMonths</sender> - <signal>valueChanged(int)</signal> - <receiver>ScheduleSettingsDialogClass</receiver> - <slot>scheduleDurationChanged(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>339</x> - <y>106</y> - </hint> - <hint type="destinationlabel"> - <x>354</x> - <y>262</y> - </hint> - </hints> - </connection> - <connection> - <sender>dateEdit_Latest</sender> - <signal>dateChanged(QDate)</signal> - <receiver>ScheduleSettingsDialogClass</receiver> - <slot>scheduleEndDateChanged(QDate)</slot> - <hints> - <hint type="sourcelabel"> - <x>370</x> - <y>166</y> - </hint> - <hint type="destinationlabel"> - <x>424</x> - <y>114</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonTestSASConnection</sender> - <signal>clicked()</signal> - <receiver>ScheduleSettingsDialogClass</receiver> - <slot>testSASconnection()</slot> - <hints> - <hint type="sourcelabel"> - <x>121</x> - <y>186</y> - </hint> - <hint type="destinationlabel"> - <x>88</x> - <y>302</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <slot>today()</slot> - <slot>scheduleStartDateChanged(QDate)</slot> - <slot>scheduleDurationChanged(int)</slot> - <slot>scheduleEndDateChanged(QDate)</slot> - <slot>testSASconnection()</slot> - </slots> -</ui> diff --git a/SAS/Scheduler/src/scheduletabledelegate.cpp b/SAS/Scheduler/src/scheduletabledelegate.cpp deleted file mode 100644 index 4d79ee817b0e6d3e1fc98063f5574e81a26db2a5..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/scheduletabledelegate.cpp +++ /dev/null @@ -1,1011 +0,0 @@ -/* - * scheduletabledelegate.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 2, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/scheduletabledelegate.cpp $ - * - */ - -#include <QtGui> -#include <qstringlist.h> -#include <qmessagebox.h> -#include <vector> -#include <string> -#include "Controller.h" -#include "lofar_utils.h" -#include "scheduletabledelegate.h" -#include "task.h" -#include "station.h" - -ScheduleTableDelegate::ScheduleTableDelegate(QObject *parent) - : QItemDelegate(parent) -{ -} - -ScheduleTableDelegate::~ScheduleTableDelegate() { -} - -// create the widget and load it with possible choices/items -QWidget *ScheduleTableDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &/* option */, - const QModelIndex &index) const -{ - QComboBox * comboBox = 0; - QListWidget * listWidget = 0; - QSpinBox * spinBox = 0; - QTimeEdit * timeEdit = 0; - QDateEdit * dateEdit = 0; - QLineEdit * lineEdit = 0; - QDateTimeEdit * dateTimeEdit = 0; - QStringList items; - - int task_type = index.model()->data(index.model()->index(index.row(),TASK_TYPE),USERDATA_ROLE).toInt(); - int task_status = index.model()->data(index.model()->index(index.row(),TASK_STATUS),USERDATA_ROLE).toInt(); - - if (task_status < Task::SCHEDULED) { - if ((task_type == Task::RESERVATION) || (task_type == Task::MAINTENANCE)) { - switch (index.column()) { - case STATION_ID: - listWidget = new QListWidget(parent); - listWidget->setSelectionMode(QAbstractItemView::MultiSelection); - listWidget->setFixedHeight(100); - listWidget->setViewMode(QListView::IconMode); - listWidget->setMovement(QListView::Static); - if (!Controller::theSchedulerSettings.getStationList().empty()) { - for (stationDefinitionsMap::const_iterator it = Controller::theSchedulerSettings.getStationList().begin(); - it != Controller::theSchedulerSettings.getStationList().end() ; ++it) { - items << it->first.c_str(); - } - } - else { - items << "no stations defined"; - } - listWidget->addItems(items); - return listWidget; - case TASK_DURATION: // duration - lineEdit = new QLineEdit(parent); - lineEdit->setToolTip("hhhh:mm:ss"); - lineEdit->setInputMask("0000:00:00"); - return lineEdit; - case TASK_NAME: - case PROJECT_ID: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - case TASK_DESCRIPTION: - lineEdit = new QLineEdit(parent); - return lineEdit; - case FILTER_TYPE: // filter type - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_FILTER_TYPES ; ++i) { - items << filter_types_str[i]; - } - comboBox->addItems(items); - return comboBox; - case ANTENNA_MODE: // antenna mode - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_ANTENNA_MODES ; ++i) { - items << antenna_modes_str[i]; - } - comboBox->addItems(items); - return comboBox; - case CLOCK_FREQUENCY: // clock frequencies - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_CLOCK_FREQUENCIES; ++i) { - items << clock_frequencies_str[i]; - } - comboBox->addItems(items); - return comboBox; - case PLANNED_START: // date-time edit - case PLANNED_END: - dateTimeEdit = new QDateTimeEdit(parent); - dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss"); - dateTimeEdit->setCalendarPopup(true); - return dateTimeEdit; - case TASK_STATUS: // task status - comboBox = new QComboBox(parent); - items << task_states_str[Task::PRESCHEDULED] << task_states_str[Task::ON_HOLD]; - comboBox->addItems(items); - return comboBox; - default: - return 0; - } - } - else if (task_type == Task::PIPELINE) { - switch (index.column()) { - case PREDECESSORS: // predecessors IDs - lineEdit = new QLineEdit(parent); - return lineEdit; - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: - timeEdit = new QTimeEdit(parent); - timeEdit->setDisplayFormat("hh:mm:ss"); - return timeEdit; - case PRED_MIN_TIME_DIF: - case PRED_MAX_TIME_DIF: - case TASK_DURATION: // duration - lineEdit = new QLineEdit(parent); - lineEdit->setToolTip("hhhh:mm:ss"); - lineEdit->setInputMask("0000:00:00"); - return lineEdit; - case TASK_NAME: - case PROJECT_ID: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - case PRIORITY: // priority - case TASK_DESCRIPTION: - lineEdit = new QLineEdit(parent); - return lineEdit; - case FIRST_POSSIBLE_DATE: // date edit - case LAST_POSSIBLE_DATE: - dateEdit = new QDateEdit(parent); - dateEdit->setDisplayFormat("yyyy-MM-dd"); - dateEdit->setCalendarPopup(true); - return dateEdit; - case PLANNED_START: // date-time edit - case PLANNED_END: - dateTimeEdit = new QDateTimeEdit(parent); - dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss"); - dateTimeEdit->setCalendarPopup(true); - return dateTimeEdit; - case FIXED_DAY: // fixed day and time (0/1) - case FIXED_TIME: - lineEdit = new QLineEdit(parent); - lineEdit->setToolTip("0/1"); - lineEdit->setInputMask("9"); - return lineEdit; - case TASK_STATUS: // task status - comboBox = new QComboBox(parent); - if (task_status == Task::PRESCHEDULED) { - items << task_states_str[Task::ON_HOLD] << task_states_str[Task::UNSCHEDULED] - << task_states_str[Task::PRESCHEDULED] << task_states_str[Task::SCHEDULED]; - } - else if (task_status == Task::ABORTED) { - items << task_states_str[Task::UNSCHEDULED] << task_states_str[Task::ABORTED]; - } - else { - items << task_states_str[Task::ON_HOLD] << task_states_str[Task::UNSCHEDULED] - << task_states_str[Task::PRESCHEDULED]; - } - comboBox->addItems(items); - return comboBox; - break; - } - } - else { // regular tasks: - switch (index.column()) { -/* - case TASK_TYPE: // task type - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_TASK_TYPES - 1; ++i) { - items << task_types_str[i]; - } - comboBox->addItems(items); - return comboBox; -*/ - case PREDECESSORS: // predecessors IDs - lineEdit = new QLineEdit(parent); - return lineEdit; - case STATION_ID: // station names - listWidget = new QListWidget(parent); - listWidget->setSelectionMode(QAbstractItemView::MultiSelection); - listWidget->setFixedHeight(100); - listWidget->setViewMode(QListView::IconMode); - listWidget->setMovement(QListView::Static); - if (!Controller::theSchedulerSettings.getStationList().empty()) { - for (stationDefinitionsMap::const_iterator it = Controller::theSchedulerSettings.getStationList().begin(); - it != Controller::theSchedulerSettings.getStationList().end() ; ++it) { - items << it->first.c_str(); - } - } - else { - items << "no stations defined"; - } - listWidget->addItems(items); - return listWidget; - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: - timeEdit = new QTimeEdit(parent); - timeEdit->setDisplayFormat("hh:mm:ss"); - return timeEdit; - case PRED_MIN_TIME_DIF: - case PRED_MAX_TIME_DIF: - case TASK_DURATION: // duration - lineEdit = new QLineEdit(parent); - lineEdit->setToolTip("hhhh:mm:ss"); - lineEdit->setInputMask("0000:00:00"); - return lineEdit; - case TASK_NAME: - case PROJECT_ID: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - case PRIORITY: // priority - case TASK_DESCRIPTION: - lineEdit = new QLineEdit(parent); - return lineEdit; - case FILTER_TYPE: // filter type - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_FILTER_TYPES ; ++i) { - items << filter_types_str[i]; - } - comboBox->addItems(items); - return comboBox; - case ANTENNA_MODE: // antenna mode - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_ANTENNA_MODES ; ++i) { - items << antenna_modes_str[i]; - } - comboBox->addItems(items); - return comboBox; - case CLOCK_FREQUENCY: // clock frequencies - comboBox = new QComboBox(parent); - for (short int i=0; i < NR_CLOCK_FREQUENCIES; ++i) { - items << clock_frequencies_str[i]; - } - comboBox->addItems(items); - return comboBox; - case FIRST_POSSIBLE_DATE: // date edit - case LAST_POSSIBLE_DATE: - dateEdit = new QDateEdit(parent); - dateEdit->setDisplayFormat("yyyy-MM-dd"); - dateEdit->setCalendarPopup(true); - return dateEdit; - case PLANNED_START: // date-time edit - case PLANNED_END: - dateTimeEdit = new QDateTimeEdit(parent); - dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss"); - dateTimeEdit->setCalendarPopup(true); - return dateTimeEdit; - case FIXED_DAY: // fixed day and time (0/1) - case FIXED_TIME: - lineEdit = new QLineEdit(parent); - lineEdit->setToolTip("0/1"); - lineEdit->setInputMask("9"); - return lineEdit; - case TASK_STATUS: // task status - comboBox = new QComboBox(parent); - if (task_status == Task::PRESCHEDULED) { - items << task_states_str[Task::ON_HOLD] << task_states_str[Task::UNSCHEDULED] - << task_states_str[Task::PRESCHEDULED] << task_states_str[Task::SCHEDULED]; - } - else if (task_status == Task::ABORTED) { - items << task_states_str[Task::UNSCHEDULED] << task_states_str[Task::ABORTED]; - } - else if (task_status == Task::CONFLICT) { - items << task_states_str[Task::ON_HOLD] << task_states_str[Task::UNSCHEDULED] - << task_states_str[Task::PRESCHEDULED]; - } - else { - items << task_states_str[Task::ON_HOLD] << task_states_str[Task::UNSCHEDULED] - << task_states_str[Task::PRESCHEDULED]; - } - comboBox->addItems(items); - return comboBox; - break; - case NIGHT_TIME_WEIGHT_FACTOR: // night time weight factor (spinbox) - spinBox = new QSpinBox(parent); - spinBox->setRange(0, 100); - return spinBox; - } - } - } - else { // all tasks with status > SCHEDULED - if (index.column() == TASK_STATUS) { - comboBox = new QComboBox(parent); - if (task_status == Task::SCHEDULED) { - items << task_states_str[Task::ON_HOLD] << task_states_str[Task::UNSCHEDULED] << task_states_str[Task::PRESCHEDULED] << task_states_str[Task::SCHEDULED]; // we allow also aborting a task which in the scheduler has state SCHEDULED (it could already be running) - comboBox->addItems(items); - return comboBox; - } - else if (task_status == Task::ABORTED) { // from ABORTED we can go to UNSCHEDULED only - items << task_states_str[Task::UNSCHEDULED] << task_states_str[Task::ABORTED]; - comboBox->addItems(items); - return comboBox; - } - else if (task_status == Task::OBSOLETE) { - items << task_states_str[Task::UNSCHEDULED]; - comboBox->addItems(items); - return comboBox; - } - } - } - return 0; -} - -// setEditorData sets the correct value when user wants to edit the table cell -void ScheduleTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const -{ - QString valueStr; - unsigned int uValue; - QSpinBox * spinBox = 0; - QListWidget * listWidget = 0; - QComboBox * comboBox = 0; - QTimeEdit * timeEdit = 0; - QDateEdit * dateEdit = 0; - QLineEdit * lineEdit = 0; - QTime time; - QDateTimeEdit * dateTimeEdit = 0; - QDateTime dateTimeValue; - QStringList stringListItems; - QList<QListWidgetItem *> listItems; - int count; - bool found; - switch (index.column()) { - case TASK_TYPE: // task type - comboBox = static_cast<QComboBox *>(editor); // convert the editor into a combobox for the task type column - valueStr = index.model()->data(index).toString(); - for (short int i=0; i < NR_TASK_TYPES; ++i) { - if (valueStr.compare(task_types_str[i]) == 0) { - comboBox->setCurrentIndex(i); - break; - } - } - break; - case STATION_ID: // station names - listWidget = static_cast<QListWidget *>(editor); // convert the editor into a listbox to select station (names) - stringListItems = index.model()->data(index).toStringList(); - for (QStringList::const_iterator sit = stringListItems.begin(); sit != stringListItems.end(); ++sit) { - listItems = listWidget->findItems(*sit, Qt::MatchExactly); - if (!listItems.empty()) - listItems.first()->setSelected(true); - } - break; - case TASK_NAME: - case PROJECT_ID: - case CONTACT_NAME: - case CONTACT_PHONE: - case CONTACT_EMAIL: - case PREDECESSORS: // predecessor ID - case PRIORITY: // station IDs - case PRED_MIN_TIME_DIF: - case PRED_MAX_TIME_DIF: - case TASK_DURATION: // duration - case TASK_DESCRIPTION: - case STORAGE_SIZE: // storage units - lineEdit = static_cast<QLineEdit *>(editor); - valueStr = index.model()->data(index).toString(); - lineEdit->setText(valueStr); - break; - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: - timeEdit = static_cast<QTimeEdit *>(editor); - time = index.model()->data(index).toTime(); - timeEdit->setDisplayFormat("hh:mm:ss"); - timeEdit->setTime(time); - break; - case FILTER_TYPE: // filter type - comboBox = static_cast<QComboBox *>(editor); - valueStr = index.model()->data(index).toString(); - for (short int i=0; i < NR_FILTER_TYPES; ++i) { - if (valueStr.compare(filter_types_str[i]) == 0) { - comboBox->setCurrentIndex(i); - break; - } - } - break; - case ANTENNA_MODE: // antenna mode - comboBox = static_cast<QComboBox *>(editor); - valueStr = index.model()->data(index).toString(); - for (short int i=0; i < NR_ANTENNA_MODES ; ++i) { - if (valueStr.compare( antenna_modes_str[i]) == 0) { - comboBox->setCurrentIndex(i); - break; - } - } - break; - case CLOCK_FREQUENCY: // clock frequencies - comboBox = static_cast<QComboBox *>(editor); // convert the editor into a combobox for the task type column - valueStr = index.model()->data(index).toString(); - for (short int i=0; i < NR_CLOCK_FREQUENCIES; ++i) { - if (valueStr.compare(clock_frequencies_str[i]) == 0) { - comboBox->setCurrentIndex(i); - break; - } - } - break; - case FIRST_POSSIBLE_DATE: // date edit - case LAST_POSSIBLE_DATE: - dateEdit = static_cast<QDateEdit *>(editor); - dateEdit->setDisplayFormat("yyyy-MM-dd"); - dateEdit->setDate(index.model()->data(index).toDate()); - break; - case PLANNED_START: // date-time edit - case PLANNED_END: - dateTimeEdit = static_cast<QDateTimeEdit *>(editor); - dateTimeEdit->setDisplayFormat("yyyy-MM-dd hh:mm:ss"); - dateTimeValue = index.model()->data(index).toDateTime(); - if (dateTimeValue.isNull()) { - QDateTime cDate(QDateTime::currentDateTimeUtc()); - dateTimeEdit->setDateTime(QDateTime(cDate.date(),QTime(cDate.time().hour(),cDate.time().minute(),0))); - } - else { - dateTimeEdit->setDateTime(dateTimeValue); - } - break; - case FIXED_DAY: // fixed day and time (1/0) - case FIXED_TIME: - lineEdit = static_cast<QLineEdit *>(editor); - uValue = index.model()->data(index).toUInt(); - if ((uValue == 0) || (uValue == 1)) { - lineEdit->setText(index.model()->data(index).toString()); - } - break; - case TASK_STATUS: // task status - comboBox = static_cast<QComboBox *>(editor); // convert the editor into a combobox for the task type column - valueStr = index.model()->data(index).toString(); - // check if task is finished - // check task type -// task_type = index.model()->data(index.model()->index(index.row(),TASK_TYPE),USERDATA_ROLE).toInt(); - count = 0; - found = false; - while (count < comboBox->count()) { - if (valueStr.compare(comboBox->itemText(count)) == 0) { - comboBox->setCurrentIndex(count); - found = true; - break; - } - ++count; - } - if (!found) { - for (count=0; count < NR_TASK_STATES ; ++count) { - if (valueStr.compare(task_states_str[count]) == 0) { - comboBox->addItem(task_states_str[count]); - comboBox->setCurrentIndex(comboBox->count()-1); - break; - } - } - } - break; - case NIGHT_TIME_WEIGHT_FACTOR: // night time weight factor (spinbox) - spinBox = static_cast<QSpinBox *>(editor); - uValue = index.model()->data(index).toUInt(); - spinBox->setValue(uValue); - break; - } -} - -void ScheduleTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const -{ - bool change = false; - int pos=0; - QString strValue, strValue2; - QListWidget * listWidget = 0; - QComboBox * comboBox = 0; - QSpinBox * spinBox = 0; - QTimeEdit * timeEdit; - QDateEdit * dateEdit; - QDateTimeEdit * dateTimeEdit = 0; - QLineEdit * lineEdit = 0; - QDoubleValidator dValidator(editor); - QIntValidator iValidator(editor); - QRegExpValidator regExpValidator(editor); - QRegExp regExpEmail("[A-Z0-9._%+-]{1,64}@[A-Z0-9-]{1,253}.[A-Z]{2,4}"); - regExpEmail.setCaseSensitivity(Qt::CaseInsensitive); - QList<QListWidgetItem *> selectedItems; - QStringList stringListItems, prev_list; - - unsigned taskID = model->data(model->index(index.row(), TASK_ID, QModelIndex())).toUInt(); - QVariant newValue; - - switch (index.column()) { - case TASK_TYPE: // task type - comboBox = static_cast<QComboBox *>(editor); - strValue = model->data(index).toString(); - if (strValue.compare(task_types_str[comboBox->currentIndex()]) != 0) { - model->setData(index, QVariant(task_types_str[comboBox->currentIndex()])); - newValue = model->data(index).toString(); - change = true; - } - break; - case TASK_NAME: - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - if (strValue.length() < 3) { - QMessageBox::warning(editor, tr("Task name not valid"), - tr("The task name must contain at least three characters"), - QMessageBox::Ok, QMessageBox::Ok); - } - else { - model->setData(index, strValue); - newValue = strValue; - change = true; - } - break; - case PROJECT_ID: - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - if (strValue.length() < 3) { - QMessageBox::warning(editor, tr("Project name not valid"), - tr("The project name must contain at least three characters"), - QMessageBox::Ok, QMessageBox::Ok); - } - else { - model->setData(index, strValue); - newValue = strValue; - change = true; - } - break; - case CONTACT_NAME: - case CONTACT_PHONE: - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - model->setData(index, strValue); - newValue = strValue; - change = true; - break; - case CONTACT_EMAIL: - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - regExpValidator.setRegExp(regExpEmail); - if ((regExpValidator.validate(strValue, pos) == QValidator::Acceptable) | (strValue == "")) { - model->setData(index, strValue); - newValue = strValue; - change = true; - } - else { - QMessageBox::warning(editor, tr("Not a valid e-mail address"), - tr("This is not a valid e-mail address.\n" - "Please enter a valid e-mail address"), - QMessageBox::Ok, QMessageBox::Ok); - //model->setData(index,strValue); - editor->parentWidget()->setFocus(); // set focus on cell again so user doesn't have to reselect it again for editing -// this->setEditorData(editor,index); -// emit openEditor(index, strValue); - } - break; - case TASK_DESCRIPTION: - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - model->setData(index, strValue); - newValue = strValue; - change = true; - break; - /* - case PREDECESSOR: // predecessor ID - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - if ((iValidator.validate(strValue,pos) == QValidator::Acceptable) | (strValue == "")) { - if (model->data(index).toString().compare(strValue)) { - model->setData(index, QVariant(strValue)); - newValue = model->data(index).toUInt(); - change = true; - } - } - else { - QMessageBox::warning(editor, tr("Not a valid task ID value"), - tr("This is not a valid task ID value.\n" - "Valid task ID values are positive integral numbers greater than 0"), - QMessageBox::Ok, QMessageBox::Ok); - editor->parentWidget()->setFocus(); - } - break; - */ - case STATION_ID: // station names - listWidget = static_cast<QListWidget *>(editor); - prev_list = model->data(index).toStringList(); // previous list of selected stations - selectedItems = listWidget->selectedItems(); - if (!selectedItems.empty()) { - if ((*selectedItems.begin())->text().compare("no stations defined") != 0) { - for (QList<QListWidgetItem *>::const_iterator qit = selectedItems.begin(); qit != selectedItems.end(); ++qit) { - stringListItems.append((*qit)->text()); - } - stringListItems.sort(); - if (selectedItems.size() != prev_list.size()) { - model->setData(index, stringListItems); - change = true; - } - else { // same number of selected stations, see if they are the same stations - for (QList<QListWidgetItem *>::const_iterator qit = selectedItems.begin(); qit != selectedItems.end(); ++qit) { - if (!(prev_list.contains((*qit)->text()))) { - model->setData(index, stringListItems); - change = true; - break; - } - } - } - if (change) { - for (QStringList::const_iterator it = stringListItems.begin(); it != stringListItems.end()-1; ++it) { - strValue += *it + ";"; - } - strValue += stringListItems.back(); - newValue = strValue; - } - } - } - else { // no stations selected - if (prev_list.size() != 0) { - model->setData(index, QStringList("")); - change = true; - } - } - break; - case PREDECESSORS: - case PRED_MIN_TIME_DIF: // time edit - case PRED_MAX_TIME_DIF: - case TASK_DURATION: // duration - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - model->setData(index, strValue); - newValue = strValue; - change = true; - break; - case STORAGE_SIZE: // storage - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - if (model->data(index).toString().compare(strValue)) { - model->setData(index, QVariant(strValue)); - newValue = model->data(index).toInt(); - change = true; - } - break; - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: - timeEdit = static_cast<QTimeEdit *>(editor); - if (model->data(index).toTime() != timeEdit->time()) { - model->setData(index, QVariant(timeEdit->time())); - newValue = timeEdit->text(); - change = true; - } - break; - case PRIORITY: // priority (double) - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text().trimmed(); - dValidator.setRange(0.0,10.0,20); - if (dValidator.validate(strValue,pos) == QValidator::Acceptable) { - if (model->data(index).toString().compare(strValue)) { - model->setData(index, QVariant(strValue)); - newValue = lineEdit->text().toDouble(); - change = true; - } - } - else { - QMessageBox::warning(editor, tr("Not a valid priority value"), - tr("This is not a valid priority value.\n" - "Valid priority values are positive floating point numbers up to 10.0"), - QMessageBox::Ok, QMessageBox::Ok); - editor->parentWidget()->setFocus(); - } - break; - case FILTER_TYPE: // filter type - comboBox = static_cast<QComboBox *>(editor); - strValue = model->data(index).toString(); - if (strValue.compare(filter_types_str[comboBox->currentIndex()]) != 0) { - model->setData(index, filter_types_str[comboBox->currentIndex()]); - newValue = model->data(index).toString(); - change = true; - } - break; - case ANTENNA_MODE: // antenna mode - comboBox = static_cast<QComboBox *>(editor); - strValue = model->data(index).toString(); - if (strValue.compare(antenna_modes_str[comboBox->currentIndex()]) != 0) { - model->setData(index, antenna_modes_str[comboBox->currentIndex()]); - newValue = model->data(index).toString(); - change = true; - } - break; - case CLOCK_FREQUENCY: // clock frequencies - comboBox = static_cast<QComboBox *>(editor); - strValue = model->data(index).toString(); - if (strValue.compare(clock_frequencies_str[comboBox->currentIndex()]) != 0) { - model->setData(index, clock_frequencies_str[comboBox->currentIndex()]); - newValue = model->data(index).toString(); - change = true; - } - break; - case FIRST_POSSIBLE_DATE: // date edit - case LAST_POSSIBLE_DATE: - dateEdit = static_cast<QDateEdit *>(editor); - if (model->data(index).toDate() != dateEdit->date()) { - model->setData(index, QVariant(dateEdit->date())); - strValue = dateEdit->text(); - newValue = strValue; - change = true; - } - break; - case PLANNED_START: // date-time edit - case PLANNED_END: - dateTimeEdit = static_cast<QDateTimeEdit *>(editor); - if (model->data(index).toDateTime() != dateTimeEdit->dateTime()) { - model->setData(index, QVariant(dateTimeEdit->dateTime())); - newValue = dateTimeEdit->text(); - change = true; - } - break; - case FIXED_DAY: // fixed day and time (checkbox) - case FIXED_TIME: - lineEdit = static_cast<QLineEdit *>(editor); - strValue = lineEdit->text(); - iValidator.setRange(0,1); - if (iValidator.validate(strValue,pos) == QValidator::Acceptable) { - if (model->data(index).toString().compare(strValue)) { - model->setData(index, strValue); - newValue = model->data(index).toBool(); - change =true; - } - } - else { - QMessageBox::warning(editor, tr("Not a valid value"), - tr("This is not a valid value.\n" - "Valid values are 1 (true) or 0 (false)"), - QMessageBox::Ok, QMessageBox::Ok); - } - break; - case TASK_STATUS: // task status - comboBox = static_cast<QComboBox *>(editor); - strValue = model->data(index).toString(); - strValue2 = comboBox->currentText(); - if (strValue.compare(strValue2) != 0) { // if the status was changed - model->setData(index, strValue2); - newValue = strValue2; - change = true; - } -// task_type = index.model()->data(index.model()->index(index.row(),TASK_TYPE),USERDATA_ROLE).toInt(); -// if ((task_type == Task::RESERVATION) | (task_type == Task::MAINTENANCE)) { -// if (comboBox->currentIndex() == 0) { -// if (strValue.compare(task_states_str[Task::SCHEDULED]) != 0) { // did the status change? -// model->setData(index, QVariant(QString(task_states_str[Task::SCHEDULED]))); -// newValue = QString(task_states_str[Task::SCHEDULED]); -// change = true; -// } -// } -// else { -// if (strValue.compare(task_states_str[Task::ON_HOLD]) != 0) { // did the status change? -// model->setData(index, QVariant(QString(task_states_str[Task::ON_HOLD]))); -// newValue = QString(task_states_str[Task::ON_HOLD]); -// change = true; -// } -// } -// } -// else { -// if (strValue.compare(task_states_str[comboBox->currentIndex()]) != 0) { -// model->setData(index, QVariant(task_states_str[comboBox->currentIndex()])); -// newValue = model->data(index).toString(); -// change = true; -// } -// } - break; - case NIGHT_TIME_WEIGHT_FACTOR: // night time weight factor (spinbox) -// case CEP_PROCESSING_UNITS: // CEP processing % -// case OFFLINE_PROCESSING_UNITS: // offline processing % - spinBox = static_cast<QSpinBox *>(editor); - if (model->data(index).toInt() != spinBox->value()) { - model->setData(index, QVariant(spinBox->value())); - newValue = model->data(index).toUInt(); - change = true; - } - break; - } - if (change) { - emit tableItemChanged(taskID, static_cast<data_headers>(index.column()), newValue, index); // sends the new value - } -} - -void ScheduleTableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - drawText(painter, option, index); - if (index.column() == PLANNED_END && !index.model()->data(index, Qt::ToolTipRole).toString().isEmpty()) { - QPolygon polygonTriangle(3); - polygonTriangle.setPoint(0, QPoint(option.rect.x()+8, option.rect.y())); - polygonTriangle.setPoint(1, QPoint(option.rect.x(), option.rect.y())); - polygonTriangle.setPoint(2, QPoint(option.rect.x(), option.rect.y()+8)); - painter->save(); - QColor color((Qt::GlobalColor)index.model()->data(index, Qt::UserRole+1).toInt()); - painter->setRenderHint(QPainter::Antialiasing); - painter->setBrush(QBrush(color)); - painter->setPen(QPen(color)); - painter->drawPolygon(polygonTriangle); - painter->restore(); - } -} - -void ScheduleTableDelegate::writeTime(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QString str = index.model()->data(index).toString(); - if (str.compare("::") == 0) { // if empty string specified (delete) - str = ""; - } - int m = str.indexOf(':'); // first ':' - if (m == 0) { // if ':' is first character - str = "0" + str; - } - else { // trim first zeros except last one before ':' - for (short n=0; n < m-1; ++n) { - if (str[n] == '0') { - str = str.right(str.length()-1); - --n; - --m; - } - else break; - } - } - // minutes cannot be left empty :: - if (str.contains("::")) { - str.insert(str.indexOf(':')+1,'0'); // insert a zero for the minutes - } - // take care of seconds part - if ((str.length() > 1)) { - if (str.right(2) == "::") { - str = str.left(str.length()-1) + "0:0"; - } - else if (str.right(1) == ":") { - str = str + '0'; - } - } - QRect rect_inner = option.rect; - rect_inner.adjust(5,5,-5,-5); - painter->drawText(rect_inner , Qt::AlignLeft | Qt::AlignVCenter, str); -} - -void ScheduleTableDelegate::writeStations(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QString str; - QStringList stringItems = index.model()->data(index).toStringList(); - if (!(stringItems.empty())) { - for (QStringList::const_iterator it = stringItems.begin(); it != stringItems.end()-1; ++it) { - str += *it; - str += ";"; - } - str += *(stringItems.end()-1); - QRect rect_inner = option.rect; - rect_inner.adjust(5,5,-5,-5); - painter->drawText(rect_inner , Qt::AlignLeft | Qt::AlignVCenter, str); - } -} - - -void ScheduleTableDelegate::drawText(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QRect rect_text = option.rect; - rect_text.adjust(5,0,0,0); // make sure to keep a left text margin in the cell of 5 pixels - if (option.state & QStyle::State_Selected) { - painter->setPen(Qt::SolidLine); - QRect rect_inner = option.rect; - rect_inner.adjust(2,2,-2,-2); - painter->fillRect(rect_inner, QBrush(0x005577aa/*Qt::blue*/)); - painter->setPen(Qt::white); - } - else { - painter->setPen(index.model()->data(index,Qt::ForegroundRole).toString()); - painter->fillRect(option.rect, QBrush(index.model()->data(index,Qt::BackgroundRole).toString(),Qt::SolidPattern)); - } - // now draw the text - int task_type = index.model()->data(index.model()->index(index.row(),TASK_TYPE),USERDATA_ROLE).toInt(); - if (task_type == Task::RESERVATION) { - switch (index.column()) { - case PREDECESSORS: - case PRIORITY: - case PRED_MIN_TIME_DIF: - case PRED_MAX_TIME_DIF: - case FIRST_POSSIBLE_DATE: - case LAST_POSSIBLE_DATE: - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: -// case FIXED_DAY: -// case FIXED_TIME: - case NR_OF_SUBBANDS: - case NIGHT_TIME_WEIGHT_FACTOR: -// case STORAGE_SIZE: - // don't write these for reservations or maintenance tasks - break; - case TASK_DURATION: - writeTime(painter, option, index); - break; - case PLANNED_START: - case PLANNED_END: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toDateTime().toString("yyyy-MM-dd hh:mm:ss")); - break; - case STATION_ID: - writeStations(painter, option, index); - break; - case UNSCHEDULED_REASON: - painter->setPen(Qt::black); - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toString()); - break; - default: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toString()); - break; - } - } - else if (task_type == Task::MAINTENANCE) { - switch (index.column()) { - case PREDECESSORS: - case PRED_MIN_TIME_DIF: - case PRED_MAX_TIME_DIF: - case PRIORITY: - case ANTENNA_MODE: - case CLOCK_FREQUENCY: - case FILTER_TYPE: - case FIRST_POSSIBLE_DATE: - case LAST_POSSIBLE_DATE: - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: -// case FIXED_DAY: -// case FIXED_TIME: - case NR_OF_SUBBANDS: - case NIGHT_TIME_WEIGHT_FACTOR: - case STORAGE_SIZE: - // don't write these for maintenance tasks - break; - case TASK_DURATION: - writeTime(painter, option, index); - break; - case PLANNED_START: - case PLANNED_END: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toDateTime().toString("yyyy-MM-dd hh:mm:ss")); - break; - case STATION_ID: - writeStations(painter, option, index); - break; - case UNSCHEDULED_REASON: - painter->setPen(Qt::black); - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toString()); - break; - default: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toString()); - break; - } - } - else if (task_type == Task::PIPELINE) { - switch (index.column()) { - case ANTENNA_MODE: - case CLOCK_FREQUENCY: - case FILTER_TYPE: - case FIRST_POSSIBLE_DATE: - case LAST_POSSIBLE_DATE: - case WINDOW_MINIMUM_TIME: - case WINDOW_MAXIMUM_TIME: - case FIXED_DAY: - case FIXED_TIME: - case NR_OF_SUBBANDS: - case NIGHT_TIME_WEIGHT_FACTOR: - case STATION_ID: -// case STORAGE_SIZE: - // don't write these for maintenance tasks - break; - case TASK_DURATION: - writeTime(painter, option, index); - break; - case PLANNED_START: - case PLANNED_END: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toDateTime().toString("yyyy-MM-dd hh:mm:ss")); - break; - default: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toString()); - break; - } - } - else { // regular tasks - switch (index.column()) { - case PRED_MIN_TIME_DIF: - case PRED_MAX_TIME_DIF: - case TASK_DURATION: - writeTime(painter, option, index); - break; - case FIRST_POSSIBLE_DATE: - case LAST_POSSIBLE_DATE: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toDate().toString("yyyy-MM-dd")); - break; - case PLANNED_START: - case PLANNED_END: - painter->drawText(rect_text, Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toDateTime().toString("yyyy-MM-dd hh:mm:ss")); - break; - case STATION_ID: - writeStations(painter, option, index); - break; - default: - painter->drawText(rect_text,Qt::AlignLeft | Qt::AlignVCenter, index.model()->data(index).toString()); - break; - } - } -} - -void ScheduleTableDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &/* index */) const -{ - editor->setGeometry(option.rect); -} diff --git a/SAS/Scheduler/src/scheduletabledelegate.h b/SAS/Scheduler/src/scheduletabledelegate.h deleted file mode 100644 index a66c9c3185243a11fe09305b11530b5f66ce0eaf..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/scheduletabledelegate.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * scheduletabledelegate.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 2, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/scheduletabledelegate.h $ - * - */ - -#ifndef SCHEDULETABLEDELEGATE_H_ -#define SCHEDULETABLEDELEGATE_H_ - -#include <QItemDelegate> -#include <QModelIndex> -#include <QObject> -#include <QSize> -#include <QSpinBox> -#include "lofar_scheduler.h" - -class ScheduleTableDelegate : public QItemDelegate -{ - Q_OBJECT - -public: - ScheduleTableDelegate(QObject *parent = 0); - virtual ~ScheduleTableDelegate(); - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - - void updateEditorGeometry(QWidget *editor, - - const QStyleOptionViewItem &option, const QModelIndex &index) const; - -private: - void drawText(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &) const; - void writeTime(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - void writeStations(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - - -signals: -// void tableItemChanged(const QModelIndex &) const; -// void tableItemAboutToBeChanged(const QModelIndex &) const; - void tableItemNotChanged(void) const; - void tableItemChanged(unsigned, data_headers, const QVariant &, const QModelIndex &) const; - void openEditor(const QModelIndex &, const QVariant &) const; -}; - -#endif /* SCHEDULETABLEDELEGATE_H_ */ diff --git a/SAS/Scheduler/src/shifttasksdialog.cpp b/SAS/Scheduler/src/shifttasksdialog.cpp deleted file mode 100644 index 891b5ff06848cb5b96b06d0695ba8b76e9de8683..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/shifttasksdialog.cpp +++ /dev/null @@ -1,789 +0,0 @@ -/* - * ShiftTasksDialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : sept-2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/shifttasksdialog.cpp $ - * - */ - -#include "shifttasksdialog.h" -#include <QTime> -#include <QMessageBox> -#include <QDateTime> -#include <vector> -#include <map> -#include <string> -#include "astrotime.h" -#include "DigitalBeam.h" -#include "redistributetasksdialog.h" - -ShiftTasksDialog::ShiftTasksDialog(QWidget *parent, Controller *controller) - : QDialog(parent), itsController(controller), itsMoveType(MOVE_RIGHT) -{ - ui.setupUi(this); - connect(ui.pushButtonShiftToNow, SIGNAL(clicked()), this, SLOT(calculateNow(void))); - connect(ui.pushButtonCenterAtLST, SIGNAL(clicked()), this, SLOT(calculateLST(void))); - connect(ui.radioButtonShiftLeft, SIGNAL(clicked()), this, SLOT(setLeftMoveType(void))); - connect(ui.radioButtonShiftRight, SIGNAL(clicked()), this, SLOT(setRightMoveType(void))); - connect(ui.pushButtonApplyAbsMove, SIGNAL(clicked()), this, SLOT(applyShift(void))); - connect(ui.pushButtonApplyLSTnow, SIGNAL(clicked()), this, SLOT(applyPreview(void))); - connect(ui.dateTimeEditNow, SIGNAL(dateChanged(const QDate &)), this, SLOT(doLSTCheck(void))); - ui.tableWidgetTasks->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui.tableWidgetTasks, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showTableContextMenu(const QPoint &))); - ui.treeWidgetAngles->setColumnCount(4); - - QStringList header; - header << "SAS ID" << "task description" << "start time (UTC)" << "duration"; - ui.treeWidgetAngles->setHeaderLabels(header); - ui.treeWidgetAngles->setSortingEnabled(true); - - header.clear(); - header << "SAS ID" << "task name" << "planned start (UTC)" << "planned end (UTC)" << "duration" << "task description" << "status" << "task type"; - ui.tableWidgetTasks->setColumnCount(header.size()); - ui.tableWidgetTasks->setHorizontalHeaderLabels(header); - ui.tableWidgetTasks->horizontalHeader()->setStretchLastSection(true); - ui.tableWidgetTasks->setSelectionBehavior(QAbstractItemView::SelectRows); - connect(ui.tableWidgetTasks->horizontalHeader(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(sortPreview(int, Qt::SortOrder))); - - loadTargets(); - loadTasks(); - - itsRedistributeDialog = new redistributeTasksDialog(this); - QTime step(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks().toQTime()); - itsRedistributeDialog->setTimeStep1(step); - itsRedistributeDialog->setTimeStep2(step); - sortPreview(2,Qt::AscendingOrder); - // select all tasks that can be moved (i.e. have status below PRESCHEDULED - ui.tableWidgetTasks->setSelectionMode(QTableView::MultiSelection); - int nrRows(ui.tableWidgetTasks->rowCount()); - for (int row = 0; row < nrRows; ++row) { - if (static_cast<Task::task_status>(ui.tableWidgetTasks->item(row, 6)->data(Qt::UserRole).toInt()) <= Task::PRESCHEDULED) { - ui.tableWidgetTasks->selectRow(row); - } - } - ui.tableWidgetTasks->setSelectionMode(QTableView::ExtendedSelection); - - exec(); -} - -ShiftTasksDialog::~ShiftTasksDialog() -{ -} - -// put rowB directly before rowA -void ShiftTasksDialog::insertTaskBefore(int rowA, int rowB) { - std::vector<QTableWidgetItem *> rowItemsA, rowItemsB; - for (int col = 0; col < ui.tableWidgetTasks->columnCount(); ++col) { - rowItemsB.push_back(ui.tableWidgetTasks->takeItem(rowB, col)); - } - // delete the row - ui.tableWidgetTasks->removeRow(rowB); - // insert a new row before rowA - ui.tableWidgetTasks->insertRow(rowA); - for (int col = 0; col < ui.tableWidgetTasks->columnCount(); ++col) { - ui.tableWidgetTasks->setItem(rowA, col, rowItemsB.at(col)); - } -} - -void ShiftTasksDialog::sortPreview(int col, Qt::SortOrder sortorder) { - ui.tableWidgetTasks->blockSignals(true); - ui.tableWidgetTasks->horizontalHeader()->blockSignals(true); - // step1: sort normally - ui.tableWidgetTasks->sortByColumn(col, sortorder); - // step2: go through list and check that each item is below all its predecessors - const Task *predTask(0); - int rowIdx1(0); - while (rowIdx1 < ui.tableWidgetTasks->rowCount()) { - bool insertedTasks(false); - // get the tasks predecessors if any - const Task *pTask(itsController->getTask(ui.tableWidgetTasks->item(rowIdx1, 0)->data(Qt::UserRole).toInt())); - // search for the last predecessor end time - const IDvector &predecessors(pTask->getPredecessors()); - if (!predecessors.empty()) { - for (IDvector::const_iterator prit = predecessors.begin(); prit != predecessors.end(); ++prit) { - unsigned predID(0); - if (prit->second != ID_SCHEDULER) { - predTask = itsController->getTask(prit->second, prit->first); - if (predTask) { - predID = predTask->getID(); - } - } - else { - predID = prit->second; - } - if (predID) { - for (int rowIdx2 = rowIdx1+1; rowIdx2 < ui.tableWidgetTasks->rowCount(); ++rowIdx2) { - if (predID == ui.tableWidgetTasks->item(rowIdx2, 0)->data(Qt::UserRole).toUInt()) { - // insert this predecessor directly before current task - insertTaskBefore(rowIdx1, rowIdx2); - insertedTasks = true; - break; - } - } - } - } - } - if (!insertedTasks) { - ++rowIdx1; - } - } - - ui.tableWidgetTasks->horizontalHeader()->setSortIndicator(col, sortorder); - ui.tableWidgetTasks->horizontalHeader()->setSortIndicatorShown(true); - ui.tableWidgetTasks->horizontalHeader()->blockSignals(false); - ui.tableWidgetTasks->blockSignals(false); -} - -void ShiftTasksDialog::showTableContextMenu(const QPoint &pos) { - QMenu menu; - if (!ui.tableWidgetTasks->selectedItems().isEmpty()) { - QAction *action = menu.addAction("Select observations"); - action->setToolTip("select all observations in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectObservations(void))); - action = menu.addAction("Select all pipelines"); - action->setToolTip("select all pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectAllPipelines(void))); - action = menu.addAction("Select calibrator pipelines"); - action->setToolTip("select all calibrator pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectCalibratorPipelines(void))); - action = menu.addAction("Select target pipelines"); - action->setToolTip("select all target pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectTargetPipelines(void))); - action = menu.addAction("Select pre-processing pipelines"); - action->setToolTip("select all pre-processing pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectPreProcessingPipelines(void))); - action = menu.addAction("Select long-baseline pipelines"); - action->setToolTip("select all long-baseline pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectLongBaselinePipelines(void))); - action = menu.addAction("Select imaging pipelines"); - action->setToolTip("select all imaging pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectImagingPipelines(void))); - action = menu.addAction("Select pulsar pipelines"); - action->setToolTip("select all pulsar pipelines in this list"); - connect(action, SIGNAL(triggered()), this, SLOT(selectPulsarPipelines(void))); - action = menu.addAction("Redistribute tasks"); - action->setToolTip("redistribute selected tasks given a start time and a time distance in the sequence such as shown here"); - connect(action, SIGNAL(triggered()), this, SLOT(redistributeSelectedTasks(void))); - action = menu.addAction("Schedule directly after predecessor"); - action->setToolTip("schedule selected tasks directly after each task's last predecessor"); - connect(action, SIGNAL(triggered()), this, SLOT(scheduleAfterPredecessor(void))); - } - menu.exec(ui.tableWidgetTasks->viewport()->mapToGlobal(pos)); -} - -QList<int> ShiftTasksDialog::getSelectedRows(void) const { - QList<int> rows, newRows; - QList<QTableWidgetSelectionRange> ranges(ui.tableWidgetTasks->selectedRanges()); - - foreach (QTableWidgetSelectionRange range, ranges) { - int sr = range.bottomRow(); - int er = range.topRow(); - if (sr > er) { - int tmp(er); - er = sr; - sr = tmp; - } - while (sr <= er) { - rows.push_back(sr); - ++sr; - } - } - qSort(rows); - bool showWarning(false); - const Task *pTask(0); - for (QList<int>::iterator it = rows.begin(); it != rows.end(); ++it) { - pTask = itsController->getTask(ui.tableWidgetTasks->item(*it, 0)->data(Qt::UserRole).toInt()); - if (pTask->getStatus() <= Task::PRESCHEDULED) { - newRows.append(*it); - } - else { - showWarning = true; - } - } - - if (showWarning) { - ui.tableWidgetTasks->clearSelection(); - QTableView::SelectionMode prevMode(ui.tableWidgetTasks->selectionMode()); - ui.tableWidgetTasks->setSelectionMode(QTableView::MultiSelection); - for (QList<int>::iterator it = newRows.begin(); it != newRows.end(); ++it) { - ui.tableWidgetTasks->selectRow(*it); - } - QMessageBox::warning(0, tr("Some tasks could not be moved"), - "Some tasks have a status above PRESCHEDULED. These tasks cannot not be moved and have been deselected.", tr("Close")); - ui.tableWidgetTasks->setSelectionMode(prevMode); - } - - return newRows; -} - -void ShiftTasksDialog::selectTasks(int type) { - ui.tableWidgetTasks->clearSelection(); - ui.tableWidgetTasks->setSelectionMode(QAbstractItemView::MultiSelection); - if (type >= SEL_CALIBRATOR_PIPELINES && type <= SEL_PULSAR_PIPELINES) { // i.e. all pipeline types - // pipelines cannot be moved to LST, so if the current move type is MOVE_TO_CENTER (= 'move to LST') - // then change the move typ to MOVE_TO_START to update the redistribute dialog settings shown - if (itsMoveType == MOVE_TO_CENTER) { - itsMoveType = MOVE_TO_START; - } - } - for (int row = 0; row < ui.tableWidgetTasks->rowCount(); ++row) { - if (ui.tableWidgetTasks->item(row, 7)->data(Qt::UserRole).toInt() == type) { - ui.tableWidgetTasks->selectRow(row); - } - } - ui.tableWidgetTasks->setSelectionMode(QAbstractItemView::ExtendedSelection); -} - -void ShiftTasksDialog::selectAllPipelines(void) { - ui.tableWidgetTasks->clearSelection(); - ui.tableWidgetTasks->setSelectionMode(QAbstractItemView::MultiSelection); - // pipelines cannot be moved to LST, so if the current move type is MOVE_TO_CENTER (= 'move to LST') - // then change the move typ to MOVE_TO_START to update the redistribute dialog settings shown - if (itsMoveType == MOVE_TO_CENTER) { - itsMoveType = MOVE_TO_START; - } - for (int row = 0; row < ui.tableWidgetTasks->rowCount(); ++row) { - int rowType(ui.tableWidgetTasks->item(row, 7)->data(Qt::UserRole).toInt()); - if (rowType >= SEL_CALIBRATOR_PIPELINES && rowType <= SEL_PULSAR_PIPELINES) { - ui.tableWidgetTasks->selectRow(row); - } - } - ui.tableWidgetTasks->setSelectionMode(QAbstractItemView::ExtendedSelection); -} - -void ShiftTasksDialog::redistributeSelectedTasks(void) { - QList<int> rows = getSelectedRows(); - - if (!rows.isEmpty()) { - itsRedistributeDialog->setRedistributeMode(); - // fetch the earliest start time from the selected tasks - QDateTime earliestStart, cstart; - for (QList<int>::const_iterator rowIt = rows.begin(); rowIt < rows.end(); ++rowIt) { - if (earliestStart.isNull()) { - if (!ui.tableWidgetTasks->item(*rowIt, 2)->text().isEmpty()) { - earliestStart = ui.tableWidgetTasks->item(*rowIt, 2)->data(Qt::UserRole).toDateTime(); - } - } - else { - if (!ui.tableWidgetTasks->item(*rowIt, 2)->text().isEmpty()) { - cstart = ui.tableWidgetTasks->item(*rowIt, 2)->data(Qt::UserRole).toDateTime(); - if (cstart < earliestStart) { - earliestStart = cstart; - } - } - } - } - if (earliestStart.isNull()) { - itsRedistributeDialog->setStartTime(QDateTime::currentDateTimeUtc()); - } - else { - itsRedistributeDialog->setStartTime(earliestStart); - } - itsMoveType == MOVE_TO_CENTER ? itsRedistributeDialog->setMoveToLSTType() : itsRedistributeDialog->setMoveToStartType(); - if (itsRedistributeDialog->exec()) { - const QDateTime start(itsRedistributeDialog->getStartTime()); - const QTime timeStep1(itsRedistributeDialog->getTimeStep1()); - const QTime timeStep2(itsRedistributeDialog->getTimeStep2()); - int nrParallelTasks(itsRedistributeDialog->getNrParallelTasks()); - - AstroTime gap1(timeStep1), gap2(timeStep2); - AstroDateTime startTime(start); - AstroDateTime endTime(startTime.addSeconds(ui.tableWidgetTasks->item(rows.first(), 4)->data(Qt::UserRole).toInt())); - if (static_cast<Task::task_status>(ui.tableWidgetTasks->item(rows.first(), 6)->data(Qt::UserRole).toInt()) <= Task::PRESCHEDULED) { - ui.tableWidgetTasks->item(rows.first(), 2)->setText(startTime.toString().c_str()); - ui.tableWidgetTasks->item(rows.first(), 2)->setData(Qt::UserRole, startTime.toQDateTime()); - ui.tableWidgetTasks->item(rows.first(), 3)->setText(endTime.toString().c_str()); - ui.tableWidgetTasks->item(rows.first(), 3)->setData(Qt::UserRole, endTime.toQDateTime()); - } - int taskCounter = 0; - AstroTime gap(gap1); - bool gapAlternator(true); - for (int idx = 1; idx < rows.size(); ++idx) { - int row(rows.at(idx)); - Task::task_status state(static_cast<Task::task_status>(ui.tableWidgetTasks->item(row, 6)->data(Qt::UserRole).toInt())); - int durationSec(ui.tableWidgetTasks->item(row, 4)->data(Qt::UserRole).toInt()); - if (state <= Task::PRESCHEDULED) { - if (++taskCounter == nrParallelTasks) { - taskCounter = 0; - startTime = endTime + gap; // use same start time for parallel task - // alternate between gap1 and gap2 - if (gapAlternator) { - gap = gap2; - gapAlternator = false; - } - else { - gap = gap1; - gapAlternator = true; - } - } - endTime = startTime.addSeconds(durationSec); - - ui.tableWidgetTasks->item(row, 2)->setText(startTime.toString().c_str()); - ui.tableWidgetTasks->item(row, 2)->setData(Qt::UserRole, startTime.toQDateTime()); - ui.tableWidgetTasks->item(row, 3)->setText(endTime.toString().c_str()); - ui.tableWidgetTasks->item(row, 3)->setData(Qt::UserRole, endTime.toQDateTime()); - } - } - - if (itsMoveType == MOVE_TO_CENTER) { // now move them to LST if necessary - applyPreview(); - } - } - } -} - -void ShiftTasksDialog::scheduleAfterPredecessor(void) { - QList<int> rows = getSelectedRows(); - if (!rows.isEmpty()) { - itsRedistributeDialog->setAfterPredecessorMode(); - itsRedistributeDialog->setStartTime(ui.dateTimeEditNow->dateTime()); - if (itsRedistributeDialog->exec()) { - AstroTime timeStep(itsRedistributeDialog->getTimeStep1()); - const Task *predTask(0); - QString errStr; - for (int idx = 0; idx < rows.size(); ++idx) { - QDateTime lastPredEnd; - int row(rows.at(idx)); - const Task *pTask(itsController->getTask(ui.tableWidgetTasks->item(row, 0)->data(Qt::UserRole).toInt())); - if (pTask->getStatus() <= Task::PRESCHEDULED) { - // search for the last predecessor end time - const IDvector &predecessors(pTask->getPredecessors()); - if (!predecessors.empty()) { - // now look for these predecessors in the preview list and use the specified times from there - // (they might already be changed and thus be different from the times in the schedule) - bool timeSet(false); - for (IDvector::const_iterator prit = predecessors.begin(); prit != predecessors.end(); ++prit) { - unsigned predID(0); - if (prit->first != ID_SCHEDULER) { - predTask = itsController->getTask(prit->second, prit->first); - if (predTask) { - predID = predTask->getID(); - } - } - else { - predID = prit->second; - } - if (predID) { - bool found(false); - for (int rowIdx = 0; rowIdx < ui.tableWidgetTasks->rowCount(); ++rowIdx) { - if (predID == ui.tableWidgetTasks->item(rowIdx, 0)->data(Qt::UserRole).toUInt()) { - found = true; - const QDateTime &predEndTime = ui.tableWidgetTasks->item(rowIdx, 3)->data(Qt::UserRole).toDateTime(); - if (predEndTime.isValid() && predEndTime > lastPredEnd) { - lastPredEnd = predEndTime; - timeSet = true; - } - break; // search for next predecessor - } - } - if (!found) { - errStr += QString::number(pTask->getSASTreeID()) + " predecessor:" + QString::number(prit->second) + " not found!\n"; - } - } - } - - if (timeSet) { - AstroDateTime newStart = lastPredEnd + timeStep; - AstroDateTime endTime = newStart.addSeconds(ui.tableWidgetTasks->item(row, 4)->data(Qt::UserRole).toInt()); - ui.tableWidgetTasks->item(row, 2)->setText(newStart.toString().c_str()); - ui.tableWidgetTasks->item(row, 2)->setData(Qt::UserRole, newStart.toQDateTime()); - ui.tableWidgetTasks->item(row, 3)->setText(endTime.toString().c_str()); - ui.tableWidgetTasks->item(row, 3)->setData(Qt::UserRole, endTime.toQDateTime()); - } - } - else { - errStr += QString::number(pTask->getSASTreeID()) + " does not have predecessors defined\n"; - } - } - } - if (!errStr.isEmpty()) { - QMessageBox::warning(this, tr("Troubles"), errStr, tr("Close")); - } - } - } -} - - -void ShiftTasksDialog::loadTargets(void) { - bool beamsLoaded(false); - const std::vector<unsigned> &tasks(itsController->selectedTasks()); - if (!tasks.empty()) { - const Observation *pObs; - for (std::vector<unsigned>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - pObs = itsController->getObservation(*it); - if (pObs) { - QStringList props; - const std::map<unsigned, DigitalBeam> &beams(pObs->getDigitalBeams()); - if (!beams.empty()) { - props << QString::number(pObs->getSASTreeID()) << pObs->getTaskDescription() << pObs->getScheduledStart().toString().c_str() << pObs->getDuration().toString(3).c_str(); - QTreeWidgetItem *obsItem = new QTreeWidgetItem(ui.treeWidgetAngles, props); - obsItem->setFlags(Qt::ItemIsEnabled); - - for (std::map<unsigned, DigitalBeam>::const_iterator beamIt = beams.begin(); beamIt != beams.end(); ++beamIt) { - props.clear(); - props << "" << beamIt->second.angle1().HMSstring().c_str() << beamIt->second.target().c_str(); - QTreeWidgetItem *beamItem = new QTreeWidgetItem(obsItem, props); - // QTreeWidgetItem *item = new QTreeWidgetItem(str.c_str(), ui.treeWidgetAngles); - // beamItem->setData(0, Qt::UserRole, beamIt->second.angle1().HMSstring().c_str()); - std::string angleStr(beamIt->second.angle1().HMSstring()); - beamItem->setData(0, Qt::UserRole, angleStr.substr(0, angleStr.find_first_of(".")).c_str()); - beamItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable); - beamsLoaded = true; - } - } - } - } - } - ui.treeWidgetAngles->expandAll(); - ui.treeWidgetAngles->resizeColumnToContents(0); - ui.treeWidgetAngles->resizeColumnToContents(1); - ui.treeWidgetAngles->resizeColumnToContents(2); - ui.treeWidgetAngles->resizeColumnToContents(3); - ui.pushButtonCenterAtLST->setEnabled(beamsLoaded); -} - -void ShiftTasksDialog::loadTasks(void) { - const std::vector<unsigned> &tasks(itsController->selectedTasks()); - if (!tasks.empty()) { - ui.tableWidgetTasks->setRowCount(tasks.size()); - const Task *task; - int row(0); - for (std::vector<unsigned>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - task = itsController->getTask(*it); - if (task) { - // SAS ID - QTableWidgetItem *item = new QTableWidgetItem(QString::number(task->getSASTreeID())); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - item->setData(Qt::UserRole, *it); // save the task id in the user data, for later reference - ui.tableWidgetTasks->setItem(row, 0, item); - // task name - item = new QTableWidgetItem(task->getTaskName()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - ui.tableWidgetTasks->setItem(row, 1, item); - // planned start - item = new QTableWidgetItem(task->getScheduledStart().toString().c_str()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - item->setData(Qt::UserRole, task->getScheduledStart().toQDateTime()); - ui.tableWidgetTasks->setItem(row, 2, item); - // planned end - item = new QTableWidgetItem(task->getScheduledEnd().toString().c_str()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - item->setData(Qt::UserRole, task->getScheduledEnd().toQDateTime()); - ui.tableWidgetTasks->setItem(row, 3, item); - // duration - item = new QTableWidgetItem(task->getDuration().toString(3).c_str()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - item->setData(Qt::UserRole, task->getDuration().totalSeconds()); - ui.tableWidgetTasks->setItem(row, 4, item); - // task description - item = new QTableWidgetItem(task->SASTree().description().c_str()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - ui.tableWidgetTasks->setItem(row, 5, item); - // status - item = new QTableWidgetItem(task->getStatusStr()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - item->setData(Qt::UserRole, task->getStatus()); // save the task status - ui.tableWidgetTasks->setItem(row, 6, item); - // type - item = new QTableWidgetItem(task->getTypeStr()); - item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsDragEnabled); - // save the task type - Task::task_type type(task->getType()); - if (type == Task::OBSERVATION) { - item->setData(Qt::UserRole, SEL_OBSERVATIONS); // observation - } - else if ((type == Task::PIPELINE) && (task->getStrategy().contains("calibrator", Qt::CaseInsensitive))) { - item->setData(Qt::UserRole, SEL_CALIBRATOR_PIPELINES); // calibrator pipeline - } - else if ((type == Task::PIPELINE) && (task->getStrategy().contains("target", Qt::CaseInsensitive))) { - item->setData(Qt::UserRole, SEL_TARGET_PIPELINES); // target pipeline - } - else if (task->getProcessSubtype() == PST_AVERAGING_PIPELINE) { - item->setData(Qt::UserRole, SEL_PREPROCESSING_PIPELINES); // pre-processing pipeline - } - else if (task->getProcessSubtype() == PST_IMAGING_PIPELINE || task->getProcessSubtype() == PST_MSSS_IMAGING_PIPELINE) { - item->setData(Qt::UserRole, SEL_IMAGING_PIPELINES); // imaging pipeline - } - else if (task->getProcessSubtype() == PST_LONG_BASELINE_PIPELINE) { - item->setData(Qt::UserRole, SEL_LONGBASELINE_PIPELINES); // long-baseline pipeline - } - else if (type == Task::RESERVATION) { - item->setData(Qt::UserRole, SEL_RESERVATION); // reservation - } - else if (type == Task::MAINTENANCE) { - item->setData(Qt::UserRole, SEL_MAINTENANCE); // maintenance - } - else if (type == Task::SYSTEM) { - item->setData(Qt::UserRole, SEL_SYSTEM); // system - } - else { - item->setData(Qt::UserRole, SEL_UNKNOWN); // unknown type - } - ui.tableWidgetTasks->setItem(row, 7, item); - } - ++row; - } - ui.tableWidgetTasks->resizeColumnsToContents(); - } -} - -void ShiftTasksDialog::accept(void) { - QApplication::setOverrideCursor(Qt::WaitCursor); - QCoreApplication::processEvents(); // force update to paint dialog - if (itsController) { - std::map<unsigned, AstroDateTime> tasks; - for (int row = 0; row < ui.tableWidgetTasks->rowCount(); ++row) { - if (static_cast<Task::task_status>(ui.tableWidgetTasks->item(row,6)->data(Qt::UserRole).toInt()) <= Task::PRESCHEDULED) { - if (!ui.tableWidgetTasks->item(row, 2)->text().isEmpty()) { - tasks[ui.tableWidgetTasks->item(row, 0)->data(Qt::UserRole).toInt()] = - AstroDateTime(ui.tableWidgetTasks->item(row, 2)->data(Qt::UserRole).toDateTime()); - } - } - } - if (itsController->moveTasks(tasks)) { - QDialog::accept(); - } - } - QApplication::restoreOverrideCursor(); - QCoreApplication::processEvents(); // force update to paint dialog -} - -void ShiftTasksDialog::applyPreview(void) { - QList<int> rows = getSelectedRows(); - std::map<unsigned, Task> shiftedTasks; - if (!rows.isEmpty()) { - bool showWarning(false); - std::vector<int> taskRows; - for (int idx = 0; idx < rows.size(); ++idx) { - int row(rows.at(idx)); - if (static_cast<Task::task_status>(ui.tableWidgetTasks->item(row, 6)->data(Qt::UserRole).toInt()) <= Task::PRESCHEDULED) { - taskRows.push_back(row); - } - else showWarning = true; - } - - AstroDateTime new_start, new_end; - if ((itsMoveType == MOVE_LEFT) || (itsMoveType == MOVE_RIGHT)) { // these are relative moves so interpret only the time part of date_time (as a relative time) - for (std::vector<int>::iterator it = taskRows.begin(); it != taskRows.end(); ++it) { - switch (itsMoveType) { - case MOVE_LEFT: - new_start = AstroDateTime(ui.tableWidgetTasks->item(*it, 2)->data(Qt::UserRole).toDateTime()) - AstroTime(ui.lineEditTimeShift->text()); - break; - default: // MOVE_RIGHT - new_start = AstroDateTime(ui.tableWidgetTasks->item(*it, 2)->data(Qt::UserRole).toDateTime()) + AstroTime(ui.lineEditTimeShift->text()); - break; - } - new_end = new_start.addSeconds(ui.tableWidgetTasks->item(*it, 4)->data(Qt::UserRole).toInt()); - - // apply to preview - ui.tableWidgetTasks->item(*it, 2)->setText(new_start.toString().c_str()); - ui.tableWidgetTasks->item(*it, 2)->setData(Qt::UserRole, new_start.toQDateTime()); // save the task id in the user data, for later reference - ui.tableWidgetTasks->item(*it, 3)->setText(new_end.toString().c_str()); - ui.tableWidgetTasks->item(*it, 3)->setData(Qt::UserRole, new_end.toQDateTime()); - } - } - else if (itsMoveType == MOVE_TO_START) { // shift to absolute specified time - if (!taskRows.empty()) { - AstroDateTime earliestStartTime = AstroDateTime(ui.tableWidgetTasks->item(taskRows.front(), 2)->data(Qt::UserRole).toDateTime()), startTime; - for (std::vector<int>::iterator it = taskRows.begin(); it != taskRows.end(); ++it) { - startTime = AstroDateTime(ui.tableWidgetTasks->item(*it, 2)->data(Qt::UserRole).toDateTime()); - if (startTime < earliestStartTime) { - earliestStartTime = startTime; - } - } - - AstroDateTime newFirstTime(ui.dateTimeEditNow->dateTime()); - AstroTime dif; - bool left_right; - if (earliestStartTime < newFirstTime) { // shift right - dif = newFirstTime - earliestStartTime; - left_right = true; - - } - else { // shift left - dif = earliestStartTime - newFirstTime; - left_right = false; - } - - for (std::vector<int>::iterator it = taskRows.begin(); it != taskRows.end(); ++it) { - startTime = AstroDateTime(ui.tableWidgetTasks->item(*it, 2)->data(Qt::UserRole).toDateTime()); - if (left_right) { - new_start = startTime + dif; - } - else { - new_start = startTime - dif; - } - new_end = new_start.addSeconds(ui.tableWidgetTasks->item(*it, 4)->data(Qt::UserRole).toInt()); - - // apply to preview - ui.tableWidgetTasks->item(*it, 2)->setText(new_start.toString().c_str()); - ui.tableWidgetTasks->item(*it, 2)->setData(Qt::UserRole, new_start.toQDateTime()); // save the task id in the user data, for later reference - ui.tableWidgetTasks->item(*it, 3)->setText(new_end.toString().c_str()); - ui.tableWidgetTasks->item(*it, 3)->setData(Qt::UserRole, new_end.toQDateTime()); - - } - } - } - else { // MOVE_TO_CENTER - if (!taskRows.empty()) { - AstroDateTime earliestStartTime = AstroDateTime(ui.tableWidgetTasks->item(taskRows.front(), 2)->data(Qt::UserRole).toDateTime()), startTime, endTime; - AstroDateTime latestEndTime = AstroDateTime(ui.tableWidgetTasks->item(taskRows.front(), 3)->data(Qt::UserRole).toDateTime()); - selector_types type; - for (std::vector<int>::iterator it = taskRows.begin(); it != taskRows.end(); ++it) { - type = static_cast<selector_types>(ui.tableWidgetTasks->item(*it, 7)->data(Qt::UserRole).toInt()); - if (type == SEL_OBSERVATIONS) { // only look at observations to determine the shift for a CENTER = LST move - startTime = AstroDateTime(ui.tableWidgetTasks->item(*it, 2)->data(Qt::UserRole).toDateTime()); - endTime = AstroDateTime(ui.tableWidgetTasks->item(*it, 3)->data(Qt::UserRole).toDateTime()); - if (startTime < earliestStartTime) { - earliestStartTime = startTime; - } - if (endTime > latestEndTime) { - latestEndTime = endTime; - } - } - } - - AstroDateTime oldCenterTime((latestEndTime.toJulian() + earliestStartTime.toJulian()) / 2); - AstroTime dif = AstroDateTime(ui.dateTimeEditNow->dateTime()) - oldCenterTime; - - for (std::vector<int>::iterator it = taskRows.begin(); it != taskRows.end(); ++it) { - startTime = AstroDateTime(ui.tableWidgetTasks->item(*it, 2)->data(Qt::UserRole).toDateTime()); - new_start = startTime + dif; - new_end = new_start.addSeconds(ui.tableWidgetTasks->item(*it, 4)->data(Qt::UserRole).toInt()); - - ui.tableWidgetTasks->item(*it, 2)->setText(new_start.toString().c_str()); - ui.tableWidgetTasks->item(*it, 2)->setData(Qt::UserRole, new_start.toQDateTime()); // save the task id in the user data, for later reference - ui.tableWidgetTasks->item(*it, 3)->setText(new_end.toString().c_str()); - ui.tableWidgetTasks->item(*it, 3)->setData(Qt::UserRole, new_end.toQDateTime()); - } - } - } - - - if (showWarning) { - QMessageBox::warning(this, tr("Some tasks could not be moved"), - "Some tasks have a status above PRESCHEDULED. These tasks cannot not be moved.", tr("Close")); - } - - // now apply the preview - for (std::map<unsigned, Task>::const_iterator taskit = shiftedTasks.begin(); taskit != shiftedTasks.end(); ++taskit) { - for (int row = 0; row < ui.tableWidgetTasks->rowCount(); ++row) { - if (ui.tableWidgetTasks->item(row, 0)->data(Qt::UserRole).toUInt() == taskit->first) { - ui.tableWidgetTasks->item(row, 2)->setText(taskit->second.getScheduledStart().toString().c_str()); - ui.tableWidgetTasks->item(row, 2)->setData(Qt::UserRole, taskit->second.getScheduledStart().toQDateTime()); // save the task id in the user data, for later reference - ui.tableWidgetTasks->item(row, 3)->setText(taskit->second.getScheduledEnd().toString().c_str()); - ui.tableWidgetTasks->item(row, 3)->setData(Qt::UserRole, taskit->second.getScheduledEnd().toQDateTime()); - break; - } - } - } - } -} - - -void ShiftTasksDialog::doLSTCheck(void) { - if (itsMoveType == MOVE_TO_CENTER) { // MOVE_TO_CENTER means LST move here - calculateLST(); - } - else { - applyPreview(); - } -} - - -void ShiftTasksDialog::calculateNow(void) { - itsMoveType = MOVE_TO_START; - QDateTime nu; - nu = QDateTime::currentDateTimeUtc(); - nu = nu.addSecs(300); - ui.dateTimeEditNow->blockSignals(true); - ui.dateTimeEditNow->setDateTime(nu); - ui.dateTimeEditNow->blockSignals(false); - ui.lineEditTimeShift->setText("0000:00:00"); -// applyPreview(); -} - -int ShiftTasksDialog::getSelectedTasksTimeSpan(void) const { - QList<int> rows = getSelectedRows(); - QDateTime startTime, endTime, earliestStartTime, latestEndTime; - bool isSet(false); - if (!rows.isEmpty()) { - for (int idx = 0; idx < rows.size(); ++idx) { - int row(rows.at(idx)); - const QDateTime &startTime = ui.tableWidgetTasks->item(row, 2)->data(Qt::UserRole).toDateTime(); - const QDateTime &endTime = ui.tableWidgetTasks->item(row, 2)->data(Qt::UserRole).toDateTime(); - if (!isSet) { - earliestStartTime = startTime; - latestEndTime = endTime; - isSet = true; - } - else { - if (startTime < earliestStartTime) { - earliestStartTime = startTime; - } - if (endTime > latestEndTime) { - latestEndTime = endTime; - } - } - } - } - if (isSet) { - return (latestEndTime - earliestStartTime).totalSeconds(); - } - else return 0; -} - -void ShiftTasksDialog::applyShift(void) { - itsMoveType = ui.radioButtonShiftLeft->isChecked() ? MOVE_LEFT : MOVE_RIGHT; - applyPreview(); -} - -void ShiftTasksDialog::calculateLST(void) { - itsMoveType = MOVE_TO_CENTER; - QList<QTreeWidgetItem *> items(ui.treeWidgetAngles->selectedItems()); - // if the date(day) has already been set by the user then don't change the date - // if it has not been set then set it to today - AstroDate day; - if (ui.dateTimeEditNow->date().toJulianDay() == J2000_EPOCH) { // by default the date equals the J2000_EPOCH - day = AstroDate(QDateTime::currentDateTime().date()); - ui.dateTimeEditNow->blockSignals(true); - ui.dateTimeEditNow->setDate(QDateTime::currentDateTime().date()); - ui.dateTimeEditNow->blockSignals(false); - } - else { - day = AstroDate(ui.dateTimeEditNow->date()); - } - if (!items.isEmpty()) { - AstroTime time; - double tmean(0.0); - for (QList<QTreeWidgetItem *>::const_iterator lit = items.begin(); lit != items.end(); ++lit) { - time = (*lit)->data(0, Qt::UserRole).toString(); // the angle right ascension interpreted as a time - tmean += time.toJulian(); - } - tmean = tmean / items.count(); - time = AstroTime(tmean); - - AstroDateTime UTC = AstroDateTime::UTfromLST(time, day); - int halfTimeSpanSeconds = getSelectedTasksTimeSpan() / 2; - - while (UTC.subtractSeconds(halfTimeSpanSeconds).toQDateTime() < QDateTime::currentDateTime().toUTC()) { - day = day.addDays(1); - UTC = AstroDateTime::UTfromLST(time, day); - } - ui.dateTimeEditNow->blockSignals(true); - ui.dateTimeEditNow->setDateTime(UTC.toQDateTime()); - ui.dateTimeEditNow->blockSignals(false); - - // now update the tasks table accordingly to show the preview of the results -// applyPreview(); - - } - else { - QMessageBox::warning(this, "Select a beam right ascension", "First select one or more beam right ascension(s) to center upon.\nSelecting multiple will calculate the mean LST for these right ascensions."); - } -} diff --git a/SAS/Scheduler/src/shifttasksdialog.h b/SAS/Scheduler/src/shifttasksdialog.h deleted file mode 100644 index cee4a0152ddf87dd4253342bd03bf4a8bb6b2a02..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/shifttasksdialog.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ShiftTasksDialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : sept-2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/shifttasksdialog.h $ - * - */ - -#ifndef SHIFTTASKSDIALOG_H -#define SHIFTTASKSDIALOG_H - -enum moveType { - MOVE_LEFT, - MOVE_RIGHT, - MOVE_TO_CENTER, - MOVE_TO_START -}; - -#include <QDialog> -#include "ui_shifttasksdialog.h" -#include "Controller.h" - -class redistributeTasksDialog; - -class ShiftTasksDialog : public QDialog -{ - Q_OBJECT - -public: - ShiftTasksDialog(QWidget *parent = 0, Controller *controller = 0); - ~ShiftTasksDialog(); - -private slots: - void accept(void); - void applyPreview(void); // only applies to this dialog preview, doesn't close the dialog - void calculateNow(void); - void applyShift(void); - void calculateLST(void); - void setLeftMoveType(void) {itsMoveType = MOVE_LEFT;} - void setRightMoveType(void) {itsMoveType = MOVE_RIGHT;} - void doLSTCheck(void); - void showTableContextMenu(const QPoint &); - void redistributeSelectedTasks(void); - void scheduleAfterPredecessor(void); - void selectObservations(void) {selectTasks(SEL_OBSERVATIONS);} - void selectAllPipelines(void); - void selectCalibratorPipelines(void) {selectTasks(SEL_CALIBRATOR_PIPELINES);} - void selectTargetPipelines(void) {selectTasks(SEL_TARGET_PIPELINES);} - void selectPreProcessingPipelines(void) {selectTasks(SEL_PREPROCESSING_PIPELINES);} - void selectLongBaselinePipelines(void) {selectTasks(SEL_LONGBASELINE_PIPELINES);} - void selectImagingPipelines(void) {selectTasks(SEL_IMAGING_PIPELINES);} - void selectPulsarPipelines(void) {selectTasks(SEL_PULSAR_PIPELINES);} - void sortPreview(int, Qt::SortOrder); - -private: - void loadTargets(void); - void loadTasks(void); - void selectTasks(int type); - QList<int> getSelectedRows(void) const; - int getSelectedTasksTimeSpan(void) const; - void insertTaskBefore(int rowA, int rowB); - -private: - Ui::ShiftTasksDialogClass ui; - Controller *itsController; - redistributeTasksDialog *itsRedistributeDialog; - - moveType itsMoveType; -}; - -#endif // SHIFTTASKSDIALOG_H diff --git a/SAS/Scheduler/src/shifttasksdialog.ui b/SAS/Scheduler/src/shifttasksdialog.ui deleted file mode 100644 index 40d002ef924a7f8c5ab5470b6638c38e9e3dd28c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/shifttasksdialog.ui +++ /dev/null @@ -1,267 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>ShiftTasksDialogClass</class> - <widget class="QDialog" name="ShiftTasksDialogClass"> - <property name="windowModality"> - <enum>Qt::ApplicationModal</enum> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>1010</width> - <height>700</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="windowTitle"> - <string>ShiftTasksDialog</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <property name="modal"> - <bool>false</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="3"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Please specify the size of the shift in hhhh:mm:ss</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QRadioButton" name="radioButtonShiftLeft"> - <property name="text"> - <string>Shift left</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QRadioButton" name="radioButtonShiftRight"> - <property name="text"> - <string>Shift right</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QLineEdit" name="lineEditTimeShift"> - <property name="toolTip"> - <string>hhhh:mm:ss</string> - </property> - <property name="inputMask"> - <string>0000:00:00; </string> - </property> - <property name="text"> - <string>0000:00:00</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QPushButton" name="pushButtonApplyAbsMove"> - <property name="toolTip"> - <string>apply the shift to the selected task in the preview pane</string> - </property> - <property name="text"> - <string>Apply</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QPushButton" name="pushButtonCenterAtLST"> - <property name="text"> - <string>Center at LST</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QPushButton" name="pushButtonShiftToNow"> - <property name="toolTip"> - <string>shift so that the earliest task shifts to now + 5 minutes</string> - </property> - <property name="text"> - <string>Shift to now</string> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QDateTimeEdit" name="dateTimeEditNow"> - <property name="displayFormat"> - <string>yyyy-MM-dd hh:mm:ss</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="QPushButton" name="pushButtonApplyLSTnow"> - <property name="toolTip"> - <string>apply the shown LST/now time to the selected task in the preview pane</string> - </property> - <property name="text"> - <string>Apply</string> - </property> - </widget> - </item> - <item row="3" column="0" colspan="2"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Select targets for LST calculation:</string> - </property> - </widget> - </item> - <item row="4" column="0" colspan="8"> - <widget class="QSplitter" name="splitter"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <widget class="QTreeWidget" name="treeWidgetAngles"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="baseSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::MultiSelection</enum> - </property> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - <widget class="QTableWidget" name="tableWidgetTasks"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </widget> - </item> - <item row="5" column="7"> - <widget class="QPushButton" name="pushButtonOk"> - <property name="text"> - <string>Ok</string> - </property> - <property name="default"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="5"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>340</width> - <height>24</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="7"> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="6"> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="5" column="6"> - <widget class="QPushButton" name="pushButtonCancel"> - <property name="text"> - <string>Cancel</string> - </property> - <property name="autoDefault"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <tabstops> - <tabstop>radioButtonShiftLeft</tabstop> - <tabstop>radioButtonShiftRight</tabstop> - <tabstop>lineEditTimeShift</tabstop> - <tabstop>pushButtonCenterAtLST</tabstop> - <tabstop>pushButtonShiftToNow</tabstop> - <tabstop>dateTimeEditNow</tabstop> - <tabstop>treeWidgetAngles</tabstop> - <tabstop>tableWidgetTasks</tabstop> - </tabstops> - <resources/> - <connections> - <connection> - <sender>pushButtonCancel</sender> - <signal>clicked()</signal> - <receiver>ShiftTasksDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>909</x> - <y>690</y> - </hint> - <hint type="destinationlabel"> - <x>102</x> - <y>99</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonOk</sender> - <signal>clicked()</signal> - <receiver>ShiftTasksDialogClass</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>1000</x> - <y>690</y> - </hint> - <hint type="destinationlabel"> - <x>330</x> - <y>111</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/signalhandler.cpp b/SAS/Scheduler/src/signalhandler.cpp deleted file mode 100644 index 800ac9d6412a6e8bb37aa96eb513a624b39d0780..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/signalhandler.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * main.cpp - * - * Author : Wouter Klijn - * e-mail : klijn@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 28-oct-2014 - * URL : $URL: https://svn.astron.nl/ROD/branches/LOFAR_Scheduler-Task6767/main.cpp $ - * - */ - -#include "signalhandler.h" -#include "Controller.h" - -#include <iostream> - - - -SignalHandler::SignalHandler(QApplication *app, Controller *c) -{ - itsApplication = app; - itsController = c; - // Create the connection between the SignalHandler class and the possible - // items to action upon. - //connect(itsController->gui->getSchedulerGUIClass().action_DownloadSASSchedule, - // SIGNAL(triggered()), itsController, SLOT(downloadSASSchedule())); -} - -int SignalHandler::signalForward(std::string action, std::string /*parameter*/) -{ - // IF then tree to select specific signals to send. - // TODO: This feels clutchy might be a better solution. Might have to wait - // untill next refactor step. - - std::cerr << "Received command: " << action << std::endl; - - if (action == "DownloadSASSchedule") - emit itsController->gui->getSchedulerGUIClass( - ).action_DownloadSASSchedule->trigger(); - else if (action == "DownloadSASScheduleClose") - { - - QApplication::sendEvent( - &itsController->itsSASConnection->progressDialog(), - new QCloseEvent()); - // TODO: Might cause an xevent que mixup - // Xlib: sequence lost (0x1037e > 0x381) in reply type 0x9! - //(google gives comparable/same erros - // and the possible cause - } - else if (action == "MainWindowClose") - { - QApplication::sendEvent( - itsApplication, - new QCloseEvent()); - - } - // This action does not work. Saving this as a starting point for a next - // atempt. - else if (action == "PresNoInSaveDialog") - { - QMessageBox* box = itsController->possiblySaveMessageBox; - std::cout << "debug 1" << std::endl; - if (!box) // If null pointer we cannot press a button in the dialog - return 0; - std::cout << "debug 2" << std::endl; - - //TODO: Emit a "do not save button clicked event" - - //QAbstractButton* noButton = box->button(QMessageBox::No); - //QPushButton* noButton = dynamic_cast<QPushButton*>(box->button(QMessageBox::No)); - - //std::cout << "result: " << box->result() << std::endl; - //box->setResult(QMessageBox::No); - //std::cout << "result: " << box->result() << std::endl; - - //QPushButton* pushButton = box->findChild<QPushButton*>(); - //std::cout << "debug 3" << std::endl; - //std::cout << "Found buttons: " << pushButton << std::cout; - - - } - - else{ // If an unknown action string is received return 1 - // TODO: Add to logfile line that unknown signal was received. - throw 1; - } - // Incorrect code should result in exceptions. to be caught by test framework - - return 0; -} - - diff --git a/SAS/Scheduler/src/signalhandler.h b/SAS/Scheduler/src/signalhandler.h deleted file mode 100644 index 4407fc4b8e9dd68022dc9ba9e1b0c6cf15bab0f8..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/signalhandler.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef SIGNALHANDLER_H -#define SIGNALHANDLER_H - -#include <QObject> -#include <QApplication> -#include <string> - -// TOd prevent circular dependency on the controller declare instead of include controller -class Controller; - -// SignalHandler QObject that forwards received actions trings to internals of the -// scheduler. It is expoced as interface on the ligscheduler via the function -// signalForward in libScheduler.h -class SignalHandler : public QObject -{ - Q_OBJECT - -public: - // Contructor, needs the internal objects QApplication and Controller - explicit SignalHandler(QApplication *app, Controller *c); - - // Switch function emiting signals based on action string - int signalForward(std::string action, std::string parameter); - -signals: - // TODO: We might need signals back: - // - gui opened - // - exit called - // - sas download complete - // - etc. - -public slots: - -private: - Controller *itsController; - QApplication *itsApplication; -}; - -#endif // SIGNALHANDLER_H diff --git a/SAS/Scheduler/src/statehistorydialog.cpp b/SAS/Scheduler/src/statehistorydialog.cpp deleted file mode 100644 index 72f2e002140461b1c6e8d15e7e21c1a2caf817ac..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/statehistorydialog.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "statehistorydialog.h" - -StateHistoryDialog::StateHistoryDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); - ui.tableWidgetStateInfo->setColumnCount(5); - QStringList header; - header << "tree ID" << "mom ID" << "new state" << "user name" << "modification time"; - ui.tableWidgetStateInfo->setHorizontalHeaderLabels(header); - ui.tableWidgetStateInfo->setEditTriggers(QAbstractItemView::NoEditTriggers); - ui.tableWidgetStateInfo->horizontalHeader()->setStretchLastSection(true); -#if QT_VERSION >= 0x050000 - ui.tableWidgetStateInfo->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); -#else - ui.tableWidgetStateInfo->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); -#endif - this->setWindowTitle("Task state change history"); -} - -StateHistoryDialog::~StateHistoryDialog() -{ - -} - -void StateHistoryDialog::addStateInfo(const QString &treeID, const QString &momID, - const QString &state, const QString &username, const QDateTime &modtime) { - int row(ui.tableWidgetStateInfo->rowCount()); - ui.tableWidgetStateInfo->insertRow(ui.tableWidgetStateInfo->rowCount()); - QTableWidgetItem *newItem = new QTableWidgetItem(treeID); - ui.tableWidgetStateInfo->setItem(row, 0, newItem); - newItem = new QTableWidgetItem(momID); - ui.tableWidgetStateInfo->setItem(row, 1, newItem); - newItem = new QTableWidgetItem(state); - ui.tableWidgetStateInfo->setItem(row, 2, newItem); - newItem = new QTableWidgetItem(username); - ui.tableWidgetStateInfo->setItem(row, 3, newItem); - newItem = new QTableWidgetItem(modtime.toString("yyyy-MM-dd hh:mm:ss")); - ui.tableWidgetStateInfo->setItem(row, 4, newItem); - -#if QT_VERSION >= 0x050000 - ui.tableWidgetStateInfo->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); -#else - ui.tableWidgetStateInfo->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); -#endif -} diff --git a/SAS/Scheduler/src/statehistorydialog.h b/SAS/Scheduler/src/statehistorydialog.h deleted file mode 100644 index 87d4915862136914875be489ac6996cc43797765..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/statehistorydialog.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef STATEHISTORYDIALOG_H -#define STATEHISTORYDIALOG_H - -#include <QDialog> -#include "ui_statehistorydialog.h" -#include <QDateTime> - -class StateHistoryDialog : public QDialog -{ - Q_OBJECT - -public: - StateHistoryDialog(QWidget *parent = 0); - ~StateHistoryDialog(); - - void addStateInfo(const QString &treeID, const QString &momID, - const QString &state, const QString &username, const QDateTime &modtime); - void clear(void) {ui.tableWidgetStateInfo->clearContents(); ui.tableWidgetStateInfo->setRowCount(0);} - -private: - Ui::StateHistoryDialogClass ui; -}; - -#endif // STATEHISTORYDIALOG_H diff --git a/SAS/Scheduler/src/statehistorydialog.ui b/SAS/Scheduler/src/statehistorydialog.ui deleted file mode 100644 index 59a82db5991755c628643a7c65a23ba53b705dca..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/statehistorydialog.ui +++ /dev/null @@ -1,65 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>StateHistoryDialogClass</class> - <widget class="QDialog" name="StateHistoryDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>511</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>StateHistoryDialog</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" colspan="3"> - <widget class="QTableWidget" name="tableWidgetStateInfo"/> - </item> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButtonClose"> - <property name="text"> - <string>Close</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButtonClose</sender> - <signal>clicked()</signal> - <receiver>StateHistoryDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>378</x> - <y>275</y> - </hint> - <hint type="destinationlabel"> - <x>393</x> - <y>273</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/station.cpp b/SAS/Scheduler/src/station.cpp deleted file mode 100644 index 3fdf755c9a8abb56acfd720793498302f3ab84b0..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/station.cpp +++ /dev/null @@ -1,471 +0,0 @@ -/* - * station.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 21, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/station.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "station.h" -#include "task.h" -#include "Controller.h" -#include <map> -#include <vector> -#include <cmath> -#include <algorithm> -using std::vector; -using std::map; -#ifdef DEBUG_SCHEDULER -#include <iostream> -#endif - -const char *antenna_modes_str[NR_ANTENNA_MODES] = {"UNSPECIFIED", "LBA INNER", - "LBA OUTER", "LBA SPARSE EVEN", "LBA SPARSE ODD", "LBA X", "LBA Y", "HBA ZERO", "HBA ZERO INNER", "HBA ONE", "HBA ONE INNER", "HBA DUAL", "HBA DUAL INNER", "HBA JOINED", "HBA JOINED INNER"}; - -const char *SAS_antenna_modes_str[NR_ANTENNA_MODES] = {"","LBA_INNER", - "LBA_OUTER", "LBA_SPARSE_EVEN", "LBA_SPARSE_ODD", "LBA_X", "LBA_Y", "HBA_ZERO", "HBA_ZERO_INNER", "HBA_ONE", "HBA_ONE_INNER", "HBA_DUAL", "HBA_DUAL_INNER", "HBA_JOINED", "HBA_JOINED_INNER"}; - -const char *clock_frequencies_str[NR_CLOCK_FREQUENCIES] = {"UNSPECIFIED","160MHz","200MHz"}; - -const char *filter_types_str[NR_FILTER_TYPES] = {"UNSPECIFIED", "LBA 10-70MHz", "LBA 30-70MHz", - "LBA 10-90MHz", "LBA 30-90MHz", "HBA 110-190MHz", "HBA 170-230MHz", "HBA 210-250MHz"}; - -const char *SAS_filter_types_str[NR_FILTER_TYPES] = {"", "LBA_10_70", "LBA_30_70", - "LBA_10_90", "LBA_30_90", "HBA_110_190", "HBA_170_230", "HBA_210_250"}; - -station_clock stringToStationClockType(const std::string &str) { - if (!str.empty()) { - for (short i = 0; i < END_STATION_CLOCK; ++i) { - if (str.compare(clock_frequencies_str[i]) == 0) { - return static_cast<station_clock>(i); - } - } - } - return static_cast<station_clock>(0); -} - -Station::Station() : - station_id(0) -{ - -} - -Station::Station(const std::string &name, unsigned id) : - station_id(id), itsName(name) -{ - -} - -Station::Station(const Station &other) : - station_id(other.getStationID()), itsName(other.getName()), itsTasks(other.getTasks()) -{ -} - -Station::~Station() -{ -} - -Station & Station::operator=(const Station &rhs) { - station_id = rhs.getStationID(); - itsName = rhs.getName(); - itsTasks = rhs.getTasks(); - return *this; -} - -QDataStream& operator<< (QDataStream &out, const Station &station) { // used for writing to binary file - out << (quint16) station.station_id - << station.itsName - << (quint32) station.itsTasks.size(); // number of tasks - for (stationTasksVector::const_iterator it = station.itsTasks.begin(); it != station.itsTasks.end(); ++it) { - out << (quint32) it->first << it->second.first << it->second.second; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, Station &station) { - station.itsTasks.clear(); - quint32 nrOfTasks; - quint32 taskID; - AstroDateTime dateTime; - std::pair<AstroDateTime, AstroDateTime > timePair; - in >> station.station_id // station ID - >> station.itsName - //read the numer of tasks assigned to this station - >> nrOfTasks; - for (quint32 i = 0; i < nrOfTasks; ++i) { - in >> taskID; - in >> dateTime; - timePair.first = dateTime; - in >> dateTime; - timePair.second = dateTime; - station.itsTasks.push_back( - std::pair<unsigned, std::pair<AstroDateTime, AstroDateTime > >(taskID, timePair) - ); - } - return in; -} - -/* -bool Station::getConflicts(const AstroDateTime &request_start, const AstroDateTime &request_end, vector<unsigned> &conflict_ids) -{ - bool bConflicts = false; - map<AstroDateTime, unsigned>::iterator it; - if (it = startTimes.lower_bound(request_start) != startTimes.end()) { - AstroDateTime end_confl_task = endTimes.find(it.second); - if (end_confl_task < request_end + MIN_TIME_BETWEEN_TASKS) { - conflict_ids.push_back(it.second); - bConflicts = true; - } - } - if (it = endTimes.lower_bound(request_start) != startTimes.end()) { - AstroDateTime start_confl_task = startTimes.find(it.second); - if (start_confl_task < request_end + MIN_TIME_BETWEEN_TASKS) { - conflict_ids.push_back(it.second); - bConflicts = true; - } - } - return bConflicts; -} -*/ - -stationTasksVector::const_iterator Station::lower_bound(const AstroDateTime &date) const -{ - // binary search for first task that has an end time later than the time specified in date - stationTasksVector::const_iterator it = itsTasks.begin(); - if (itsTasks.size() > 1) { // more than one element? - unsigned iu = itsTasks.size()-1, il = 0, i = 0; - it = it + (iu / 2); - while (true) { - if (it->second.second > date) { - iu = (il + iu) / 2; - } - else { - il = (il + iu) / 2; - } - i = (il + iu) / 2; - it = itsTasks.begin() + i; - if ((iu - il) <= 1) { // check stop conditions - if (itsTasks.at(il).second.second >= date) { - it = itsTasks.begin() + il; - return it; - } - else if (itsTasks.at(iu).second.second >= date) { - it = itsTasks.begin() + iu; - return it; - } - else { - return itsTasks.end(); - } - } - } - } - else if (itsTasks.size() == 1) { // only one element in itsTasks vector - if (itsTasks.at(0).second.second >= date) { - return itsTasks.begin(); - } - else { - return itsTasks.end(); - } - } - - return itsTasks.end(); -} - - -bool Station::findFirstOpportunity(const Task &task, AstroDateTime &first_possible, const AstroTime &min_time_between_tasks, unsigned reservation_id) -{ - bool result(true), stop(false); - unsigned sday = first_possible.getDate().toJulian(); - unsigned last_day = task.getWindowLastDay().toJulian(); - unsigned first_day = task.getWindowFirstDay().toJulian(); - double stime = first_possible.toJulian() - sday; - double mintime = task.getWindowMinTime().toJulian(); - double maxtime = task.getWindowMaxTime().toJulian(); - - // do some checks on the start time and date - if (sday > last_day) { - first_possible = 0.0; // AstroDateTime(); - result = false; - } - else if (sday < first_day) { - sday = first_day; - stime = mintime; - } - if ((stime < mintime) & (sday <= first_day)) { - stime = mintime; - sday = first_day; - } - if ((stime > maxtime) & (sday >= last_day)) { - first_possible = 0.0; //AstroDateTime(); - result = false; - } - - // printAllTasks(); - // if the task is part of a reservation the ignore that reservation while finding a time slot - // we do this by temporarily removing the reservation from the task list - stationTask reservation; - if (reservation_id) { - reservation = removeTask(reservation_id); - } - else { - if (task.isObservation()) { - const Observation *pTask = static_cast<const Observation *>(&task); - if ((reservation_id = pTask->getReservation())) { - reservation = removeTask(reservation_id); - } - } - } - - if (result & !itsTasks.empty()) { - for (unsigned day = sday; day <= last_day; ++day) - { - AstroDateTime first_time(day, stime); // first possible time at this day - AstroTime max_time = task.getWindowMaxTime(); - AstroTime duration = task.getDuration(); - stationTasksVector::const_iterator first_later_task = lower_bound(first_time); - AstroDateTime projected_start, projected_end; - - if (first_later_task != itsTasks.end()) { // found the first task that has an end time later than the first possible time on this day - // check if the task we found still ends on this day - if (first_later_task->second.second.getDate().toJulian() == static_cast<int>(day)) { - // check if the task can be scheduled at first_time - if (first_time + duration + min_time_between_tasks < first_later_task->second.first) { - first_possible = first_time; - result = true; - break; - } - // possibly the start time of the task found is also later than the first possible time. Check if the new task fits before this task - projected_start = first_later_task->second.first - static_cast<AstroDateTime>(min_time_between_tasks) - static_cast<AstroDateTime>(duration); - if (projected_start >= first_time) { - // still enough distance between the projected start and the previous task? - if (projected_start - static_cast<AstroDateTime>(min_time_between_tasks) >= (first_later_task-1)->second.second) { - first_possible = projected_start; - result = true; - break; - } - } - while (true) { // here we start checking for a scheduling space after the task found by lower_bound - projected_start = first_later_task->second.second + static_cast<AstroDateTime>(min_time_between_tasks); - projected_end = projected_start + static_cast<AstroDateTime>(duration); - if (projected_end.getDate() <= task.getWindowLastDay()) { - if (task.getWindowMinTime() + task.getDuration() < task.getWindowMaxTime()) { // if the task can fit within one day time window - // then also check if the projected end time is smaller than the specified end time of the time window - if (projected_end > max_time) { // on this day the task doesn't fit the end time requirement of the time window - break; // goto next day in while loop - } - } - if (first_later_task+1 != itsTasks.end()) { // if there is a next task: - // check if gap between the two tasks is big enough to fit this task in between - AstroDateTime tmp = projected_end + static_cast<AstroDateTime>(min_time_between_tasks); - if ((first_later_task+1)->second.first >= tmp) - { // yes, gap is big enough! schedule the task after the task found. - first_possible = projected_start; - result = true; - stop = true; - break; - } - ++first_later_task; // check gaps between next tasks until we run of this day - } - else { // the task found was the last task. try to schedule the requested task after this last task. - // check if the requested task can still be scheduled on this day or has to be scheduled on the next - first_possible = projected_start; - result = true; - stop = true; - break; - } - } - else { // end time or date is beyond time window for this task - first_possible = 0.0; - result = false; - stop = true; - break; - } - } - if (stop) break; - } - else { // the first task we found with an end time later than our requested first day has an end time on a later day, we can check if the current task fits before the task found. - if (first_time + static_cast<AstroDateTime>(min_time_between_tasks) + static_cast<AstroDateTime>(duration) <= first_later_task->second.first) { // fits before? - first_possible = first_time; - result = true; - stop = true; - break; - } - } - } - else { // no tasks found with an end time later than the time requested, but there could be tasks - // so make sure we meet the minimum distance requirements from the last task in the vector - first_possible = std::max(itsTasks.back().second.second + static_cast<AstroDateTime>(min_time_between_tasks), first_time); - result = true; - stop = true; - break; - } - if (stop) break; - } - } - else { // no tasks found, the task list is still empty for this station - first_possible = sday + stime; - result = true; - } - - // put back the temporarily removed reservation task - if (reservation_id) { - addTasktoStation(reservation_id, reservation.second.first, reservation.second.second); - } - - return result; -} - -void Station::printAllTasks(void) const { - std::cout << "All tasks for station " << station_id << ":"; - if (!itsTasks.empty()) { - std::cout << std::endl; - for (stationTasksVector::const_iterator it=itsTasks.begin(); it != itsTasks.end(); ++it) { - std::cout << it->first << ": start: " << it->second.first.toString() << ", end: " << it->second.second.toString() << std::endl; - } - } - else { - std::cout << "no tasks." << std::endl; - } -} - - -void Station::sortTasks2EndTime() -{ - sort(itsTasks.begin(), itsTasks.end(), cmp_TaskEndTime()); -} - - -bool Station::addTasktoStation(unsigned task_id, const AstroDateTime &start, const AstroDateTime &end) -{ - // Insert task in the vector tasks and sort the vector on the end times - for (stationTasksVector::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - if (it->first == task_id) { -//#ifdef DEBUG_SCHEDULER -// std::cerr << "Station::addTasktoStation: tried to schedule a task which is already scheduled on this station." << std::endl; -//#endif -// return false; - // already scheduled on this station. - // this happens e.g. when the task goes from PRESCHEDULED to SCHEDULED state - // only update the start and end time - it->second.first = start; - it->second.second = end; - sortTasks2EndTime(); - return true; - } - } - std::pair<AstroDateTime, AstroDateTime> times = std::pair<AstroDateTime, AstroDateTime>(start,end); - stationTask task = - ( - stationTask(task_id, times) - ); - itsTasks.push_back(task); - sortTasks2EndTime(); - return true; -} - -bool Station::moveTask(unsigned task_id, const AstroDateTime &start, const AstroDateTime &end) -{ - for (stationTasksVector::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - if (it->first == task_id) { - it->second = std::pair<AstroDateTime, AstroDateTime>(start,end); - sortTasks2EndTime(); - return true; - } - } - return false; -} - -/* -std::vector<unsigned> Station::getParallelTasks(const AstroDateTime &req_start, const AstroDateTime &req_end) { - std::vector<unsigned> taskIDs; - stationTasksVector::const_iterator first_later_task = lower_bound(req_start); - // while not yet at end of task vector AND - // while (start time of first_later_task <= requested start end) AND (end time of first_later_task >= requested start) - // then the task pointed to by first_later_task iterator overlaps with the period between requested start and end time. - while (first_later_task++ != itsTasks.end() && (first_later_task->second.first <= req_end && first_later_task->second.second >= req_start)) { - taskIDs.push_back(first_later_task->first); - } -} -*/ - - -stationTask Station::removeTask(unsigned task_id) { - stationTask removed_task; - for (stationTasksVector::iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - if (it->first == task_id) { - removed_task.first = task_id; - removed_task.second = it->second; - itsTasks.erase(it); - return removed_task; - } - } - return removed_task; -} -/* -void Station::removeTask(unsigned taskID) { - if (!itsTasks.empty()) { - // find the task with the specified taskID - for (stationTasksVector::iterator i = itsTasks.begin(); i != itsTasks.end(); ++i) { - if (i->first == taskID) { - itsTasks.erase(i); - return; - } - } - } -} -*/ - -std::vector<unsigned> Station::getTaskswithinTimeSpan(const AstroDateTime &start, const AstroDateTime &end) const { - std::vector<unsigned> tasks; - AstroTime min_time_between_tasks(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks()); -// std::cout << "getting tasks from station:" << itsName << std::endl -// << " within timespan " << start.toString() << " - " << end.toString() << std::endl; - for (stationTasksVector::const_iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { -// std::cout << "task:" << it->first << ", start: " << it->second.first.toString() << ", end: " << it->second.second.toString() <<std::endl; -// std::cout << "test 1:" << static_cast<int>(it->second.first < end + min_time_between_tasks) << ", test 2:" << static_cast<int>(it->second.second > start - min_time_between_tasks) << std::endl; - if ((it->second.first < end + min_time_between_tasks) & (it->second.second > start - min_time_between_tasks)) { - tasks.push_back(it->first); - } - } - return tasks; -} - -unsigned Station::getTask(const AstroDateTime &start) const { - stationTasksVector::const_iterator cit = lower_bound(start); - if (cit != itsTasks.end()) { - return cit->first; - } - else return 0; -} - - -const char * getStationClockStr(station_clock clock) { - if (clock >= 0 && clock <= NR_CLOCK_FREQUENCIES-1) { - return clock_frequencies_str[clock]; - } - return "UNKOWN"; -} - -unsigned getStationClock(station_clock clock) { - if (clock == clock_160Mhz) return 160; - else if (clock == clock_200Mhz) return 200; - else { - debugErr("s","Unsupported clock frequency!"); - return 0; - } -} - -const char * getAntennaModeStr(station_antenna_mode mode) { - if (mode >= 0 && mode <= NR_ANTENNA_MODES-1) { - return antenna_modes_str[mode]; - } - return "UNKNOWN"; -} - - diff --git a/SAS/Scheduler/src/station.h b/SAS/Scheduler/src/station.h deleted file mode 100644 index 8732a49aab9a0f9a5481c28211bd0bf12cbd628b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/station.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * station.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 21, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/station.h $ - * - */ - -#ifndef STATION_H_ -#define STATION_H_ - -#include <map> -#include <vector> -#include <utility> -#include <fstream> -#include <QDataStream> -#include "lofar_utils.h" -#include "astrodatetime.h" - -class Task; - -// station antenna modes -enum station_antenna_mode { - UNSPECIFIED_ANTENNA_MODE = 0, - LBA_INNER, - LBA_OUTER, - LBA_SPARSE_EVEN, - LBA_SPARSE_ODD, - LBA_X, - LBA_Y, - HBA_ZERO, - HBA_ZERO_INNER, - HBA_ONE, - HBA_ONE_INNER, - HBA_DUAL, - HBA_DUAL_INNER, - HBA_JOINED, - HBA_JOINED_INNER, - ANTENNA_MODE_END -}; - -#define NR_ANTENNA_MODES ANTENNA_MODE_END - -// station clock frequencies -enum station_clock { - UNSPECIFIED_CLOCK, - clock_160Mhz, - clock_200Mhz, - END_STATION_CLOCK -}; -#define NR_CLOCK_FREQUENCIES END_STATION_CLOCK - -// station filter types -enum station_filter_type { - UNSPECIFIED_FILTER, - LBA_10_70, - LBA_30_70, - LBA_10_90, - LBA_30_90, - HBA_110_190, - HBA_170_230, - HBA_210_250, - FILTER_TYPE_END -}; -#define NR_FILTER_TYPES FILTER_TYPE_END - -extern const char *antenna_modes_str[NR_ANTENNA_MODES]; -extern const char *SAS_antenna_modes_str[NR_ANTENNA_MODES]; -extern const char *clock_frequencies_str[NR_CLOCK_FREQUENCIES]; -extern const char *filter_types_str[NR_FILTER_TYPES]; -extern const char *SAS_filter_types_str[NR_FILTER_TYPES]; - - -typedef std::pair<unsigned, std::pair<AstroDateTime, AstroDateTime > > stationTask; -typedef std::vector<stationTask> stationTasksVector; - -class Station { -public: - Station(); - Station(const Station &); - Station(const std::string &name, unsigned id); - virtual ~Station(); - - Station &operator=(const Station &rhs); - // returns the first available slot within the requested periods specified in the task. - // returns false if no slot available. If true is returned then start_time and stop_time hold the - //bool GetFirstAvailableSlot(Task *ptask, AstroDateTime &start_time, AstroDateTime &stop_time); - - friend QDataStream& operator<< (QDataStream &out, const Station &station); - friend QDataStream& operator>> (QDataStream &in, Station &station); // used for reading data from binary file - - // Schedules the task with the given times. - unsigned getStationID(void) const { return station_id; } - void setName(const std::string & name) { itsName = name; } - const std::string & getName(void) const { return itsName; } - const stationTasksVector &getTasks(void) const {return itsTasks;} - const char * getStationClockStr(station_clock clock); - unsigned getStationClock(station_clock clock); - bool addTasktoStation(unsigned task_id, const AstroDateTime &start, const AstroDateTime &end); - bool moveTask(unsigned task_id, const AstroDateTime &start, const AstroDateTime &end); - stationTask removeTask(unsigned taskID); // removes the task with the specified task ID and returns it when successful - void removeAllTasks(void) {itsTasks.clear();} - std::vector<unsigned> getTaskswithinTimeSpan(const AstroDateTime &start, const AstroDateTime &end) const; - unsigned getTask(const AstroDateTime &start) const; - - bool findFirstOpportunity(const Task &task, AstroDateTime &first_possible, const AstroTime &min_time_between_tasks, unsigned reservation_id = 0); - // find the first task that has a date later than date - void sortTasks2EndTime(void); // sort the tasks vector according to the end times of the tasks - void printAllTasks(void) const; - -private: - stationTasksVector::const_iterator lower_bound(const AstroDateTime &date) const; - - quint16 station_id; - std::string itsName; - stationTasksVector itsTasks; -}; - - -// the following class is needed to be able to sort a vector of pointers to Task objects -// according to the priority attribute of the Task objects - -class cmp_TaskEndTime -{ -public: - bool operator() (const stationTask &t1, const stationTask &t2) const - { - return t1.second.second < t2.second.second; - } -}; - -extern station_clock stringToStationClockType(const std::string &str); - -#endif /* STATION_H_ */ diff --git a/SAS/Scheduler/src/stationlistwidget.cpp b/SAS/Scheduler/src/stationlistwidget.cpp deleted file mode 100644 index 4a5a7e6e47179602b882e4d00b8bef1ba4e6c85b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationlistwidget.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * stationlistwidget.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 6, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/stationlistwidget.cpp $ - * - */ - -#include "stationlistwidget.h" -#include <QMimeData> -#include <QDrag> -#include <QDragEnterEvent> -#include <QDragMoveEvent> -#include <QDropEvent> - -#include <iostream> - -StationListWidget::StationListWidget(QWidget *parent) - : QListWidget(parent) -{ - ui.setupUi(this); - setAcceptDrops(true); - setDragDropMode(QAbstractItemView::DragDrop); - setDefaultDropAction(Qt::MoveAction); - setSelectionMode(QAbstractItemView::ExtendedSelection); -} - -StationListWidget::~StationListWidget() -{ - -} - -void StationListWidget::addStations(const QStringList &stations) { - for (QStringList::const_iterator it = stations.begin(); it != stations.end(); ++it) { - if (findItems(*it, Qt::MatchExactly).isEmpty()) { - addItem(*it); - } - } - sortItems(); -} - -void StationListWidget::removeStation(const QString &station) { - QList<QListWidgetItem *> list = findItems(station, Qt::MatchExactly); - if (!list.isEmpty()) { - QModelIndex idx = indexFromItem(list.first()); - delete takeItem(idx.row()); - } -} - -void StationListWidget::dragEnterEvent(QDragEnterEvent *event) { - if (event->source() != this) - event->accept(); -} - -void StationListWidget::dragMoveEvent(QDragMoveEvent * event) { - if (event->source()) - event->accept(); -} - -void StationListWidget::mousePressEvent(QMouseEvent * event) { - // when space key was pressed the multiselection mode (keyboard selection) was set, now go back to extendedselection for mouse selection - setSelectionMode(QAbstractItemView::ExtendedSelection); - QListWidget::mousePressEvent(event); -} - -void StationListWidget::keyPressEvent(QKeyEvent * event) { - QStringList stationList; - QList<QListWidgetItem*> items; - switch (event->key()) { - case Qt::Key_Space: - setSelectionMode(QAbstractItemView::MultiSelection); - QListWidget::keyPressEvent(event); - break; - case Qt::Key_Right: - case Qt::Key_Plus: - case Qt::Key_Return: - case Qt::Key_Insert: - items = this->selectedItems(); - for (QList<QListWidgetItem *>::const_iterator it = items.begin(); it != items.end(); ++it) { - stationList.append((*it)->text()); - delete *it; - } - emit addStationsToUse(stationList); - - break; - default: - QListWidget::keyPressEvent(event); - break; - } -} - -bool StationListWidget::dropMimeData(int /*index*/, const QMimeData *data, Qt::DropAction /*action*/) -{ -// bool possibleChange(false); - QStringList listOfStations = data->text().split("|"); - if (!listOfStations.isEmpty()) { - for (QStringList::const_iterator it = listOfStations.begin(); it != listOfStations.end(); ++it) { // add top-level item(s) - QListWidgetItem *stationItem = new QListWidgetItem(*it, this); - stationItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled); -// possibleChange = true; - } - sortItems(); - } - if (!listOfStations.isEmpty()) emit stationsRemoved(); - return true; - -} - - -QMimeData *StationListWidget::mimeData(const QList<QListWidgetItem *> items) const { - QMimeData *mimeData = new QMimeData; - QString stationList; - for (QList<QListWidgetItem *>::const_iterator it = items.begin(); it != items.end()-1; ++it) { - stationList += (*it)->text() + "|"; - } - stationList += items.back()->text(); - - mimeData->setText(stationList); - return mimeData; -} diff --git a/SAS/Scheduler/src/stationlistwidget.h b/SAS/Scheduler/src/stationlistwidget.h deleted file mode 100644 index b7dea39d5b923a9ca718e39fcad86662a3a9cb15..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationlistwidget.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * stationlistwidget.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 6, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/stationlistwidget.h $ - * - */ - -#ifndef STATIONLISTWIDGET_H -#define STATIONLISTWIDGET_H - -#include <QListWidget> -#include "ui_stationlistwidget.h" - -class QMouseEvents; -class QDragEnterEvent; -class QDragMoveEvent; -class QDropEvent; - - -// class used as list of available stations -class StationListWidget : public QListWidget -{ - Q_OBJECT - -public: - StationListWidget(QWidget *parent = 0); - ~StationListWidget(); - - void addStations(const QStringList &stations); - void removeStation(const QString &station); - -protected: - void dragEnterEvent(QDragEnterEvent *event); - void dragMoveEvent(QDragMoveEvent * event); - bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action); - void keyPressEvent ( QKeyEvent * event ); - void mousePressEvent ( QMouseEvent * event ); - QMimeData *mimeData(const QList<QListWidgetItem *> items) const; - -signals: -// void updateUsedStations(void) const; - void stationsRemoved(void) const; - void addStationsToUse(const QStringList &) const; - -private: - Ui::StationListWidgetClass ui; - QPoint startPos; -}; - -#endif // STATIONLISTWIDGET_H diff --git a/SAS/Scheduler/src/stationlistwidget.ui b/SAS/Scheduler/src/stationlistwidget.ui deleted file mode 100644 index 09a92fde35f8d38afd94d6c17344b66697bc9549..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationlistwidget.ui +++ /dev/null @@ -1,19 +0,0 @@ -<ui version="4.0" > - <class>StationListWidgetClass</class> - <widget class="QWidget" name="StationListWidgetClass" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle" > - <string>StationListWidget</string> - </property> - </widget> - <layoutdefault spacing="6" margin="11" /> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/stationtask.cpp b/SAS/Scheduler/src/stationtask.cpp deleted file mode 100644 index c199cdd2226d2ac58cf2555b087b9a0a8795269b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationtask.cpp +++ /dev/null @@ -1,526 +0,0 @@ -/* - * stationtask.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/stationtask.cpp $ - * - */ - -#include "stationtask.h" -#include "Controller.h" - -StationTask::StationTask(task_type type) - : Task(), itsNrVirtualStations(0), itsAntennaMode(UNSPECIFIED_ANTENNA_MODE), itsClockFrequency(UNSPECIFIED_CLOCK), itsFilterType(UNSPECIFIED_FILTER), - itsNrOfDataslotsPerRSPboard(61) -{ - itsTaskType = type; -} - -StationTask::StationTask(unsigned task_id, task_type type) - : Task(task_id), itsNrVirtualStations(0), itsAntennaMode(UNSPECIFIED_ANTENNA_MODE), itsClockFrequency(UNSPECIFIED_CLOCK), itsFilterType(UNSPECIFIED_FILTER), - itsNrOfDataslotsPerRSPboard(61) -{ - itsTaskType = type; -} - - -StationTask::StationTask(unsigned task_id, const OTDBtree &SAS_tree, task_type type) - : Task(task_id, SAS_tree), itsNrVirtualStations(0), itsAntennaMode(UNSPECIFIED_ANTENNA_MODE), itsClockFrequency(UNSPECIFIED_CLOCK), itsFilterType(UNSPECIFIED_FILTER), - itsNrOfDataslotsPerRSPboard(61) -{ - itsTaskType = type; -} - -StationTask::StationTask(const QSqlQuery &query, const OTDBtree &SAS_tree, task_type type) - : Task(query, SAS_tree), itsNrVirtualStations(0), itsAntennaMode(UNSPECIFIED_ANTENNA_MODE), itsClockFrequency(UNSPECIFIED_CLOCK), itsFilterType(UNSPECIFIED_FILTER), - itsNrOfDataslotsPerRSPboard(61) -{ - itsTaskType = type; -} - -QDataStream& operator<< (QDataStream &out, const StationTask &task) { - if (out.status() == QDataStream::Ok) { - out << static_cast<const Task &>(task); - - // write station names and IDs for this task - out << (quint32) task.itsStations.size(); - for (taskStationsMap::const_iterator it = task.itsStations.begin(); it != task.itsStations.end(); ++it) { - out << it->first << (quint16) it->second; - } - // itsSuperStations - out << (quint32) task.itsSuperStations.size(); - for (superStationMap::const_iterator it = task.itsSuperStations.begin(); it != task.itsSuperStations.end(); ++it) { - out << it->first << (quint32) it->second.size(); - for (std::vector<unsigned>::const_iterator vit = it->second.begin(); vit != it->second.end(); ++vit) { - out << (quint16) *vit; - } - } - - // itsAntennaMode, itsFilterType, itsClockFrequency - out << (quint8) task.itsAntennaMode << (quint8) task.itsFilterType << (quint8) task.itsClockFrequency; - - // data slot list (don't write this?) - out << (quint32) task.itsDataSlots.size(); - for (dataSlotMap::const_iterator it = task.itsDataSlots.begin(); it != task.itsDataSlots.end(); ++it) { - out << (quint16) it->first // stationID - << (quint32) it->second.size(); // nr of RSP boards assigned - for (stationDataSlotMap::const_iterator sdit = it->second.begin(); sdit != it->second.end(); ++sdit) { - out << (quint8) sdit->first // RSP board number - << (quint16) sdit->second.first // minimum dataslot used on this board - << (quint16) sdit->second.second; // maximum dataslot used on this board - } - } - - // itsNrOfDataslotsPerRSPboard - out << task.itsNrOfDataslotsPerRSPboard; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, StationTask &task) { - if (in.status() == QDataStream::Ok) { - quint32 nrOfObjects, nrOfObjects2; - quint16 stationID; - quint8 mode, filter, clock; - std::string tmpString; - - in >> static_cast<Task &>(task); - - task.itsStations.clear(); - // read station ids for this task - in >> nrOfObjects; - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> tmpString >> stationID; // station name, station id - task.itsStations[tmpString] = stationID; - } - - // itsSuperStations - std::vector<unsigned> station_ids; - task.itsSuperStations.clear(); - in >> nrOfObjects; - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> tmpString >> nrOfObjects2; // super station name, number of stations in the superstation list - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> stationID; - station_ids.push_back(stationID); - } - task.itsSuperStations[tmpString] = station_ids; - station_ids.clear(); - } - - // itsAntennaMode, itsFilterType, itsClockFrequency - in >> mode >> filter >> clock; - task.itsAntennaMode = (station_antenna_mode) mode; - task.itsFilterType = (station_filter_type) filter; - task.itsClockFrequency = (station_clock) clock; - - // data slot list - task.itsDataSlots.clear(); - std::pair<unsigned, unsigned> dataSlotPair; - quint8 RSPboard; - quint16 minDataSlot, maxDataSlot; - stationDataSlotMap dsMap; - in >> nrOfObjects; // number of stations in dataSlotMap - for (quint32 i=0; i < nrOfObjects; ++i) { - in >> stationID // stationID - >> nrOfObjects2; // number of RSPBoards assigned - for (quint32 i = 0; i < nrOfObjects2; ++i) { - in >> RSPboard // RSP board number - >> minDataSlot // lowest data slot number on this board that is used - >> maxDataSlot; // highest data slot number on this board that is used - dataSlotPair.first = minDataSlot; - dataSlotPair.second = maxDataSlot; - dsMap[RSPboard] = dataSlotPair; - task.itsDataSlots[stationID] = dsMap; - } - dsMap.clear(); - } - - // itsNrOfDataslotsPerRSPboard - in >> task.itsNrOfDataslotsPerRSPboard; - } - - task.calculateNrVirtualStations(); - - return in; -} - -StationTask & StationTask::operator=(const Task &other) { - if (this != &other) { - Task::operator=(other); - const StationTask *pOther = dynamic_cast<const StationTask *>(&other); - if (pOther) { - itsStations = pOther->itsStations; - itsNrVirtualStations = pOther->itsNrVirtualStations; - itsSuperStations = pOther->itsSuperStations; - itsAntennaMode = pOther->itsAntennaMode; - itsClockFrequency = pOther->itsClockFrequency; - itsFilterType = pOther->itsFilterType; - itsDataSlots = pOther->itsDataSlots; - nonExistingStationDataSlotMap = pOther->nonExistingStationDataSlotMap; - itsNrOfDataslotsPerRSPboard = pOther->itsNrOfDataslotsPerRSPboard; - } - } - return *this; -} - -void StationTask::removeStation(const std::string &station_name) -{ - taskStationsMap::iterator sit; - if ((sit = itsStations.find(station_name)) != itsStations.end()) { - itsStations.erase(sit); - } -} - -std::string StationTask::getAntennaField(void) const { - switch (itsAntennaMode) { - case LBA_INNER: - case LBA_OUTER: - case LBA_SPARSE_EVEN: - case LBA_SPARSE_ODD: - case LBA_X: - case LBA_Y: - return "LBA"; - break; - case HBA_ZERO: - case HBA_ZERO_INNER: - return "HBA0"; - break; - case HBA_ONE: - case HBA_ONE_INNER: - return "HBA1"; - break; - case HBA_DUAL: - case HBA_DUAL_INNER: - return "HBA_DUAL"; - break; - case HBA_JOINED: - case HBA_JOINED_INNER: - return "HBA"; - break; - default: - break; - } - return std::string(); -} - -std::string StationTask::antennaFieldName(const std::string &station) const { - return station + getAntennaField(); -} - -bool StationTask::setAntennaMode(station_antenna_mode mode) { - if ((mode >= 0) && mode < ANTENNA_MODE_END) { - itsAntennaMode = mode; - calculateNrVirtualStations(); - return true; - } - else if (isObservation()) { - debugWarn("sisi", "Task:", taskID, ", Unknown antenna mode: ", static_cast<int>(mode)); - } - return false; -} - -bool StationTask::setAntennaMode(const std::string &mode) { - if (!mode.empty()) { - for (unsigned int idx = 0; idx != NR_ANTENNA_MODES; ++idx) { - if (mode.compare(antenna_modes_str[idx]) == 0) { - itsAntennaMode = static_cast<station_antenna_mode>(idx); - calculateNrVirtualStations(); - return true; - } - } - } - else if (isObservation()) { - debugWarn("siss", "Task:", taskID, " , Unknown antenna mode: ", mode.c_str()); - } - return false; -} - -bool StationTask::setSASAntennaMode(const std::string &mode) { - if (!mode.empty()) { - for (unsigned int idx = 0; idx != NR_ANTENNA_MODES; ++idx) { - if (mode.compare(SAS_antenna_modes_str[idx]) == 0) { - itsAntennaMode = static_cast<station_antenna_mode>(idx); - calculateNrVirtualStations(); - return true; - } - } - } - else if (isObservation()) { - debugWarn("siss", "Task:", taskID, " , Unknown antenna mode: ", mode.c_str()); - } - return false; -} - -bool StationTask::setAntennaMode(unsigned short mode) { - if (mode < ANTENNA_MODE_END) { - itsAntennaMode = static_cast<station_antenna_mode>(mode); - calculateNrVirtualStations(); - return true; - } - else if (isObservation()) { - debugWarn("sisi", "Task:", taskID, " , Could not set antenna mode to:", mode); - } - return false; -} - -bool StationTask::setFilterType(station_filter_type filter) { - if ((filter >= 0) && filter < FILTER_TYPE_END) { - itsFilterType = filter; - return true; - } - else if (isObservation()) { - debugWarn("sisi", "Task:", taskID, ", Unknown filter type: ", static_cast<int>(filter)); - } - return false; -} - -bool StationTask::setFilterType(const std::string &filter) { - if (!filter.empty()) { - for (unsigned int idx = 0; idx != NR_FILTER_TYPES; ++idx) { - if (filter.compare(filter_types_str[idx]) == 0) { - itsFilterType = static_cast<station_filter_type>(idx); - return true; - } - } - } - else if (isObservation()) { - debugWarn("siss", "Task:", taskID, " , Unknown filter type: ", filter.c_str()); - } - return false; -} - -bool StationTask::setSASFilterType(const std::string &filter) { - if (!filter.empty()) { - for (unsigned int idx = 0; idx != NR_FILTER_TYPES; ++idx) { - if (filter.compare(SAS_filter_types_str[idx]) == 0) { - itsFilterType = static_cast<station_filter_type>(idx); - return true; - } - } - } - else if (isObservation()) { - debugWarn("siss", "Task:", taskID, " , Unknown filter type: ", filter.c_str()); - } - return false; -} - -bool StationTask::setFilterType(unsigned short filter) { - if (filter < FILTER_TYPE_END) { - itsFilterType = static_cast<station_filter_type>(filter); - return true; - } - else if (isObservation()) { - debugWarn("sisi", "Task:", taskID, " , Could not set filter type to:", filter); - } - return false; -} - - -bool StationTask::setStationClock(station_clock clock) { - station_clock prevClock = itsClockFrequency; - if (clock >= clock_160Mhz && clock <= clock_200Mhz) { - itsClockFrequency = clock; - if (itsClockFrequency != prevClock) { - } - return true; - } - else if (isObservation()) { - debugWarn("s", "The requested clock frequency is not supported"); - } - return false; -} - -bool StationTask::setStationClock(unsigned int clk) { - station_clock prevClock = itsClockFrequency; - if (clk == 160) { - itsClockFrequency = clock_160Mhz; - if (itsClockFrequency != prevClock) { - } - return true; - } - else if (clk == 200) { - itsClockFrequency = clock_200Mhz; - if (itsClockFrequency != prevClock) { - } - return true; - } - else if (isObservation()) { - debugWarn("sis", "The requested clock frequency: ", clk, "is not supported"); - } - return false; -} - -bool StationTask::setStationClock(const std::string &clock) { - station_clock prevClock = itsClockFrequency; - if (!clock.empty()) { - for (unsigned int idx = 0; idx != NR_CLOCK_FREQUENCIES; ++idx) { - if (clock.compare(clock_frequencies_str[idx]) == 0) { - itsClockFrequency = static_cast<station_clock>(idx); - if (itsClockFrequency != prevClock) { - } - return true; - } - } - } - else if (isObservation()) { - debugWarn("siss", "Task:", taskID, " , Error:Unknown station clock: ", clock.c_str()); - } - return false; -} - -const stationDataSlotMap &StationTask::getStationDataSlots(unsigned stationID) const { - dataSlotMap::const_iterator it = itsDataSlots.find(stationID); - if (it != itsDataSlots.end()) - return it->second; - else - return nonExistingStationDataSlotMap; -} - -//check beamformers check the beamformers for removed stations -void StationTask::checkSuperStations(void) { - superStationMap newSuperStations; - std::vector<unsigned> tmpIDs; - for (superStationMap::iterator it = itsSuperStations.begin(); it != itsSuperStations.end(); ++it) { // super-stations - tmpIDs.clear(); - for (std::vector<unsigned>::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { // station IDs for this super-stations - for (taskStationsMap::const_iterator ssit = itsStations.begin(); ssit != itsStations.end(); ++ssit) { // search assigned stations - if (ssit->second == *sit) { - tmpIDs.push_back(*sit); - break; - } - } - } - if (!tmpIDs.empty()) { - newSuperStations.insert(superStationMap::value_type(it->first, tmpIDs)); - } - } - itsSuperStations = newSuperStations; -} - -void StationTask::setStations(const std::vector<std::string> &stations) { - itsStations.clear(); - for (std::vector<std::string>::const_iterator it = stations.begin(); it != stations.end(); ++it) { - itsStations[*it] = Controller::theSchedulerSettings.getStationID(*it); - } - calculateNrVirtualStations(); - checkSuperStations(); -} - -void StationTask::setStations(const std::vector<QString> &stations) { - itsStations.clear(); - for (std::vector<QString>::const_iterator it = stations.begin(); it != stations.end(); ++it) { - const std::string &stationName = it->toStdString(); - itsStations[stationName] = Controller::theSchedulerSettings.getStationID(stationName); - } - checkSuperStations(); - calculateNrVirtualStations(); -} - -void StationTask::setStations(const QString &stations, const QChar &separator) { - setStations(string2VectorOfStrings(stations, separator)); -} - -void StationTask::setStations(const taskStationsMap &newStations) { - itsStations = newStations; - checkSuperStations(); - calculateNrVirtualStations(); -} - -void StationTask::calculateNrVirtualStations(void) { - itsNrVirtualStations = 0; - if ((itsAntennaMode == HBA_DUAL) || (itsAntennaMode == HBA_DUAL_INNER)) { - for (taskStationsMap::const_iterator it = itsStations.begin(); it != itsStations.end(); ++it) { - if (it->first.compare(0,2,"CS") == 0) itsNrVirtualStations += 2; - else ++itsNrVirtualStations; - } - } - else itsNrVirtualStations = itsStations.size(); -} - -void StationTask::updateStationIDs(void) { - unsigned int id; - for (taskStationsMap::iterator it = itsStations.begin(); it != itsStations.end(); ++it) { - id = Controller::theSchedulerSettings.getStationID(it->first); - if (id) { - it->second = id; - } - else { - it->second = 0; - } - } -} - - -std::string StationTask::getStationNamesStr(const char separater, int nrStationsOnLine, const std::string &newLine) const { - std::string stations; - if (!itsStations.empty()) { - int idx(1); - for (taskStationsMap::const_iterator it = itsStations.begin(); it != itsStations.end(); ++it) { - stations += it->first; - if (nrStationsOnLine && (idx % nrStationsOnLine == 0)) { - stations += newLine; - idx = 1; - } - else { - stations += separater; - ++idx; - } - } - std::string::iterator sit = stations.end() - 1; - if (*sit == separater) { - stations.erase(sit); - } - } - - return stations; -} - -std::string StationTask::getSASStationList(void) const { - std::string stations; - if (!itsStations.empty()) { - stations = "["; - for (taskStationsMap::const_iterator it = itsStations.begin(); it != itsStations.end(); ++it) { - stations += it->first + ","; - } - stations = stations.substr(0,stations.length()-1) + "]"; - } - return stations; -} - -/* - * diff check for difference between this task and other task. - * return true if difference - * parameter dif - */ -bool StationTask::diff(const Task *other, task_diff &dif) const { - bool taskDif(Task::diff(other, dif)); - - const StationTask *pOther = dynamic_cast<const StationTask *>(other); - if (pOther) { - dif.station_ids = itsStations != pOther->getStations() ? true : false; - return (taskDif || dif.station_ids || dif.antenna_mode || dif.clock_frequency || dif.filter_type); - } - return taskDif; -} - -QString StationTask::diffString(const task_diff &dif) const { - QString difstr(Task::diffString(dif)); - if (!difstr.isEmpty()) difstr += ","; - - if (dif.station_ids) difstr += QString(SAS_item_names[TP_STATION_IDS]) + ","; - if (dif.antenna_mode) difstr += QString(SAS_item_names[TP_ANTENNA_MODE]) + ","; - if (dif.clock_frequency) difstr += QString(SAS_item_names[TP_CLOCK_FREQUENCY]) + ","; - if (dif.filter_type) difstr += QString(SAS_item_names[TP_FILTER_TYPE]) + ","; - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} diff --git a/SAS/Scheduler/src/stationtask.h b/SAS/Scheduler/src/stationtask.h deleted file mode 100644 index 28e4ee357f5519dfc2861b26dbe7496c24cf5e50..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationtask.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * stationtask.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/stationtask.h $ - * - */ - -#ifndef STATIONTASK_H -#define STATIONTASK_H - -#include <QSqlQuery> -#include "task.h" -#include "station.h" -#include "OTDBtree.h" - -typedef std::map<unsigned short, std::pair<unsigned, unsigned> >stationDataSlotMap; -// dataSlotMap: key = station ID -typedef std::map<unsigned, stationDataSlotMap> dataSlotMap; -typedef std::map<std::string, std::vector<unsigned> > superStationMap; -typedef std::map<std::string, unsigned int> taskStationsMap; - -class StationTask : public Task -{ -public: - StationTask(task_type type); - StationTask(unsigned task_id, task_type type); - StationTask(unsigned task_id, const OTDBtree &SAS_tree, task_type type); - StationTask(const QSqlQuery &query, const OTDBtree &SAS_tree, task_type type); - - virtual StationTask & operator=(const Task &); - - virtual void clone(const Task *other) { - if (this != other) { - const StationTask *pOther = dynamic_cast<const StationTask *>(other); - if (pOther) { - unsigned myTaskID = taskID; - *this = *pOther; - taskID = myTaskID; - } - } - } - - friend QDataStream& operator<< (QDataStream &out, const StationTask &task); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, StationTask &task); // used for reading data from binary file - - // getters - inline const char * getSASFilterType() const {return SAS_filter_types_str[itsFilterType];} - station_filter_type getFilterType(void) const {return itsFilterType; } - inline const char * getFilterTypeStr() const {return filter_types_str[itsFilterType];} - station_antenna_mode getAntennaMode() const { return itsAntennaMode; } - inline const char * getAntennaModeStr() const {return antenna_modes_str[itsAntennaMode];} - inline const char * getSASAntennaSet() const {return SAS_antenna_modes_str[itsAntennaMode];} - unsigned short getStationClockFrequency() const { return itsClockFrequency == clock_160Mhz ? 160 : 200;} - station_clock getStationClock() const { return itsClockFrequency; } - inline const char * getStationClockStr() const {return clock_frequencies_str[itsClockFrequency];} - const taskStationsMap &getStations(void) const {return itsStations;} - unsigned int getNrVirtualStations(void) const {return itsNrVirtualStations;} - void updateStationIDs(); - std::string getStationNamesStr(const char separater = ',', int nrStationsOnLine = 0, const std::string &newLine = "\n") const; - std::string getSASStationList(void) const; - const dataSlotMap &getDataSlots(void) const {return itsDataSlots;} - std::string getAntennaField(void) const; - const stationDataSlotMap &getStationDataSlots(unsigned stationID) const; - unsigned getNrOfDataslotsPerRSPboard(void) const {return itsNrOfDataslotsPerRSPboard;} - - // settters - // sets the dataSlots for the digital beam with index - void clearDataSlots(void) {itsDataSlots.clear();} - void assignDataSlots(unsigned stationID, const stationDataSlotMap &dataSlots) {itsDataSlots[stationID] = dataSlots;} - - bool setAntennaMode(station_antenna_mode); - bool setAntennaMode(const std::string &mode); - bool setAntennaMode(unsigned short mode); - bool setSASAntennaMode(const std::string &mode); - bool setFilterType(station_filter_type); - bool setFilterType(const std::string &filter); - bool setFilterType(unsigned short filter); - bool setSASFilterType(const std::string &filter); - bool setStationClock(station_clock); - bool setStationClock(unsigned int); - bool setStationClock(const std::string &clock); - void setStations(const QString &stations, const QChar &separator); - void setStations(const std::vector<QString> &stations); - void setStations(const std::vector<std::string> &stations); - void setStations(const taskStationsMap &newStations); - taskStationsMap &getStationsForChange(void) {return itsStations;} - void removeStation(const std::string &station_name); - inline void setSuperStations(const superStationMap &super_stations) {itsSuperStations = super_stations;} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - -private: - // calculates the number of virtual stations (for HBA_DUAL & HBA_DUAL_INNER core stations count for two) - void calculateNrVirtualStations(void); - //check beamformers check the beamformers for removed stations - void checkSuperStations(void); - std::string antennaFieldName(const std::string &station) const; - -protected: - taskStationsMap itsStations; // list of required stations for this task - unsigned int itsNrVirtualStations; - superStationMap itsSuperStations; // list of super stations (= beamformers) - station_antenna_mode itsAntennaMode; // the station antenna configuration for this task - station_clock itsClockFrequency; // the station clock frequency (clock_160Mhz or clock_200Mhz) - station_filter_type itsFilterType; // the type of RCU filter used - dataSlotMap itsDataSlots; - stationDataSlotMap nonExistingStationDataSlotMap; - quint16 itsNrOfDataslotsPerRSPboard; -}; - -#endif // STATIONTASK_H diff --git a/SAS/Scheduler/src/stationtreewidget.cpp b/SAS/Scheduler/src/stationtreewidget.cpp deleted file mode 100644 index e0ab7a07e650cf80e9df31a5296c740838e23a06..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationtreewidget.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/* - * stationtreewidget.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 6, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/stationtreewidget.cpp $ - * - */ - -#include "lofar_scheduler.h" -#include "stationtreewidget.h" -#include <QMimeData> -#include <QDrag> -#include <QDragEnterEvent> -#include <QDragMoveEvent> -#include <QDropEvent> -#include <iostream> - -StationTreeWidget::StationTreeWidget(QWidget *parent) - : QTreeWidget(parent), itsNrOfSuperStations(0), itsHasChanged(false), itsIsMixed(false) -{ - ui.setupUi(this); - setAcceptDrops(true); -// setDragDropMode(QAbstractItemView::DragDrop); - setDragEnabled(true); - setDefaultDropAction(Qt::MoveAction); - setSelectionMode(QAbstractItemView::ExtendedSelection); - setSelectionBehavior(QAbstractItemView::SelectItems); - setRootIsDecorated(true); -// setSortingEnabled(true); - setAnimated(true); - setHeaderHidden(true); - connect(this, SIGNAL(prepareRemoveStations(unsigned)), this, SLOT(updateNrStationsToRemove(unsigned))); -} - -StationTreeWidget::~StationTreeWidget() -{ - -} - -void StationTreeWidget::addStations(const QStringList &stations) { - if (itsIsMixed) { - clear(); // remove MIXED - itsIsMixed = false; - } - if (!stations.isEmpty()) { - for (QStringList::const_iterator it = stations.begin(); it != stations.end(); ++it) { - QTreeWidgetItem * stationItem = new QTreeWidgetItem(this, QStringList(*it)); - stationItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled); - } - itsHasChanged = true; - } - sortItems(1,Qt::AscendingOrder); - sortItems(0,Qt::AscendingOrder); -} - -QTreeWidgetItem * StationTreeWidget::addSuperStation(void) { - QTreeWidgetItem *superStation = new QTreeWidgetItem(this, QStringList(QString(">Super station ") + QString::number(++itsNrOfSuperStations))); - superStation->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDropEnabled); - itsHasChanged = true; - return superStation; -} - -void StationTreeWidget::addSuperStationAndChilds(void) { - QTreeWidgetItem *superStation = addSuperStation(); - QList<QTreeWidgetItem *> selectedStations = selectedItems(); - if (!selectedStations.isEmpty()) { - QList<QTreeWidgetItem *> deleteChildren, deleteSuperStations; - for (QList<QTreeWidgetItem *>::iterator it = selectedStations.begin(); it != selectedStations.end(); ++it) { - if ((*it)->text(0).startsWith(">")) { - for (int i = 0; i < (*it)->childCount(); ++i) { - QTreeWidgetItem *copy = new QTreeWidgetItem(*(*it)->child(i)); - superStation->addChild(copy); - } - deleteSuperStations.append(*it); - } - else { - QTreeWidgetItem *copy = new QTreeWidgetItem(**it); - superStation->addChild(copy); - deleteChildren.append(*it); - } - } - this->addTopLevelItem(superStation); - for (QList<QTreeWidgetItem *>::iterator it = deleteChildren.begin(); it != deleteChildren.end(); ++it) { - delete *it; - } - for (QList<QTreeWidgetItem *>::iterator it = deleteSuperStations.begin(); it != deleteSuperStations.end(); ++it) { - delete *it; - } - sortItems(1,Qt::AscendingOrder); - sortItems(0,Qt::AscendingOrder); - itsHasChanged = true; - } -} - -void StationTreeWidget::setMixed(void) { - clear(); - new QTreeWidgetItem(this, QStringList("MIXED")); - itsIsMixed = true; -} - -void StationTreeWidget::dragEnterEvent(QDragEnterEvent *event) { - if (event->source()) { - if (itsIsMixed) { - clear(); // remove the '(MIXED)' item - itsIsMixed = false; - } - // event->setDropAction(Qt::MoveAction); - event->accept(); - itsHasChanged = true; - } -} - -void StationTreeWidget::dragMoveEvent(QDragMoveEvent * event) { - if (event->source()) { - event->accept(); - } -} - -void StationTreeWidget::dragLeaveEvent ( QDragLeaveEvent * event ) { -// if (event->source()) { - event->accept(); - itsHasChanged = true; -// } -} - -void StationTreeWidget::dropEvent(QDropEvent * event) { - QTreeWidget::dropEvent(event); - sortItems(1,Qt::AscendingOrder); - sortItems(0,Qt::AscendingOrder); - emit checkForStationChanges(); -} - -// which mime types can be dropped on this StationTreeWidget -QStringList StationTreeWidget::mimeTypes () const -{ - QStringList qstrList; - // list of accepted mime types for drop - qstrList.append("text/uri-list"); - return qstrList; -} - -// which actions are supported by this StationTreeWidget class -Qt::DropActions StationTreeWidget::supportedDropActions () const -{ - // returns what actions are supported when dropping - return Qt::MoveAction; -} - -// mimeData: function that creates the dragged data -QMimeData *StationTreeWidget::mimeData(const QList<QTreeWidgetItem *> items) const -{ - unsigned nrStationsToRemove(0); - QMimeData *mimeData = new QMimeData; - QString stationList; - for (QList<QTreeWidgetItem *>::const_iterator it = items.begin(); it != items.end()-1; ++it) { - stationList += (*it)->text(0) + "|"; - if (!((*it)->parent())) { // if this station does not come from a super station - ++nrStationsToRemove; // count the number of stations that will be removed - } - } - QString lastItemStr(items.back()->text(0)); - if (lastItemStr.compare(MULTIPLE_VALUE_TEXT) != 0) { // if the user is not dragging '(MIXED)' - stationList += items.back()->text(0); - if (!(items.back()->parent())) { - ++nrStationsToRemove; - } - mimeData->setText(stationList); - emit prepareRemoveStations(nrStationsToRemove); - } - - return mimeData; -} - -// dropMimeData: function that adds the data dropped on the tree widget -bool StationTreeWidget::dropMimeData(QTreeWidgetItem *parent, int /*index*/, const QMimeData *data, Qt::DropAction /*action*/) -{ - bool possibleChange(false); - QStringList listOfStations = data->text().split("|"); - if (parent == 0) { - for (QStringList::const_iterator it = listOfStations.begin(); it != listOfStations.end(); ++it) { // add top-level item(s) - QStringList stationItemText(*it); - QTreeWidgetItem *stationItem = new QTreeWidgetItem(this, stationItemText); - stationItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled); - possibleChange = true; - } - } - else { - if (parent->text(0).startsWith(">")) { // add to existing super station parent - for (QStringList::const_iterator it = listOfStations.begin(); it != listOfStations.end(); ++it) { // add stations to a super-station - QStringList stationItemText(*it); - QTreeWidgetItem *stationItem = new QTreeWidgetItem(parent, stationItemText); - stationItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled); // these stations should not have children - possibleChange = true; - } - } - } - sortItems(1,Qt::AscendingOrder); - sortItems(0,Qt::AscendingOrder); - if (possibleChange) { - itsHasChanged = true; - emit checkForStationChanges(); - } - return true; -} - -void StationTreeWidget::keyPressEvent (QKeyEvent * event) { - int key(event->key()); - if ((key == Qt::Key_Delete) | (key == Qt::Key_Left) | (key == Qt::Key_Minus)) { - QStringList deletedStations; - QList<QTreeWidgetItem *> deleteChildren, deleteSuperStations; - QList<QTreeWidgetItem *> selectedStations = selectedItems(); - for (QList<QTreeWidgetItem *>::iterator it = selectedStations.begin(); it != selectedStations.end(); ++it) { - if ((*it)->text(0).startsWith(">")) { - for (int i = 0; i < (*it)->childCount(); ++i) { - deletedStations.append((*it)->child(i)->text(0)); - } - deleteSuperStations.append(*it); - } - else { - deletedStations.append((*it)->text(0)); - deleteChildren.append(*it); - } - } - if (!deleteChildren.isEmpty()) { - // now delete the items from the tree - for (QList<QTreeWidgetItem *>::iterator it = deleteChildren.begin(); it != deleteChildren.end(); ++it) { - delete *it; - } - itsHasChanged = true; - } - if (!deleteSuperStations.isEmpty()) { - for (QList<QTreeWidgetItem *>::iterator it = deleteSuperStations.begin(); it != deleteSuperStations.end(); ++it) { - delete *it; - } - itsHasChanged = true; - } - emit stationsDeleted(deletedStations); // emit signal to start adding the stations to the list of available stations - emit checkForStationChanges(); - } - else if ((event->key() == Qt::Key_A) && (event->modifiers() == Qt::AltModifier)) { // select All - selectAll(); - } - else if (event->key() == Qt::Key_S) { - sortItems(1,Qt::AscendingOrder); - sortItems(0,Qt::AscendingOrder); - } - else { - QTreeWidget::keyPressEvent(event); - } -} diff --git a/SAS/Scheduler/src/stationtreewidget.h b/SAS/Scheduler/src/stationtreewidget.h deleted file mode 100644 index 9d61b8fcd64f83b9ab28f3b006ed4ed7850f8c6b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationtreewidget.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * stationtreewidget.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Apr 6, 2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/stationtreewidget.h $ - * - */ - -#ifndef STATIONTREEWIDGET_H -#define STATIONTREEWIDGET_H - -#include <QTreeWidget> -#include "ui_stationtreewidget.h" - -// class used as tree of used stations -class StationTreeWidget : public QTreeWidget -{ - Q_OBJECT - -public: - StationTreeWidget(QWidget *parent = 0); - ~StationTreeWidget(); - - void addStations(const QStringList &stations); - QTreeWidgetItem * addSuperStation(void); - void dragEnterEvent(QDragEnterEvent *event); - void dragMoveEvent(QDragMoveEvent * event); - void dragLeaveEvent(QDragLeaveEvent * event); - bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); - QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const; - QStringList mimeTypes() const; - Qt::DropActions supportedDropActions () const; - void keyPressEvent (QKeyEvent * event); - void addSuperStationAndChilds(void); - void clear(void) {QTreeWidget::clear(); itsNrOfSuperStations = 0; itsHasChanged = false; itsIsMixed = false; itsNrStationsToRemove = 0;} - unsigned getNrStationsRemoved(void) const {return itsNrStationsToRemove;} - void resetHasChangedFlag(void) {itsHasChanged = false;} - bool hasChanged(void) const {return itsHasChanged;} - bool isMixed(void) const {return itsIsMixed;} - void setMixed(void); - -protected: - void dropEvent(QDropEvent * event); - -private slots: - void updateNrStationsToRemove(unsigned nrStations) {itsNrStationsToRemove = nrStations;} - -signals: - void stationsDeleted(const QStringList &) const; - void checkForStationChanges(void) const; - void prepareRemoveStations(unsigned) const; - -private: - Ui::StationTreeWidgetClass ui; - unsigned itsNrStationsToRemove; - QPoint startPos; - int itsNrOfSuperStations; - bool itsHasChanged; - bool itsIsMixed; -}; - -#endif // STATIONTREEWIDGET_H diff --git a/SAS/Scheduler/src/stationtreewidget.ui b/SAS/Scheduler/src/stationtreewidget.ui deleted file mode 100644 index 468a601176727f4414205dcc242c150c026b9753..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/stationtreewidget.ui +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>StationTreeWidgetClass</class> - <widget class="QWidget" name="StationTreeWidgetClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>393</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle"> - <string>StationTreeWidget</string> - </property> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/storage_definitions.h b/SAS/Scheduler/src/storage_definitions.h deleted file mode 100644 index c3c739368efc0333da79c6888a5b187638c225a3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/storage_definitions.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * storage_definitions.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 29-july-2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/storage_definitions.h $ - * description : header file to include all storage definition classes and typedefs - * - */ - -#ifndef STORAGE_DEFINITIONS_H -#define STORAGE_DEFINITIONS_H - -#include <map> -#include <vector> -#include <string> - -enum pipelineType { - PIPELINE_IMAGING, - PIPELINE_CALIBRATION, - PIPELINE_PULSAR, - PIPELINE_LONGBASELINE, - PIPELINE_UNKNOWN -}; - -enum task_conflict { - CONFLICT_NO_CONFLICT, - CONFLICT_BITMODE, - CONFLICT_OUT_OF_DATASLOTS, - CONFLICT_MAINTENANCE, - CONFLICT_RESERVATION, - CONFLICT_STATIONS, - CONFLICT_INSUFFICIENT_STORAGE, - CONFLICT_STORAGE_NO_DATA, - CONFLICT_STORAGE_EXCEEDS_BANDWIDTH, - CONFLICT_STORAGE_NODE_INACTIVE, - CONFLICT_STORAGE_NODE_INEXISTENT, - CONFLICT_STORAGE_NO_NODES, - CONFLICT_STORAGE_TOO_FEW_NODES, - CONFLICT_STORAGE_MINIMUM_NODES, - CONFLICT_STORAGE_NO_OPTIONS, - CONFLICT_STORAGE_NODE_SPACE, - CONFLICT_STORAGE_WRITE_SPEED, - CONFLICT_RAID_ARRRAY_NOT_FOUND, - CONFLICT_STORAGE_TIME_TOO_EARLY, - CONFLICT_STORAGE_NODE_BANDWIDTH, - CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH, - CONFLICT_GROUP_STORAGE_MODE_DIFFERENT, - CONFLICT_GROUP_STORAGE_UNEQUAL_DATAPRODUCTS, - CONFLICT_NO_STORAGE_ASSIGNED, - CONFLICT_NON_INTEGER_OUTPUT_FILES, - _END_CONFLICTS_ -}; -extern const char * TASK_CONFLICTS[_END_CONFLICTS_]; - -enum dataProductTypes { - _BEGIN_DATA_PRODUCTS_ENUM_, - DP_CORRELATED_UV = _BEGIN_DATA_PRODUCTS_ENUM_, - DP_COHERENT_STOKES, - DP_INCOHERENT_STOKES, - DP_INSTRUMENT_MODEL, - DP_PULSAR, - DP_SKY_IMAGE, - DP_UNKNOWN_TYPE, - _END_DATA_PRODUCTS_ENUM_ -}; -#define NR_DATA_PRODUCT_TYPES _END_DATA_PRODUCTS_ENUM_ - -// storageVector: pairs of <storage node ID, location ID> for each subband or beam -typedef std::vector<std::pair<int,int> > storageVector; -//storageMap contains the storage nodes and raid arrays IDs for all dataProductTypes -typedef std::map<dataProductTypes, storageVector> storageMap; - -class StorageNode; - -class storageOption { -public: - storageOption(int raid_id, const double &remainingspace_kb, unsigned nr_units) - : raidID(raid_id), remainingSpacekB(remainingspace_kb), nrUnits(nr_units) {} - int raidID; - double remainingSpacekB; // the smallest remaining space on the raid array (during the claim's period) - unsigned nrUnits; // the number of units of size of the claim which would fit on the raid array according to remaining bandwidth and write speed -}; - -typedef std::vector<storageOption> nodeStorageOptions; -typedef std::vector<std::pair<int, nodeStorageOptions> > storageLocationOptions; - -// storageNodesMap: key=nodeID, value = storageNode object -typedef std::map<int, StorageNode> storageNodesMap; - -class storageResult { -public: - storageResult(dataProductTypes dataProduct, int node_id, int raid_id, task_conflict conflictType) - : dataProductType(dataProduct), storageNodeID(node_id), storageRaidID(raid_id), conflict(conflictType) { } - dataProductTypes dataProductType; - int storageNodeID, storageRaidID; - task_conflict conflict; -}; - -// storagePartitionsMap: the storage partitions (IDs) and their total capacity -// key= raidID, value=pair<location string, total capacity of location> -typedef std::map<int, std::pair<std::string, double> > storagePartitionsMap; - - -#endif // STORAGE_DEFINITIONS_H diff --git a/SAS/Scheduler/src/storageplot.cpp b/SAS/Scheduler/src/storageplot.cpp deleted file mode 100644 index be3504bf8666c12df114117ef7bea46d47cf1c31..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/storageplot.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * storageplot.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : June 25, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/storageplot.h $ - * - */ - -#include "storageplot.h" -#include "Storage.h" - -StoragePlot::StoragePlot(QWidget *parent) : - QCustomPlot(parent) -{ -} - -void StoragePlot::init(unsigned nrPlots) { - plotLayout()->clear(); // clear default axis rect so we can start from scratch - // synchronize the left and right margins of the top and bottom axis rects: - QCPMarginGroup *marginGroup = new QCPMarginGroup(this); - - for (unsigned plotNr = 0; plotNr < nrPlots; ++plotNr) { - QCPAxisRect *plot = new QCPAxisRect(this); - plot->setupFullAxesBox(true); - this->plotLayout()->addElement(plotNr, 0, plot); // insert axis rect in first row - plot->setMarginGroup(QCP::msLeft, marginGroup); - QCPGraph *graph = addGraph(plot->axis(QCPAxis::atBottom), plot->axis(QCPAxis::atLeft)); - itsPlots[plotNr] = graph; - graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(Qt::black), QBrush(Qt::white), 6)); - graph->setPen(QPen(QColor(120, 120, 120), 2)); - graph->setBrush(QColor(255, 161, 0, 50)); - graph->setName("locus001"); - plot->axis(QCPAxis::atLeft)->setLabel("free space (GB)"); - } - - // move newly created axes on "axes" layer and grids on "grid" layer: - foreach (QCPAxisRect *rect, this->axisRects()) - { - foreach (QCPAxis *axis, rect->axes()) - { - axis->setLayer("axes"); - axis->grid()->setLayer("grid"); - } - } -} - -void StoragePlot::plot(const Storage &storage) { - QCPGraph *graph(0); - QVector<double> x(100), data(100); - const storageNodesMap &storageNodes(storage.storageNodes()); - int i = 0; - for (storageNodesMap::const_iterator it = storageNodes.begin(); it != storageNodes.end(); ++it) { - double xValue(0); - graph = itsPlots[i++]; - const std::vector<capacityLogPoint> &capLog(it->second.getRemainingSpace().begin()->second); - int xcount(0); - for (std::vector<capacityLogPoint>::const_iterator cit = capLog.begin(); cit != capLog.end(); ++cit) { - - data[xcount] = cit->remainingDiskSpacekB; - x[xcount++] = xValue; - -// data.push_back(cit->remainingDiskSpacekB); -// x.push_back(xValue); - xValue += 1.0; - } - graph->setData(x, data); - graph->rescaleAxes(); - if (i>=5) break; // REMOVE - } - - // prepare data: -// QVector<double> x1a(20), y1a(20); -// for (int i=0; i<x1a.size(); ++i) -// { -// x1a[i] = i/(double)(x1a.size()-1)*10-5.0; -// y1a[i] = qCos(x1a[i]); -// } - -// QCPGraph *graph = itsPlots[0];//this->graph(); -// storage->getStoragePlotData(); -// graph->setData(x1a, y1a); -// graph->rescaleAxes(); - -} diff --git a/SAS/Scheduler/src/storageplot.h b/SAS/Scheduler/src/storageplot.h deleted file mode 100644 index b7ae6c5bd3d01c6cfbcd107bf3e25f5521164a1b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/storageplot.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * storageplot.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : June 25, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/storageplot.h $ - * - */ - -#ifndef STORAGEPLOT_H -#define STORAGEPLOT_H - -#include "qcustomplot.h" -#include <QMap> - -class Storage; - -class StoragePlot : public QCustomPlot -{ - Q_OBJECT -public: - explicit StoragePlot(QWidget *parent = 0); - - void init(unsigned nrPlots); - void plot(const Storage &storage); - -signals: - -public slots: - -private: - QMap<unsigned , QCPGraph *> itsPlots; -}; - -#endif // STORAGEPLOT_H diff --git a/SAS/Scheduler/src/storageresourceview.ui b/SAS/Scheduler/src/storageresourceview.ui deleted file mode 100644 index b7e1e254f27a290cf7345fddc89822f985118113..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/storageresourceview.ui +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>Form</class> - <widget class="QWidget" name="Form"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>640</width> - <height>480</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QCustomPlot" name="storage_1" native="true"/> - </item> - <item> - <widget class="QCustomPlot" name="storage_2" native="true"/> - </item> - <item> - <widget class="QCustomPlot" name="storage_3" native="true"/> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>QCustomPlot</class> - <extends>QWidget</extends> - <header>qcustomplot.h</header> - <container>1</container> - </customwidget> - </customwidgets> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/tablecolumnselectdialog.cpp b/SAS/Scheduler/src/tablecolumnselectdialog.cpp deleted file mode 100644 index 1015a82c4dacf7938bf7469ff326849049fed757..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tablecolumnselectdialog.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "tablecolumnselectdialog.h" -#include "lofar_scheduler.h" - -tableColumnSelectDialog::tableColumnSelectDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); - initDialog(); -} - -tableColumnSelectDialog::~tableColumnSelectDialog() -{ - -} - -void tableColumnSelectDialog::show(void) { - for (std::vector<unsigned int>::const_iterator it = itsSelectedColumns.begin(); it != itsSelectedColumns.end(); ++it) { - ui.listWidget_Columns->item(*it)->setSelected(true); - } - ui.listWidget_Columns->setFocus(); - this->showNormal(); -} - -void tableColumnSelectDialog::accept(void) { - itsSelectedColumns.clear(); - for (int i = 0; i < ui.listWidget_Columns->count(); ++i) { - if (ui.listWidget_Columns->item(i)->isSelected()) { - itsSelectedColumns.push_back(i); - } - } - this->hide(); - emit viewColumns(itsSelectedColumns); -} - -void tableColumnSelectDialog::toggleSelection(void) { - if (selectAll) { - ui.listWidget_Columns->selectAll(); - ui.pushButton_Select->setText("Select none"); - selectAll = false; - } - else { - ui.listWidget_Columns->clearSelection(); - ui.pushButton_Select->setText("Select all"); - selectAll = true; - } - ui.listWidget_Columns->setFocus(); -} - -void tableColumnSelectDialog::initDialog(void) { - for (int i = 0; i < NR_DATA_HEADERS; ++i) { - ui.listWidget_Columns->addItem(DATA_HEADERS[i]); - itsSelectedColumns.push_back(i); - } - ui.listWidget_Columns->selectAll(); - ui.pushButton_Select->setText("Select none"); - selectAll = false; - connect(ui.pushButton_Select, SIGNAL(clicked()), this, SLOT(toggleSelection())); -} diff --git a/SAS/Scheduler/src/tablecolumnselectdialog.h b/SAS/Scheduler/src/tablecolumnselectdialog.h deleted file mode 100644 index 265d19e12a92401a5e2861808d39bb3b38e6cbcd..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tablecolumnselectdialog.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef TABLECOLUMNSELECTDIALOG_H -#define TABLECOLUMNSELECTDIALOG_H - -#include <QDialog> -#include "ui_tablecolumnselectdialog.h" - -class tableColumnSelectDialog : public QDialog -{ - Q_OBJECT - -public: - tableColumnSelectDialog(QWidget *parent = 0); - ~tableColumnSelectDialog(); - - void show(void); - -private: - void initDialog(void); - -private: - void accept(void); - -private slots: - void toggleSelection(void); - -signals: - void viewColumns(const std::vector<unsigned int> &) const; - -private: - Ui::tableColumnSelectDialogClass ui; - std::vector<unsigned int> itsSelectedColumns; - bool selectAll; -}; - -#endif // TABLECOLUMNSELECTDIALOG_H diff --git a/SAS/Scheduler/src/tablecolumnselectdialog.ui b/SAS/Scheduler/src/tablecolumnselectdialog.ui deleted file mode 100644 index bdef3c3098ba6960e62483d97f94e28ef81703d2..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tablecolumnselectdialog.ui +++ /dev/null @@ -1,100 +0,0 @@ -<ui version="4.0" > - <class>tableColumnSelectDialogClass</class> - <widget class="QDialog" name="tableColumnSelectDialogClass" > - <property name="geometry" > - <rect> - <x>0</x> - <y>0</y> - <width>400</width> - <height>300</height> - </rect> - </property> - <property name="windowTitle" > - <string>Select colums to view</string> - </property> - <layout class="QGridLayout" name="gridLayout" > - <item row="2" column="0" > - <spacer name="horizontalSpacer" > - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0" > - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="3" > - <widget class="QPushButton" name="pushButton_Ok" > - <property name="text" > - <string>Ok</string> - </property> - </widget> - </item> - <item row="2" column="2" > - <widget class="QPushButton" name="pushButton_Cancel" > - <property name="text" > - <string>Cancel</string> - </property> - </widget> - </item> - <item row="0" column="0" colspan="4" > - <widget class="QListWidget" name="listWidget_Columns" > - <property name="selectionMode" > - <enum>QAbstractItemView::MultiSelection</enum> - </property> - </widget> - </item> - <item row="2" column="1" > - <widget class="QPushButton" name="pushButton_Select" > - <property name="text" > - <string>PushButton</string> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11" /> - <tabstops> - <tabstop>listWidget_Columns</tabstop> - <tabstop>pushButton_Cancel</tabstop> - <tabstop>pushButton_Ok</tabstop> - </tabstops> - <resources/> - <connections> - <connection> - <sender>pushButton_Cancel</sender> - <signal>clicked()</signal> - <receiver>tableColumnSelectDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel" > - <x>249</x> - <y>276</y> - </hint> - <hint type="destinationlabel" > - <x>204</x> - <y>272</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButton_Ok</sender> - <signal>clicked()</signal> - <receiver>tableColumnSelectDialogClass</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel" > - <x>377</x> - <y>275</y> - </hint> - <hint type="destinationlabel" > - <x>395</x> - <y>258</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/src/tableview.cpp b/SAS/Scheduler/src/tableview.cpp deleted file mode 100644 index c99f1f38c0cb66c7ce82f2331bd2325267b8e46b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tableview.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "tableview.h" -#include <QMouseEvent> -#include <iostream> - -TableView::TableView(QWidget *parent) - : QTableView(parent) -{ -} - -TableView::~TableView() -{ - -} - -void TableView::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { - if (event->modifiers() == Qt::ControlModifier) { // control or shift key is held down - if (selectionMode() != QAbstractItemView::MultiSelection) { - QModelIndexList list(this->selectedIndexes()); - setSelectionMode(QAbstractItemView::MultiSelection); - setSelectionBehavior(QAbstractItemView::SelectRows); - for (QModelIndexList::iterator lit = list.begin(); lit != list.end(); ++lit) { - QModelIndex index = this->model()->index(lit->row(), lit->column()); - this->selectionModel()->select(index, QItemSelectionModel::Deselect); - for (int col = 0; col < this->model()->columnCount(); ++col) { - QModelIndex index = this->model()->index(lit->row(), col); - this->selectionModel()->select(index, QItemSelectionModel::Select); - } - } - } - else { - // make sure that the clicked row selection is toggled. - // user clicked on it while multiselection was already on, - // meaning the clicked row was either selected or deselected -// int row(this->indexAt(event->pos()).row()); -// for (int col = 0; col < this->model()->columnCount(); ++col) { -// QModelIndex index = this->model()->index(row, col); -// this->selectionModel()->select(index, QItemSelectionModel::Toggle); -// } - selectRow(this->indexAt(event->pos()).row()); - setCurrentIndex(this->indexAt(event->pos())); - } - } - else if (event->modifiers() == Qt::ShiftModifier) { - if (selectionMode() != QAbstractItemView::ContiguousSelection) { - setSelectionMode(QAbstractItemView::ContiguousSelection); - setSelectionBehavior(QAbstractItemView::SelectRows); - clearSelection(); - selectRow(this->indexAt(event->pos()).row()); - } - } - - else if (selectionMode() != QAbstractItemView::SingleSelection) { - setSelectionMode(QAbstractItemView::SingleSelection); - clearSelection(); - setSelectionBehavior(QAbstractItemView::SelectItems); - } - } - - QModelIndex index = this->indexAt(event->pos()); - if (index.row() != -1) { - QTableView::mousePressEvent(event); - emit mouseClick(index, event); - } -} - -void TableView::contextMenuEvent(QContextMenuEvent *event) { - // first check if this should apply to multiple tasks - QModelIndex index(indexAt(event->pos())); - if (index.row() != -1) { - QTableView::contextMenuEvent(event); - emit tableContextMenuRequest(index, event); - } -} - -QSet<int> TableView::selectedRows(void) const { - QSet<int> set; - QModelIndexList indexes(selectedIndexes()); - QModelIndex index; - foreach(index, indexes) { - set.insert(index.row()); - } - return set; -} diff --git a/SAS/Scheduler/src/tableview.h b/SAS/Scheduler/src/tableview.h deleted file mode 100644 index 668579b8e44c1a24df0e157ac3feac06b9c4efe8..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tableview.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef TABLEVIEW_H -#define TABLEVIEW_H - -#include <QTableView> -#include <QSet> - -class TableView : public QTableView -{ - Q_OBJECT - -public: - TableView(QWidget *parent = 0); - ~TableView(); - - void mousePressEvent(QMouseEvent *event); -// Qt::KeyboardModifiers getModifierKeys(void) const {return modifierKeys;} - virtual QModelIndexList selectedIndexes(void) const {return QTableView::selectedIndexes();} - QSet<int> selectedRows(void) const; - -protected: - void contextMenuEvent(QContextMenuEvent *event); - -signals: - void mouseClick(const QModelIndex &index, QMouseEvent *event); - void tableContextMenuRequest(const QModelIndex &index, QContextMenuEvent *event); - -private: -// Qt::KeyboardModifiers modifierKeys; -}; - -#endif // TABLEVIEW_H diff --git a/SAS/Scheduler/src/task.cpp b/SAS/Scheduler/src/task.cpp deleted file mode 100755 index b25f8fcfa9bec902cda29da766d34260fdba66c6..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/task.cpp +++ /dev/null @@ -1,960 +0,0 @@ -/* - * task.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 21, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/task.cpp $ - * - */ - - -#include "lofar_scheduler.h" -#include "lofar_utils.h" -#include "task.h" -#include "Controller.h" -#include "SASConnection.h" -#include <QSqlRecord> -#include <sstream> -#include <vector> -#include <string> -#include <stdio.h> -#include <cmath> -using std::vector; -using std::string; -#ifdef DEBUG_SCHEDULER -#include <iostream> -#endif - -const char *task_types_str[NR_TASK_TYPES] = {"OBSERVATION","RESERVATION","MAINTENANCE","PIPELINE","SYSTEM","UNKNOWN"}; - -const char *task_states_str[NR_TASK_STATES] = {"IDLE", "ERROR", "DESCRIBED", "PREPARED", "ON_HOLD", - "UNSCHEDULED", "CONFLICT", "PRESCHEDULED", "SCHEDULED", "STARTING", "ACTIVE", "COMPLETING", "FINISHED", "ABORTED", "OBSOLETE"}; - -const char *unscheduled_reason_str[NR_REASONS] = { - "", - "Warning!", - "Task does does not fulfill reservation constraints", - "The digital beam duration differs from the observation duration", - "Task is scheduled in the past or too close to now", - "Task has conflicts with other tasks", - "Task duration is zero", - "Task start time is not set", - "Task end time is not set", - "Task has empty subband list", - "Task has too many subbands", - "Unknown bit mode", - "Task is outside schedule bounds", - "No predecessor defined", - "Predecessor(s) not found or does not exist", - "Maximum distance to predecessor exceeded", - "Predecessor is not scheduled", - "Predecessor minimum distance later than maximum distance", - "Start time is before or too close to the predecessor task", - "first date too late for predecessor to fit before", - "Last possible date too early to maintain distance to predecessor", - "Planned start later than end", - "Empty station list", - "Task uses non-existing station(s)", - "Forbidden station combination for HBA1", - "No opening found", - "Task is on hold", - "Task has errors", - "Antenna mode unspecified", - "Station clock unspecified", - "Station filter unspecified", - "Incompatible station clock and antenna mode", - "Incompatible station clock and filter type", - "Task specification incomplete", - "No incoherent TABs defined while incoherent data output is enabled", - "No coherent TABs defined while coherent data output is enabled", - "No TABs defined and fley's eye is off while in Stokes mode", - "Channels per subband no integer multiple of coherent/incoherent channels per subband", - "skyImages = input MS subbands / (subbands_per_image * slices_per_image) (needs to be integer value)", - "No data output type selected (coherent/incoherent/correlated)", - "A required input data product could not be found within the predecessor tasks", - "demix freq.step and time step should be multiples of resp. averaging freq.step and time step", - "one of the specified sources to be demixed is unknown", - "Mismatch between input and output node location, retry assigning resources: LOC 1", - "Mismatch between input and output node location, retry assigning resources: LOC 2", -}; - -const char * TASK_CONFLICTS[_END_CONFLICTS_] = { - "no conflicts", //NO_CONFLICT - "bit mode cannot be different", // BITMODE - "no more data slots available", // OUT_OF_DATASLOTS - "Station is in maintenance", // MAINTENANCE - "Station is reserved", // RESERVATION - "Station in use by other observation", // STATIONS - "Not enough total free storage space", // INSUFFICIENT_STORAGE - "No data output for this task", // NO_DATA - "Not enough available storage nodes for required bandwidth", // CONFLICT_STORAGE_EXCEEDS_BANDWIDTH - "Storage node inactive", // STORAGE_NODE_INACTIVE - "Storage node does not exist", // CONFLICT_STORAGE_NODE_INEXISTENT - "No storage nodes available", // CONFLICT_STORAGE_NO_NODES - "Number of storage nodes available less than minimum required", // CONFLICT_STORAGE_TOO_FEW_NODES - "Number of assigned storage nodes is less than minimum required", // CONFLICT_STORAGE_MINIMUM_NODES - "No suitable storage options found", // NO_OPTIONS - "Storage raid array has insufficient free space", // STORAGE_NODE_SPACE - "Exceeds maximum write speed for raid array", // STORAGE_WRITE_SPEED - "Raid array not found", // RAID_ARRRAY_NOT_FOUND - "Requested start time in the past", // STORAGE_TIME_TOO_EARLY - "Network bandwidth to storage node too high", // STORAGE_NODE_BANDWIDTH - "Bandwidth required for single file too high", // CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH - "Storage auto selection modes are different within group", // CONFLICT_GROUP_STORAGE_MODE_DIFFERENT - "Grouped tasks have unequal number of data products", // CONFLICT_GROUP_STORAGE_UNEQUAL_DATAPRODUCTS - "No storage nodes assigned to some data products", // NO_STORAGE_ASSIGNED - "skyImages = input MS subbands / (subbands_per_image * slices_per_image) (needs to be integer value)" // NON_INTEGER_SKYIMAGES -}; - -const char *SAS_item_names[NR_TASK_PROPERTIES] = {"task_id", "antenna mode", "clock", "contact e-mail", "contact name", "contact phone", - "data slots", "filter type", "first possible day", "fixed day", "fixed time", "last possible day", - "nighttime weightfactor", "pred.max.time dif.", "pred.min.time dif.", "predecessor", "priority", - "project ID", "group ID", "reservation", "scheduled end", "scheduled start", "stations", - "duration", "task name", "status", "type", "window max.time", "window min.time", "analog beam settings", - "digital beam settings", "tied array beam settings", "bandpass correction", "delay comp.", - "flys eye", "Coherent dedispersion", "coherent stokes settings", "incoherent stokes settings", - "correlator int. time", "bits per sample", "channels per subband", "slices_per_image", "subbands_per_image", - "imaging specify fov", "imaging fov", "imaging npix", "imaging cellsize", "subbands_per_subbandgroup", "subbandgroups_per_MS", - "demix always", "demix_if_needed", "demix_skyModel", "demix_freqstep", "demix_timestep", - "avg.freqstep", "avg.timestep", "cal_skyModel", "pulsar pipeline settings", "enabled output data types", - "output storage settings", "output data products", "TBB piggyback", "Aartfaac piggyback", "input data products", "description"}; - -const char * DATA_TYPES[_END_DATA_TYPES] = {"I", "IQUV", "XXYY", "UNDEFINED"}; - -dataTypes stringToStokesType(const std::string &str) { - if (!str.empty()) { - for (short i = 0; i < DATA_TYPE_UNDEFINED; ++i) { - if (str.compare(DATA_TYPES[i]) == 0) { - return static_cast<dataTypes>(i); - } - } - } - return static_cast<dataTypes>(DATA_TYPE_UNDEFINED); -} - -const char * DATA_PRODUCTS[NR_DATA_PRODUCT_TYPES] = {"Correlated", "Coherent Stokes", "Incoherent Stokes", - "Instrument Model", "Pulsar", "Sky Image", "Unknown data type"}; - -dataProductTypes stringToDataProductType(const std::string &str) { - if (!str.empty()) { - for (dataProductTypes i = _BEGIN_DATA_PRODUCTS_ENUM_; i < _END_DATA_PRODUCTS_ENUM_; i = dataProductTypes(i + 1)) { - if (str.compare(DATA_PRODUCTS[i]) == 0) { - return i; - } - } - } - return DP_UNKNOWN_TYPE; -} - -Task::task_status taskStatusFromString(const std::string &statusStr) { - Task::task_status status(Task::TASK_STATUS_END); - for (unsigned int idx = 0; idx != NR_TASK_STATES; ++idx) { - if (statusStr.compare(task_states_str[idx]) == 0) { - status = static_cast<Task::task_status>(idx); - break; - } - } - return status; -} - -Task::task_type taskTypeFromString(std::string processType) { - Task::task_type type(Task::UNKNOWN); - std::transform(processType.begin(), processType.end(), processType.begin(), ::toupper); - if (!processType.empty()) { - for (unsigned int idx = 0; idx != NR_TASK_TYPES; ++idx) { - if (processType.compare(task_types_str[idx]) == 0) { - type = static_cast<Task::task_type>(idx); - break; - } - } - } - return type; -} - -Task *cloneTask(const Task *pTask) { - const Observation *orgObs(0); - const StationTask *orgStat(0); - const Pipeline * orgPipe(0); - const CalibrationPipeline *orgCalPipe(0); - const ImagingPipeline *orgImgPipe(0); - const PulsarPipeline *orgPulsPipe(0); - const LongBaselinePipeline *orgLBPipe(0); - - orgStat = dynamic_cast<const StationTask *>(pTask); - if (orgStat) { // is this a StationTask or derived type? - if ((orgObs = dynamic_cast<const Observation *>(pTask))) { - return new Observation(*orgObs); - } - else return new StationTask(*orgStat); - } - else if ((orgPipe = dynamic_cast<const Pipeline *>(pTask))) { // is this a Pipeline or derived type? - if ((orgCalPipe = dynamic_cast<const CalibrationPipeline *>(pTask))) return new CalibrationPipeline(*orgCalPipe); - else if ((orgImgPipe = dynamic_cast<const ImagingPipeline *>(pTask))) return new ImagingPipeline(*orgImgPipe); - else if ((orgPulsPipe = dynamic_cast<const PulsarPipeline *>(pTask))) return new PulsarPipeline(*orgPulsPipe); - else if ((orgLBPipe = dynamic_cast<const LongBaselinePipeline *>(pTask))) return new LongBaselinePipeline(*orgLBPipe); - } - - return 0; -} - -Task::task_status convertSASstatus(SAS_task_status sas_state) { - switch (sas_state) { - case SAS_STATE_IDLE: - return Task::IDLE; - case SAS_STATE_DESCRIBED: - return Task::DESCRIBED; - case SAS_STATE_PREPARED: - return Task::PREPARED; - case SAS_STATE_ON_HOLD: - return Task::ON_HOLD; - case SAS_STATE_APPROVED: // the state where the observation has been approved by all parties, the task doesn't have a start and stop time yet. - return Task::UNSCHEDULED; - case SAS_STATE_CONFLICT: - return Task::CONFLICT; - case SAS_STATE_PRESCHEDULED: // the task has a tentavive start and stop time - return Task::PRESCHEDULED; - case SAS_STATE_SCHEDULED: // the state scheduled if the observation has a start and stop time and can be started - return Task::SCHEDULED; - case SAS_STATE_QUEUED: // the state the SAS observation is being started - return Task::STARTING; - case SAS_STATE_ACTIVE: // when the SAS observation is running - return Task::ACTIVE; - case SAS_STATE_COMPLETING: - return Task::COMPLETING; - case SAS_STATE_FINISHED: - return Task::FINISHED; - case SAS_STATE_ABORTED: - return Task::ABORTED; - case SAS_STATE_OBSOLETE: - return Task::OBSOLETE; - case SAS_STATE_ERROR: - return Task::ERROR; - default: - return Task::TASK_STATUS_END; - } -} - -Task::Task() -: taskID(0), itsPriority(0.0), itsStatus(DESCRIBED), itsTaskType(UNKNOWN), - fixed_day(false), fixed_time(false), itsPenalty(0), penaltyCalculationNeeded(true), itsShiftDirection(SHIFT_RIGHT), - itsOutputDataproductCluster("---") -{ - clearAllConflicts(); - // set the time window equal to the schedule boundaries - firstPossibleDay = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - lastPossibleDay = Controller::theSchedulerSettings.getLatestSchedulingDay(); - windowMaxTime = AstroTime(23,59,59); -} - -Task::Task(unsigned task_id) -: taskID(task_id), itsPriority(0.0), itsStatus(UNSCHEDULED), itsTaskType(UNKNOWN), - fixed_day(false), fixed_time(false), itsPenalty(0), penaltyCalculationNeeded(true), - itsShiftDirection(SHIFT_RIGHT), itsOutputDataproductCluster("---") -{ - clearAllConflicts(); - // set the time window equal to the schedule boundaries - firstPossibleDay = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - lastPossibleDay = Controller::theSchedulerSettings.getLatestSchedulingDay(); - windowMaxTime = AstroTime(23,59,59); -} - -// the following constructor creates a new task which can be used when the SAS tree doesn't contain a 'Scheduler' branch -Task::Task(unsigned task_id, const OTDBtree &SAS_tree) -: itsProjectName(SAS_tree.campaign()), taskID(task_id), itsPriority(0.0), - fixed_day(false), fixed_time(false), itsPenalty(0), penaltyCalculationNeeded(true), - itsShiftDirection(SHIFT_RIGHT), itsOutputDataproductCluster("---"), itsSASTree(SAS_tree) - -{ - setType(SAS_tree.processType(), SAS_tree.processSubType(), SAS_tree.strategy()); - - setStatusSAS(SAS_tree.state()); - - clearAllConflicts(); - // set the time window equal to the schedule boundaries - firstPossibleDay = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - lastPossibleDay = Controller::theSchedulerSettings.getLatestSchedulingDay(); - windowMaxTime = AstroTime(23,59,59); -} - -Task::Task(const QSqlQuery &query, const OTDBtree &SAS_tree) -: itsProjectName(SAS_tree.campaign()), - itsPenalty(0), penaltyCalculationNeeded(true), itsShiftDirection(SHIFT_RIGHT), itsOutputDataproductCluster("---"), itsSASTree(SAS_tree) - -{ - setType(SAS_tree.processType(), SAS_tree.processSubType(),SAS_tree.strategy()); - - unsigned secondsDuration = query.value(query.record().indexOf("taskDuration")).toUInt(); - if (secondsDuration) { - itsDuration = itsDuration.addSeconds(secondsDuration); - } - - setStatusSAS(SAS_tree.state()); - - taskID = query.value(query.record().indexOf("taskID")).toUInt(); - itsContactEmail = query.value(query.record().indexOf("contactEmail")).toString().toStdString(); - itsContactName = query.value(query.record().indexOf("contactName")).toString().toStdString(); - itsContactPhone = query.value(query.record().indexOf("contactPhone")).toString().toStdString(); - int day = query.value(query.record().indexOf("firstPossibleDay")).toInt(); - if (day) { - firstPossibleDay = day; - } - else { // first possible day not set use the schedule start day or the current date whichever is latest - firstPossibleDay = std::max(QDate::currentDate().toJulianDay() - J2000_EPOCH, (qint64)Controller::theSchedulerSettings.getEarliestSchedulingDay().toJulian()); - } - QString time = query.value(query.record().indexOf("windowMaximumTime")).toString(); - if (!time.isEmpty()) { - windowMaxTime = time; - } - else { - windowMaxTime = AstroTime("23:59:59"); - } - - time = query.value(query.record().indexOf("windowMinimumTime")).toString(); - if (!time.isEmpty()) { - windowMinTime = time; - } - else { - windowMinTime = AstroTime("00:00:00"); - } - fixed_day = query.value(query.record().indexOf("fixedDay")).toBool(); - fixed_time = query.value(query.record().indexOf("fixedTime")).toBool(); - day = query.value(query.record().indexOf("lastPossibleDay")).toInt(); - if (day) { - lastPossibleDay = day; - } - else { // first possible day not set use the schedule start day - lastPossibleDay = Controller::theSchedulerSettings.getLatestSchedulingDay(); - } - predecessorMaxTimeDif = query.value(query.record().indexOf("predMaxTimeDif")).toString(); - predecessorMinTimeDif = query.value(query.record().indexOf("predMinTimeDif")).toString(); - setPredecessors(query.value(query.record().indexOf("predecessors")).toString()); - itsPriority = query.value(query.record().indexOf("priority")).toDouble(); - itsTaskName = query.value(query.record().indexOf("taskName")).toString().toStdString(); - setReason(query.value(query.record().indexOf("reason")).toString().toStdString()); - clearAllConflicts(); -} - -Task::~Task() -{ -} - -QDataStream& operator<< (QDataStream &out, const Task &task) { - if (out.status() == QDataStream::Ok) { - out << task.taskID - << task.itsProjectID - << task.itsProjectName - << task.itsProjectPI - << task.itsProjectCO_I - << task.itsTaskName - << task.itsContactName - << task.itsContactPhone - << task.itsContactEmail - << (quint8) task.itsTaskType; - - // predecessors - const IDvector &predecessors(task.getPredecessors()); - out << (quint32) predecessors.size(); - for (IDvector::const_iterator it = predecessors.begin(); it != predecessors.end(); ++it) { - out << (quint8) it->first << it->second; - } - out << task.predecessorMinTimeDif << task.predecessorMaxTimeDif; - - // successors - const IDvector &sucessors(task.getSuccessors()); - out << (quint32) sucessors.size(); - for (IDvector::const_iterator it = sucessors.begin(); it != sucessors.end(); ++it) { - out << (quint8) it->first << it->second; - } - - out << task.itsPriority - << task.firstPossibleDay - << task.lastPossibleDay - << task.windowMinTime - << task.windowMaxTime - << task.itsDuration - << task.scheduledStart - << task.scheduledEnd - << task.fixed_day - << task.fixed_time - << (quint8) task.itsStatus - << task.itsPenalty - << task.itsShiftDirection - << task.itsSASTree; - } - return out; -} - -QDataStream& operator>> (QDataStream &in, Task &task) { - if (in.status() == QDataStream::Ok) { - quint32 nrOfObjects, taskID; - quint8 status, type; - - in >> task.taskID - >> task.itsProjectID - >> task.itsProjectName - >> task.itsProjectPI - >> task.itsProjectCO_I - >> task.itsTaskName - >> task.itsContactName - >> task.itsContactPhone - >> task.itsContactEmail; - - in >> type; - task.itsTaskType = (Task::task_type) type; - - // predecessors - task.clearPredecessors(); - in >> nrOfObjects; - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> type >> taskID; - task.itsPredecessors.push_back(IDvector::value_type(static_cast<id_type>(type), taskID)); - } - in >> task.predecessorMinTimeDif >> task.predecessorMaxTimeDif; - - // successors - task.clearSuccessors(); - in >> nrOfObjects; - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> type >> taskID; - task.itsSuccessors.push_back(IDvector::value_type(static_cast<id_type>(type), taskID)); - } - - in >> task.itsPriority - >> task.firstPossibleDay - >> task.lastPossibleDay - >> task.windowMinTime - >> task.windowMaxTime - >> task.itsDuration - >> task.scheduledStart - >> task.scheduledEnd - >> task.fixed_day - >> task.fixed_time; - - in >> status; - task.itsStatus = (Task::task_status) status; - - in >> task.itsPenalty - >> task.itsShiftDirection - >> task.itsSASTree; - } - return in; -} - -Task & Task::operator=(const Task &other) { - if (this != &other) { - itsProjectID = other.itsProjectID; - itsProjectName = other.itsProjectName; - itsProjectPI = other.itsProjectPI; - itsProjectCO_I = other.itsProjectCO_I; - itsTaskName = other.itsTaskName; - itsContactName = other.itsContactName; - itsContactPhone = other.itsContactPhone; - itsContactEmail = other.itsContactEmail; - taskID = other.taskID; - itsPriority = other.itsPriority; - itsStatus = other.itsStatus; - itsTaskType = other.itsTaskType; - fixed_day = other.fixed_day; - fixed_time = other.fixed_time; - itsPenalty = other.itsPenalty; - penaltyCalculationNeeded = other.penaltyCalculationNeeded; - itsReason = other.itsReason; - itsShiftDirection = other.itsShiftDirection; - itsPredecessors = other.itsPredecessors; - itsSuccessors = other.itsSuccessors; - itsConflicts = other.itsConflicts; - predecessorMinTimeDif = other.predecessorMinTimeDif; - predecessorMaxTimeDif = other.predecessorMaxTimeDif; - windowMinTime = other.windowMinTime; - windowMaxTime = other.windowMaxTime; - scheduledStart = other.scheduledStart; - scheduledEnd = other.scheduledEnd; - itsDuration = other.itsDuration; - firstPossibleDay = other.firstPossibleDay; - lastPossibleDay = other.lastPossibleDay; - itsSASTree = other.itsSASTree; - itsOutputDataproductCluster = other.itsOutputDataproductCluster; - } - return *this; -} - -void Task::syncStartStopTimes(void) { - itsSASTree.setStartTime(scheduledStart); - itsSASTree.setStopTime(scheduledEnd); -} - -void Task::setScheduledPeriod(const AstroDateTime &start, const AstroDateTime &end) { - scheduledStart = start; - scheduledEnd = end; - if (scheduledEnd > scheduledStart) { - itsDuration = scheduledEnd - scheduledStart; - } - else { - itsDuration.clearTime(); - } -} - -void Task::setConflict(task_conflict conflict, bool enable) { - switch (conflict) { - case CONFLICT_BITMODE: - itsConflicts.bitmode = enable; - break; - case CONFLICT_OUT_OF_DATASLOTS: - itsConflicts.out_of_dataslots = enable; - break; - case CONFLICT_MAINTENANCE: - itsConflicts.maintenance = enable; - break; - case CONFLICT_RESERVATION: - itsConflicts.storage_insufficient = enable; - break; - case CONFLICT_STATIONS: - itsConflicts.stations = enable; - break; - case CONFLICT_INSUFFICIENT_STORAGE: - itsConflicts.storage_insufficient = enable; - break; - case CONFLICT_STORAGE_NO_DATA: - itsConflicts.storage_no_data = enable; - break; - case CONFLICT_STORAGE_EXCEEDS_BANDWIDTH: - itsConflicts.storage_exceeds_bandwidth = enable; - break; - case CONFLICT_STORAGE_NODE_INACTIVE: - itsConflicts.storage_node_inactive = enable; - break; - case CONFLICT_STORAGE_NODE_INEXISTENT: - itsConflicts.storage_node_inexistent = enable; - break; - case CONFLICT_STORAGE_NO_NODES: - itsConflicts.storage_no_nodes = enable; - break; - case CONFLICT_STORAGE_TOO_FEW_NODES: - itsConflicts.storage_not_enough_nodes = enable; - break; - case CONFLICT_STORAGE_MINIMUM_NODES: - itsConflicts.storage_minimum_nodes = enable; - break; - case CONFLICT_STORAGE_NO_OPTIONS: - itsConflicts.storage_no_options = enable; - break; - case CONFLICT_STORAGE_NODE_SPACE: - itsConflicts.storage_node_space = enable; - break; - case CONFLICT_STORAGE_WRITE_SPEED: - itsConflicts.storage_write_speed = enable; - break; - case CONFLICT_RAID_ARRRAY_NOT_FOUND: - itsConflicts.storage_raid_not_found = enable; - break; - case CONFLICT_STORAGE_TIME_TOO_EARLY: - itsConflicts.storage_time_to_early = enable; - break; - case CONFLICT_STORAGE_NODE_BANDWIDTH: - itsConflicts.storage_node_bandwidth = enable; - break; - case CONFLICT_STORAGE_SINGLE_FILE_BW_TOO_HIGH: - itsConflicts.storage_single_file_bw_too_high = enable; - break; - case CONFLICT_GROUP_STORAGE_MODE_DIFFERENT: - itsConflicts.storage_mode_different = enable; - break; - case CONFLICT_GROUP_STORAGE_UNEQUAL_DATAPRODUCTS: - itsConflicts.storage_unequal_dataproducts = enable; - break; - case CONFLICT_NO_STORAGE_ASSIGNED: - itsConflicts.storage_no_storage_assigned = enable; - break; - case CONFLICT_NON_INTEGER_OUTPUT_FILES: - itsConflicts.non_integer_nr_output_files = enable; - break; - default: - break; - } -} - -void Task::clearAllConflicts(void) { - itsConflicts.bitmode = false; - itsConflicts.out_of_dataslots = false; - itsConflicts.maintenance = false; - itsConflicts.reservation = false; - itsConflicts.stations = false; - itsConflicts.storage_insufficient = false; - itsConflicts.storage_no_data = false; - itsConflicts.storage_exceeds_bandwidth = false; - itsConflicts.storage_node_inactive = false; - itsConflicts.storage_node_inexistent = false; - itsConflicts.storage_no_nodes = false; - itsConflicts.storage_not_enough_nodes = false; - itsConflicts.storage_minimum_nodes = false; - itsConflicts.storage_no_options = false; - itsConflicts.storage_node_space = false; - itsConflicts.storage_write_speed = false; - itsConflicts.storage_raid_not_found = false; - itsConflicts.storage_time_to_early = false; - itsConflicts.storage_node_bandwidth = false; - itsConflicts.storage_single_file_bw_too_high = false; - itsConflicts.storage_mode_different = false; - itsConflicts.storage_unequal_dataproducts = false; - itsConflicts.storage_no_storage_assigned = false; - itsConflicts.non_integer_nr_output_files = false; -} - -void Task::clearAllStorageConflicts(void) { - itsConflicts.storage_insufficient = false; - itsConflicts.storage_no_data = false; - itsConflicts.storage_exceeds_bandwidth = false; - itsConflicts.storage_node_inactive = false; - itsConflicts.storage_node_inexistent = false; - itsConflicts.storage_no_nodes = false; - itsConflicts.storage_not_enough_nodes = false; - itsConflicts.storage_minimum_nodes = false; - itsConflicts.storage_no_options = false; - itsConflicts.storage_node_space = false; - itsConflicts.storage_write_speed = false; - itsConflicts.storage_raid_not_found = false; - itsConflicts.storage_time_to_early = false; - itsConflicts.storage_node_bandwidth = false; - itsConflicts.storage_single_file_bw_too_high = false; - itsConflicts.storage_mode_different = false; - itsConflicts.storage_unequal_dataproducts = false; - itsConflicts.storage_no_storage_assigned = false; -} - -std::vector<std::string> Task::getTypesStrings(void) const { - std::vector<std::string> typesVec; - for (short int i = 0; i < NR_TASK_TYPES; ++i) - typesVec.push_back(task_types_str[i]); - return typesVec; -} - -void Task::setStatus(const std::string &stat) { - if (!stat.empty()) { - setStatus(taskStatusFromString(stat)); - } -} - -void Task::setStatusSAS(SAS_task_status sas_status) { - itsStatus = convertSASstatus(sas_status); - itsSASTree.itsTreeState = sas_status; -} - -void Task::setStatus(const task_status stat) { - if (stat >= 0 && stat < TASK_STATUS_END) { - itsStatus = stat; - switch (stat) { - case IDLE: - itsSASTree.itsTreeState = SAS_STATE_IDLE; - break; - case DESCRIBED: - itsSASTree.itsTreeState = SAS_STATE_DESCRIBED; - break; - case PREPARED: - itsSASTree.itsTreeState = SAS_STATE_PREPARED; - break; - case ON_HOLD: - itsSASTree.itsTreeState = SAS_STATE_ON_HOLD; - break; - case UNSCHEDULED: - itsSASTree.itsTreeState = SAS_STATE_APPROVED; - break; - case CONFLICT: - itsSASTree.itsTreeState = SAS_STATE_CONFLICT; - break; - case PRESCHEDULED: - itsSASTree.itsTreeState = SAS_STATE_PRESCHEDULED; - break; - case SCHEDULED: - itsSASTree.itsTreeState = SAS_STATE_SCHEDULED; - break; - case STARTING: - itsSASTree.itsTreeState = SAS_STATE_QUEUED; - break; - case ACTIVE: - itsSASTree.itsTreeState = SAS_STATE_ACTIVE; - break; - case COMPLETING: - itsSASTree.itsTreeState = SAS_STATE_COMPLETING; - break; - case FINISHED: - itsSASTree.itsTreeState = SAS_STATE_FINISHED; - break; - case ABORTED: - itsSASTree.itsTreeState = SAS_STATE_ABORTED; - break; - case ERROR: - itsSASTree.itsTreeState = SAS_STATE_ERROR; - break; - case OBSOLETE: - itsSASTree.itsTreeState = SAS_STATE_OBSOLETE; - break; - default: - break; - } - } - else { - debugWarn("s", "Unknown task status specified!"); - } -} - -void Task::setType(const QString &processType, processSubTypes processSubtype, const QString &strategy) { - itsTaskType = Task::UNKNOWN; - if (!processType.isEmpty()) { // processType may not be empty - for (unsigned int idx = 0; idx != NR_TASK_TYPES; ++idx) { - if (processType.compare(task_types_str[idx]) == 0) { - itsTaskType = static_cast<task_type>(idx); - itsSASTree.itsProcessType = processType; - break; - } - } - } - itsSASTree.itsProcessSubtype = processSubtype; - itsSASTree.itsStrategy = strategy; -} - -void Task::setType(const task_type tasktype) { - if (tasktype >= 0 && tasktype < TASK_TYPE_END) { - itsTaskType = tasktype; - } - else { - itsTaskType = Task::UNKNOWN; - debugWarn("s", "Unknown task type specified!"); - } -} - -void Task::setReason(unscheduled_reasons reason) { - if (reason < UNSCHEDULED_REASON_END) { - itsReason = unscheduled_reason_str[reason]; - } - else { - debugWarn("sis", "Task:", taskID, " , Error:Unknown unscheduled reason"); - } -} - -/* -bool Task::setReason(unsigned short reason) { - if (reason < UNSCHEDULED_REASON_END) { - unscheduledReason = unscheduled_reason_str[reason]; - return true; - } - debugWarn("sis", "Task:", taskID, " , Error:Unknown unscheduled reason"); - return false; -} - -bool Task::setReason(const std::string &reason) { - if (!reason.empty()) { - for (unsigned int idx = 0; idx != NR_REASONS; ++idx) { - if (reason.compare(unscheduled_reason_str[idx]) == 0) { - unscheduledReason = static_cast<unscheduled_reasons>(idx); - return true; - } - } - } - debugWarn("siss", "Task:", taskID, " , Error:Unknown unscheduled reason: ", reason.c_str()); - return false; -} -*/ - -QString Task::getPredecessorsString(const QChar &separater) const { - QStringList predlist; - const QString & ObsIDPrefix(Controller::theSchedulerSettings.getObservationIDprefix()); - QString prefix; - for (IDvector::const_iterator it = itsPredecessors.begin(); it != itsPredecessors.end(); ++it) { - switch (it->first) { - case ID_SCHEDULER: - prefix = "S"; - break; - case ID_MOM: - prefix = "M"; - break; - case ID_SAS: - prefix = ObsIDPrefix; - break; - } - predlist.append(prefix + QString::number(it->second)); - } - return "[" + predlist.join(separater) + "]"; -} - -void Task::setPredecessors(const QString &predecessors) { - itsPredecessors.clear(); - const QString & ObsIDPrefix(Controller::theSchedulerSettings.getObservationIDprefix()); - std::vector<QString> preds(string2VectorOfStrings(predecessors)); - for (std::vector<QString>::const_iterator it = preds.begin(); it != preds.end(); ++it) { - if (it->startsWith('S')) { - addPredecessor(it->right(it->size()-1).toUInt(),ID_SCHEDULER); - } - else if (it->startsWith('M')) { - addPredecessor(it->right(it->size()-1).toUInt(),ID_MOM); - } - else if (it->startsWith(ObsIDPrefix)) { - addPredecessor(it->right(it->size()-1).toUInt(),ID_SAS); - } - else { - debugWarn("sis","Task:", taskID, " predecessors contain unknown IDs"); - } - } -} - - -bool Task::setPriority(const double &prio) { - if (prio >= 0.0f) { - itsPriority = prio; - return true; - } - else { - debugWarn("s", "Task priority cannot be negative"); - return false; - } -} - -AstroDateTime Task::getFirstPossibleDateTime() const { - AstroDateTime firstdate(firstPossibleDay, windowMinTime); - return firstdate; -} - -AstroDateTime Task::getLastPossibleDateTime() const { - AstroDateTime lastdate(lastPossibleDay, windowMaxTime); - return lastdate; -} - -const char * Task::getStatusStr(void) const { - if (itsStatus >= 0 && itsStatus < TASK_STATUS_END) - { - return task_states_str[itsStatus]; - } - debugErr("s","Unknown task status!"); - return "Unknown"; -} - -const char * Task::getTypeStr(void) const { - if (itsTaskType >=0 && itsTaskType < TASK_TYPE_END) { - return task_types_str[itsTaskType]; - } - debugErr("s","Unknown task type!"); - return "Unknown"; -} - -QColor Task::getStatusColor(void) const { - switch (itsStatus) { - case SCHEDULED: - return Qt::blue; - case STARTING: - return Qt::magenta; - case ACTIVE: - return Qt::yellow; - case COMPLETING: - return QColor(170,170,255); // (purple background) - case FINISHED: - return QColor(40,255,40); // bright greenish - case ABORTED: - return QColor(255,135,55); // bright orange - case OBSOLETE: - return Qt::darkGray; - default: - return Qt::darkYellow; - } -} - -QColor Task::getTypeColor(void) const { - switch (itsTaskType) { - case OBSERVATION: - return Qt::darkBlue; - case RESERVATION: - if (itsSASTree.processSubType() == PST_STAND_ALONE) { - return Qt::black; - } - else { - return Qt::darkRed; - } - case MAINTENANCE: - return Qt::darkCyan; - case PIPELINE: - return Qt::darkMagenta; - case SYSTEM: - return Qt::darkYellow; - case UNKNOWN: - return Qt::darkGreen; - default: // includes UNKNOWN - return Qt::darkGreen; - } -} - -/* - * diff check for difference between this task and other task. - * return true if difference - * parameter dif - */ -bool Task::diff(const Task *other, task_diff &dif) const { - taskID != other->getID() ? dif.task_id = true : dif.task_id = false; - itsProjectID.compare(other->getProjectID()) != 0 ? dif.project_ID = true : dif.project_ID = false; - itsSASTree.itsGroupID != other->getGroupID() ? dif.group_ID = true : dif.group_ID = false; - itsTaskName.compare(other->getTaskName()) != 0 ? dif.task_name = true : dif.task_name = false; - itsContactName.compare(other->getContactName()) != 0 ? dif.contact_name = true : dif.contact_name = false; - itsContactPhone.compare(other->getContactPhone()) != 0 ? dif.contact_phone = true : dif.contact_phone = false; - itsContactEmail.compare(other->getContactEmail()) != 0 ? dif.contact_email = true : dif.contact_email = false; - itsTaskType != other->getType() ? dif.task_type = true : dif.task_type = false; - itsPredecessors != other->getPredecessors() ? dif.predecessors = true : dif.predecessors = false; - predecessorMinTimeDif != other->getPredecessorMinTimeDif() ? dif.pred_min_time_dif = true : dif.pred_min_time_dif = false; - predecessorMaxTimeDif != other->getPredecessorMaxTimeDif() ? dif.pred_max_time_dif = true : dif.pred_max_time_dif = false; - itsPriority != other->getPriority() ? dif.priority = true : dif.priority = false; - firstPossibleDay != other->getWindowFirstDay() ? dif.first_possible_day = true : dif.first_possible_day = false; - lastPossibleDay != other->getWindowLastDay() ? dif.last_possible_day = true : dif.last_possible_day = false; - windowMinTime != other->getWindowMinTime() ? dif.window_minimum_time = true : dif.window_minimum_time = false; - windowMaxTime != other->getWindowMaxTime() ? dif.window_maximum_time = true : dif.window_maximum_time = false; - itsDuration != other->getDuration() ? dif.task_duration = true : dif.task_duration = false; - scheduledStart != other->getScheduledStart() ? dif.scheduled_start = true : dif.scheduled_start = false; - scheduledEnd != other->getScheduledEnd() ? dif.scheduled_end = true : dif.scheduled_end = false; - fixed_day != other->getFixedDay() ? dif.fixed_day = true : dif.fixed_day = false; - fixed_time != other->getFixedTime() ? dif.fixed_time = true : dif.fixed_time = false; - itsStatus != other->getStatus() ? dif.task_status = true : dif.task_status = false; - // SAS tree setttings - itsSASTree.itsDescription.compare(other->itsSASTree.itsDescription) != 0 ? dif.description = true : dif.description = false; - - // task_id on its own should not be detected as a change, only when other properties of that task need to be saved will task_id (if different) also be saved. - return (dif.project_ID || dif.group_ID || dif.task_name || dif.contact_name || dif.contact_phone || dif.contact_email - || dif.task_type || dif.predecessors || dif.pred_min_time_dif || dif.pred_max_time_dif || dif.priority - || dif.first_possible_day || dif.last_possible_day - || dif.window_minimum_time || dif.window_maximum_time || dif.task_duration || dif.scheduled_start - || dif.scheduled_end || dif.fixed_day || dif.fixed_time || dif.task_status || dif.description); -} - -QString Task::diffString(const task_diff &dif) const { - QString difstr; - if (dif.antenna_mode) difstr += QString(SAS_item_names[TP_ANTENNA_MODE]) + ","; - if (dif.clock_frequency) difstr += QString(SAS_item_names[TP_CLOCK_FREQUENCY]) + ","; - if (dif.contact_email) difstr += QString(SAS_item_names[TP_CONTACT_EMAIL]) + ","; - if (dif.contact_name) difstr += QString(SAS_item_names[TP_CONTACT_NAME]) + ","; - if (dif.contact_phone) difstr += QString(SAS_item_names[TP_CONTACT_PHONE]) + ","; - if (dif.filter_type) difstr += QString(SAS_item_names[TP_FILTER_TYPE]) + ","; - if (dif.first_possible_day) difstr += QString(SAS_item_names[TP_FIRST_POSSIBLE_DATE]) + ","; - if (dif.fixed_day) difstr += QString(SAS_item_names[TP_FIXED_DAY]) + ","; - if (dif.fixed_time) difstr += QString(SAS_item_names[TP_FIXED_TIME]) + ","; - if (dif.last_possible_day) difstr += QString(SAS_item_names[TP_LAST_POSSIBLE_DATE]) + ","; - if (dif.pred_max_time_dif) difstr += QString(SAS_item_names[TP_PRED_MAX_TIME_DIF]) + ","; - if (dif.pred_min_time_dif) difstr += QString(SAS_item_names[TP_PRED_MIN_TIME_DIF]) + ","; - if (dif.predecessors) difstr += QString(SAS_item_names[TP_PREDECESSOR]) + ","; - if (dif.priority) difstr += QString(SAS_item_names[TP_PRIORITY]) + ","; - if (dif.project_ID) difstr += QString(SAS_item_names[TP_PROJECT_ID]) + ","; - if (dif.group_ID) difstr += QString(SAS_item_names[TP_GROUP_ID]) + ","; - if (dif.scheduled_start) difstr += QString(SAS_item_names[TP_SCHEDULED_START]) + ","; - if (dif.scheduled_end) difstr += QString(SAS_item_names[TP_SCHEDULED_END]) + ","; - if (dif.task_duration) difstr += QString(SAS_item_names[TP_DURATION]) + ","; - if (dif.task_name) difstr += QString(SAS_item_names[TP_TASK_NAME]) + ","; - if (dif.task_status) difstr += QString(SAS_item_names[TP_STATUS]) + ","; - if (dif.task_type) difstr += QString(SAS_item_names[TP_TYPE]) + ","; - if (dif.window_minimum_time) difstr += QString(SAS_item_names[TP_WINDOW_MIN_TIME]) + ","; - if (dif.window_maximum_time) difstr += QString(SAS_item_names[TP_WINDOW_MAX_TIME]) + ","; - if (dif.description) difstr += QString(SAS_item_names[TP_DESCRIPTION]) + ","; - if (dif.task_id) difstr += QString(SAS_item_names[TP_TASK_ID]) + ","; - - if (difstr.endsWith(',')) { - difstr.remove(difstr.length()-1,1); - } - - return difstr; -} diff --git a/SAS/Scheduler/src/task.h b/SAS/Scheduler/src/task.h deleted file mode 100755 index d4f1d90b204d6565e2dfd004b623571af3b9e03c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/task.h +++ /dev/null @@ -1,494 +0,0 @@ -/* - * task.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 21, 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/task.h $ - * - */ - -#ifndef TASK_H_ -#define TASK_H_ - -#include <vector> -#include <map> -#include <string> -#include <fstream> -#include <iostream> -#include <algorithm> -#include <QtSql> -#include <QColor> -#include "lofar_scheduler.h" -#include "storage_definitions.h" - -class TaskStorage; - -enum dataTypes { - DATA_TYPE_STOKES_I, - DATA_TYPE_STOKES_IQUV, - DATA_TYPE_XXYY, - DATA_TYPE_UNDEFINED, - _END_DATA_TYPES -}; - -// CAUTION: The items in the following enum TASK_PROPERTIES and the subsequent static const array declaration must be kept synchronized! -enum TASK_PROPERTIES { TP_TASK_ID, TP_ANTENNA_MODE, TP_CLOCK_FREQUENCY, TP_CONTACT_EMAIL, TP_CONTACT_NAME, TP_CONTACT_PHONE, - TP_DATASLOTS, TP_FILTER_TYPE, TP_FIRST_POSSIBLE_DATE, TP_FIXED_DAY, TP_FIXED_TIME, TP_LAST_POSSIBLE_DATE, - TP_NIGHT_TIME_WEIGHT_FACTOR, TP_PRED_MAX_TIME_DIF, TP_PRED_MIN_TIME_DIF, TP_PREDECESSOR, TP_PRIORITY, - TP_PROJECT_ID, TP_GROUP_ID, TP_RESERVATION, TP_SCHEDULED_END, TP_SCHEDULED_START, TP_STATION_IDS, - TP_DURATION, TP_TASK_NAME, TP_STATUS, TP_TYPE, TP_WINDOW_MAX_TIME, TP_WINDOW_MIN_TIME, TP_ANA_BEAM_SETTINGS, - TP_DIGI_BEAM_SETTINGS, TP_TAB_SETTINGS, TP_RTCP_BANDPASS_CORR, TP_RTCP_DELAY_COMP, - TP_RTCP_FLYS_EYE, TP_RTCP_COHERENT_DEDISPERSION, TP_RTCP_COHERENT_STOKES_SETTINGS, TP_RTCP_INCOHERENT_STOKES_SETTINGS, - TP_RTCP_COR_INT_TIME, TP_RTCP_BITS_PER_SAMPLE, TP_RTCP_CHANNELS_PER_SUBBAND, TP_IMAGING_SLICES_PER_IMAGE, TP_IMAGING_SUBBANDS_PER_IMAGE, - TP_IMAGING_SPECIFY_FOV, TP_IMAGING_FOV, TP_IMAGING_NPIX, TP_IMAGING_CELLSIZE, TP_LONGBASELINE_SB_PER_SBGROUP, TP_LONGBASELINE_SBGROUP_PER_MS, - TP_DEMIX_ALWAYS, TP_DEMIX_IF_NEEDED, TP_DEMIX_SKYMODEL, TP_DEMIX_FREQSTEP, TP_DEMIX_TIMESTEP, TP_AVG_FREQSTEP, TP_AVG_TIMESTEP, - TP_CALIBRATION_SKYMODEL, TP_PULSAR_PIPELINE_SETTINGS, TP_OUTPUT_DATA_TYPES, TP_OUTPUT_STORAGE_SETTINGS, TP_OUTPUT_DATA_PRODUCTS, TP_TBB_PIGGYBACK, - TP_AARTFAAC_PIGGYBACK, TP_INPUT_DATA_PRODUCTS, TP_DESCRIPTION, - _END_TASK_PROPERTIES_ENUM_}; - -#define NR_TASK_PROPERTIES _END_TASK_PROPERTIES_ENUM_ -extern const char * SAS_item_names[NR_TASK_PROPERTIES]; - -extern const char * DATA_TYPES[_END_DATA_TYPES]; -#define NR_TASK_TYPES 6 -extern const char *task_types_str[NR_TASK_TYPES]; -#define NR_TASK_STATES 15 -extern const char *task_states_str[NR_TASK_STATES]; - -// put the non-blocking errors first -enum unscheduled_reasons { - NO_ERROR, - USER_WARNING, - NOT_COMPATIBLE_WITH_RESERVATION, - BEAM_DURATION_DIFFERENT, - SCHEDULED_TOO_EARLY, - TASK_CONFLICT, - ZERO_DURATION, // from here only ERRORs - START_TIME_NOT_SET, - END_TIME_NOT_SET, - EMPTY_SUBBAND_LIST, - TOO_MANY_SUBBANDS, - UNKNOWN_BITMODE, - OUTSIDE_SCHEDULE_BOUNDS, - NO_PREDECESSOR_DEFINED, - PREDECESSOR_NOT_FOUND, - MAX_DISTANCE_PREDECESSOR, - PREDECESSOR_UNSCHEDULED, - PRED_MIN_TIME_GREATER_MAX_TIME, - TOO_CLOSE_OR_BEFORE_PREDECESSOR, - FIRST_DATE_TOO_LATE, - LAST_DATE_TOO_EARLY, - START_LATER_THEN_END, - NO_STATIONS_DEFINED, - NON_EXISTING_STATION, - WRONG_STATION_COMBINATION, - NO_MUTUAL_OPENING_FOUND, - TASK_ON_HOLD, - TASK_HAS_ERROR, - ANTENNA_MODE_UNSPECIFIED, - CLOCK_FREQUENCY_UNSPECIFIED, - FILTER_TYPE_UNSPECIFIED, - INCOMPATIBLE_ANTENNA_AND_FILTER, - INCOMPATIBLE_CLOCK_AND_FILTER, - SPECIFICATION_INCOMPLETE, - NO_INCOHERENT_TABS_DEFINED, - NO_COHERENT_TABS_DEFINED, - NO_TABS_DEFINED, - WRONG_CHANNEL_COLLAPSE, - NON_INTEGER_NR_OUTPUT_FILES, - NO_DATA_OUTPUT_SELECTED, - INPUT_DATA_PRODUCT_NOT_FOUND, - INCOMPATIBLE_DEMIX_SETTINGS, - UNKNOWN_DEMIX_SOURCE, - INPUT_OUTPUT_LOCATION_MISMATCH1, - INPUT_OUTPUT_LOCATION_MISMATCH2, - UNSCHEDULED_REASON_END -}; -#define NR_REASONS UNSCHEDULED_REASON_END - -extern const char *unscheduled_reason_str[NR_REASONS]; - -#include "astrodatetime.h" -#include "astrotime.h" -#include "astrodate.h" -#include "OTDBtree.h" - -struct task_conflicts { - bool bitmode; - bool out_of_dataslots; - bool maintenance; - bool reservation; - bool stations; - bool storage_insufficient; - bool storage_no_data; - bool storage_exceeds_bandwidth; - bool storage_node_inactive; - bool storage_node_inexistent; - bool storage_no_nodes; - bool storage_not_enough_nodes; - bool storage_minimum_nodes; - bool storage_no_options; - bool storage_node_space; - bool storage_write_speed; - bool storage_raid_not_found; - bool storage_time_to_early; - bool storage_node_bandwidth; - bool storage_single_file_bw_too_high; - bool storage_mode_different; - bool storage_unequal_dataproducts; - bool storage_no_storage_assigned; - bool non_integer_nr_output_files; -}; - -enum id_type { - ID_SCHEDULER, - ID_MOM, - ID_SAS -}; - -typedef std::vector<std::pair<id_type, quint32> > IDvector; - -class task_diff { -public: - // TODO: Code smell: Ownership of state. - // These changed bools should be owned by the respected gui elements - // each gui element should expose a changed member - task_diff() : task_id(false), antenna_mode(false), clock_frequency (false), contact_email (false), contact_name(false), contact_phone(false), - dataslots(false), filter_type(false), first_possible_day(false), fixed_day(false), fixed_time(false), last_possible_day(false), - night_time_weight_factor(false), pred_max_time_dif(false), pred_min_time_dif(false), predecessors(false), priority(false), project_ID(false), - group_ID(false), reservation(false), scheduled_end(false), scheduled_start(false), station_ids(false), task_duration(false), task_name(false), - task_status(false), task_type(false),window_maximum_time(false), window_minimum_time(false), ana_beam_angle1(false), ana_beam_angle2(false), - ana_beam_direction_type(false), ana_beam_starttime(false), ana_beam_duration(false), digital_beam_settings(false), tiedarray_beam_settings(false), - RTCP_correct_bandpass(false), RTCP_delay_compensation(false), RTCP_pencil_flys_eye(false), RTCP_coherent_dedispersion(false), RTCP_coherent_stokes_settings(false), - RTCP_incoherent_stokes_settings(false), RTCP_cor_int_time(false), RTCP_nr_bits_per_sample(false), RTCP_channels_per_subband(false), Imaging_nr_slices_per_image(false), - Imaging_nr_subbands_per_image(false), Imaging_npix(false), Imaging_specify_fov(false), Imaging_fov(false), Imaging_cellsize(false), - LongBaseline_nr_sb_per_sbgroup(false), LongBaseline_nr_sbgroup_per_MS(false), demix_always(false), demix_if_needed(false), - demix_skymodel(false), demix_freqstep(false), demix_timestep(false), freqstep(false), timestep(false), calibration_skymodel(false), pulsar_pipeline_settings(false), - TBBPiggybackAllowed(false), AartfaacPiggybackAllowed(false), input_data_products(false), output_data_types(false), output_storage_settings(false), output_data_products(false), description(false) - { } - -public: - bool task_id, antenna_mode, clock_frequency , contact_email , contact_name, contact_phone, - dataslots, filter_type, first_possible_day, fixed_day, fixed_time, last_possible_day, - night_time_weight_factor, pred_max_time_dif, pred_min_time_dif, predecessors, priority, project_ID, - group_ID, reservation, scheduled_end, scheduled_start, station_ids, task_duration, task_name, - task_status, task_type,window_maximum_time, window_minimum_time, ana_beam_angle1, ana_beam_angle2, - ana_beam_direction_type, ana_beam_starttime, ana_beam_duration, digital_beam_settings, tiedarray_beam_settings, - RTCP_correct_bandpass, RTCP_delay_compensation, RTCP_pencil_flys_eye, RTCP_coherent_dedispersion, RTCP_coherent_stokes_settings, - RTCP_incoherent_stokes_settings, RTCP_cor_int_time, RTCP_nr_bits_per_sample, RTCP_channels_per_subband, Imaging_nr_slices_per_image, - Imaging_nr_subbands_per_image, Imaging_npix, Imaging_specify_fov, Imaging_fov, Imaging_cellsize, - LongBaseline_nr_sb_per_sbgroup, LongBaseline_nr_sbgroup_per_MS, demix_always, demix_if_needed, - demix_skymodel, demix_freqstep, demix_timestep, freqstep, timestep, calibration_skymodel, pulsar_pipeline_settings, - TBBPiggybackAllowed, AartfaacPiggybackAllowed, input_data_products, output_data_types, output_storage_settings, output_data_products, description; -}; - -dataTypes stringToStokesType(const std::string &str); - -class Task -{ -public: - enum task_status { - IDLE = 0, - ERROR, - DESCRIBED,// = 100, - PREPARED,// = 200, - ON_HOLD, - UNSCHEDULED,// = 300, = APPROVED in SAS - CONFLICT, // = 335 - PRESCHEDULED,// = 350, - SCHEDULED,// = 400, // scheduled means fixed in the schedule and waiting for execution - STARTING,// = 500, // = QUEUED in SAS - ACTIVE,// = 600, // currently being executed - COMPLETING, // = 900 - FINISHED,// = 1000, (from this state up are inactive states) - ABORTED,//= 1100, - OBSOLETE,// = 1200, - TASK_STATUS_END - }; - - // define task types - enum task_type { - OBSERVATION, - RESERVATION, - MAINTENANCE, - PIPELINE, - SYSTEM, - UNKNOWN, - TASK_TYPE_END - }; - - enum task_color_mode { - TASK_TYPE_COLOR_MODE, - TASK_STATUS_COLOR_MODE - }; - - Task(); - Task(unsigned task_id); -#ifdef HAS_SAS_CONNECTION - Task(unsigned task_id, const OTDBtree &SAS_tree); // constructor used for incomplete SAS tasks that have no stored scheduler properties - Task(const QSqlQuery &query, const OTDBtree &SAS_tree); -#endif - virtual ~Task(); - - friend QDataStream& operator<< (QDataStream &out, const Task &task); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, Task &task); // used for reading data from binary file - - // make me an exact copy of the original task but keep my ID - virtual void clone(const Task *other) { - if (this != other) { - unsigned myTaskID = taskID; - *this = *other; - taskID = myTaskID; - } - } - - virtual Task & operator=(const Task &); - bool operator==(unsigned int taskID) const {return (this->getID() == taskID);} - - virtual bool diff(const Task *other, task_diff &dif) const; - virtual QString diffString(const task_diff &dif) const; - - //get methods - unsigned getID(void) const {return taskID;} - quint32 getMomID(void) const {return itsSASTree.itsMomID;} - quint32 getGroupID(void) const {return itsSASTree.itsGroupID;} - quint32 getSASTreeID(void) const {return itsSASTree.itsTreeID;} - SAS_task_status getSAStreeState(void) const {return itsSASTree.state();} - int getOriginalTreeID(void) const {return itsSASTree.itsOriginalTree;} - QColor getTypeColor(void) const; - QColor getStatusColor(void) const; - bool isScheduled(void) const {return ((itsStatus == Task::STARTING) || (itsStatus == Task::ACTIVE) || - (itsStatus == Task::PRESCHEDULED) || (itsStatus == Task::SCHEDULED));} - // predecessorVector const &getPredecessors() const { return predecessors; }; // returns the list of predecessors - bool hasPredecessors(void) const {return !itsPredecessors.empty();} - bool hasSuccesors(void) const {return !itsSuccessors.empty();} - bool hasLinkedTask(void) const {return (hasPredecessors() | hasSuccesors());} - const IDvector &getPredecessors(void) const { return itsPredecessors; } // returns the predecessor vector - IDvector &getPredecessorsForChange(void) { return itsPredecessors; } // returns the predecessor vector as a non-const - QString getPredecessorsString(const QChar &separater = QChar(',')) const; - const IDvector &getSuccessors(void) const { return itsSuccessors; } // returns the successors vector - bool isReservation(void) const {return itsTaskType == Task::RESERVATION;} - bool isMaintenance(void) const {return itsTaskType == Task::MAINTENANCE;} - bool isObservation(void) const {return itsTaskType == Task::OBSERVATION;} - bool isStationTask(void) const {return ((itsTaskType == Task::OBSERVATION) || (itsTaskType == Task::RESERVATION) || (itsTaskType == Task::MAINTENANCE));} - bool isPipeline(void) const {return itsTaskType == Task::PIPELINE;} - bool isSystem(void) const {return itsTaskType == Task::SYSTEM;} - bool isUnknown(void) const {return itsTaskType == Task::UNKNOWN;} - const AstroTime &getPredecessorMinTimeDif() const {return predecessorMinTimeDif;} - const AstroTime &getPredecessorMaxTimeDif() const {return predecessorMaxTimeDif;} - unsigned int getPenalty() const { return itsPenalty; }//if (penaltyCalculationNeeded) { calculatePenalty(); } return itsPenalty; } -// bool isPenaltyCalculationNeeded(void) const {return penaltyCalculationNeeded;} - unsigned int calculatePenalty(void) { if (penaltyCalculationNeeded) { doCalculatePenalty(); }; return itsPenalty; } - const double &getPriority() const { return itsPriority; } - inline Task::task_status getStatus() const { return itsStatus; } - const char * getStatusStr(void) const; - const QString &getProcessType(void) const {return itsSASTree.itsProcessType;} - processSubTypes getProcessSubtype(void) const {return itsSASTree.itsProcessSubtype;} - inline const char *getProcessSubtypeStr(void) const {return itsSASTree.getProcessSubtypeStr();} - const QString &getStrategy(void) const {return itsSASTree.itsStrategy;} - Task::task_type getType() const { return itsTaskType; } - const char * getTypeStr(void) const; - std::vector<std::string> getTypesStrings(void) const; - const char * getProjectName(void) const {return itsProjectName.c_str();} - const char * getProjectID(void) const {return itsProjectID.c_str();} - const char * getProjectPI(void) const {return itsProjectPI.c_str();} - const char * getProjectCO_I(void) const {return itsProjectCO_I.c_str();} - const char * getTaskName(void) const {return itsTaskName.c_str();} - const char * getTaskDescription(void) const {return itsSASTree.itsDescription.c_str();} - const char * getContactName(void) const {return itsContactName.c_str();} - const char * getContactPhone(void) const {return itsContactPhone.c_str();} - const char * getContactEmail(void) const {return itsContactEmail.c_str();} - const AstroDateTime &getScheduledStart(void) const { return scheduledStart; } - const AstroDateTime &getScheduledEnd(void) const { return scheduledEnd; } - const AstroDateTime &getRealStart(void) const {return itsSASTree.startTime();} - const AstroDateTime &getRealEnd(void) const {return itsSASTree.stopTime();} - const AstroDate &getWindowFirstDay() const { return firstPossibleDay; } - const AstroDate &getWindowLastDay() const { return lastPossibleDay; } - const AstroTime &getWindowMinTime() const { return windowMinTime; } - const AstroTime &getWindowMaxTime() const { return windowMaxTime; } - AstroDateTime getFirstPossibleDateTime() const; - AstroDateTime getLastPossibleDateTime() const; - const AstroTime &getDuration() const { return itsDuration; } - bool getFixedDay(void) const { return fixed_day; } - bool getFixedTime(void) const { return fixed_time; } - const std::string &getReason() const {return itsReason;} - bool getPenaltyCalculationNeeded(void) const {return penaltyCalculationNeeded;} - bool getShiftDirection(void) const {return itsShiftDirection;} - const task_conflicts &getConflicts(void) const {return itsConflicts;} - const QString &getOutputDataproductCluster(void) const {return itsOutputDataproductCluster;} // Added to support CEP4, maybe should be std::string /AR - - // set methods - void setID(unsigned id) {taskID = id;} - void setStatus(const task_status stat); - void setStatus(const std::string &stat); - void setStatusSAS(SAS_task_status status); // set the task status according to the SAS states - void setType(const task_type tasktype); - void setType(const QString &processType, processSubTypes processSubtype, const QString &strategy); - void syncStartStopTimes(void); // synchronizes the start and stop times in the meta-data of the OTDBtree with the scheduledStart and scheduledEnd times - inline void setProcessType(const QString &processType) {itsSASTree.itsProcessType = processType;} - inline void setProcessSubtype(processSubTypes process_subtype) {itsSASTree.itsProcessSubtype = process_subtype;} - inline void setStrategy(const QString &strategy) {itsSASTree.itsStrategy = strategy;} - inline void setPenalty(unsigned int penalty) {this->itsPenalty = penalty; this->penaltyCalculationNeeded = false;} - inline void clearPredecessors(void) {itsPredecessors.clear();} - inline void clearSuccessors(void) {itsSuccessors.clear();} - void addPredecessor(unsigned int taskID, id_type type = ID_SCHEDULER) {itsPredecessors.push_back(IDvector::value_type(type, taskID));} - void setPredecessors(const QString &predecessors); - inline void addSuccessor(unsigned int taskID, id_type type = ID_SCHEDULER) {itsSuccessors.push_back(IDvector::value_type(type, taskID));} - inline void setPredecessorMinTimeDif(const AstroTime &minTime) { predecessorMinTimeDif = minTime; } - inline void setPredecessorMaxTimeDif(const AstroTime &maxTime) { predecessorMaxTimeDif = maxTime; } - inline void setProjectName(const std::string &project_name) {itsProjectName = project_name;} - inline void setProjectID(const std::string &project_id) {itsProjectID = project_id; itsSASTree.itsCampaign = project_id;} - inline void setProjectPI(const std::string &project_leader) {itsProjectPI = project_leader;} - inline void setProjectCO_I(const std::string &project_coi) {itsProjectCO_I = project_coi;} - inline void setTaskName(const std::string &task_name) {itsTaskName = task_name;} - inline void setTaskDescription(const std::string &description) {itsSASTree.itsDescription = description;} - inline void setContactName(const std::string &contact_name) {itsContactName = contact_name;} - inline void setContactPhone(const std::string &contact_phone) {itsContactPhone = contact_phone;} - inline void setContactEmail(const std::string &contact_email) {itsContactEmail = contact_email;} - inline void setOriginalTreeID(int original_tree) {itsSASTree.itsOriginalTree = original_tree;} - bool setPriority(const double &); - inline void setWindowFirstDay(const QString &day) { firstPossibleDay = day; } - inline void setWindowFirstDay(const AstroDate &day) { firstPossibleDay = day;} - inline void setWindowFirstDay(unsigned long int day) { firstPossibleDay = AstroDate(day);} - inline void setWindowLastDay(const QString &day) {lastPossibleDay = day; } - inline void setWindowLastDay(const AstroDate &day) {lastPossibleDay = day; } - inline void setWindowLastDay(unsigned long int day) { lastPossibleDay = AstroDate(day);} - inline void setWindowMinTime(const AstroTime &time) { windowMinTime = time;} - inline void setWindowMaxTime(const AstroTime &time) {windowMaxTime = time; } - void setScheduledStart(const AstroDateTime &start) { scheduledStart = start; scheduledEnd = scheduledStart + itsDuration; penaltyCalculationNeeded = true;} - void setScheduledStart(double start) { scheduledStart = start; scheduledEnd = scheduledStart + itsDuration; penaltyCalculationNeeded = true;} - void setScheduledStart(const QString &start) { scheduledStart = start; scheduledEnd = scheduledStart + itsDuration; penaltyCalculationNeeded = true;} - void setScheduledEnd(const AstroDateTime &end) { scheduledEnd = end; itsDuration = scheduledEnd - scheduledStart; penaltyCalculationNeeded = true; /*itsRecalcStorageNeeded = true;*/} - void setScheduledEnd(double end) { scheduledEnd = end; itsDuration = scheduledEnd - scheduledStart; penaltyCalculationNeeded = true; /*itsRecalcStorageNeeded = true;*/} - void setScheduledEnd(const QString &end) { scheduledEnd = end; itsDuration = scheduledEnd - scheduledStart; penaltyCalculationNeeded = true; /*itsRecalcStorageNeeded = true;*/} - void resetRealTimes(void) {itsSASTree.resetTimes();} - void setScheduledPeriod(const AstroDateTime &start, const AstroDateTime &end); - void setDuration(const AstroTime &dur) { itsDuration = dur; scheduledEnd = scheduledStart + itsDuration; /*itsRecalcStorageNeeded = true;*/} - inline void setFixDay(bool fix_day) { fixed_day = fix_day; } - inline void setFixTime(bool fix_time) { fixed_time = fix_time; } - inline void setReason(const std::string &reason) {itsReason = reason;} - void setReason(unscheduled_reasons reason); - inline void clearReason(void) {itsReason = "";} - inline void clearPenalty(void) {itsPenalty = 0; penaltyCalculationNeeded = true;} - inline void setShiftDirection(bool direction) {itsShiftDirection = direction;} - inline void setSASTree(const OTDBtree &tree) {itsSASTree = tree;} - inline void setSASTreeID(int treeID) {itsSASTree.itsTreeID = treeID;} - inline void setGroupID(unsigned groupID) {itsSASTree.itsGroupID = groupID;} - inline void setMoMID(int momID) {itsSASTree.itsMomID = momID;} - inline void setOutputDataproductCluster(const QString &clusterName) {itsOutputDataproductCluster = clusterName;} // Added to support CEP4, maybe should be std::string /AR - - - void clearAllStorageConflicts(void); - - virtual TaskStorage *storage(void) {return 0;} - virtual const TaskStorage *storage(void) const {return 0;} - virtual bool hasStorage(void) const {return false;} - virtual void calculateDataFiles() { } - - void setConflict(task_conflict conflict, bool enable = true); - void clearConflict(task_conflict conflict) {setConflict(conflict, false);} - void clearAllConflicts(void); - // calculate the output data sizes, needs to be implemented in derived classes observation and pipeline - -private: - virtual void doCalculatePenalty() {itsPenalty = 0;} - -protected: - // attributes - std::string itsProjectID, itsProjectName, itsProjectPI, itsProjectCO_I, itsTaskName, itsContactName, itsContactPhone, itsContactEmail; - quint32 taskID; // unique task ID - double itsPriority; // priority of this task from 1 (high) to 5 (low) - task_status itsStatus; // the current status of this task - task_type itsTaskType; // the major type of this task e.g. PIPELINE / OBSERVATION / RESERVATION - bool fixed_day; // if set to true fixes the day - bool fixed_time; // if set to true fixes the day - quint16 itsPenalty; // the penalty for this task - bool penaltyCalculationNeeded; // determines if penalty needs to be recalculated - std::string itsReason; - bool itsShiftDirection; - IDvector itsPredecessors, itsSuccessors; - task_conflicts itsConflicts; - QString itsOutputDataproductCluster; // Added to support CEP4, maybe should be std::string /AR - - // objects -// std::vector<unsigned int> successors; - AstroTime predecessorMinTimeDif; - AstroTime predecessorMaxTimeDif; - AstroTime windowMinTime; // scheduling time window minimum time - AstroTime windowMaxTime; // scheduling time window maximum time - AstroDateTime scheduledStart; // the currently scheduled start time - AstroDateTime scheduledEnd; // the currently scheduled end time - AstroTime itsDuration; - AstroDate firstPossibleDay; // time window first possible scheduling date - AstroDate lastPossibleDay; // time window last possible scheduling date - - // SAS parameters -//#ifdef HAS_SAS_CONNECTION - OTDBtree itsSASTree; -public : - const OTDBtree &SASTree(void) const {return itsSASTree;} -//#endif -}; - - -// the following class is needed to be able to sort a vector of pointers to Task objects -// according to the priority attribute or the scheduled start time of the Task objects - -class cmp_TaskPriority -{ -public: - bool operator() (const Task * t1, const Task * t2) const - { - return t1->getPriority() > t2->getPriority(); - } -}; - -class cmp_taskScheduledStart -{ -public: - bool operator() (const Task *t1, const Task *t2) const - { - return t1->getScheduledStart() < t2->getScheduledStart(); - } -}; - -class cmp_taskFirstPossibleDateTime -{ -public: - bool operator() (const Task *t1, const Task *t2) const - { - return t1->getFirstPossibleDateTime() < t2->getFirstPossibleDateTime(); - } -}; - -class cmp_intPairFirst -{ -public: - bool operator() (const std::pair<int,int> &p1, const std::pair<int,int> &p2) const - { - return p1.first < p2.first; - } -}; - -class cmp_intPairSecond -{ -public: - bool operator() (const std::pair<int,int> &p1, const std::pair<int,int> &p2) const - { - return p1.second < p2.second; - } -}; - -// static helper functions -Task *cloneTask(const Task *pTask); // creates an exact clone of the supplied task -Task::task_status taskStatusFromString(const std::string &statusStr); -Task::task_type taskTypeFromString(std::string processType); -Task::task_status convertSASstatus(SAS_task_status sas_state); - -#endif /* TASK_H_ */ - - diff --git a/SAS/Scheduler/src/taskcopydialog.cpp b/SAS/Scheduler/src/taskcopydialog.cpp deleted file mode 100644 index 115d9291422794163e95348ca35953d33e6c1c73..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskcopydialog.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "taskcopydialog.h" -#include "Controller.h" - -TaskCopyDialog::TaskCopyDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); - connect(ui.pushButton_Ok, SIGNAL(clicked()), this, SLOT(okClicked(void))); - connect(ui.pushButton_Cancel, SIGNAL(clicked()), this, SLOT(cancelClicked(void))); - QStringList states; - states << task_states_str[Task::UNSCHEDULED] << task_states_str[Task::PRESCHEDULED]; - ui.comboBoxNewStatus->addItems(states); - ui.comboBoxNewStatus->setCurrentIndex(1); // set to PRESCHEDULED by default - ui.pushButton_Ok->setDefault(true); - connect(ui.spinBoxNrCopies, SIGNAL(valueChanged(int)), this, SLOT(nrCopiesChanged(int))); - // set the default start time to 10 minutes from now - QDateTime startTime = QDateTime::currentDateTime().toUTC(); - QDateTime minTime = startTime; - startTime = startTime.addSecs(630); // add the task 10.5 minutes from now and round to start at complete minutes - startTime.setTime(QTime(startTime.time().hour(), startTime.time().minute())); - ui.dateTimeEditStartTime->setMinimumDate(minTime.date()); - ui.dateTimeEditStartTime->setDateTime(startTime); - ui.lineEditTimeStep->setText(Controller::theSchedulerSettings.getMinimumTimeBetweenTasks().toString().c_str()); -} - -TaskCopyDialog::~TaskCopyDialog() -{ - -} - -void TaskCopyDialog::okClicked(void) { - QDateTime start(ui.dateTimeEditStartTime->dateTime()); - itsStartTime = AstroDateTime(start.date().day(), start.date().month(), start.date().year(), - start.time().hour(), start.time().minute(), start.time().second()); - itsTimeStep = ui.lineEditTimeStep->text(); - itsTaskState = taskStatusFromString(ui.comboBoxNewStatus->currentText().toStdString()); - done (ui.spinBoxNrCopies->value()); -} - -void TaskCopyDialog::cancelClicked(void) { - done(0); -} - -void TaskCopyDialog::nrCopiesChanged(int nrCopies) { - if (nrCopies == 1) { - ui.lineEditTimeStep->setEnabled(false); - ui.labelTimeStep->setEnabled(false); - } - else { - ui.lineEditTimeStep->setEnabled(true); - ui.labelTimeStep->setEnabled(true); - } -} diff --git a/SAS/Scheduler/src/taskcopydialog.h b/SAS/Scheduler/src/taskcopydialog.h deleted file mode 100644 index 2a4417451237e5b6c933d098f792d3f8278018c3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskcopydialog.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef TASKCOPYDIALOG_H -#define TASKCOPYDIALOG_H - -#include <QDialog> -#include "ui_taskcopydialog.h" -#include "astrodatetime.h" -#include "astrotime.h" -#include "task.h" - -class TaskCopyDialog : public QDialog -{ - Q_OBJECT - -public: - TaskCopyDialog(QWidget *parent = 0); - ~TaskCopyDialog(); - - const AstroDateTime &getStartTime(void) const {return itsStartTime;} - const AstroTime &getTimeStep(void) const {return itsTimeStep;} - const Task::task_status &getTaskState(void) const {return itsTaskState;} - void setStartTime(const AstroDateTime &start_time); - void setTimeStep(const AstroTime &time_step); - -private slots: - void okClicked(void); - void cancelClicked(void); - void nrCopiesChanged(int nrCopies); - -private: - Ui::TaskCopyDialogClass ui; - AstroDateTime itsStartTime; - AstroTime itsTimeStep; - Task::task_status itsTaskState; -}; - -#endif // TASKCOPYDIALOG_H diff --git a/SAS/Scheduler/src/taskcopydialog.ui b/SAS/Scheduler/src/taskcopydialog.ui deleted file mode 100644 index 37a069a037cd5e8e910f521b27127f4f8959341e..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskcopydialog.ui +++ /dev/null @@ -1,211 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>TaskCopyDialogClass</class> - <widget class="QDialog" name="TaskCopyDialogClass"> - <property name="windowModality"> - <enum>Qt::WindowModal</enum> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>328</width> - <height>168</height> - </rect> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>328</width> - <height>168</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>328</width> - <height>168</height> - </size> - </property> - <property name="windowTitle"> - <string>Copy Tasks</string> - </property> - <widget class="QLabel" name="label"> - <property name="geometry"> - <rect> - <x>9</x> - <y>9</y> - <width>251</width> - <height>21</height> - </rect> - </property> - <property name="text"> - <string>How many copies should be created?</string> - </property> - </widget> - <widget class="QPushButton" name="pushButton_Cancel"> - <property name="geometry"> - <rect> - <x>166</x> - <y>135</y> - <width>75</width> - <height>27</height> - </rect> - </property> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - <widget class="QPushButton" name="pushButton_Ok"> - <property name="geometry"> - <rect> - <x>246</x> - <y>135</y> - <width>75</width> - <height>27</height> - </rect> - </property> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Ok</string> - </property> - </widget> - <widget class="QDateTimeEdit" name="dateTimeEditStartTime"> - <property name="geometry"> - <rect> - <x>140</x> - <y>38</y> - <width>181</width> - <height>26</height> - </rect> - </property> - <property name="toolTip"> - <string>the new start time of (the first) observation</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd hh:mm:ss</string> - </property> - </widget> - <widget class="QSpinBox" name="spinBoxNrCopies"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="geometry"> - <rect> - <x>260</x> - <y>8</y> - <width>60</width> - <height>26</height> - </rect> - </property> - <property name="toolTip"> - <string>the number of copies of the (group) of observations</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>1000</number> - </property> - </widget> - <widget class="QLabel" name="label_2"> - <property name="geometry"> - <rect> - <x>10</x> - <y>40</y> - <width>151</width> - <height>21</height> - </rect> - </property> - <property name="text"> - <string>Start time (first task):</string> - </property> - </widget> - <widget class="QLabel" name="labelTimeStep"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="geometry"> - <rect> - <x>10</x> - <y>70</y> - <width>211</width> - <height>21</height> - </rect> - </property> - <property name="text"> - <string>Time step between tasks:</string> - </property> - </widget> - <widget class="QComboBox" name="comboBoxNewStatus"> - <property name="geometry"> - <rect> - <x>180</x> - <y>98</y> - <width>141</width> - <height>26</height> - </rect> - </property> - <property name="toolTip"> - <string>set the status of the copies to...</string> - </property> - </widget> - <widget class="QLabel" name="label_4"> - <property name="geometry"> - <rect> - <x>10</x> - <y>100</y> - <width>171</width> - <height>20</height> - </rect> - </property> - <property name="text"> - <string>Set status of copies to:</string> - </property> - </widget> - <widget class="QLineEdit" name="lineEditTimeStep"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="geometry"> - <rect> - <x>240</x> - <y>68</y> - <width>81</width> - <height>26</height> - </rect> - </property> - <property name="toolTip"> - <string>When copying a single observation: -the time between each copy - -When copying a group of observations: -the time between each group of observations</string> - </property> - <property name="inputMask"> - <string>0000:00:00; </string> - </property> - <property name="text"> - <string>0000:00:00</string> - </property> - </widget> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections/> -</ui> diff --git a/SAS/Scheduler/src/taskdialog.cpp b/SAS/Scheduler/src/taskdialog.cpp deleted file mode 100644 index 339ef7a54573d003848e4e0ad566d0ba4d3c814c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskdialog.cpp +++ /dev/null @@ -1,7626 +0,0 @@ -/* - * taskdialog.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Nov 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/taskdialog.cpp $ - * - */ - -#include "taskdialog.h" -#include "task.h" -#include "lofar_utils.h" -#include "lofar_scheduler.h" -#include "astrodatetime.h" -#include "DateEdit.h" -#include "DateTimeEdit.h" -#include "TimeEdit.h" -#include "LineEdit.h" -#include "CheckBox.h" -#include "SpinBox.h" -#include "doublespinbox.h" -#include "ListWidget.h" -#include "ComboBox.h" -#include "Controller.h" -#include "station.h" -#include "stationtreewidget.h" -#include "stationlistwidget.h" -#include "demixingsettings.h" -#include <QSpacerItem> -#include <QLabel> -#include <QMessageBox> -#include <QDoubleValidator> -#include <QGraphicsOpacityEffect> -#include <string> -#include <algorithm> -#include <iostream> -#include <iomanip> -#include <cmath> -#include <limits> - -#define STORAGE_NODE_ID_ROLE 200 -#define STORAGE_RAID_ID_ROLE 300 -#define NO_WARNING true - -const char *tab_names[NR_TABS] = {"Schedule","Station settings","Station beams","Processing","Storage","Imaging Pipelines","Pulsar Pipeline","Long-Baseline Pipeline","Extra info"}; - -TaskDialog::TaskDialog(QWidget *parentGUI, Controller *controller) - : QDialog(parentGUI), itsController(controller), itsTask(0), itsStorageOverflow(false), changeSchedule(false), - changeStations(false), changeBeams(false), changeProcessing(false), - changeStorage(false), changePipeline(false), changePulsar(false), changeLongBaseline(false), - changeExtraInfo(false), changeEnabledInputFiles(false), itsStationsLoaded(false), addingTask(false), addingPipeline(false), - addingReservation(false), blockChangeDetection(true) -{ - this->blockSignals(true); // to avoid early changes - ui.setupUi(this); - - itsOutputDataTypes.correlated = false; - itsOutputDataTypes.coherentStokes = false; - itsOutputDataTypes.incoherentStokes = false; - itsOutputDataTypes.instrumentModel = false; - itsOutputDataTypes.skyImage = false; - - ui.comboBoxProcessType->blockSignals(true); - for (short i = 0; i < NR_TASK_TYPES; ++i) { - ui.comboBoxProcessType->addItem(task_types_str[i]); - } - ui.comboBoxProcessType->blockSignals(false); - - ui.lineEditDuration->setDefaultText("00:00:00"); - ui.lineEditPriority->setDefaultText("1.0"); - - const AstroDate &earliest(Controller::theSchedulerSettings.getEarliestSchedulingDay()); - QDate earliestDate(earliest.getYear(), earliest.getMonth(), earliest.getDay()); - ui.dateTimeEditScheduledStart->setMinimumDate(earliestDate); - ui.dateTimeEditScheduledStart->setDefaultDateTime(earliest); - ui.dateTimeEditScheduledEnd->setMinimumDate(earliestDate); - ui.dateTimeEditScheduledEnd->setDefaultDateTime(Controller::theSchedulerSettings.getLatestSchedulingDay()); - - // ************** END frameScheduleGeneral ****************************************************************************** - - ui.spinBoxDataslotsPerRSPboard->setMinimum(1); - ui.spinBoxDataslotsPerRSPboard->setMaximum(MAX_DATASLOT_PER_RSP_16_BITS + 1); - - // Station beams tab - - QStringList items; - // analog beam direction types - items.clear(); - for (short int i=0; i < DIR_TYPE_UNDEFINED ; ++i) { - items << BEAM_DIRECTION_TYPES[i]; - } - ui.comboBoxAnalogBeamCoordinates->addItems(items); - - // analog beam units (defaults to J2000 coordinates (HMS,DMS) - items.clear(); - for (short int i=0; i < END_ANGLE_PAIRS; ++i) { - items << ANGLE_PAIRS[i]; - } - ui.comboBoxAnalogBeamUnits->addItems(items); - - // fill antenna modes comboBox - items.clear(); - for (short int i=0; i < NR_ANTENNA_MODES ; ++i) { - items << antenna_modes_str[i]; - } - ui.comboBoxStationAntennaMode->blockSignals(true); - ui.comboBoxStationAntennaMode->addItems(items); - ui.comboBoxStationAntennaMode->blockSignals(false); - - // fill station filter types comboBox - items.clear(); - for (short int i=0; i < NR_FILTER_TYPES ; ++i) { - items << filter_types_str[i]; - } - ui.comboBoxStationFilter->blockSignals(true); - ui.comboBoxStationFilter->addItems(items); - ui.comboBoxStationFilter->blockSignals(false); - - // fill clock frequencies combobox - items.clear(); - for (short int i=0; i < NR_CLOCK_FREQUENCIES; ++i) { - items << clock_frequencies_str[i]; - } - ui.comboBoxStationClock->blockSignals(true); - ui.comboBoxStationClock->addItems(items); - ui.comboBoxStationClock->blockSignals(false); - - // storage node selection method combo box - items.clear(); - for (short int i=0; i < NR_STORAGE_SELECTION_MODES; ++i) { - items << storage_select_mode_str[i]; - } - ui.comboBoxStorageSelectionMode->blockSignals(true); - ui.comboBoxStorageSelectionMode->addItems(items); - ui.comboBoxStorageSelectionMode->blockSignals(false); - - - // digital beam table header - ui.tableWidgetDigitalBeams->setColumnCount(11); - QStringList header; - header << "Target" << "Coord." << "Units" << "Angle 1" << "Angle 2" - << "subband list" << "# subbands" << "start time" << "duration" << "# TAB rings" << "TAB ring size"; - ui.tableWidgetDigitalBeams->setHorizontalHeaderLabels(header); - - ui.tableWidgetDigitalBeams->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui.tableWidgetDigitalBeams, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayDigitalBeamContextMenu(const QPoint &))); - - - // Tied array beams table - ui.tableWidgetTiedArrayBeams->setColumnCount(4); - ui.tableWidgetTiedArrayBeams->setSelectionBehavior(QAbstractItemView::SelectRows); - ui.tableWidgetTiedArrayBeams->setSelectionMode(QAbstractItemView::ExtendedSelection); - ui.tableWidgetTiedArrayBeams->setEditTriggers(QAbstractItemView::NoEditTriggers); - header.clear(); - header << "Angle 1 (rad)" << "Angle 2 (rad)" << "Type" << "Dispersion measure"; - ui.tableWidgetTiedArrayBeams->setHorizontalHeaderLabels(header); - ui.tableWidgetTiedArrayBeams->setColumnWidth(0,150); - ui.tableWidgetTiedArrayBeams->setColumnWidth(1,150); - ui.tableWidgetTiedArrayBeams->setColumnWidth(2,130); - ui.tableWidgetTiedArrayBeams->horizontalHeader()->setStretchLastSection(true); -#if QT_VERSION >= 0x050000 - ui.tableWidgetTiedArrayBeams->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); -#else - ui.tableWidgetTiedArrayBeams->horizontalHeader()->setResizeMode(QHeaderView::Interactive); -#endif - - // enable default output data type - ui.checkBoxCorrelatedData->blockSignals(true); - ui.checkBoxCorrelatedData->setChecked(true); - ui.checkBoxCorrelatedData->blockSignals(false); - - // storage nodes tree header - header.clear(); - ui.treeWidgetStorageNodes->setColumnCount(4); - header << "Storage node" << "Partition" << "Total Size" << "Free Space"; - ui.treeWidgetStorageNodes->setHeaderLabels(header); - ui.treeWidgetStorageNodes->header()->resizeSection(0, 150); - ui.treeWidgetStorageNodes->header()->resizeSection(1, 70); - ui.treeWidgetStorageNodes->header()->resizeSection(2, 55); - ui.treeWidgetStorageNodes->header()->resizeSection(3, 55); - ui.treeWidgetStorageNodes->setSelectionMode(QAbstractItemView::ExtendedSelection); - itsActionStorageOverride = new QAction("&Manual override", ui.treeWidgetStorageNodes); - itsActionStorageCheckSelected = new QAction("&Check selected", ui.treeWidgetStorageNodes); - itsActionStorageUncheckSelected = new QAction("&Uncheck selected", ui.treeWidgetStorageNodes); - connect(itsActionStorageCheckSelected, SIGNAL(triggered()), this, SLOT(doCheckSelectedStorage())); - connect(itsActionStorageUncheckSelected, SIGNAL(triggered()), this, SLOT(doUnCheckSelectedStorage())); - connect(ui.treeWidgetStorageNodes, SIGNAL(clicked(QModelIndex)), this, SLOT(detectStorageLocationChanges(void))); - connect(ui.treeWidgetInputDataProducts, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(detectInputFilesEnabledChanges(void))); - ui.treeWidgetStorageNodes->addAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->addAction(itsActionStorageUncheckSelected); - ui.treeWidgetStorageNodes->setContextMenuPolicy(Qt::ActionsContextMenu); - - // dataproducts tree header - ui.treeWidgetOutputDataProducts->setColumnCount(1); - ui.treeWidgetOutputDataProducts->header()->hide(); - ui.treeWidgetInputDataProducts->setColumnCount(1); - ui.treeWidgetInputDataProducts->header()->hide(); - - // Stokes types - items.clear(); - for (short int i = 0; i < DATA_TYPE_XXYY; ++i) { - items << DATA_TYPES[i]; - } - ui.comboBoxIncoherentStokesType->addItems(items); - - items << DATA_TYPES[DATA_TYPE_XXYY]; // add XXYY to the coherent stokes type (i.e. for Complex Voltages) - ui.comboBoxCoherentStokesType->addItems(items); - - // bits per sample - items.clear(); - items /*<< "2"*/ << "4" << "8" << "16"; - ui.comboBoxBitsPerSample->addItems(items); - - QPalette palet = ( ui.lineEditStorageConflict->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - palet.setColor( QPalette::Text, Qt::white ); - ui.lineEditStorageConflict->setPalette(palet); - ui.lineEditStorageConflict->hide(); - - enableFOVedit(1); - - // connect signals and slots - connect(ui.comboBoxTaskStatus, SIGNAL(currentIndexChanged(int)), this, SLOT(statusChanged())); - connect(ui.lineEditAnalogBeamAngle1, SIGNAL(editingFinished()), this, SLOT(setAnalogBeamAngle1())); - connect(ui.lineEditAnalogBeamAngle2, SIGNAL(editingFinished()), this, SLOT(setAnalogBeamAngle2())); - connect(ui.pushButtonAddSuperStation, SIGNAL(clicked()), this, SLOT(addSuperStation())); - connect(ui.treeWidgetUsedStations, SIGNAL(stationsDeleted(const QStringList &)), this, SLOT(addAvailableStations(const QStringList &))); - connect(ui.treeWidgetUsedStations, SIGNAL(checkForStationChanges()), this, SLOT(checkIfStationChanged())); - connect(ui.listWidgetAvailableStations, SIGNAL(stationsRemoved()), this, SLOT(applyStationsRemoved())); - connect(ui.listWidgetAvailableStations, SIGNAL(addStationsToUse(const QStringList &)), this, SLOT(addStationsToUsedStations(const QStringList &))); - connect(ui.pushButtonAddBeam, SIGNAL(clicked()), this, SLOT(addDigitalBeam(void))); - connect(ui.pushButtonDeleteBeams, SIGNAL(clicked()), this, SLOT(deleteDigitalBeam(void))); - connect(ui.pushButtonEditBeam, SIGNAL(clicked()), this, SLOT(editDigitalBeam(void))); - connect(ui.pushButtonClearAllBeams, SIGNAL(clicked()), this, SLOT(clearAllDigitalBeams(void))); - connect(ui.tableWidgetDigitalBeams, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(editDigitalBeam(void))); - connect(ui.tableWidgetDigitalBeams, SIGNAL(cellClicked(int,int)), this, SLOT(showTiedArrayBeams(int))); - connect(ui.tableWidgetTiedArrayBeams, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(editTiedArrayBeam(void))); - connect(ui.pushButtonAddTiedArrayBeam, SIGNAL(clicked()), this, SLOT(addTiedArrayBeam(void))); - connect(ui.pushButtonDeleteTiedArrayBeam, SIGNAL(clicked()), this, SLOT(deleteTiedArrayBeam(void))); - connect(ui.pushButtonEditTiedArrayBeam, SIGNAL(clicked()), this, SLOT(editTiedArrayBeam(void))); - connect(ui.pushButtonClearAllTiedArrayBeam, SIGNAL(clicked()), this, SLOT(clearAllTiedArrayBeams(void))); - - connect(ui.tabWidgetMain, SIGNAL(currentChanged(int)), this, SLOT(doTabChangeUpdate(int))); - connect(ui.pushButtonUpdateCampaigns, SIGNAL(clicked()), this, SLOT(updateProjects())); - connect(ui.lineEditAnalogBeamDuration, SIGNAL(textEdited(const QString &)), this, SLOT(analogBeamDurationChanged(const QString &))); - connect(ui.comboBoxAnalogBeamCoordinates, SIGNAL(currentIndexChanged(int)), this, SLOT(AnalogBeamDirectionTypeChanged(void))); - connect(ui.comboBoxAnalogBeamUnits, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(AnalogBeamAngleUnitChanged(const QString &))); - connect(ui.comboBoxProjectID, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(applyProjectChange(const QString &))); - connect(ui.comboBoxStationAntennaMode, SIGNAL(currentIndexChanged(int)), this, SLOT(AntennaModeChanged(int))); - connect(ui.comboBoxStationFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(FilterTypeChanged(int))); - connect(ui.comboBoxStationClock, SIGNAL(currentIndexChanged(int)), this, SLOT(StationClockModeChanged(int))); - connect(ui.comboBoxStorageSelectionMode, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStorageSelectionMode(int))); - - connect(ui.checkBoxSpecifyFOV,SIGNAL(stateChanged(int)), this, SLOT(enableFOVedit(int))); - connect(ui.pushButtonClearDemixAlways, SIGNAL(clicked()), this, SLOT(clearDemixAlways())); - connect(ui.pushButtonClearDemixIfNeeded, SIGNAL(clicked()), this, SLOT(clearDemixIfNeeded())); - connect(ui.comboBoxBitsPerSample, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMaxDataslotsPerRSP())); - connect(ui.checkBoxCorrelatedData, SIGNAL(stateChanged(int)), this, SLOT(outputDataTypesChanged())); - connect(ui.checkBoxCoherentStokes, SIGNAL(stateChanged(int)), this, SLOT(outputDataTypesChanged())); - connect(ui.checkBoxIncoherentStokes, SIGNAL(stateChanged(int)), this, SLOT(outputDataTypesChanged())); - connect(ui.comboBoxCoherentStokesType, SIGNAL(currentIndexChanged(int)), this, SLOT(outputDataTypesChanged())); - connect(ui.comboBoxIncoherentStokesType, SIGNAL(currentIndexChanged(int)), this, SLOT(outputDataTypesChanged())); - - // set the default button - ui.pushButtonOk->setDefault(true); - this->blockSignals(false); // to avoid early changes - - itsDigitalBeamDialog = new DigitalBeamDialog(this); - itsTiedArrayBeamDialog= new TiedArrayBeamDialog(this); -} - -TaskDialog::~TaskDialog() -{ - delete itsTask; - delete itsDigitalBeamDialog; - delete itsTiedArrayBeamDialog; -} - -void TaskDialog::statusChanged(void) { - Task::task_status state(taskStatusFromString(ui.comboBoxTaskStatus->currentText().toStdString())); - if (state <= Task::PRESCHEDULED) setNormalTaskMode(); // again enables all widgets that might have been disabled - else if (state == Task::SCHEDULED) setScheduledTaskMode(); - else if (state > Task::SCHEDULED) setFinishedTaskMode(); - detectChanges(); -} - -void TaskDialog::enableFOVedit(int state) { - ui.lineEditFieldOfView->setEnabled(state); - ui.labelFOV->setEnabled(state); - ui.lineEditCellSize->setEnabled(!state); - ui.labelCellSize->setEnabled(!state); - ui.spinBoxNumberOfPixels->setEnabled(!state); - ui.labelNpix->setEnabled(!state); - detectChanges(); -} - -void TaskDialog::strategyChanged(void) { - updateOriginalTreeID(); - detectChanges(); -} - -void TaskDialog::updateOriginalTreeID(void) { - ui.lineEditOriginalTreeID->setText(QString::number(Controller::theSchedulerSettings.getSASDefaultTreeID(ui.comboBoxProcessType->currentText(), ui.comboBoxProcessSubType->currentText(), ui.comboBoxStrategies->currentText()))); -} - -void TaskDialog::loadProcessTypes(void) { - ui.comboBoxProcessType->blockSignals(true); - ui.comboBoxProcessSubType->blockSignals(true); - const QStringList &processTypes(Controller::theSchedulerSettings.getAllProcessTypes()); - QStandardItemModel* model = qobject_cast<QStandardItemModel*>(ui.comboBoxProcessType->model()); - if (model) { - QStandardItem* item; - // check if OBSERVATION is in processTypes and set it as the default - item = model->item(0); - if (processTypes.indexOf(task_types_str[Task::OBSERVATION]) == -1) { // check if a default template of type OBSERVATION exists - // disable OBSERVATION process type in combobox - item->setEnabled(false); - item->setToolTip("No OBSERVATION default template found in SAS database.\nCannot add OBSERVATION tasks."); - processTypeChanged(ui.comboBoxProcessType->currentIndex()); - } - else { - item->setEnabled(true); - item->setToolTip(""); - ui.comboBoxProcessType->setCurrentIndex(0); - // fetch processSubTypes for processType = OBSERVATION - updateProcessSubtypes(task_types_str[Task::OBSERVATION]); -// processTypeChanged(0); - // set the default processSubtype to BEAM OBSERVATION if it exists - int idx(ui.comboBoxProcessSubType->findText("BEAM OBSERVATION")); - if (idx != -1) { - ui.comboBoxProcessSubType->setCurrentIndex(idx); - } - } - - item = model->item(1); - if (processTypes.indexOf("RESERVATION") == -1) { // check if RESERVATION is in processTypes if not disable it - item->setEnabled(false); - item->setToolTip("No RESERVATION default templates found in SAS database.\nCannot add RESERVATION tasks."); - } - else { - item->setEnabled(true); - item->setToolTip(""); - } - - item = model->item(2); - if (processTypes.indexOf("MAINTENANCE") == -1) { // check if MAINTENANCE is in processTypes if not disable it - item->setEnabled(false); - item->setToolTip("No MAINTENANCE default templates found in SAS database.\nCannot add MAINTENANCE tasks."); - } - else { - item->setEnabled(true); - item->setToolTip(""); - } - - item = model->item(3); - if (processTypes.indexOf("PIPELINE") == -1) { // check if PIPELINE is in processTypes if not disable it - item->setEnabled(false); - item->setToolTip("No PIPELINE default templates found in SAS database.\nCannot add PIPELINE tasks."); - } - else { - item->setEnabled(true); - item->setToolTip(""); - } - - item = model->item(4); - if (processTypes.indexOf("SYSTEM") == -1) { // check if PIPELINE is in processTypes if not disable it - item->setEnabled(false); - item->setToolTip("No SYSTEM default templates found in SAS database.\nCannot add SYSTEM tasks."); - } - else { - item->setEnabled(true); - item->setToolTip(""); - } - } - ui.comboBoxProcessType->setEnabled(true); - ui.comboBoxProcessSubType->setEnabled(true); - ui.comboBoxStrategies->setEnabled(true); - ui.comboBoxProcessType->setToolTip(""); - ui.comboBoxProcessSubType->setToolTip(""); - ui.comboBoxStrategies->setToolTip(""); - - ui.comboBoxProcessType->blockSignals(false); - ui.comboBoxProcessSubType->blockSignals(false); -} - -void TaskDialog::setProcessSubProcessStrategy(const Task *pTask) { - ui.comboBoxProcessType->blockSignals(true); - ui.comboBoxProcessSubType->blockSignals(true); - ui.comboBoxStrategies->blockSignals(true); - // set processType according to task type - Task::task_type type = pTask->getType(); - ui.comboBoxProcessType->setCurrentIndex(type); - - QString pstype(pTask->getProcessSubtypeStr()); - const QString &ptype(pTask->getProcessType()), strategy(pTask->getStrategy()); - - // set process subtype - ui.comboBoxProcessSubType->clear(); - ui.comboBoxProcessSubType->addItems(Controller::theSchedulerSettings.getAllProcessSubTypes(ptype)); - int idx(ui.comboBoxProcessSubType->findText(pstype)); - if (idx != -1) { - ui.comboBoxProcessSubType->setCurrentIndex(idx); - } - else { - ui.comboBoxProcessSubType->addItem(pstype); - ui.comboBoxProcessSubType->setCurrentIndex(ui.comboBoxProcessSubType->count()-1); - } - - // set strategy - ui.comboBoxStrategies->clear(); - ui.comboBoxStrategies->addItems(Controller::theSchedulerSettings.getAllStrategies(ptype, pstype)); - idx = ui.comboBoxStrategies->findText(strategy); - if (idx != -1) { - ui.comboBoxStrategies->setCurrentIndex(idx); - } - else { - ui.comboBoxStrategies->addItem(strategy); - ui.comboBoxStrategies->setCurrentIndex(ui.comboBoxStrategies->count()-1); - } - - ui.comboBoxProcessType->blockSignals(false); - ui.comboBoxProcessSubType->blockSignals(false); - ui.comboBoxStrategies->blockSignals(false); -} - -void TaskDialog::processTypeChanged(int ptype) { - ui.comboBoxProcessSubType->blockSignals(true); - ui.comboBoxProcessSubType->clear(); - ui.comboBoxProcessSubType->addItems(Controller::theSchedulerSettings.getAllProcessSubTypes(task_types_str[ptype])); - updateStrategiesComboBox(); - ui.comboBoxProcessSubType->blockSignals(false); - - enableApplyButtons(true); - changeSchedule = true; - - int task_id(itsTask->getID()); - Task::task_type type = static_cast<Task::task_type>(ptype); - switch (type) { - case Task::OBSERVATION: - default: - delete itsTask; - itsTask = new Observation(task_id); - setNormalTaskMode(); - break; - case Task::RESERVATION: - case Task::MAINTENANCE: - delete itsTask; - itsTask = new StationTask(task_id, type); - if (addingTask) { - addingReservation = true; - } - setReservationTaskMode(); - if (!itsStationsLoaded) { - loadAvailableStations(); - } - case Task::PIPELINE: - if (addingTask) { - addingPipeline = true; - this->setWindowTitle(QString("Add pipeline ") + QString::number(task_id)); - setPipelineType(); - } - break; - case Task::SYSTEM: - delete itsTask; - itsTask = new Task(task_id); - setWindowTitle("Add System task"); - break; - } - enableTabs(); - detectChanges(); -} - -void TaskDialog::updateProcessSubtypes(const QString &processType) { - ui.comboBoxProcessSubType->blockSignals(true); - ui.comboBoxProcessSubType->clear(); - ui.comboBoxProcessSubType->addItems(Controller::theSchedulerSettings.getAllProcessSubTypes(processType)); - ui.comboBoxProcessSubType->setCurrentIndex(0); - updateStrategiesComboBox(); - ui.comboBoxProcessSubType->blockSignals(false); -} - -void TaskDialog::updateStrategiesComboBox(void) { - ui.comboBoxStrategies->blockSignals(true); - ui.comboBoxStrategies->clear(); - ui.comboBoxStrategies->addItems(Controller::theSchedulerSettings.getAllStrategies(ui.comboBoxProcessType->currentText(), ui.comboBoxProcessSubType->currentText())); - updateOriginalTreeID(); - setPipelineType(); // if this is a pipeline - ui.comboBoxStrategies->blockSignals(false); -} - - -void TaskDialog::setPipelineProperties(void) { - if (itsTask->isPipeline()) { - const CalibrationPipeline *calpipe(dynamic_cast<const CalibrationPipeline *>(itsTask)); - const ImagingPipeline *impipe(0); - const PulsarPipeline *pulsepipe(0); - const LongBaselinePipeline *lbpipe(0); - - if (calpipe) { - setDemixSettings(calpipe->demixingSettings()); - setCalibrationPipelineSettings(calpipe); - disableImagingPipelineSettings(); - } - else if ((impipe = dynamic_cast<const ImagingPipeline *>(itsTask))) { - setImagingPipelineSettings(impipe); - disableCalibrationPipelineSettings(); - disableDemixSettings(); - } - else if ((pulsepipe = dynamic_cast<const PulsarPipeline *>(itsTask))) { - setPulsarPipelineSettings(pulsepipe); - } - else if ((lbpipe = dynamic_cast<const LongBaselinePipeline *>(itsTask))) { - setLongBaselinePipelineSettings(lbpipe); - } - else { - disableDemixSettings(); - disableCalibrationPipelineSettings(); - disableImagingPipelineSettings(); - } - - setInputDataProductsTree(*itsTask); - } -} - -void TaskDialog::setPipelineType(void) { - if (ui.comboBoxProcessType->currentIndex() == Task::PIPELINE) { - int task_id(itsTask->getID()); - delete itsTask; - const QString &pst(ui.comboBoxProcessSubType->currentText()); - if (pst == PROCESS_SUBTYPES[PST_CALIBRATION_PIPELINE] || pst == PROCESS_SUBTYPES[PST_AVERAGING_PIPELINE]) { - itsTask = new CalibrationPipeline(task_id); -// setDemixSettings(static_cast<CalibrationPipeline *>(itsTask)->demixingSettings()); - } - else if (pst == PROCESS_SUBTYPES[PST_PULSAR_PIPELINE]) { - itsTask = new PulsarPipeline(task_id); - } - else if (pst == PROCESS_SUBTYPES[PST_IMAGING_PIPELINE] || pst == PROCESS_SUBTYPES[PST_MSSS_IMAGING_PIPELINE]) { - itsTask = new ImagingPipeline(task_id); -// setImagingPipelineSettings(static_cast<ImagingPipeline *>(itsTask)); - } - else if (pst == PROCESS_SUBTYPES[PST_LONG_BASELINE_PIPELINE]) { - itsTask = new LongBaselinePipeline(task_id); - } - else { - itsTask = new Pipeline(task_id); - } -// setPipelineProperties(); - enableTabs(); - } -} - -void TaskDialog::enableApplyButtons(bool enable) { - if (enable) { - ui.pushButtonCancelClose->setText("Cancel"); - ui.pushButtonApply->setEnabled(true); - ui.pushButtonOk->setEnabled(true); - } - else { - ui.pushButtonCancelClose->setText("Close"); - ui.pushButtonApply->setEnabled(false); - ui.pushButtonOk->setEnabled(false); - } -} - -void TaskDialog::updateStorageSelectionMode(int newMode) { - if (isMultiTasks) { - // check if set to manual if so enable manual override - if (static_cast<storage_selection_mode>(newMode) == STORAGE_MODE_MANUAL) { - doManualStorageOverride(); - } - else { - setStorageEditable(false); - } - } - else { // single task - if (static_cast<storage_selection_mode>(newMode) == STORAGE_MODE_MANUAL) { - setStorageEditable(true); - } - else { - setStorageEditable(false); - } - } - detectChanges(); -} - -void TaskDialog::displayDigitalBeamContextMenu(const QPoint &pos) { - if (!isMultiTasks) { - Task::task_status status = itsTask->getStatus(); - QMenu menu(this); - QAction *copy_angles(0), *copy_all(0), *reset_duration(0), *action(0), *edit(0), *show(0); - if (ui.groupBoxAnalogBeam->isEnabled()) { - if (status <= Task::SCHEDULED) { - copy_angles = menu.addAction("copy angles to analog beam"); - copy_all = menu.addAction("copy all setting to analog beam"); - reset_duration = menu.addAction("synchronize times with observation"); - edit = menu.addAction("edit"); - } - else { - show = menu.addAction("show"); - } - } - else { - if (status <= Task::SCHEDULED) { - reset_duration = menu.addAction("synchronize times with observation"); - edit = menu.addAction("edit"); - } - else { - show = menu.addAction("show"); - } - } - action = menu.exec(QCursor::pos()); - if (action == copy_angles) { - QTableWidgetItem *item = ui.tableWidgetDigitalBeams->itemAt(pos); - if (item) { - std::map<unsigned, DigitalBeam>::const_iterator bit = itsDigitalBeams.find(item->row()); - if (bit != itsDigitalBeams.end()) { - itsAnalogBeamSettings.angle1.setRadianAngle(bit->second.angle1().radian()); - itsAnalogBeamSettings.angle2.setRadianAngle(bit->second.angle2().radian()); - itsAnalogBeamSettings.directionType = bit->second.directionType(); - ui.comboBoxAnalogBeamCoordinates->setCurrentIndex(itsAnalogBeamSettings.directionType); - setComboBoxAnalogBeamUnits(); - itsAnalogBeamAnglePair = bit->second.units(); - setAnalogBeamAnglePair(itsAnalogBeamAnglePair); - enableApplyButtons(true); - changeBeams = true; - } - } - } - else if (action == copy_all) { - QTableWidgetItem *item = ui.tableWidgetDigitalBeams->itemAt(pos); - if (item) { - // copy angles - std::map<unsigned, DigitalBeam>::const_iterator bit = itsDigitalBeams.find(item->row()); - if (bit != itsDigitalBeams.end()) { - itsAnalogBeamSettings.angle1.setRadianAngle(bit->second.angle1().radian()); - itsAnalogBeamSettings.angle2.setRadianAngle(bit->second.angle2().radian()); - itsAnalogBeamSettings.directionType = bit->second.directionType(); - itsAnalogBeamSettings.duration = bit->second.duration(); - itsAnalogBeamSettings.startTime = bit->second.startTime(); - ui.comboBoxAnalogBeamCoordinates->setCurrentIndex(itsAnalogBeamSettings.directionType); - setComboBoxAnalogBeamUnits(); - itsAnalogBeamAnglePair = bit->second.units(); - setAnalogBeamAnglePair(itsAnalogBeamAnglePair); - ui.timeEditAnalogBeamStartTime->setTime(QTime(itsAnalogBeamSettings.startTime.getHours(), - itsAnalogBeamSettings.startTime.getMinutes(),itsAnalogBeamSettings.startTime.getSeconds())); - ui.lineEditAnalogBeamDuration->setText(itsAnalogBeamSettings.duration.toString()); - enableApplyButtons(true); - changeBeams = true; - } - } - } - else if (action == reset_duration) { - QTableWidgetItem *item = ui.tableWidgetDigitalBeams->itemAt(pos); - if (item) { - std::map<unsigned, DigitalBeam>::iterator bit = itsDigitalBeams.find(item->row()); - bit->second.setDuration(ui.lineEditDuration->text()); - bit->second.zeroStartTime(); - setDigitalBeam(item->row(),bit->second,true); - changeBeams = true; - } - } - else if (action == edit) { - QTableWidgetItem *item = ui.tableWidgetDigitalBeams->itemAt(pos); - if (item) { - itsDigitalBeamDialog->setReadOnly(false); - itsDigitalBeamDialog->loadBeamSettings(item->row(), itsDigitalBeams.at(item->row())); - itsDigitalBeamDialog->exec(); - } - } - else if (action == show) { - QTableWidgetItem *item = ui.tableWidgetDigitalBeams->itemAt(pos); - if (item) { - itsDigitalBeamDialog->setReadOnly(true); - itsDigitalBeamDialog->loadBeamSettings(item->row(), itsDigitalBeams.at(item->row())); - itsDigitalBeamDialog->exec(); - } - } - } -} - - -void TaskDialog::setInputDataProductsTree(const Task &task) { - ui.treeWidgetInputDataProducts->clear(); - const TaskStorage *task_storage(task.storage()); - if (task_storage) { - const std::map<dataProductTypes, TaskStorage::inputDataProduct> &inputData(task_storage->getInputDataProducts()); - QTreeWidgetItem *dataProductTypeItem, *fileItem; - QList<QTreeWidgetItem *> dataProductTypeList; - bool inputDisabled; - for (std::map<dataProductTypes, TaskStorage::inputDataProduct>::const_iterator it = inputData.begin(); it != inputData.end(); ++it) { - QStringList itemValues; - itemValues << QString(DATA_PRODUCTS[it->first]) + " data products"; - dataProductTypeItem = new QTreeWidgetItem((QTreeWidget*)0, itemValues); - dataProductTypeItem->setData(0, Qt::UserRole, static_cast<int>(it->first)); - if (task_storage->isInputDataProduktEnabled(it->first)) { - dataProductTypeItem->setCheckState(0, Qt::Checked); - inputDisabled = false; - } - else { - dataProductTypeItem->setCheckState(0, Qt::Unchecked); - inputDisabled = true; - } - unsigned nrFiles(it->second.filenames.size()); - bool useSkip(it->second.skip.size() == nrFiles); - for (unsigned idx = 0; idx < nrFiles; ++idx) { - itemValues.clear(); - itemValues << it->second.locations.at(idx) + it->second.filenames.at(idx); - fileItem = new QTreeWidgetItem(dataProductTypeItem, itemValues); - fileItem->setData(0, Qt::UserRole, static_cast<int>(it->first)); // data product type - if (useSkip) { - if (!it->second.skip.at(idx)) { - fileItem->setCheckState(0,Qt::Checked); - } - else { - fileItem->setCheckState(0,Qt::Unchecked); - } - } - else { - fileItem->setCheckState(0,Qt::Checked); - } - fileItem->setDisabled(inputDisabled); - } - dataProductTypeList.append(dataProductTypeItem); - } - ui.treeWidgetInputDataProducts->insertTopLevelItems(0, dataProductTypeList); - ui.treeWidgetInputDataProducts->expandAll(); - ui.treeWidgetInputDataProducts->resizeColumnToContents(0); - } -} - -// update the enabled input data product types in itsTask according to the current enabled types in the inputDataTreeWidget -void TaskDialog::updateEnabledInputDataTypes(void) { - TaskStorage *task_storage(itsTask->storage()); - if (task_storage) { - QTreeWidgetItem *dpItem(0); - dataProductTypes dpType; - for (short i = 0; i < ui.treeWidgetInputDataProducts->topLevelItemCount(); ++i) { - dpItem = ui.treeWidgetInputDataProducts->topLevelItem(i); - // which data product type? - dpType = static_cast<dataProductTypes>(dpItem->data(0, Qt::UserRole).toInt()); - task_storage->setInputDataProductEnabled(dpType, dpItem->checkState(0) == Qt::Checked); - } - } -} - -// get the enabled input files which are currently selected in the input data product tree -std::map<dataProductTypes, std::vector<bool> > TaskDialog::getInputDataFilesCheckState(void) { - std::map<dataProductTypes, std::vector<bool> > retMap; - QTreeWidgetItemIterator it(ui.treeWidgetInputDataProducts, QTreeWidgetItemIterator::NoChildren); - dataProductTypes type, prevType(DP_UNKNOWN_TYPE); - std::vector<bool> vec; - if (*it) { - prevType = static_cast<dataProductTypes>((*it)->data(0,Qt::UserRole).toInt()); // file data product type - } - while (*it) { - type = static_cast<dataProductTypes>((*it)->data(0,Qt::UserRole).toInt()); // file data product type - if (prevType != type) { - retMap[prevType] = vec; // store current data product type items - vec.clear(); - prevType = type; - } - if ((*it)->checkState(0) == Qt::Checked) { - vec.push_back(false); - } - else { - vec.push_back(true); - } - ++it; - } - if (!vec.empty()) { - retMap[prevType] = vec; // store last data product type items - } - - return retMap; -} - -void TaskDialog::detectInputFilesEnabledChanges(void) { - const TaskStorage *task_storage(itsTask->storage()); - changeEnabledInputFiles = false; - if (task_storage) { - // detect if an input data product is completely disabled - QTreeWidgetItem *dpItem(0); - bool disable(false); - ui.treeWidgetInputDataProducts->blockSignals(true); - for (short i = 0; i < ui.treeWidgetInputDataProducts->topLevelItemCount(); ++i) { - dpItem = ui.treeWidgetInputDataProducts->topLevelItem(i); - disable = dpItem->checkState(0) == Qt::Checked ? false : true; - for (int i = 0; i < dpItem->childCount(); ++i) { - dpItem->child(i)->setDisabled(disable); - } - // detect changes - dataProductTypes dpType = static_cast<dataProductTypes>(dpItem->data(0,Qt::UserRole).toInt()); - if (task_storage->isInputDataProduktEnabled(dpType) == disable) { - changeEnabledInputFiles = true; - } - } - ui.treeWidgetInputDataProducts->blockSignals(false); - - // detect individual input file enabled/disabled - if (!changeEnabledInputFiles) { - std::map<dataProductTypes, std::vector<bool> > files(getInputDataFilesCheckState()); - const std::map<dataProductTypes, TaskStorage::inputDataProduct> &inputDataProducts(task_storage->getInputDataProducts()); - std::map<dataProductTypes, TaskStorage::inputDataProduct>::const_iterator init; - for (std::map<dataProductTypes, std::vector<bool> >::const_iterator it = files.begin(); it != files.end(); ++it) { - init = inputDataProducts.find(it->first); - if (init != inputDataProducts.end()) { - if (init->second.skip != it->second) { - changeEnabledInputFiles = true; - return; - } - } - } - } - - enableApplyButtons(ifSettingsChanged()); - } -} - - -void TaskDialog::generateFileList(const Task *task, bool noWarnings = false) { - const TaskStorage *task_storage(task->storage()); - ui.treeWidgetOutputDataProducts->clear(); - - if (task_storage) { - const std::map<dataProductTypes, TaskStorage::outputDataProduct> &files = task_storage->getOutputDataProducts(); - QStringList itemValues; - bool storage_assigned(false); - if (files.size() > 0) { - if (!noWarnings) { - if (task->getSASTreeID() == 0) { - QMessageBox::warning(this, tr("New task does not have SAS ID yet"), - tr("This appears to be a new task which does not have an observation ID (SAS ID) yet.\nThe shown locations and filenames will not contain the correct observation IDs")); - } - } - QList<QTreeWidgetItem *> dataProductTypeList; - QTreeWidgetItem *dataProductTypeItem, *fileItem; - std::map<dataProductTypes, TaskStorage::outputDataProduct>::const_iterator it = files.begin(); - unsigned nrFiles; - while (it != files.end()) { - itemValues.clear(); - nrFiles = it->second.filenames.size(); - if (nrFiles > 0) { - storage_assigned = true; - itemValues << QString(DATA_PRODUCTS[it->first]) + " data products"; - dataProductTypeItem = new QTreeWidgetItem((QTreeWidget*)0, itemValues); - dataProductTypeList.append(dataProductTypeItem); - for (unsigned idx = 0; idx < nrFiles; ++idx) { - itemValues.clear(); - itemValues << it->second.locations.at(idx) + it->second.filenames.at(idx); - fileItem = new QTreeWidgetItem(dataProductTypeItem, itemValues); - dataProductTypeList.append(fileItem); - } - } - ++it; - } - ui.treeWidgetOutputDataProducts->insertTopLevelItems(0, dataProductTypeList); - ui.treeWidgetOutputDataProducts->expandAll(); - } - if (!storage_assigned) { - if (task->isPipeline() && task->getConflicts().non_integer_nr_output_files) { // TODO: pragmatic, but not really pretty... - ui.treeWidgetOutputDataProducts->insertTopLevelItem(0,new QTreeWidgetItem(QStringList(TASK_CONFLICTS[CONFLICT_NON_INTEGER_OUTPUT_FILES]))); - } - else { - ui.treeWidgetOutputDataProducts->insertTopLevelItem(0,new QTreeWidgetItem(QStringList("No storage assigned yet"))); - } - } - ui.treeWidgetOutputDataProducts->resizeColumnToContents(0); - } -} - - -void TaskDialog::updateProjects(void) { - itsController->updateProjects(); -} - - -void TaskDialog::setExistingProjects(const campaignMap &projects) { - if (!projects.empty()) { - ui.comboBoxProjectID->blockSignals(true); - ui.comboBoxProjectID->clear(); - QStringList items; - int sidx(0); - bool found(false); - for (campaignMap::const_iterator cit = projects.begin(); cit != projects.end(); ++cit) { - items << cit->second.name.c_str(); - if (itsTask && !(found) && (cit->first == itsTask->getProjectID())) { - found = true; - } - else if (!found) ++sidx; - } - ui.comboBoxProjectID->addItems(items); - ui.comboBoxProjectID->setCurrentIndex(sidx); - ui.comboBoxProjectID->blockSignals(false); - } -} - -dataProductTypes TaskDialog::getSelectedStorageDataProduct(void) { - QString dpstr(ui.comboBoxStorageDataType->currentText()); - if (dpstr.compare(DATA_PRODUCTS[DP_CORRELATED_UV]) == 0) return DP_CORRELATED_UV; - else if (dpstr.compare(DATA_PRODUCTS[DP_COHERENT_STOKES]) == 0) return DP_COHERENT_STOKES; - else if (dpstr.compare(DATA_PRODUCTS[DP_INCOHERENT_STOKES]) == 0) return DP_INCOHERENT_STOKES; - else if (dpstr.compare(DATA_PRODUCTS[DP_INSTRUMENT_MODEL]) == 0) return DP_INSTRUMENT_MODEL; - else if (dpstr.compare(DATA_PRODUCTS[DP_PULSAR]) == 0) return DP_PULSAR; - else if (dpstr.compare(DATA_PRODUCTS[DP_SKY_IMAGE]) == 0) return DP_SKY_IMAGE; - else return DP_UNKNOWN_TYPE; -} - - -void TaskDialog::detectStorageLocationChanges(void) { - const TaskStorage *task_storage(itsTask->storage()); - if (task_storage) { - getDisplayedStorageLocations(); // get the current choices from the dialog and store in itsTmpStorage - if (itsTmpStorage != task_storage->getStorageLocations()) { - enableApplyButtons(true); - return; - } - if (!changeBeams && !changeExtraInfo && !changeProcessing && !changeSchedule && !changeStorage - && !changeStations && !changeEnabledInputFiles && !changePipeline) { // nothing has changed disable 'apply' buttons - enableApplyButtons(false); - } - } -} - -void TaskDialog::updateStorageTab(void) { - if (isMultiTasks) { - ui.treeWidgetOutputDataProducts->clear(); - ui.treeWidgetOutputDataProducts->insertTopLevelItem(0,new QTreeWidgetItem(QStringList(MULTIPLE_VALUE_TEXT))); - } - else if (itsTask->getStatus() <= Task::PRESCHEDULED) { - // copy the current dialog settings to a temporary task to be able to calculate storage properties according to latest changes - bool incomplete(false); - Task *tmpTask = cloneTask(itsTask); - tmpTask->setType(static_cast<Task::task_type>(ui.comboBoxProcessType->currentIndex())); - tmpTask->setDuration(ui.lineEditDuration->text()); - - if (tmpTask->isObservation()) { - Observation *tmpObs = static_cast<Observation *>(tmpTask); - tmpObs->setRTCPsettings(getRTCPSettings()); - tmpObs->setDigitalBeams(itsDigitalBeams); - if (ui.comboBoxStationAntennaMode->currentText().compare(antenna_modes_str[UNSPECIFIED_ANTENNA_MODE]) != 0) { - tmpObs->setAntennaMode(antenna_modes_str[ui.comboBoxStationAntennaMode->currentIndex()]); - } - else incomplete = true; - - if (ui.comboBoxStationClock->currentText().compare(clock_frequencies_str[UNSPECIFIED_CLOCK]) != 0) { - tmpObs->setStationClock(stringToStationClockType(ui.comboBoxStationClock->currentText().toStdString())); - } - else incomplete = true; - - const std::vector<std::string> &stations = getAssignedStationNames(); - if (!stations.empty()) { - tmpObs->setStations(stations); - } - else incomplete = true; - - } - - TaskStorage *task_storage(tmpTask->storage()); - if (task_storage) { - task_storage->setEnabledOutputDataProducts(itsOutputDataTypes); - tmpTask->calculateDataFiles(); - task_storage->generateFileList(); - generateFileList(tmpTask, true); - updateStorageTree(); - QPalette palet; - if (!task_storage->hasStorageLocations()) { - ui.lineEditStorageAssigned->setText("No storage set"); - ui.lineEditStorageAssigned->setPalette(palette()); - } - else if (!task_storage->checkStorageAssigned()) { - ui.lineEditStorageAssigned->setText("Storage not assigned"); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditStorageAssigned->setPalette(palet); - } - else { - ui.lineEditStorageAssigned->setText("Storage is assigned"); - palet.setColor( QPalette::Base, Qt::green ); - ui.lineEditStorageAssigned->setPalette(palet); - } - - unsigned minNrOfNodes(0); - itsMinNrOfRequiredNodes = task_storage->getMinimumNrOfStorageNodes(); - for (std::map<dataProductTypes, int>::const_iterator it = itsMinNrOfRequiredNodes.begin(); it != itsMinNrOfRequiredNodes.end(); ++it) { - if (it->second == -1) { // single file storage node network bandwidth exceeded for this data product - minNrOfNodes = 0; - itsStorageOverflow = true; - ui.lineEditStorageConflict->setText("Current settings exceed storage node network bandwidth. The task cannot be scheduled."); - ui.lineEditStorageConflict->setToolTip(QString("The individual files for the ") + DATA_PRODUCTS[it->first] + " output will exceed the bandwidth of a single storage node.\nThe data size for this data type needs to reduced."); - ui.lineEditStorageConflict->show(); - } - else { - minNrOfNodes = std::max(minNrOfNodes, (unsigned)it->second); - } - } - if ((!itsStorageOverflow) && (itsController->isDataMonitorConnected())) { // following checks only when there is a data monitor connection - size_t nrAvailableNodes = itsController->getNrOfStorageNodesAvailable(); - if (nrAvailableNodes > 0) { - if (minNrOfNodes > nrAvailableNodes) { - itsStorageOverflow = true; - ui.lineEditStorageConflict->setText("Too many storage nodes required. The task cannot be scheduled."); - ui.lineEditStorageConflict->setToolTip("The minimum number of storage nodes required to obtain the required network bandwidth exceeds the number of active storage nodes."); - ui.lineEditStorageConflict->show(); - } - else { - ui.lineEditStorageConflict->hide(); - } - } - else { - itsStorageOverflow = true; - ui.lineEditStorageConflict->setText("No storage nodes available. The task cannot be scheduled."); - ui.lineEditStorageConflict->setToolTip("There are no storage nodes available. The task cannot be scheduled"); - ui.lineEditStorageConflict->show(); - } - } - else { - ui.lineEditStorageConflict->hide(); - } - checkStorageSettingsEnable(); - - int totalSeconds = tmpTask->getDuration().totalSeconds(); - if (totalSeconds > 0 && !incomplete) { - - // set the newly calculated total data size in the appropriate lineEdit - long double kbps = task_storage->getTotalStoragekBytes() / totalSeconds * 8; - ui.lineEditTotalStorageSize->setText(humanReadableUnits((long double)task_storage->getTotalStoragekBytes(), SIZE_UNITS).c_str()); - ui.lineEditTotalBandwidth->setText(humanReadableUnits(kbps, BANDWIDTH_UNITS).c_str()); - ui.lineEditNrOfDataFiles->setText(QString::number(task_storage->getNrFiles())); - } - else { - ui.lineEditTotalStorageSize->setText("0.0 kB"); - ui.lineEditTotalBandwidth->setText("0.0 kbit/s"); - ui.lineEditNrOfDataFiles->setText("0"); - ui.lineEditStorageConflict->hide(); - } - - std::map<dataProductTypes, int>::const_iterator minNodesIt(itsMinNrOfRequiredNodes.find(getSelectedStorageDataProduct())); - if (minNodesIt != itsMinNrOfRequiredNodes.end()) { - ui.lineEditMinNrStorageNodes->setText(QString::number(minNodesIt->second)); - } - else { - ui.lineEditMinNrStorageNodes->setText("0"); - } - } - delete tmpTask; - } - else { // status >= SCHEDULED show the current task storage (no need to check all changes, because storage cannot be changed in the >= SCHEDULED states - itsTask->calculateDataFiles(); - TaskStorage *task_storage(itsTask->storage()); - if (task_storage) { - generateFileList(itsTask, true); - updateStorageTree(); - // set the calculated total data size in the appropriate lineEdit - long double kbps = task_storage->getTotalStoragekBytes() / itsTask->getDuration().totalSeconds() * 8; - ui.lineEditTotalStorageSize->setText(humanReadableUnits((long double)task_storage->getTotalStoragekBytes(), SIZE_UNITS).c_str()); - ui.lineEditTotalBandwidth->setText(humanReadableUnits(kbps, BANDWIDTH_UNITS).c_str()); - ui.lineEditNrOfDataFiles->setText(QString::number(task_storage->getNrFiles())); - // minimum number of storage nodes - itsMinNrOfRequiredNodes = task_storage->getMinimumNrOfStorageNodes(); - std::map<dataProductTypes, int>::const_iterator minNodesIt(itsMinNrOfRequiredNodes.find(getSelectedStorageDataProduct())); - if (minNodesIt != itsMinNrOfRequiredNodes.end()) { - ui.lineEditMinNrStorageNodes->setText(QString::number(minNodesIt->second)); - } - else { - ui.lineEditMinNrStorageNodes->setText("0"); - } - QPalette palet; - if (!task_storage->hasStorageLocations()) { - ui.lineEditStorageAssigned->setText("No storage set"); - ui.lineEditStorageAssigned->setPalette(palette()); - } - else if (!task_storage->checkStorageAssigned()) { - ui.lineEditStorageAssigned->setText("Storage not assigned"); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditStorageAssigned->setPalette(palet); - } - else { - ui.lineEditStorageAssigned->setText("Storage is assigned"); - palet.setColor( QPalette::Base, Qt::green ); - ui.lineEditStorageAssigned->setPalette(palet); - } - } - } -} - - -void TaskDialog::doTabChangeUpdate(int /*currentTab*/) { - if (ui.tabWidgetMain->currentWidget() == ui.tab_Storage) { // Storage tab - updateStorageTab(); - } -} - - -void TaskDialog::addSuperStation(void) { - ui.treeWidgetUsedStations->addSuperStationAndChilds(); - ui.labelAssignedStations->setText("Assigned stations (" + QString::number(countStations()) + ")"); -} - -void TaskDialog::addAvailableStations(const QStringList &stations) { - ui.listWidgetAvailableStations->addStations(stations); -} - -void TaskDialog::setCorrelatorIntegrationTime(void) { - double integrationTime = ui.lineEditCorrelatorIntegrationTime->text().toDouble(); - if (integrationTime < MINIMUM_CORRELATOR_INTEGRATION_TIME) { - QPalette palet = ( ui.lineEditCorrelatorIntegrationTime->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditCorrelatorIntegrationTime->setPalette(palet); - QMessageBox::warning(this, tr("Wrong integration time value"), - tr("The entered correlator integration time is too small\n The minimum value is ") + - QString::number(MINIMUM_CORRELATOR_INTEGRATION_TIME) + tr(" sec")); - QApplication::beep(); - } - else { - ui.lineEditCorrelatorIntegrationTime->setPalette(QPalette()); -// itsTask->setCorrelatorIntegrationTime(integrationTime); - } -} - -bool TaskDialog::checkEmail() { - QRegExp regExpEmail("[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}"); - regExpEmail.setCaseSensitivity(Qt::CaseInsensitive); - QRegExpValidator regExpValidator(regExpEmail, this); - QString strValue = ui.lineEdit_ContactEmail->text(); - int pos; - if ((regExpValidator.validate(strValue, pos) == QValidator::Acceptable) | (strValue == "")) { - return true; - } - else { - QMessageBox::warning(this, tr("Not a valid e-mail contact address"), - tr("The contact's e-mail address in not a valid.\nPlease enter a valid e-mail address")); - ui.tabWidgetMain->setCurrentWidget(ui.tab_ExtraInfo); - ui.lineEdit_ContactEmail->setFocus(); - ui.lineEdit_ContactEmail->selectAll(); - return false; - } -} - -void TaskDialog::enablePredecessorSettings(bool enable) { - ui.lineEditMinPredDistance->setEnabled(enable); - ui.lineEditMaxPredDistance->setEnabled(enable); - ui.labelMinPredDistance->setEnabled(enable); - ui.labelMaxPredDistance->setEnabled(enable); -} - -void TaskDialog::loadAvailableStations(void) { - ui.listWidgetAvailableStations->clear(); - stationDefinitionsMap stations = Controller::theSchedulerSettings.getStationList(); - for (stationDefinitionsMap::const_iterator it = stations.begin(); it != stations.end(); ++it) { - ui.listWidgetAvailableStations->addItem(it->first.c_str()); - } - itsStationsLoaded = true; -} - -void TaskDialog::updateDuration(void) { // called when user fiddles with the scheduled end time box - if ((!ui.dateTimeEditScheduledStart->isUndefined()) & (!ui.lineEditDuration->isUndefined())) { - AstroTime duration = AstroDateTime(ui.dateTimeEditScheduledEnd->dateTime() - ui.dateTimeEditScheduledStart->dateTime()); - ui.lineEditDuration->blockSignals(true); - ui.lineEditDuration->setText(duration.toString()); - ui.lineEditDuration->blockSignals(false); - detectChanges(); - } -} - -void TaskDialog::updateScheduledEnd(void) { // called when user changes duration or scheduled start time box - if (ui.lineEditDuration->isUndefined()) { // if duration edit is not set - ui.dateTimeEditScheduledEnd->setUndefined(); // set end time back on undefined when duration is undefined (=MULTIPLE values) - } - else if (!ui.dateTimeEditScheduledStart->isUndefined()) { - AstroDateTime end = AstroDateTime(ui.dateTimeEditScheduledStart->dateTime()) + AstroTime(ui.lineEditDuration->text()); - setScheduledEnd(QDateTime(QDate(end.getYear(), end.getMonth(), end.getDay()), QTime(end.getHours(), end.getMinutes(), end.getSeconds()))); - } - detectChanges(); -} - -void TaskDialog::setScheduledStart(const QDateTime &start) { - ui.dateTimeEditScheduledStart->blockSignals(true); // prevents automatic update - ui.dateTimeEditScheduledStart->setDateTime(start); - ui.dateTimeEditScheduledStart->blockSignals(false); -} - - -void TaskDialog::setScheduledEnd(const QDateTime &end) { - ui.dateTimeEditScheduledEnd->blockSignals(true); // prevents automatic update - ui.dateTimeEditScheduledEnd->setDateTime(end); - ui.dateTimeEditScheduledEnd->blockSignals(false); -} - - -void TaskDialog::detectChanges(void) { - if (!blockChangeDetection) { - - QString tabName = ui.tabWidgetMain->tabText(ui.tabWidgetMain->currentIndex()); - - if(tabName.contains(tab_names[TAB_SCHEDULE])) { // Schedule tab - changeSchedule = false; - if (ui.lineEditPredecessors->hasBeenChanged()) changeSchedule = true; - else if (ui.lineEditGroupID->hasBeenChanged()) changeSchedule = true; - else if (ui.lineEditMaxPredDistance->hasBeenChanged()) changeSchedule = true; - else if (ui.lineEditMinPredDistance->hasBeenChanged()) changeSchedule = true; - else if (ui.lineEditPriority->hasBeenChanged()) changeSchedule = true; - else if (ui.checkBoxFixedDate->hasBeenChanged()) changeSchedule = true; - else if (ui.checkBoxFixedTime->hasBeenChanged()) changeSchedule = true; - else if (ui.timeEditFirstPossibleTime->hasBeenChanged()) changeSchedule = true; - else if (ui.timeEditLastPossibleTime->hasBeenChanged()) changeSchedule = true; - else if (ui.dateEditFirstPossibleDate->hasBeenChanged()) changeSchedule = true; - else if (ui.dateEditLastPossibleDate->hasBeenChanged()) changeSchedule = true; - else if (ui.lineEditTaskName->hasBeenChanged()) changeSchedule = true; - else if (ui.comboBoxProjectID->hasBeenChanged()) changeSchedule = true; - else if (ui.lineEditDuration->hasBeenChanged()) changeSchedule = true; - else if (ui.dateTimeEditScheduledStart->hasBeenChanged()) changeSchedule = true; - else if (ui.dateTimeEditScheduledEnd->hasBeenChanged()) changeSchedule = true; - else if (ui.comboBoxTaskStatus->hasBeenChanged()) changeSchedule = true; - else if (ui.comboBoxProcessType->hasBeenChanged()) changeSchedule = true; - else if (ui.comboBoxProcessSubType->hasBeenChanged()) changeSchedule = true; - else if (ui.comboBoxStrategies->hasBeenChanged()) changeSchedule = true; - setTabModified(TAB_SCHEDULE, changeSchedule); - } - - if (tabName.contains(tab_names[TAB_STATION_SETTINGS])) { // Station settings tab - changeStations = false; - if (ui.checkBoxTBBPiggybackAllowed->hasBeenChanged()) changeStations = true; - else if (ui.checkBoxAartfaacPiggybackAllowed->hasBeenChanged()) changeStations = true; - setTabModified(TAB_STATION_SETTINGS, changeStations); - } - - else if (tabName.contains(tab_names[TAB_STATION_BEAMS])) { // beams tab - changeBeams = false; - if (ui.lineEditAnalogBeamAngle1->hasBeenChanged()) changeBeams = true; - else if (ui.lineEditAnalogBeamAngle2->hasBeenChanged()) changeBeams = true; - else if (ui.timeEditAnalogBeamStartTime->hasBeenChanged()) changeBeams = true; - else if (ui.lineEditAnalogBeamDuration->hasBeenChanged()) changeBeams = true; - else if (itsTempAnalogBeamSettings.directionType != itsAnalogBeamSettings.directionType) changeBeams = true; - else if (itsTempAnalogBeamSettings.startTime != itsAnalogBeamSettings.startTime) changeBeams = true; - else if (itsTempAnalogBeamSettings.duration != itsAnalogBeamSettings.duration) changeBeams = true; - // digital beams (including tied array beam) differences - else if (itsTempDigitalBeams != itsDigitalBeams) changeBeams = true; - setTabModified(TAB_STATION_BEAMS, changeBeams); - } - - else if (tabName.contains(tab_names[TAB_PROCESSING])) { // processing - changeProcessing = false; - if (ui.checkBoxCorrelatedData->hasBeenChanged()) changeProcessing = true; - else if (ui.checkBoxCoherentStokes->hasBeenChanged()) changeProcessing = true; - else if (ui.checkBoxIncoherentStokes->hasBeenChanged()) changeProcessing = true; - else if (ui.checkBox_BandpassCorrection->hasBeenChanged()) changeProcessing = true; - else if (ui.checkBox_CoherentDedispersion->hasBeenChanged()) changeProcessing = true; - else if (ui.checkBox_DelayCompensation->hasBeenChanged()) changeProcessing = true; - else if (ui.checkBoxPencilFlysEye->hasBeenChanged()) changeProcessing = true; - else if (ui.comboBoxBitsPerSample->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxChannelsPerSubband->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxCoherentTimeIntegration->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxIncoherentTimeIntegration->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxCoherentChannelsPerSubband->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxIncoherentChannelsPerSubband->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxCoherentSubbandsPerFile->hasBeenChanged()) changeProcessing = true; - else if (ui.spinBoxIncoherentSubbandsPerFile->hasBeenChanged()) changeProcessing = true; - else if (ui.comboBoxCoherentStokesType->hasBeenChanged()) changeProcessing = true; - else if (ui.comboBoxIncoherentStokesType->hasBeenChanged()) changeProcessing = true; - else if (ui.lineEditCorrelatorIntegrationTime->hasBeenChanged()) changeProcessing = true; - setTabModified(TAB_PROCESSING, changeProcessing); - } - - else if (tabName.contains(tab_names[TAB_STORAGE])) { // storage - changeStorage = false; - if (ui.comboBoxStorageSelectionMode->hasBeenChanged()) changeStorage = true; - setTabModified(TAB_STORAGE, changeStorage); - } - - else if (tabName.contains(tab_names[TAB_PIPELINE])) { - changePipeline = false; - if (ui.listWidgetDemixAlways->hasBeenChanged()) changePipeline = true; - else if (ui.listWidgetDemixIfNeeded->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxDemixFreqStep->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxDemixTimeStep->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxAveragingFreqStep->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxAveragingTimeStep->hasBeenChanged()) changePipeline = true; - else if (ui.lineEditDemixSkyModel->hasBeenChanged()) changePipeline = true; - else if (ui.lineEditCalibrationSkyModel->hasBeenChanged()) changePipeline = true; - - if (!changePipeline && ui.groupBoxImaging->isEnabled()) { - if (ui.checkBoxSpecifyFOV->hasBeenChanged()) changeProcessing = true; - else if (ui.lineEditFieldOfView->hasBeenChanged()) changePipeline = true; - else if (ui.lineEditCellSize->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxSlicesPerImage->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxSubbandsPerImage->hasBeenChanged()) changePipeline = true; - else if (ui.spinBoxNumberOfPixels->hasBeenChanged()) changePipeline = true; - } - setTabModified(TAB_PIPELINE, changePipeline); - } - - else if (tabName.contains(tab_names[TAB_PULSAR_PIPELINE])) { - changePulsar = false; - if (ui.lineEditPulsarName->hasBeenChanged()) changePulsar = true; - else if (ui.lineEditDSPSRextraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.lineEditPrepdataExtraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.lineEdit2bf2fitsExtraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.lineEditRfiFindExtraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.lineEditPrepfoldExtraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.lineEditPrepsubbandExtraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.lineEditDigifilExtraOptions->hasBeenChanged()) changePulsar = true; - else if (ui.spinBoxTsubint->hasBeenChanged()) changePulsar = true; - else if (ui.spinBoxDecodeSigma->hasBeenChanged()) changePulsar = true; - else if (ui.spinBoxDecodeNblocks->hasBeenChanged()) changePulsar = true; - else if (ui.doubleSpinBox8BitConversionSigma->hasBeenChanged()) changePulsar = true; - else if (ui.doubleSpinBoxDynamicSpectrumTimeAverage->hasBeenChanged()) changePulsar = true; - else if (ui.doubleSpinBoxRratsDmRange->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_NoRFI->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_No_DSPSR->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_No_fold->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_No_pdmp->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_RawTo8Bit->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_rrats->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_Single_pulse->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_Skip_dynamic_spectrum->hasBeenChanged()) changePulsar = true; - else if (ui.checkBox_Skip_prepfold->hasBeenChanged()) changePulsar = true; - setTabModified(TAB_PULSAR_PIPELINE, changePulsar); - } - - else if (tabName.contains(tab_names[TAB_LONGBASELINE_PIPELINE])) { - changeLongBaseline = false; - if (ui.spinBoxSubbandGroupsPerMS->hasBeenChanged()) changeLongBaseline = true; - else if (ui.spinBoxSubbandsPerSubbandGroup->hasBeenChanged()) changeLongBaseline = true; - setTabModified(TAB_LONGBASELINE_PIPELINE, changeLongBaseline); - } - - else if (tabName.contains(tab_names[TAB_EXTRA_INFO])) { // Extra info tab - changeExtraInfo = false; - if (ui.lineEdit_ContactName->text().compare(itsTask->getContactName())) changeExtraInfo = true; - else if (ui.lineEdit_ContactPhone->text().compare(itsTask->getContactPhone())) changeExtraInfo = true; - else if (ui.lineEdit_ContactEmail->text().compare(itsTask->getContactEmail())) changeExtraInfo = true; - else if (ui.lineEditTaskDescription->text().compare(itsTask->SASTree().description().c_str())) changeExtraInfo = true; - setTabModified(TAB_EXTRA_INFO, changeExtraInfo); - } - - enableApplyButtons(ifSettingsChanged()); - } -} - -void TaskDialog::setAllTabsUnmodified(void) { - for (int i = 0; i < NR_TABS; ++i) { - ui.tabWidgetMain->setTabText(i, ui.tabWidgetMain->tabText(i).remove('*')); - } -} - -void TaskDialog::setTabModified(tabIndex tabIdx, bool modified) { - for (int i = 0; i < NR_TABS; ++i) { - - if (!ui.tabWidgetMain->tabText(i).contains(tab_names[tabIdx])) - continue; - - // found the right tab: - if (modified) { - ui.tabWidgetMain->setTabText(i, QString("*") + tab_names[tabIdx]); - } - else { - ui.tabWidgetMain->setTabText(i, ui.tabWidgetMain->tabText(i).remove('*')); - } - break; - - } -} - -void TaskDialog::checkEnableDataTypeSettings(void) { - bool coherentEnabled(ui.checkBoxCoherentStokes->isChecked()); - ui.comboBoxCoherentStokesType->setEnabled(coherentEnabled); - ui.label_Coherent->setEnabled(coherentEnabled); - if (ui.comboBoxCoherentStokesType->currentIndex() != DATA_TYPE_XXYY) { - ui.spinBoxCoherentTimeIntegration->setEnabled(coherentEnabled); - ui.spinBoxCoherentSubbandsPerFile->setEnabled(coherentEnabled); - ui.spinBoxCoherentChannelsPerSubband->setEnabled(coherentEnabled); - } - else { // Complex Voltages (XXYY) - ui.spinBoxCoherentTimeIntegration->setValue(1); - ui.spinBoxCoherentSubbandsPerFile->setEnabled(coherentEnabled); - ui.spinBoxCoherentChannelsPerSubband->setEnabled(coherentEnabled); - ui.spinBoxCoherentTimeIntegration->setEnabled(coherentEnabled); - } - bool incoherentEnabled(ui.checkBoxIncoherentStokes->isChecked()); - ui.label_Incoherent->setEnabled(incoherentEnabled); - ui.spinBoxIncoherentTimeIntegration->setEnabled(incoherentEnabled); - ui.spinBoxIncoherentSubbandsPerFile->setEnabled(incoherentEnabled); - ui.comboBoxIncoherentStokesType->setEnabled(incoherentEnabled); - ui.spinBoxIncoherentChannelsPerSubband->setEnabled(incoherentEnabled); - ui.checkBoxPencilFlysEye->setEnabled(coherentEnabled); - ui.label_StokesType->setEnabled(coherentEnabled || incoherentEnabled); - ui.checkBox_CoherentDedispersion->setEnabled(coherentEnabled || incoherentEnabled); - ui.label_StokesChannelsPerSubband->setEnabled(coherentEnabled || incoherentEnabled); - ui.label_StokesSubbandsPerFile->setEnabled(coherentEnabled || incoherentEnabled); - ui.label_StokesTimeIntegration->setEnabled(coherentEnabled || incoherentEnabled); -} - -void TaskDialog::outputDataTypesChanged() { - itsOutputDataTypes.correlated = ui.checkBoxCorrelatedData->isChecked(); - itsOutputDataTypes.coherentStokes = ui.checkBoxCoherentStokes->isChecked(); - itsOutputDataTypes.incoherentStokes = ui.checkBoxIncoherentStokes->isChecked(); - - if (ui.checkBoxCorrelatedData->isChecked()) { - ui.label_CorrelatorIntTime->setEnabled(true); - ui.lineEditCorrelatorIntegrationTime->setEnabled(true); - ui.labelChannelsPerSubband->setEnabled(true); - ui.spinBoxChannelsPerSubband->setEnabled(true); - } - else { - ui.label_CorrelatorIntTime->setEnabled(false); - ui.lineEditCorrelatorIntegrationTime->setEnabled(false); - ui.labelChannelsPerSubband->setEnabled(false); - ui.spinBoxChannelsPerSubband->setEnabled(false); - } - - checkEnableDataTypeSettings(); - - // check if pencil buttons (add/edit/delete) should be enabled - checkEnableBeamButtons(); - - setStorageSettings(); - - checkStorageSettingsEnable(); - detectChanges(); -} - -// update the comboBoxStorageDataType for selecting the displayed storage tree -// and checks if the storage tree itself needs to be updated as well. -void TaskDialog::setStorageSettings(bool forceUpdate) { - // add choices to comboBoxStorageDataTypes - QString curDataProduct = ui.comboBoxStorageDataType->currentText(); - ui.comboBoxStorageDataType->blockSignals(true); - ui.comboBoxStorageDataType->clear(); - QStringList items; - if (itsOutputDataTypes.correlated) items << DATA_PRODUCTS[DP_CORRELATED_UV]; - if (itsOutputDataTypes.coherentStokes) items << DATA_PRODUCTS[DP_COHERENT_STOKES]; - if (itsOutputDataTypes.incoherentStokes) items << DATA_PRODUCTS[DP_INCOHERENT_STOKES]; - if (itsOutputDataTypes.instrumentModel) items << DATA_PRODUCTS[DP_INSTRUMENT_MODEL]; - if (itsOutputDataTypes.pulsar) items << DATA_PRODUCTS[DP_PULSAR]; - if (itsOutputDataTypes.skyImage) items << DATA_PRODUCTS[DP_SKY_IMAGE]; - - ui.comboBoxStorageDataType->addItems(items); - // check if the currently displayed storage tree needs to be updated. - // only update if the current storage tree is displaying the storage settings for a data product that has now been disabled - bool update_storage_tree(true); - if (!forceUpdate) { - for (short i = 0; i < ui.comboBoxStorageDataType->count(); ++i) { - if (ui.comboBoxStorageDataType->itemText(i).compare(curDataProduct) == 0) { - ui.comboBoxStorageDataType->setCurrentIndex(i); - update_storage_tree = false; - break; - } - } - } - ui.comboBoxStorageDataType->blockSignals(false); - if (forceUpdate || update_storage_tree) { - updateStorageTree(); - } -} - -// checks if data products have been switched off by the user and removes them from itsTmpStorage if needed -void TaskDialog::checkForRemovalOfDataProducts(const TaskStorage::enableDataProdukts &edp) { - if (!edp.correlated) { - itsTmpStorage.erase(DP_CORRELATED_UV); - } - if (!edp.coherentStokes) { - itsTmpStorage.erase(DP_COHERENT_STOKES); - } - if (!edp.incoherentStokes) { - itsTmpStorage.erase(DP_INCOHERENT_STOKES); - } - if (!edp.instrumentModel) { - itsTmpStorage.erase(DP_INSTRUMENT_MODEL); - } - if (!edp.pulsar) { - itsTmpStorage.erase(DP_PULSAR); - } - if (!edp.skyImage) { - itsTmpStorage.erase(DP_SKY_IMAGE); - } -} - - -// enable/disable beam & pencilbeam add/delete/edit buttons according to current dialog settings -void TaskDialog::checkEnableBeamButtons(void) { - bool enableBeamDelAdd = false; - if (addingTask || ((itsTask->getSASTreeID() == 0) && itsTask->getStatus() <= Task::PRESCHEDULED)) enableBeamDelAdd = true; - ui.pushButtonAddBeam->setEnabled(enableBeamDelAdd); - const Task::task_status &status = itsTask->getStatus(); // get the current status from the dialog - if (!itsDigitalBeams.empty()) { // if beams are defined - ui.pushButtonEditBeam->setEnabled(true); // edit is also show button and should be enabled - if (status >= Task::SCHEDULED) { - itsDigitalBeamDialog->setReadOnly(true); - ui.pushButtonEditBeam->setText("Show"); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - } - else { - itsDigitalBeamDialog->setReadOnly(false); - ui.pushButtonEditBeam->setText("Edit"); - ui.pushButtonDeleteBeams->setEnabled(enableBeamDelAdd); // depends on VIC tree or template tree - ui.pushButtonClearAllBeams->setEnabled(enableBeamDelAdd); - } - } - else { // if no beams have been defined yet - if (status >= Task::SCHEDULED) { - itsDigitalBeamDialog->setReadOnly(true); - ui.pushButtonEditBeam->setText("Show"); - } - else { - itsDigitalBeamDialog->setReadOnly(false); - ui.pushButtonEditBeam->setText("Edit"); - } - ui.pushButtonEditBeam->setEnabled(false); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - } - - if (itsDigitalBeams.empty()) { - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - } - else { - int digiBeamNr(ui.tableWidgetDigitalBeams->currentRow()); - if (digiBeamNr >= 0) { - bool TABsLeft(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()].nrManualTABs() > 0); - // enable/disable tied array add and delete buttons - if (enableBeamDelAdd) { - ui.pushButtonAddTiedArrayBeam->setEnabled(true); - if (TABsLeft) { - ui.pushButtonClearAllTiedArrayBeam->setEnabled(true); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(true); - } - else { // no TABs left - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - } - } - else { - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); // depends on VIC tree or template tree - } - // edit tied array beams? - if ((status >= Task::SCHEDULED) || !TABsLeft) { - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - itsTiedArrayBeamDialog->setReadOnly(true); - } - else { - ui.pushButtonEditTiedArrayBeam->setEnabled(true); // show or edit button - itsTiedArrayBeamDialog->setReadOnly(false); - } - } - } -} - -void TaskDialog::checkStorageSettingsEnable(void) { - Task::task_status status = itsTask->getStatus(); - if (ui.comboBoxStorageDataType->count() == 0) { - ui.treeWidgetStorageNodes->setToolTip("No output data type (tab processing) is selected.\nNo data will be generated. Cannot set storage"); - } - else if (status != Task::PRESCHEDULED) { // only enable storage settings if task has PRESCHEDULED status - ui.treeWidgetStorageNodes->setToolTip("This task is not in PRESCHEDULED state. It is not possible to change it's storage resources"); - } - else if (!itsStorageOverflow) { - if (isMultiTasks) { - ui.treeWidgetStorageNodes->setToolTip("These storage nodes will be assigned to all multi-edited tasks"); - } - else { - ui.treeWidgetStorageNodes->setToolTip("The storage nodes and raid sets used by this task"); - } - } -} - -void TaskDialog::applyStationsRemoved(void) { - enableApplyButtons(true); - ui.labelAssignedStations->setText("Assigned stations (" + QString::number(countStations() - ui.treeWidgetUsedStations->getNrStationsRemoved()) + ")"); - -} - -void TaskDialog::addStationsToUsedStations(const QStringList &stations) { - if (!stations.empty()) { - ui.treeWidgetUsedStations->addStations(stations); - checkIfStationChanged(); - } -} - -void TaskDialog::checkIfStationChanged() { - // for now we just set as if it changed, check is to difficult to implement - enableApplyButtons(true); - ui.labelAssignedStations->setText("Assigned stations (" + QString::number(countStations()) + ")"); -} - - -void TaskDialog::ApplyFirstPossibleDateChange(void) { - QDate fpd = ui.dateEditFirstPossibleDate->date(); - ui.dateTimeEditScheduledStart->setMinimumDate(fpd); -} - -void TaskDialog::ApplyFirstPossibleTimeChange(void) { - QTime fpt = ui.timeEditFirstPossibleTime->time(); - ui.dateTimeEditScheduledStart->setMinimumTime(fpt); -} - -void TaskDialog::ApplyLastPossibleTimeChange(void) { - QTime lpt = ui.timeEditLastPossibleTime->time(); - ui.dateTimeEditScheduledEnd->setMaximumTime(lpt); -} - -void TaskDialog::cancelClicked(void) { - addingTask = false; - addingReservation = false; - blockChangeDetection = false; - isMultiTasks = false; - clearMultiTasks(); - ui.tabWidgetMain->setCurrentIndex(0); - hide(); -} - -void TaskDialog::applyClicked(void) { - apply(false); -} - -void TaskDialog::okClicked(void) { - apply(true); -} - -void TaskDialog::apply(bool close) { - blockChangeDetection = false; - bool notCommitted(false); - if (isMultiTasks) { - if (!commitMultiTasks()) { - raise(); - notCommitted = true; - close = false; - } - } - else if (itsTask->isReservation() || itsTask->isMaintenance()) { - if (!commitReservation(!close)) { - raise(); - notCommitted = true; - close = false; - } - } - else if (itsTask->isPipeline()) { - if (!commitPipeline()) { - raise(); - notCommitted = true; - close = false; - } - } - else if (!commitChanges(!close)) { - raise(); - notCommitted = true; - close = false; - } - if (close) { - // SW-933 - clearMultiTasks(); - this->close(); - } - else { - if (ui.tabWidgetMain->currentWidget() == ui.tab_Storage) { - updateStorageTab(); - } - ui.pushButtonCancelClose->setFocus(); // change focus away from apply button to cancel button - - if (!notCommitted) { - resetChangeDetection(); - setAllTabsUnmodified(); - } - } -} - -void TaskDialog::resetChangeDetection(void) { - changeSchedule = false; - changeStations = false; - changeBeams = false; - changeExtraInfo = false; - changeStorage = false; - changePipeline = false; - changePulsar = false; - changeLongBaseline = false; - changeProcessing = false; - changeEnabledInputFiles = false; - ui.lineEditTaskName->resetChangeDetect(); - ui.lineEditMinPredDistance->resetChangeDetect(); - ui.lineEditMaxPredDistance->resetChangeDetect(); - ui.lineEditAnalogBeamDuration->resetChangeDetect(); - ui.lineEditGroupID->resetChangeDetect(); - ui.lineEditCorrelatorIntegrationTime->resetChangeDetect(); - ui.lineEditPredecessors->resetChangeDetect(); - ui.lineEditAnalogBeamAngle1->resetChangeDetect(); - ui.lineEditAnalogBeamAngle2->resetChangeDetect(); - ui.dateEditFirstPossibleDate->resetChangeDetect(); - ui.dateEditLastPossibleDate->resetChangeDetect(); - ui.timeEditFirstPossibleTime->resetChangeDetect(); - ui.timeEditLastPossibleTime->resetChangeDetect(); - ui.dateTimeEditScheduledStart->resetChangeDetect(); - ui.dateTimeEditScheduledEnd->resetChangeDetect(); - ui.lineEditDuration->resetChangeDetect(); - ui.lineEditPriority->resetChangeDetect(); - ui.comboBoxTaskStatus->resetChangeDetect(); - ui.comboBoxProjectID->resetChangeDetect(); - ui.comboBoxProcessType->resetChangeDetect(); - ui.comboBoxProcessSubType->resetChangeDetect(); - ui.comboBoxStrategies->resetChangeDetect(); - ui.comboBoxStationAntennaMode->resetChangeDetect(); - ui.comboBoxStationFilter->resetChangeDetect(); - ui.comboBoxReservation->resetChangeDetect(); - ui.comboBoxStationClock->resetChangeDetect(); - ui.comboBoxBitsPerSample->resetChangeDetect(); - ui.spinBoxChannelsPerSubband->resetChangeDetect(); - ui.comboBoxStorageSelectionMode->resetChangeDetect(); - ui.comboBoxAnalogBeamCoordinates->resetChangeDetect(); - ui.comboBoxAnalogBeamUnits->resetChangeDetect(); - ui.comboBoxCoherentStokesType->resetChangeDetect(); - ui.spinBoxCoherentTimeIntegration->resetChangeDetect(); - ui.spinBoxCoherentChannelsPerSubband->resetChangeDetect(); - ui.spinBoxCoherentSubbandsPerFile->resetChangeDetect(); - ui.comboBoxIncoherentStokesType->resetChangeDetect(); - ui.spinBoxIncoherentTimeIntegration->resetChangeDetect(); - ui.spinBoxIncoherentChannelsPerSubband->resetChangeDetect(); - ui.spinBoxIncoherentSubbandsPerFile->resetChangeDetect(); - ui.listWidgetDemixAlways->resetChangeDetect(); - ui.listWidgetDemixIfNeeded->resetChangeDetect(); - ui.spinBoxDemixFreqStep->resetChangeDetect(); - ui.spinBoxDemixTimeStep->resetChangeDetect(); - ui.spinBoxAveragingFreqStep->resetChangeDetect(); - ui.spinBoxAveragingTimeStep->resetChangeDetect(); - ui.lineEditDemixSkyModel->resetChangeDetect(); - ui.lineEditFieldOfView->resetChangeDetect(); - ui.lineEditCellSize->resetChangeDetect(); - ui.spinBoxSlicesPerImage->resetChangeDetect(); - ui.spinBoxSubbandsPerImage->resetChangeDetect(); - ui.spinBoxSubbandGroupsPerMS->resetChangeDetect(); - ui.spinBoxSubbandsPerSubbandGroup->resetChangeDetect(); - ui.spinBoxNumberOfPixels->resetChangeDetect(); - ui.lineEditCalibrationSkyModel->resetChangeDetect(); - ui.checkBoxCorrelatedData->resetChangeDetect(); - ui.checkBoxCoherentStokes->resetChangeDetect(); - ui.checkBoxIncoherentStokes->resetChangeDetect(); - ui.checkBox_BandpassCorrection->resetChangeDetect(); - ui.checkBox_CoherentDedispersion->resetChangeDetect(); - ui.checkBox_DelayCompensation->resetChangeDetect(); - ui.checkBoxPencilFlysEye->resetChangeDetect(); - ui.checkBoxCoherentStokes->resetChangeDetect(); - -} - -std::vector<std::string> TaskDialog::getAssignedStationNames(void) const { - std::vector<std::string> stations; - std::string stationName; - QTreeWidgetItemIterator it(ui.treeWidgetUsedStations, QTreeWidgetItemIterator::NoChildren); - while (*it) { - stationName = (*it++)->text(0).toStdString(); - stations.push_back(stationName); - } - return stations; -} - -unsigned TaskDialog::countStations(void) const { - unsigned nrOfStations(0), superStationNrChilds(0); - QTreeWidgetItemIterator it(ui.treeWidgetUsedStations, QTreeWidgetItemIterator::All); - QString stationName; - while (*it) { - stationName = (*it)->text(0); - if (!stationName.startsWith(">") && !stationName.startsWith("MIXED")) { - ++nrOfStations; - } - else { - unsigned nrChilds = (*it)->childCount(); - if (nrChilds) { - ++nrOfStations; - superStationNrChilds += nrChilds; - } - } - ++it; - } - nrOfStations -= superStationNrChilds; - return nrOfStations; -} - -std::map<int, QStringList> TaskDialog::getSuperStationChildNames(void) const { - std::map<int, QStringList> superStations; - QTreeWidgetItemIterator ssit(ui.treeWidgetUsedStations, QTreeWidgetItemIterator::HasChildren); - QStringList childNames; - int ssidx(0); - while (*ssit) { - ++ssidx; - childNames.clear(); - for (int cc = 0; cc < (*ssit)->childCount(); ++cc) { - childNames.append((*ssit)->child(cc)->text(0)); - } - superStations.insert(std::map<int, QStringList>::value_type(ssidx, childNames)); - ++ssit; // next super station - } - return superStations; -} - -Observation::RTCPsettings TaskDialog::getRTCPSettings(void) { - Observation::RTCPsettings RTCPsettings; - RTCPsettings.correctBandPass = ui.checkBox_BandpassCorrection->isChecked(); - RTCPsettings.delayCompensation = ui.checkBox_DelayCompensation->isChecked(); - RTCPsettings.flysEye = ui.checkBoxPencilFlysEye->isChecked(); - RTCPsettings.correlatorIntegrationTime = ui.lineEditCorrelatorIntegrationTime->text().toDouble(); - RTCPsettings.nrBitsPerSample = ui.comboBoxBitsPerSample->currentText().toUInt(); - RTCPsettings.coherentDedisperseChannels = ui.checkBox_CoherentDedispersion->isChecked(); - RTCPsettings.coherentType = stringToStokesType(ui.comboBoxCoherentStokesType->currentText().toStdString()); - RTCPsettings.incoherentType = stringToStokesType(ui.comboBoxIncoherentStokesType->currentText().toStdString()); - RTCPsettings.coherentTimeIntegrationFactor = ui.spinBoxCoherentTimeIntegration->value(); - RTCPsettings.incoherentTimeIntegrationFactor = ui.spinBoxIncoherentTimeIntegration->value(); - RTCPsettings.channelsPerSubband = ui.spinBoxChannelsPerSubband->value(); - RTCPsettings.coherentSubbandsPerFile = ui.spinBoxCoherentSubbandsPerFile->value(); - RTCPsettings.incoherentSubbandsPerFile = ui.spinBoxIncoherentSubbandsPerFile->value(); - RTCPsettings.coherentChannelsPerSubband = ui.spinBoxCoherentChannelsPerSubband->value(); - RTCPsettings.incoherentChannelsPerSubband = ui.spinBoxIncoherentChannelsPerSubband->value(); - return RTCPsettings; -} - -superStationMap TaskDialog::getSuperStations(const Observation *task) const { - superStationMap superstations; - const taskStationsMap &stationMapping = task->getStations(); - taskStationsMap::const_iterator tsit; - int i(0); - std::vector<unsigned> childStations; - QTreeWidgetItemIterator ssit(ui.treeWidgetUsedStations, QTreeWidgetItemIterator::HasChildren); - std::string beamFormerName; - QTreeWidgetItem *childItem; - while (*ssit) { - childStations.clear(); - for (int cc = 0; cc < (*ssit)->childCount(); ++cc) { - childItem = (*ssit)->child(cc); - tsit = stationMapping.find(childItem->text(0).toStdString()); - if (tsit != stationMapping.end()) { - childStations.push_back(tsit->second); // push back the station id of this child - } - } - beamFormerName = "Beamformer[" + int2String(i++) + "]"; - superstations.insert(superStationMap::value_type(beamFormerName, childStations)); - ++ssit; // next super station - } - return superstations; -} - -void TaskDialog::applyProjectChange(const QString &project_id) { - const campaignInfo &campaign = Controller::theSchedulerSettings.getCampaignInfo(project_id.toStdString()); - if (!campaign.name.empty()) { - ui.lineEdit_ProjectName->setText(campaign.title.c_str()); - ui.lineEdit_ProjectPI->setText(campaign.PriInvestigator.c_str()); - ui.lineEdit_ProjectCOI->setText(campaign.CoInvestigator.c_str()); - ui.lineEdit_ContactName->setText(campaign.contact.c_str()); - } - else { - ui.lineEdit_ProjectName->clear(); - ui.lineEdit_ProjectPI->clear(); - ui.lineEdit_ProjectCOI->clear(); - ui.lineEdit_ContactName->clear(); - } - detectChanges(); -} - -bool TaskDialog::commitPipeline(void) { - Pipeline *pipeline(static_cast<Pipeline *>(itsTask)); - QString strValue = ui.lineEditTaskName->text(); - pipeline->setTaskName(strValue.toStdString()); - pipeline->setProjectName(ui.lineEdit_ProjectName->text().toStdString()); - pipeline->setProjectCO_I(ui.lineEdit_ProjectCOI->text().toStdString()); - pipeline->setProjectID(ui.comboBoxProjectID->currentText().toStdString()); - pipeline->setProjectPI(ui.lineEdit_ProjectPI->text().toStdString()); - - pipeline->setType(ui.comboBoxProcessType->currentText(), - stringToProcessSubType(ui.comboBoxProcessSubType->currentText()), - ui.comboBoxStrategies->currentText()); - pipeline->setOriginalTreeID(ui.lineEditOriginalTreeID->text().toInt()); - - Task::task_status state = taskStatusFromString(ui.comboBoxTaskStatus->currentText().toStdString()); - pipeline->setStatus(state); - - pipeline->setContactEmail(ui.lineEdit_ContactEmail->text().toStdString()); - pipeline->setContactName(ui.lineEdit_ContactName->text().toStdString()); - pipeline->setContactPhone(ui.lineEdit_ContactPhone->text().toStdString()); - pipeline->setTaskDescription(ui.lineEditTaskDescription->text().toStdString()); - - ImagingPipeline *impipe(0); - PulsarPipeline *pulsepipe(0); - LongBaselinePipeline *lbpipe(0); - CalibrationPipeline *calpipe = dynamic_cast<CalibrationPipeline *>(itsTask); - if (calpipe) { - calpipe->setSkyModel(ui.lineEditCalibrationSkyModel->text()); - if (ui.groupBoxDemixing->isEnabled()) { - DemixingSettings demix_settings; - demix_settings.itsDemixingEnabled = true; - demix_settings.itsDemixAlways = ui.listWidgetDemixAlways->checkedItemsAsString(); - demix_settings.itsDemixIfNeeded = ui.listWidgetDemixIfNeeded->checkedItemsAsString(); - demix_settings.itsDemixFreqStep = ui.spinBoxDemixFreqStep->value(); - demix_settings.itsDemixTimeStep = ui.spinBoxDemixTimeStep->value(); - demix_settings.itsFreqStep = ui.spinBoxAveragingFreqStep->value(); - demix_settings.itsTimeStep = ui.spinBoxAveragingTimeStep->value(); - demix_settings.itsSkyModel = ui.lineEditDemixSkyModel->text(); - calpipe->setDemixingSettings(demix_settings); - } - } - else if ((impipe = dynamic_cast<ImagingPipeline *>(itsTask))) { - impipe->setSpecifyFov(ui.checkBoxSpecifyFOV->isChecked()); - impipe->setFov(ui.lineEditFieldOfView->text().toDouble()); - impipe->setCellSize(ui.lineEditCellSize->text()); - impipe->setNrOfPixels(ui.spinBoxNumberOfPixels->value()); - impipe->setSlicesPerImage(ui.spinBoxSlicesPerImage->value()); - impipe->setSubbandsPerImage(ui.spinBoxSubbandsPerImage->value()); - } - - else if ((pulsepipe = dynamic_cast<PulsarPipeline *>(itsTask))) { - pulsepipe->setNoRFI(ui.checkBox_NoRFI->isChecked()); - pulsepipe->setSkipDspsr(ui.checkBox_No_DSPSR->isChecked()); - pulsepipe->setNoFold(ui.checkBox_No_fold->isChecked()); - pulsepipe->setNoPdmp(ui.checkBox_No_pdmp->isChecked()); - pulsepipe->setRawTo8Bit(ui.checkBox_RawTo8Bit->isChecked()); - pulsepipe->setRRATS(ui.checkBox_rrats->isChecked()); - pulsepipe->setSinglePulse(ui.checkBox_Single_pulse->isChecked()); - pulsepipe->setSkipDynamicSpectrum(ui.checkBox_Skip_dynamic_spectrum->isChecked()); - pulsepipe->setSkipPrepfold(ui.checkBox_Skip_prepfold->isChecked()); - pulsepipe->setTwoBf2fitsExtra(ui.lineEdit2bf2fitsExtraOptions->text()); - pulsepipe->setDigifilExtra(ui.lineEditDigifilExtraOptions->text()); - pulsepipe->setDspsrExtra(ui.lineEditDSPSRextraOptions->text()); - pulsepipe->setPrepDataExtra(ui.lineEditPrepdataExtraOptions->text()); - pulsepipe->setPrepFoldExtra(ui.lineEditPrepfoldExtraOptions->text()); - pulsepipe->setPrepSubbandExtra(ui.lineEditPrepsubbandExtraOptions->text()); - pulsepipe->setPulsarName(ui.lineEditPulsarName->text()); - pulsepipe->setRFIfindExtra(ui.lineEditRfiFindExtraOptions->text()); - pulsepipe->setDecodeNblocks(ui.spinBoxDecodeNblocks->value()); - pulsepipe->setDecodeSigma(ui.spinBoxDecodeSigma->value()); - pulsepipe->setTsubInt(ui.spinBoxTsubint->value()); - pulsepipe->setEightBitConversionSigma(ui.doubleSpinBox8BitConversionSigma->value()); - pulsepipe->setDynamicSpectrumAvg(ui.doubleSpinBoxDynamicSpectrumTimeAverage->value()); - pulsepipe->setRratsDmRange(ui.doubleSpinBoxRratsDmRange->value()); - } - else if ((lbpipe = dynamic_cast<LongBaselinePipeline *>(itsTask))) { - lbpipe->setSubbandGroupsPerMS(ui.spinBoxSubbandGroupsPerMS->value()); - lbpipe->setSubbandsPerSubbandGroup(ui.spinBoxSubbandsPerSubbandGroup->value()); - } - - // scheduled start and stop times - const AstroDate &latestDate = Controller::theSchedulerSettings.getLatestSchedulingDay(); - - QDateTime currentTime = QDateTime::currentDateTimeUtc(); - QDateTime st(ui.dateTimeEditScheduledStart->dateTime()); - AstroDateTime now = AstroDateTime(currentTime.date().day(), currentTime.date().month(), currentTime.date().year(), - currentTime.time().hour(), currentTime.time().minute(), currentTime.time().second()); - AstroDateTime start = AstroDateTime(st.date().day(), st.date().month(), st.date().year(), - st.time().hour(), st.time().minute(), st.time().second()); - - if ((start >= now) || (state < Task::PRESCHEDULED)) { - if (ui.dateTimeEditScheduledEnd->date() <= QDate(latestDate.getYear(), latestDate.getMonth(), latestDate.getDay())) { - if (!ui.dateTimeEditScheduledStart->isUndefined()) { - pipeline->setScheduledStart(ui.dateTimeEditScheduledStart->dateTime()); - } - if (!ui.dateTimeEditScheduledEnd->isUndefined()) { - pipeline->setScheduledEnd(ui.dateTimeEditScheduledEnd->dateTime()); - } - } - else { - QMessageBox::warning(this, tr("Task planned outside schedule"), tr("The task cannot be planned outside of the schedule.\nPlease correct the scheduled start and/or end dates")); - return false; - } - } - else { - QMessageBox::warning(this, tr("Task planned in the past"), tr("You cannot schedule a task in the past.\nPlease correct the scheduled start date")); - return false; - } - - // task duration - if (!ui.lineEditDuration->isUndefined()) { - pipeline->setDuration(ui.lineEditDuration->text()); - } - - //priority - pipeline->setPriority(ui.lineEditPriority->text().toDouble()); - - // group ID - pipeline->setGroupID(ui.lineEditGroupID->text().toUInt()); - - // predecessor - if (!ui.lineEditPredecessors->text().isEmpty()) { - pipeline->setPredecessors(ui.lineEditPredecessors->text()); - pipeline->setPredecessorMinTimeDif(ui.lineEditMinPredDistance->text().toStdString()); - pipeline->setPredecessorMaxTimeDif(ui.lineEditMaxPredDistance->text().toStdString()); - } else { - pipeline->clearPredecessors(); - } - - pipeline->setWindowFirstDay(ui.dateEditFirstPossibleDate->date()); - pipeline->setWindowLastDay(ui.dateEditLastPossibleDate->date()); - - pipeline->setWindowMinTime(ui.timeEditFirstPossibleTime->time()); - pipeline->setWindowMaxTime(ui.timeEditLastPossibleTime->time()); - - pipeline->setFixDay(ui.checkBoxFixedDate->isChecked()); - pipeline->setFixTime(ui.checkBoxFixedTime->isChecked()); - - TaskStorage *pipe_storage(pipeline->storage()); - - updateEnabledInputDataTypes(); // update the enabled input data product types in itsTask according to the current enabled types in the inputDataTreeWidget - pipe_storage->setInputFilesToBeProcessed(getInputDataFilesCheckState()); - - checkForRemovalOfDataProducts(itsOutputDataTypes); // checks if data products have been switched off by the user and remove them from itsTmpStorage if needed - storage_selection_mode newStorageSelectionMode(static_cast<storage_selection_mode>(ui.comboBoxStorageSelectionMode->currentIndex())); - if (newStorageSelectionMode != pipe_storage->getStorageSelectionMode()) { - itsTmpStorage.clear(); - pipe_storage->unAssignStorage(); - if (newStorageSelectionMode == STORAGE_MODE_MANUAL) { - getDisplayedStorageLocations(); - } - } - pipe_storage->setStorageSelectionMode(newStorageSelectionMode); - pipe_storage->setStorage(itsTmpStorage); - checkStorageSettingsEnable(); // enable the storage tree according to the current status which might have been changed - - // pipeline->setAutoSelectStorage(ui.checkBox_AutomaticSelectionStorageNodes->isChecked()); - - // add the end of making changes to a task hat potentially change its resources always call recalculateCheck -// pipeline->recalculateCheck(); - - if (addingPipeline) { - itsController->createPipeline(pipeline); - addingPipeline = false; - } - else if (itsController->updatePipelineTask(pipeline, true)) { - enableApplyButtons(false); - } - - return true; -} - -bool TaskDialog::commitReservation(bool storeValues = false) { - QString strValue; - addingTask = false; - strValue = ui.lineEditTaskName->text(); -/* - if (strValue.length() < 3) { - ui.tabWidgetMain->setCurrentWidget(ui.tab_TaskSettings); - ui.lineEditTaskName->setFocus(); - QMessageBox::warning(this, tr("Task name not valid"), tr("The task name must contain at least three characters")); - return false; - } -*/ - itsTask->setTaskName(strValue.toStdString()); - itsTask->setProjectName(ui.lineEdit_ProjectName->text().toStdString()); - itsTask->setProjectCO_I(ui.lineEdit_ProjectCOI->text().toStdString()); - itsTask->setProjectID(ui.comboBoxProjectID->currentText().toStdString()); - itsTask->setProjectPI(ui.lineEdit_ProjectPI->text().toStdString()); - itsTask->setContactEmail(ui.lineEdit_ContactEmail->text().toStdString()); - itsTask->setContactName(ui.lineEdit_ContactName->text().toStdString()); - itsTask->setContactPhone(ui.lineEdit_ContactPhone->text().toStdString()); - itsTask->setTaskDescription(ui.lineEditTaskDescription->text().toStdString()); - - itsTask->setType(ui.comboBoxProcessType->currentText(), - stringToProcessSubType(ui.comboBoxProcessSubType->currentText()), - ui.comboBoxStrategies->currentText()); - itsTask->setOriginalTreeID(ui.lineEditOriginalTreeID->text().toInt()); - itsTask->setStatus(ui.comboBoxTaskStatus->currentText().toStdString()); - - // scheduled start and stop times -// const AstroDate &earliestDate = Controller::theSchedulerSettings.getEarliestSchedulingDay(); -// const AstroDate &latestDate = Controller::theSchedulerSettings.getLatestSchedulingDay(); - -/* - if (addingReservation) { - if (!(ui.dateTimeEditScheduledStart->isUndefined()) & !(ui.dateTimeEditScheduledEnd->isUndefined())) { - if (ui.dateTimeEditScheduledEnd->date() <= QDate(latestDate.getYear(), latestDate.getMonth(), latestDate.getDay())) { - itsTask->setScheduledStart(ui.dateTimeEditScheduledStart->dateTime()); - itsTask->setScheduledEnd(ui.dateTimeEditScheduledEnd->dateTime()); - } - else { - QMessageBox::warning(this, tr("Task planned outside schedule"), tr("The task may not be planned outside of the schedule.\nPlease correct the scheduled start and/or end dates")); - return false; - } - } - } - else if (ui.dateTimeEditScheduledStart->date() >= QDate(earliestDate.getYear(), earliestDate.getMonth(), earliestDate.getDay()) && - (ui.dateTimeEditScheduledEnd->date() <= QDate(latestDate.getYear(), latestDate.getMonth(), latestDate.getDay()))) { - if (!ui.dateTimeEditScheduledStart->isUndefined()) { - itsTask->setScheduledStart(ui.dateTimeEditScheduledStart->dateTime()); - } - if (!ui.dateTimeEditScheduledEnd->isUndefined()) { - itsTask->setScheduledEnd(ui.dateTimeEditScheduledEnd->dateTime()); - } - } - else { - QMessageBox::warning(this, tr("Task planned outside schedule"), tr("The task may not be planned outside of the schedule.\nPlease correct the scheduled start and/or end dates")); - return false; - } - */ - // scheduled start - if (!ui.dateTimeEditScheduledStart->isUndefined()) { - itsTask->setScheduledStart(ui.dateTimeEditScheduledStart->dateTime()); - } - // scheduled end - if (!ui.dateTimeEditScheduledEnd->isUndefined()) { - itsTask->setScheduledEnd(ui.dateTimeEditScheduledEnd->dateTime()); - } - // task duration - if (!ui.lineEditDuration->isUndefined()) { - itsTask->setDuration(ui.lineEditDuration->text()); - } - - StationTask *stationTask(static_cast<StationTask *>(itsTask)); // a resevation is per definition a stationTask - - //stations - const std::vector<std::string> &stations = getAssignedStationNames(); - if (!stations.empty()) { - stationTask->setStations(stations); - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - ui.listWidgetAvailableStations->setFocus(); - QMessageBox::warning(this, tr("No stations selected"), tr("At least one station needs to be selected")); - return false; - } - - - if (!itsTask->isMaintenance()) { // for maintenance no checking and no further properties are set - stationTask->setAntennaMode(antenna_modes_str[ui.comboBoxStationAntennaMode->currentIndex()]); - stationTask->setFilterType(filter_types_str[ui.comboBoxStationFilter->currentIndex()]); - stationTask->setStationClock(clock_frequencies_str[ui.comboBoxStationClock->currentIndex()]); - -// obs->setSuperStations(getSuperStations(obs)); // the call to getSuperStations must be done after setting the task's stations - - if (!checkEmail()) { - return false; - } - } - - if (addingReservation) { - if (!itsController->createReservation(itsTask)) { - return false; - } - else { - addingReservation = false; - return true; - } - } - else { - addingReservation = false; - if (storeValues) { - StoreValues(); - } - enableApplyButtons(false); - itsController->updateTask(itsTask, true); - } - resetChangeDetection(); - return true; -} - - -bool TaskDialog::commitChanges(bool storeValues = false) { - int dummy(0); - QString strValue; - bool unAssignStorage(false); - - // first check if this is an ABORT task commit in which case only the status may be changed and no further changes are allowed - if (ui.comboBoxTaskStatus->currentText().compare("ABORTED") != 0) { - - - strValue = ui.lineEditTaskName->text(); - itsTask->setTaskName(strValue.toStdString()); - itsTask->setProjectName(ui.lineEdit_ProjectName->text().toStdString()); - itsTask->setProjectCO_I(ui.lineEdit_ProjectCOI->text().toStdString()); - itsTask->setProjectID(ui.comboBoxProjectID->currentText().toStdString()); - itsTask->setProjectPI(ui.lineEdit_ProjectPI->text().toStdString()); - - itsTask->setType(ui.comboBoxProcessType->currentText(), - stringToProcessSubType(ui.comboBoxProcessSubType->currentText()), - ui.comboBoxStrategies->currentText()); - itsTask->setOriginalTreeID(ui.lineEditOriginalTreeID->text().toInt()); - - Task::task_status state = taskStatusFromString(ui.comboBoxTaskStatus->currentText().toStdString()); - itsTask->setStatus(state); - - itsTask->setContactEmail(ui.lineEdit_ContactEmail->text().toStdString()); - itsTask->setContactName(ui.lineEdit_ContactName->text().toStdString()); - itsTask->setContactPhone(ui.lineEdit_ContactPhone->text().toStdString()); - itsTask->setTaskDescription(ui.lineEditTaskDescription->text().toStdString()); - - // scheduled start and stop times - // const AstroDate &earliestDate = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - const AstroDate &latestDate = Controller::theSchedulerSettings.getLatestSchedulingDay(); - - QDateTime currentTime = QDateTime::currentDateTimeUtc(); - QDateTime st(ui.dateTimeEditScheduledStart->dateTime()); - AstroDateTime now = AstroDateTime(currentTime.date().day(), currentTime.date().month(), currentTime.date().year(), - currentTime.time().hour(), currentTime.time().minute(), currentTime.time().second()); - AstroDateTime start = AstroDateTime(st.date().day(), st.date().month(), st.date().year(), - st.time().hour(), st.time().minute(), st.time().second()); - - if ((start >= now) || (state < Task::PRESCHEDULED)) { - if (ui.dateTimeEditScheduledEnd->date() <= QDate(latestDate.getYear(), latestDate.getMonth(), latestDate.getDay())) { - - if (!ui.dateTimeEditScheduledStart->isUndefined()) { - AstroDateTime prevStart(itsTask->getScheduledStart()); - itsTask->setScheduledStart(ui.dateTimeEditScheduledStart->dateTime()); - if (prevStart != itsTask->getScheduledStart()) unAssignStorage = true; - } - if (!ui.dateTimeEditScheduledEnd->isUndefined()) { - AstroDateTime prevEnd(itsTask->getScheduledEnd()); - itsTask->setScheduledEnd(ui.dateTimeEditScheduledEnd->dateTime()); - if (prevEnd != itsTask->getScheduledEnd()) unAssignStorage = true; - } - } - else { - QMessageBox::critical(this, tr("Task scheduled outside schedule"), tr("The task cannot be scheduled outside of the schedule.\nPlease correct the scheduled start and/or end dates")); - return false; - } - } - else { - QMessageBox::critical(this, tr("Task scheduled in the past"), tr("You cannot schedule a task in the past or too close to now.\nPlease correct the scheduled start date")); - return false; - } - - // task duration - if (!ui.lineEditDuration->isUndefined()) { - itsTask->setDuration(ui.lineEditDuration->text()); - } - - if (itsTask->isStationTask()) { - StationTask *stationtask(static_cast<StationTask *>(itsTask)); - //stations - const std::vector<std::string> &stations = getAssignedStationNames(); - if (!stations.empty()) { - taskStationsMap prevStations(stationtask->getStations()); - stationtask->setStations(stations); - if (prevStations != stationtask->getStations()) unAssignStorage = true; - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - ui.listWidgetAvailableStations->setFocus(); - QMessageBox::critical(this, tr("No stations selected"), tr("At least one station needs to be selected")); - return false; - } - - int mode = ui.comboBoxStationAntennaMode->currentIndex(); - if (mode) { - QString modeStr = ui.comboBoxStationAntennaMode->currentText(); - if (modeStr.startsWith("HBA")) { // check if Analog beam is set - if ((fabs(itsAnalogBeamSettings.angle1.radian()) < std::numeric_limits<double>::epsilon()) & - (fabs(itsAnalogBeamSettings.angle2.radian()) < std::numeric_limits<double>::epsilon()) & - (!itsAnalogBeamSettings.startTime.isSet()) & - (!itsAnalogBeamSettings.duration.isSet())) { - QApplication::beep(); - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationBeams); - ui.lineEditAnalogBeamAngle1->setFocus(); - if (QMessageBox::question(this, tr(""), - tr("For a HBA antenna mode the analog beam needs to be set. It appears not to be set.\nDo you want to continue?"), - QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes) == QMessageBox::Cancel) { - return false; - } - } - } - station_antenna_mode prevAntMode(stationtask->getAntennaMode()); - stationtask->setAntennaMode(antenna_modes_str[mode]); - station_antenna_mode antMode(stationtask->getAntennaMode()); - if (antMode != prevAntMode) unAssignStorage = true; - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - ui.comboBoxStationAntennaMode->setFocus(); - QMessageBox::critical(this, tr("Station mode not set"), tr("The stations mode must be specified.")); - return false; - } - int filter = ui.comboBoxStationFilter->currentIndex(); - if (filter) { - station_filter_type prevFilter(stationtask->getFilterType()); - stationtask->setFilterType(filter_types_str[filter]); - if (prevFilter != stationtask->getFilterType()) unAssignStorage = true; - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - ui.comboBoxStationFilter->setFocus(); - QMessageBox::critical(this, tr("Station filter not set"), tr("The stations filter type must be specified.")); - return false; - } - - int clock = ui.comboBoxStationClock->currentIndex(); - if (clock) { - station_clock prevClock(stationtask->getStationClock()); - stationtask->setStationClock(clock_frequencies_str[clock]); - if (prevClock != stationtask->getStationClock()) unAssignStorage = true; - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - ui.comboBoxStationClock->setFocus(); - QMessageBox::critical(this, tr("Station clock not set"), tr("The stations clock frequency must be specified.")); - return false; - } - - - if (stationtask->isObservation()) { - Observation *obs(static_cast<Observation *>(stationtask)); - - superStationMap prevSuperStations(obs->getSuperStations()); - obs->setSuperStations(getSuperStations(obs)); // the call to getSuperStations must be done after setting the task's stations - if (prevSuperStations != obs->getSuperStations()) unAssignStorage = true; - - obs->setNrOfDataslotsPerRSPboard(ui.spinBoxDataslotsPerRSPboard->value()); - obs->setTBBPiggybackAllowed(ui.checkBoxTBBPiggybackAllowed->isChecked()); - obs->setAartfaacPiggybackAllowed(ui.checkBoxAartfaacPiggybackAllowed->isChecked()); - - // beam settings - itsTempAnalogBeamSettings = getAnalogBeamSettings(); // itsTempAnalogBeamSettings is used for change detection - obs->setAnalogBeamSettings(itsAnalogBeamSettings); - - itsTempDigitalBeams = itsDigitalBeams; // itsTempDigitalBeams is used for change detection - obs->setDigitalBeams(itsDigitalBeams); - - Observation::RTCPsettings prevRTCP(obs->getRTCPsettings()); - if (ui.spinBoxCoherentChannelsPerSubband->value() == 0) { - QMessageBox::critical(this, tr("Wrong value"), tr("Coherent channels per subband setting may not be zero")); - return false; - } - if (ui.spinBoxIncoherentChannelsPerSubband->value() == 0) { - QMessageBox::critical(this, tr("Wrong value"), tr("Incoherent channels per subband setting may not be zero")); - return false; - } - obs->setRTCPsettings(getRTCPSettings()); - - if (prevRTCP != obs->getRTCPsettings()) unAssignStorage = true; - - } // end if = Observation - } // end if = stationTask - - TaskStorage *task_storage(itsTask->storage()); - if (task_storage) { - if (task_storage->getOutputDataProductsEnabled() != itsOutputDataTypes) { - unAssignStorage = true; - } - - if (unAssignStorage) { - itsOutputDataTypes.coherentStokesAssigned = false; - itsOutputDataTypes.correlatedAssigned = false; - itsOutputDataTypes.incoherentStokesAssigned = false; - itsOutputDataTypes.instrumentModelAssigned = false; - itsOutputDataTypes.complexVoltagesAssigned = false; - itsOutputDataTypes.skyImageAssigned = false; - task_storage->unAssignStorage(); - } - task_storage->setEnabledOutputDataProducts(itsOutputDataTypes); - checkForRemovalOfDataProducts(itsOutputDataTypes); // checks if data products have been switched off by the user and remove them from itsTmpStorage if needed - - storage_selection_mode newStorageSelectionMode(static_cast<storage_selection_mode>(ui.comboBoxStorageSelectionMode->currentIndex())); - if (newStorageSelectionMode != task_storage->getStorageSelectionMode()) { - itsTmpStorage.clear(); - unAssignStorage = true; - if (newStorageSelectionMode == STORAGE_MODE_MANUAL) { - getDisplayedStorageLocations(); - } - } - task_storage->setStorageSelectionMode(newStorageSelectionMode); - task_storage->setStorage(itsTmpStorage); - - } - checkStorageSettingsEnable(); // enable the storage tree according to the current status which might have been changed - - itsTask->setGroupID(ui.lineEditGroupID->text().toUInt()); - - //priority - QDoubleValidator dValidator(ui.lineEditPriority); - strValue = ui.lineEditPriority->text(); - dValidator.setRange(0.0,10.0,20); - if (dValidator.validate(strValue, dummy) == QValidator::Acceptable) { - itsTask->setPriority(string2Double(strValue.toStdString())); - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_TaskSettings); - ui.lineEditPriority->setFocus(); - QMessageBox::critical(this, tr("Wrong priority value"), tr("The priority value must be in the [0,10] range")); - return false; - } - - // predecessor - if (!ui.lineEditPredecessors->text().isEmpty()) { - itsTask->setPredecessors(ui.lineEditPredecessors->text()); - itsTask->setPredecessorMinTimeDif(ui.lineEditMinPredDistance->text().toStdString()); - itsTask->setPredecessorMaxTimeDif(ui.lineEditMaxPredDistance->text().toStdString()); - } else { - itsTask->clearPredecessors(); - } - - itsTask->setWindowFirstDay(ui.dateEditFirstPossibleDate->date()); - itsTask->setWindowLastDay(ui.dateEditLastPossibleDate->date()); - - itsTask->setWindowMinTime(ui.timeEditFirstPossibleTime->time()); - itsTask->setWindowMaxTime(ui.timeEditLastPossibleTime->time()); - - itsTask->setFixDay(ui.checkBoxFixedDate->isChecked()); - itsTask->setFixTime(ui.checkBoxFixedTime->isChecked()); - - if (!checkEmail()) { - return false; - } - - // add the end of making changes to a task hat potentially change its resources always call recalculateCheck -// itsTask->recalculateCheck(); - - if (addingTask) { - resetChangeDetection(); - if (!itsController->createTask(*itsTask)) { - return false; - } - else { - addingTask = false; - return true; - } - } - else { - if (storeValues) { - StoreValues(); - } - } - if (itsController->updateTask(itsTask, true)) { - enableApplyButtons(false); - return true; - } - else return false; - } // task status is set to ABORTED - else { // user put task on ABORT no other changes are allowed here to the task - if (itsTask->getStatus() == Task::ACTIVE) { - enableApplyButtons(false); - emit abortTask(itsTask->getID()); - return true; - } - else { - QMessageBox::critical(this, tr("Task is not ACTIVE"), "Task:" + QString::number(itsTask->getID()) + " is not ACTIVE. Could not ABORT the task"); - return false; - } - } -} - -bool TaskDialog::commitMultiTasks(void) { - if (!itsMultiTasks.empty()) { - QString strValue; - - bool applyTaskName(false), applyProjectID(false), applyPredecessorID(false), - applyPredecessorMinTimeDif(false), applyPredecessorMaxTimeDif(false), applyAnalogAngle1(false), applyAnalogAngle2(false), applyAnalogCoordinateSystem(false), /*applyDigitalBeamSettings(false), clearDigitalBeams(false),*/ - applyFirstPossibleDate(false), applyLastPossibleDate(false), applyFirstPossibleTime(false), applyLastPossibleTime(false), applyStatus(false), - applyStations(false), applyScheduledStart(false), applyScheduledEnd(false), applyDuration(false), applyDescription(false), applyAntennaMode(false), applyStationFilter(false), applyStationClock(false), - applyFlysEye(false), applyChannelsPerSubband(false), applyCoherentChannelsPerSubband(false), applyIncoherentChannelsPerSubband(false), applyBitsPerSample(false), - applyCoherentStokesType(false), applyCoherentIntegration(false), applyIncoherentIntegration(false), applyIncoherentStokesType(false), - applyCoherentSubbandPerFile(false), applyIncoherentSubbandPerFile(false), applyNrDataSlotsPerRSPBoard(false), applyTBBpiggyback(false), applyAartfaacPiggyback(false), - applyCorrelatorIntegrationTime(false), applyReservation(false), applyProcessType(false), applyProcessSubtype(false), applyStrategy(false), applyStorageSelectMode(false), - applyCorrelated(false), applyCoherent(false), applyIncoherent(false), applyBandpassCorrection(false), applyDelayCompensation(false), - applyCoherentDedispersion(false), applyGroupID(false), applyDemixAlways(false), applyDemixIfNeeded(false), applyDemixFreqStep(false), applyDemixTimeStep(false), - applyAvgFreqStep(false), applyAvgTimeStep(false), applyDemixSkyModel(false), applyCalibrationSkyModel(false), applySpecifyFOV(false), applyFOV(false), applyCellSize(false), - applyNrOfPixels(false), applySlicesPerImage(false), applySubbandsPerImage(false), applySubbandGroupsPerMS(false), applySubbandsPerSubbandGroup(false), - applyPulsar_noRFI(false), applyPulsar_noDSPSR(false), applyPulsar_noFold(false), applyPulsar_noPDMP(false), applyPulsar_rawTo8Bit(false), applyPulsar_RRATS(false), - applyPulsar_singlePulse(false), applyPulsar_skipDynamicSpectrum(false), applyPulsar_skipPrepfold(false), applyPulsar_twoBf2fitsExtra(false), applyPulsar_digifilExtra(false), - applyPulsar_dspsrExtra(false), applyPulsar_prepDataExtra(false), applyPulsar_prepFoldExtra(false), applyPulsar_prepSubbandExtra(false), applyPulsar_PulsarName(false), - applyPulsar_rfiFindExtra(false), applyPulsar_decodeNblocks(false), applyPulsar_decodeSigma(false), applyPulsar_tsubint(false), applyPulsar_8bitconvSigma(false), - applyPulsar_dynamicSpectrumAvg(false), applyPulsar_rratsDMRange(false); - - - strValue = ui.lineEditTaskName->text(); - - if (ui.lineEditTaskDescription->hasBeenChanged()) applyDescription = true; - if (ui.lineEditTaskName->hasBeenChanged()) applyTaskName = true; - - unsigned int reservationID(0), groupID(0); - if (ui.comboBoxReservation->hasBeenChanged()) { - reservationID = ui.comboBoxReservation->itemData(ui.comboBoxReservation->currentIndex()).toUInt(); - applyReservation = true; - } - - if (ui.lineEditGroupID->hasBeenChanged()) { - groupID = ui.lineEditGroupID->text().toUInt(); - applyGroupID = true; - } - - applyPredecessorID = ui.lineEditPredecessors->hasBeenChanged(); - applyProjectID = ui.comboBoxProjectID->hasBeenChanged(); - applyDuration = ui.lineEditDuration->hasBeenChanged(); - applyScheduledStart = ui.dateTimeEditScheduledStart->hasBeenChanged(); - applyScheduledEnd = ui.dateTimeEditScheduledEnd->hasBeenChanged(); - - AstroTime predMinTimeDif, predMaxTimeDif; - if (ui.lineEditMinPredDistance->hasBeenChanged()) { - predMinTimeDif = AstroTime(ui.lineEditMinPredDistance->text().toStdString()); - applyPredecessorMinTimeDif = true; - } - if (ui.lineEditMaxPredDistance->hasBeenChanged()) { - predMaxTimeDif = AstroTime(ui.lineEditMaxPredDistance->text().toStdString()); - applyPredecessorMaxTimeDif = true; - } - - AstroDate firstPossibleDate, lastPossibleDate; - AstroTime firstPossibleTime, lastPossibleTime; - if (ui.dateEditFirstPossibleDate->hasBeenChanged()) { - firstPossibleDate = AstroDate(ui.dateEditFirstPossibleDate->text().toStdString()); - applyFirstPossibleDate = true; - } - if (ui.dateEditLastPossibleDate->hasBeenChanged()) { - lastPossibleDate = AstroDate(ui.dateEditLastPossibleDate->text().toStdString()); - applyLastPossibleDate = true; - } - if (ui.timeEditFirstPossibleTime->hasBeenChanged()) { - firstPossibleTime = AstroTime(ui.timeEditFirstPossibleTime->text().toStdString()); - applyFirstPossibleTime = true; - } - if (ui.timeEditLastPossibleTime->hasBeenChanged()) { - lastPossibleTime = AstroTime(ui.timeEditLastPossibleTime->text().toStdString()); - applyLastPossibleTime = true; - } - - std::string statusStr; - if (ui.comboBoxTaskStatus->hasBeenChanged()) { - statusStr = ui.comboBoxTaskStatus->currentText().toStdString(); - applyStatus = true; - } - - QString processType, strategy; - processSubTypes processSubtype(PST_UNKNOWN); - Task::task_type type(Task::UNKNOWN); - if (ui.comboBoxProcessType->hasBeenChanged()) { - type = static_cast<Task::task_type>(ui.comboBoxProcessType->currentIndex()); - processType = ui.comboBoxProcessType->currentText(); - applyProcessType = true; - } - if (ui.comboBoxProcessSubType->hasBeenChanged()) { - processSubtype = stringToProcessSubType(ui.comboBoxProcessSubType->currentText()); - applyProcessSubtype = true; - } - if (ui.comboBoxStrategies->hasBeenChanged()) { - strategy = ui.comboBoxStrategies->currentText(); - applyStrategy = true; - } - - applyTBBpiggyback = ui.checkBoxTBBPiggybackAllowed->hasBeenChanged(); - applyAartfaacPiggyback = ui.checkBoxAartfaacPiggybackAllowed->hasBeenChanged(); - - // analog beam coordinate system - beamDirectionType analogBeamDirectionType(DIR_TYPE_J2000); - if (ui.comboBoxAnalogBeamCoordinates->hasBeenChanged()) { - analogBeamDirectionType = stringToBeamDirectionType(ui.comboBoxAnalogBeamCoordinates->currentText().toStdString()); - applyAnalogCoordinateSystem = true; - } - - // analog beam settings - applyAnalogAngle1 = ui.lineEditAnalogBeamAngle1->hasBeenChanged(); - applyAnalogAngle2 = ui.lineEditAnalogBeamAngle2->hasBeenChanged(); - - anglePairs analogUnits(ANGLE_PAIRS_HMS_DMS); - if (applyAnalogAngle1 || applyAnalogAngle2) { - const QString &unitStr(ui.comboBoxAnalogBeamUnits->currentText()); - if (unitStr.compare(ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS]) == 0) analogUnits = ANGLE_PAIRS_HMS_DMS; - else if (unitStr.compare(ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS]) == 0) analogUnits = ANGLE_PAIRS_DMS_DMS; - else if (unitStr.compare(ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES]) == 0) analogUnits = ANGLE_PAIRS_DECIMAL_DEGREES; - else analogUnits = ANGLE_PAIRS_RADIANS; - } - - - double correlatorIntegrationTime(1.0); - if (ui.lineEditCorrelatorIntegrationTime->hasBeenChanged()) { - correlatorIntegrationTime = ui.lineEditCorrelatorIntegrationTime->text().toDouble(); - applyCorrelatorIntegrationTime = true; - } - - applyCorrelated = ui.checkBoxCorrelatedData->hasBeenChanged(); - applyCoherent = ui.checkBoxCoherentStokes->hasBeenChanged(); - applyIncoherent = ui.checkBoxIncoherentStokes->hasBeenChanged(); - applyFlysEye = ui.checkBoxPencilFlysEye->hasBeenChanged(); - applyCoherentDedispersion = ui.checkBox_CoherentDedispersion->hasBeenChanged(); - applyBandpassCorrection = ui.checkBox_BandpassCorrection->hasBeenChanged(); - applyDelayCompensation = ui.checkBox_DelayCompensation->hasBeenChanged(); - - if (ui.comboBoxBitsPerSample->hasBeenChanged()) { - applyBitsPerSample = true; - applyNrDataSlotsPerRSPBoard = true; - } - - applyChannelsPerSubband = ui.spinBoxChannelsPerSubband->hasBeenChanged(); - applyCoherentStokesType = ui.comboBoxCoherentStokesType->hasBeenChanged(); - applyIncoherentStokesType = ui.comboBoxIncoherentStokesType->hasBeenChanged(); - applyCoherentIntegration = ui.spinBoxCoherentTimeIntegration->hasBeenChanged(); - applyIncoherentIntegration = ui.spinBoxIncoherentTimeIntegration->hasBeenChanged(); - applyCoherentSubbandPerFile = ui.spinBoxCoherentSubbandsPerFile->hasBeenChanged(); - applyIncoherentSubbandPerFile = ui.spinBoxIncoherentSubbandsPerFile->hasBeenChanged(); - applyCoherentChannelsPerSubband = ui.spinBoxCoherentChannelsPerSubband->hasBeenChanged(); - applyIncoherentChannelsPerSubband = ui.spinBoxIncoherentChannelsPerSubband->hasBeenChanged(); - - std::vector<std::string> stations; - if (ui.treeWidgetUsedStations->hasChanged()) { - stations = getAssignedStationNames(); - applyStations = true; - } - - // antenna mode - station_antenna_mode antenna_mode(UNSPECIFIED_ANTENNA_MODE); - if (ui.comboBoxStationAntennaMode->hasBeenChanged()) { - antenna_mode = static_cast<station_antenna_mode>(ui.comboBoxStationAntennaMode->currentIndex()); - applyAntennaMode = true; - } - - // station filter - int filter(0); - if (ui.comboBoxStationFilter->hasBeenChanged()) { - filter = ui.comboBoxStationFilter->currentIndex(); - applyStationFilter = true; - } - - // station clock - - int clock(0); - if (ui.comboBoxStationClock->hasBeenChanged()) { - clock = ui.comboBoxStationClock->currentIndex(); - applyStationClock = true; - } - - applyDemixAlways = ui.listWidgetDemixAlways->hasBeenChanged(); - applyDemixIfNeeded = ui.listWidgetDemixIfNeeded->hasBeenChanged(); - applyDemixFreqStep = ui.spinBoxDemixFreqStep->hasBeenChanged(); - applyDemixTimeStep = ui.spinBoxDemixTimeStep->hasBeenChanged(); - applyAvgFreqStep = ui.spinBoxAveragingFreqStep->hasBeenChanged(); - applyAvgTimeStep = ui.spinBoxAveragingTimeStep->hasBeenChanged(); - applyDemixSkyModel = ui.lineEditDemixSkyModel->hasBeenChanged(); - applyCalibrationSkyModel = ui.lineEditCalibrationSkyModel->hasBeenChanged(); - applySpecifyFOV = ui.checkBoxSpecifyFOV->hasBeenChanged(); - - applyFOV = ui.lineEditFieldOfView->hasBeenChanged(); - applyCellSize = ui.lineEditCellSize->hasBeenChanged(); - applyNrOfPixels = ui.spinBoxNumberOfPixels->hasBeenChanged(); - applySlicesPerImage = ui.spinBoxSlicesPerImage->hasBeenChanged(); - applySubbandsPerImage = ui.spinBoxSubbandsPerImage->hasBeenChanged(); - applySubbandGroupsPerMS = ui.spinBoxSubbandGroupsPerMS->hasBeenChanged(); - applySubbandsPerSubbandGroup = ui.spinBoxSubbandsPerSubbandGroup->hasBeenChanged(); - - applyPulsar_noRFI = ui.checkBox_NoRFI->hasBeenChanged(); - applyPulsar_noDSPSR = ui.checkBox_No_DSPSR->hasBeenChanged(); - applyPulsar_noFold = ui.checkBox_No_fold->hasBeenChanged(); - applyPulsar_noPDMP = ui.checkBox_No_pdmp->hasBeenChanged(); - applyPulsar_rawTo8Bit = ui.checkBox_RawTo8Bit->hasBeenChanged(); - applyPulsar_RRATS = ui.checkBox_rrats->hasBeenChanged(); - applyPulsar_singlePulse = ui.checkBox_Single_pulse->hasBeenChanged(); - applyPulsar_skipDynamicSpectrum = ui.checkBox_Skip_dynamic_spectrum->hasBeenChanged(); - applyPulsar_skipPrepfold = ui.checkBox_Skip_prepfold->hasBeenChanged(); - applyPulsar_twoBf2fitsExtra = ui.lineEdit2bf2fitsExtraOptions->hasBeenChanged(); - - applyPulsar_digifilExtra = ui.lineEditDigifilExtraOptions->hasBeenChanged(); - applyPulsar_dspsrExtra = ui.lineEditDSPSRextraOptions->hasBeenChanged(); - applyPulsar_prepDataExtra = ui.lineEditPrepdataExtraOptions->hasBeenChanged(); - applyPulsar_prepFoldExtra = ui.lineEditPrepfoldExtraOptions->hasBeenChanged(); - applyPulsar_prepSubbandExtra = ui.lineEditPrepsubbandExtraOptions->hasBeenChanged(); - applyPulsar_PulsarName = ui.lineEditPulsarName->hasBeenChanged(); - applyPulsar_rfiFindExtra = ui.lineEditRfiFindExtraOptions->hasBeenChanged(); - applyPulsar_decodeNblocks = ui.spinBoxDecodeNblocks->hasBeenChanged(); - - applyPulsar_decodeSigma = ui.spinBoxDecodeSigma->hasBeenChanged(); - applyPulsar_tsubint = ui.spinBoxTsubint->hasBeenChanged(); - applyPulsar_8bitconvSigma = ui.doubleSpinBox8BitConversionSigma->hasBeenChanged(); - applyPulsar_dynamicSpectrumAvg = ui.doubleSpinBoxDynamicSpectrumTimeAverage->hasBeenChanged(); - applyPulsar_rratsDMRange = ui.doubleSpinBoxRratsDmRange->hasBeenChanged(); - - // storage settings - if (ui.comboBoxStorageSelectionMode->hasBeenChanged() || itsStorageOverride) { - applyStorageSelectMode = true; - } - - // have the controller store an undo level of the complete schedule - itsController->storeScheduleUndo("Multi-edit of tasks"); - - // now loop through the tasks to apply these changes - bool change; - // prerequisites for applying changes - - QString tmpStr; - bool changesMade(false); - StationTask *statTask(0); - Observation *obs(0); - CalibrationPipeline *calpipe(0); - ImagingPipeline *impipe(0); - PulsarPipeline *pulspipe(0); - LongBaselinePipeline *lbpipe(0); - for (std::vector<Task *>::iterator it = itsMultiTasks.begin(); it != itsMultiTasks.end(); ++it) { - - change = false; - if (applyDuration) { - (*it)->setDuration(ui.lineEditDuration->text()); - change = true; - } - if (applyScheduledStart) { - (*it)->setScheduledStart(ui.dateTimeEditScheduledStart->dateTime()); - change = true; - } - if (applyScheduledEnd) { - (*it)->setScheduledEnd(ui.dateTimeEditScheduledEnd->dateTime()); - change = true; - } - if (applyTaskName) { - (*it)->setTaskName(ui.lineEditTaskName->text().toStdString()); - change = true; - } - if (applyGroupID) { - (*it)->setGroupID(groupID); - change = true; - } - if (applyDescription) { - tmpStr = ui.lineEditTaskDescription->text(); - tmpStr = tmpStr.replace(MULTIPLE_VALUE_TEXT,(*it)->getTaskDescription()); - (*it)->setTaskDescription(tmpStr.toStdString()); - change = true; - } - if (applyProjectID) { - (*it)->setProjectID(ui.comboBoxProjectID->currentText().toStdString()); - change = true; - } - if (applyPredecessorID) { - // TODO: IMPORTANT the predecessors line edit is not filled in multiedit causing it to be set empty when applying multi-edit - (*it)->setPredecessors(ui.lineEditPredecessors->text()); - change = true; - } - if (applyPredecessorMinTimeDif) { - (*it)->setPredecessorMinTimeDif(predMinTimeDif); - change = true; - } - if (applyPredecessorMaxTimeDif) { - (*it)->setPredecessorMaxTimeDif(predMaxTimeDif); - change = true; - } - if (applyFirstPossibleDate) { - (*it)->setWindowFirstDay(firstPossibleDate); - change = true; - } - if (applyLastPossibleDate) { - (*it)->setWindowLastDay(lastPossibleDate); - change = true; - } - if (applyFirstPossibleTime) { - (*it)->setWindowMinTime(firstPossibleTime); - change = true; - } - if (applyLastPossibleTime) { - (*it)->setWindowMaxTime(lastPossibleTime); - change = true; - } - if (applyStatus) { - (*it)->setStatus(statusStr); - change = true; - } - if (applyProcessType) { - (*it)->setType(type); - (*it)->setProcessType(processType); - change = true; - } - if (applyProcessSubtype) { - (*it)->setProcessSubtype(processSubtype); - change = true; - } - if (applyStrategy) { - (*it)->setStrategy(strategy); - change = true; - } - - - statTask = dynamic_cast<StationTask *>(*it); - if (statTask) { - if (applyStations) { - if (!stations.empty()) { - statTask->setStations(stations); - change = true; - } - else { - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - ui.listWidgetAvailableStations->setFocus(); - QMessageBox::warning(this, tr("No stations selected"), tr("At least one station needs to be selected")); - return false; - } - } - if (applyAntennaMode) { - statTask->setAntennaMode(antenna_mode); - change = true; - } - if (applyStationFilter) { - statTask->setFilterType(filter_types_str[filter]); - change = true; - } - if (applyStationClock) { - statTask->setStationClock(clock_frequencies_str[clock]); - change = true; - } - - obs = dynamic_cast<Observation *>(*it); - if (obs) { - if (applyReservation) { - obs->setReservation(reservationID); - change = true; - } - if (applyTBBpiggyback) { - obs->setTBBPiggybackAllowed(ui.checkBoxTBBPiggybackAllowed->isChecked()); - change = true; - } - if (applyAartfaacPiggyback) { - obs->setAartfaacPiggybackAllowed(ui.checkBoxAartfaacPiggybackAllowed->isChecked()); - change = true; - } - if (applyAnalogCoordinateSystem) { - obs->setAnalogBeamDirectionType(analogBeamDirectionType); - } - - // apply analog beam settings - if (applyAnalogAngle1) { - Angle angle1; - switch (analogUnits) { - case ANGLE_PAIRS_HMS_DMS: - angle1.setHMSangleStr(ui.lineEditAnalogBeamAngle1->text().toStdString()); - break; - case ANGLE_PAIRS_DMS_DMS: - angle1.setDMSangleStr(ui.lineEditAnalogBeamAngle1->text().toStdString()); - break; - case ANGLE_PAIRS_RADIANS: - angle1.setRadianAngle(ui.lineEditAnalogBeamAngle1->text().toDouble()); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - angle1.setDegreeAngle(ui.lineEditAnalogBeamAngle1->text().toDouble()); - break; - default: - break; - } - obs->setAnalogBeamAngle1(angle1); - change = true; - } - if (applyAnalogAngle2) { - Angle angle2; - switch (analogUnits) { - case ANGLE_PAIRS_HMS_DMS: - angle2.setHMSangleStr(ui.lineEditAnalogBeamAngle2->text().toStdString()); - break; - case ANGLE_PAIRS_DMS_DMS: - angle2.setDMSangleStr(ui.lineEditAnalogBeamAngle2->text().toStdString()); - break; - case ANGLE_PAIRS_RADIANS: - angle2.setRadianAngle(ui.lineEditAnalogBeamAngle2->text().toDouble()); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - angle2.setDegreeAngle(ui.lineEditAnalogBeamAngle2->text().toDouble()); - break; - default: - break; - } - obs->setAnalogBeamAngle2(angle2); - change = true; - } - - if (applyNrDataSlotsPerRSPBoard) { - obs->setNrOfDataslotsPerRSPboard(ui.spinBoxDataslotsPerRSPboard->value()); - change = true; - } - - if (applyFlysEye) { - obs->setFlysEye(ui.checkBoxPencilFlysEye->isChecked()); - change = true; - } - - if (applyCoherentDedispersion) { - obs->setCoherentDedispersion(ui.checkBox_CoherentDedispersion->isChecked()); - change = true; - } - - if (applyBandpassCorrection) { - obs->setBandPassCorrection(ui.checkBox_BandpassCorrection->isChecked()); - change = true; - } - - if (applyDelayCompensation) { - obs->setDelayCompensation(ui.checkBox_DelayCompensation->isChecked()); - change = true; - } - - if (applyCorrelatorIntegrationTime) { - obs->setCorrelatorIntegrationTime(correlatorIntegrationTime); - change = true; - } - - if (applyChannelsPerSubband) { - obs->setChannelsPerSubband(ui.spinBoxChannelsPerSubband->value()); - change = true; - } - - if (applyBitsPerSample) { - obs->setBitsPerSample(ui.comboBoxBitsPerSample->currentText().toUInt()); - change = true; - } - - if (applyCoherentStokesType) { - obs->setCoherentDataType(stringToStokesType(ui.comboBoxCoherentStokesType->currentText().toStdString())); - change = true; - } - - if (applyIncoherentStokesType) { - obs->setIncoherentDataType(stringToStokesType(ui.comboBoxIncoherentStokesType->currentText().toStdString())); - change = true; - } - - if (applyCoherentIntegration) { - obs->setCoherentTimeIntegration(ui.spinBoxCoherentTimeIntegration->value()); - change = true; - } - - if (applyIncoherentIntegration) { - obs->setIncoherentTimeIntegration(ui.spinBoxIncoherentTimeIntegration->value()); - change = true; - } - - if (applyCoherentChannelsPerSubband) { - obs->setCoherentChannelsPerSubband(ui.spinBoxCoherentChannelsPerSubband->value()); - change = true; - } - - if (applyIncoherentChannelsPerSubband) { - obs->setIncoherentChannelsPerSubband(ui.spinBoxIncoherentChannelsPerSubband->value()); - change = true; - } - - if (applyCoherentSubbandPerFile) { - obs->setCoherentSubbandsPerFile(ui.spinBoxCoherentSubbandsPerFile->value()); - change = true; - } - - if (applyIncoherentSubbandPerFile) { - obs->setIncoherentSubbandsPerFile(ui.spinBoxIncoherentSubbandsPerFile->value()); - change = true; - } - } // end if (*it)->isObservation() - } // end if (*it)->isStationTask() - else if ((*it)->isPipeline()) { - if ((calpipe = dynamic_cast<CalibrationPipeline *>(*it))) { - if (applyCalibrationSkyModel) { - calpipe->setSkyModel(ui.lineEditCalibrationSkyModel->text()); - change = true; - } - - DemixingSettings &demix(calpipe->demixingSettings()); - if (applyDemixAlways) { - demix.setDemixAlways(ui.listWidgetDemixAlways->checkedItemsAsString()); - change = true; - } - - if (applyDemixIfNeeded) { - demix.setDemixIfNeeded(ui.listWidgetDemixIfNeeded->checkedItemsAsString()); - change = true; - } - - if (applyDemixFreqStep) { - demix.setDemixFreqStep((quint16)ui.spinBoxDemixFreqStep->value()); - change = true; - } - - if (applyDemixTimeStep) { - demix.setDemixTimeStep((quint16)ui.spinBoxDemixTimeStep->value()); - change = true; - } - - if (applyAvgFreqStep) { - demix.setAvgFreqStep((quint16)ui.spinBoxAveragingFreqStep->value()); - change = true; - } - - if (applyAvgTimeStep) { - demix.setAvgTimeStep((quint16)ui.spinBoxAveragingTimeStep->value()); - change = true; - } - - if (applyDemixSkyModel) { - demix.setDemixSkyModel(ui.lineEditDemixSkyModel->text()); - change = true; - } - } - - else if ((impipe = dynamic_cast<ImagingPipeline *>(*it))) { - if (applySpecifyFOV) { - impipe->setSpecifyFov(ui.checkBoxSpecifyFOV->isChecked()); - change = true; - } - - if (applyFOV) { - impipe->setFov(ui.lineEditFieldOfView->text().toDouble()); - change = true; - } - - if (applyCellSize) { - impipe->setCellSize(ui.lineEditCellSize->text()); - change = true; - } - - if (applyNrOfPixels) { - impipe->setNrOfPixels((quint16)ui.spinBoxNumberOfPixels->value()); - change = true; - } - - if (applySlicesPerImage) { - impipe->setSlicesPerImage((quint16)ui.spinBoxSlicesPerImage->value()); - change = true; - } - - if (applySubbandsPerImage) { - impipe->setSubbandsPerImage((quint16)ui.spinBoxSubbandsPerImage->value()); - change = true; - } - } - - else if ((pulspipe = dynamic_cast<PulsarPipeline *>(*it))) { - if (applyPulsar_noRFI) { - pulspipe->setNoRFI(ui.checkBox_NoRFI->isChecked()); - change = true; - } - if (applyPulsar_noDSPSR) { - pulspipe->setSkipDspsr(ui.checkBox_No_DSPSR->isChecked()); - change = true; - } - if (applyPulsar_noFold) { - pulspipe->setNoFold(ui.checkBox_No_fold->isChecked()); - change = true; - } - if (applyPulsar_noPDMP) { - pulspipe->setNoPdmp(ui.checkBox_No_pdmp->isChecked()); - change = true; - } - if (applyPulsar_rawTo8Bit) { - pulspipe->setRawTo8Bit(ui.checkBox_RawTo8Bit->isChecked()); - change = true; - } - if (applyPulsar_RRATS) { - pulspipe->setRRATS(ui.checkBox_rrats->isChecked()); - change = true; - } - if (applyPulsar_singlePulse) { - pulspipe->setSinglePulse(ui.checkBox_Single_pulse->isChecked()); - change = true; - } - if (applyPulsar_skipDynamicSpectrum) { - pulspipe->setSkipDynamicSpectrum(ui.checkBox_Skip_dynamic_spectrum->isChecked()); - change = true; - } - if (applyPulsar_skipPrepfold) { - pulspipe->setSkipPrepfold(ui.checkBox_Skip_prepfold->isChecked()); - change = true; - } - if (applyPulsar_twoBf2fitsExtra) { - pulspipe->setTwoBf2fitsExtra(ui.lineEdit2bf2fitsExtraOptions->text()); - } - if (applyPulsar_digifilExtra) { - pulspipe->setDigifilExtra(ui.lineEditDigifilExtraOptions->text()); - } - if (applyPulsar_dspsrExtra) { - pulspipe->setDspsrExtra(ui.lineEditDSPSRextraOptions->text()); - } - if (applyPulsar_prepDataExtra) { - pulspipe->setPrepDataExtra(ui.lineEditPrepdataExtraOptions->text()); - } - if (applyPulsar_prepFoldExtra) { - pulspipe->setPrepFoldExtra(ui.lineEditPrepfoldExtraOptions->text()); - } - if (applyPulsar_prepSubbandExtra) { - pulspipe->setPrepSubbandExtra(ui.lineEditPrepsubbandExtraOptions->text()); - } - if (applyPulsar_PulsarName) { - pulspipe->setPulsarName(ui.lineEditPulsarName->text()); - } - if (applyPulsar_rfiFindExtra) { - pulspipe->setRFIfindExtra(ui.lineEditRfiFindExtraOptions->text()); - } - if (applyPulsar_decodeNblocks) { - pulspipe->setDecodeNblocks(ui.spinBoxDecodeNblocks->value()); - } - if (applyPulsar_decodeSigma) { - pulspipe->setDecodeSigma(ui.spinBoxDecodeSigma->value()); - } - if (applyPulsar_tsubint) { - pulspipe->setTsubInt(ui.spinBoxTsubint->value()); - } - if (applyPulsar_8bitconvSigma) { - pulspipe->setEightBitConversionSigma(ui.doubleSpinBox8BitConversionSigma->value()); - } - if (applyPulsar_dynamicSpectrumAvg) { - pulspipe->setDynamicSpectrumAvg(ui.doubleSpinBoxDynamicSpectrumTimeAverage->value()); - } - if (applyPulsar_rratsDMRange) { - pulspipe->setRratsDmRange(ui.doubleSpinBoxRratsDmRange->value()); - } - } - - else if ((lbpipe = dynamic_cast<LongBaselinePipeline *>(*it))) { - if (applySubbandGroupsPerMS) { - lbpipe->setSubbandGroupsPerMS(ui.spinBoxSubbandGroupsPerMS->value()); - } - if (applySubbandsPerSubbandGroup) { - lbpipe->setSubbandsPerSubbandGroup(ui.spinBoxSubbandsPerSubbandGroup->value()); - } - } - } - - TaskStorage *task_storage((*it)->storage()); - if (task_storage) { - if (applyCorrelated) { - task_storage->setOutputDataProductEnabled(DP_CORRELATED_UV, ui.checkBoxCorrelatedData->isChecked()); - change = true; - } - if (applyCoherent) { - task_storage->setOutputDataProductEnabled(DP_COHERENT_STOKES, ui.checkBoxCoherentStokes->isChecked()); - change = true; - } - if (applyIncoherent) { - task_storage->setOutputDataProductEnabled(DP_INCOHERENT_STOKES, ui.checkBoxIncoherentStokes->isChecked()); - change = true; - } - if (applyStorageSelectMode) { - task_storage->setStorageSelectionMode(static_cast<storage_selection_mode>(ui.comboBoxStorageSelectionMode->currentIndex())); - change = true; - } - - if (itsStorageOverride) { // manual override of storage nodes in multi-edit mode is active - task_storage->setStorage(itsTmpStorage); - change = true; - } - else if (static_cast<storage_selection_mode>(ui.comboBoxStorageSelectionMode->currentIndex()) == STORAGE_MODE_MANUAL) { - getDisplayedStorageLocations(); - if (itsTmpStorage != task_storage->getStorageLocations()) { - task_storage->setStorage(itsTmpStorage); - change = true; - } - } - } - - if (change) { - changesMade |= itsController->updateTask(*it, false); - } - } // END for loop through tasks - if (!changesMade) { - itsController->deleteLastStoredUndo(); - } - itsController->updateStatusBar(); - resetChangeDetection(); - enableApplyButtons(false); - } - return true; -} - -void TaskDialog::setVisibleTabs(const QVector<tabIndex> &tabs) { - ui.tabWidgetMain->clear(); - if (tabs.contains(TAB_SCHEDULE)) ui.tabWidgetMain->insertTab(TAB_SCHEDULE, ui.tab_TaskSettings, tab_names[TAB_SCHEDULE]); - if (tabs.contains(TAB_STATION_SETTINGS)) ui.tabWidgetMain->insertTab(TAB_STATION_SETTINGS, ui.tab_StationSettings, tab_names[TAB_STATION_SETTINGS]); - if (tabs.contains(TAB_STATION_BEAMS)) ui.tabWidgetMain->insertTab(TAB_STATION_BEAMS, ui.tab_StationBeams, tab_names[TAB_STATION_BEAMS]); - if (tabs.contains(TAB_PROCESSING)) ui.tabWidgetMain->insertTab(TAB_PROCESSING, ui.tab_Processing, tab_names[TAB_PROCESSING]); - if (tabs.contains(TAB_STORAGE)) ui.tabWidgetMain->insertTab(TAB_STORAGE, ui.tab_Storage, tab_names[TAB_STORAGE]); - if (tabs.contains(TAB_PIPELINE)) ui.tabWidgetMain->insertTab(TAB_PIPELINE, ui.tab_Pipeline, tab_names[TAB_PIPELINE]); - if (tabs.contains(TAB_PULSAR_PIPELINE)) ui.tabWidgetMain->insertTab(TAB_PULSAR_PIPELINE, ui.tab_PulsarPipeline, tab_names[TAB_PULSAR_PIPELINE]); - if (tabs.contains(TAB_LONGBASELINE_PIPELINE)) ui.tabWidgetMain->insertTab(TAB_LONGBASELINE_PIPELINE, ui.tab_LongBaselinePipeline, tab_names[TAB_LONGBASELINE_PIPELINE]); - if (tabs.contains(TAB_EXTRA_INFO)) ui.tabWidgetMain->insertTab(TAB_EXTRA_INFO, ui.tab_ExtraInfo, tab_names[TAB_EXTRA_INFO]); -} - -void TaskDialog::enableTabs(void) { - // tabs: - // 0 Schedule - // 1 Station settings - // 2 Station beams - // 3 Processing - // 4 Storage - // 5 Pipeline - // 6 Pulsar Pipeline - // 7 Extra Info - setUpdatesEnabled(false); - blockSignals(true); - ui.tabWidgetMain->blockSignals(true); - QVector<tabIndex> tabs; - if (isMultiTasks) { - tabs << TAB_SCHEDULE << TAB_STATION_SETTINGS << TAB_STATION_BEAMS << TAB_PROCESSING << TAB_STORAGE - << TAB_PIPELINE << TAB_PULSAR_PIPELINE << TAB_LONGBASELINE_PIPELINE << TAB_EXTRA_INFO; - } - else { - const Pipeline *pipeline(0); - switch(itsTask->getType()) { - case Task::OBSERVATION: - tabs << TAB_SCHEDULE << TAB_STATION_SETTINGS << TAB_STATION_BEAMS << TAB_PROCESSING << TAB_STORAGE << TAB_EXTRA_INFO; - break; - case Task::RESERVATION: - tabs << TAB_SCHEDULE << TAB_STATION_SETTINGS << TAB_STORAGE << TAB_EXTRA_INFO; - break; - case Task::MAINTENANCE: - tabs << TAB_SCHEDULE << TAB_STATION_SETTINGS << TAB_EXTRA_INFO; - break; - case Task::PIPELINE: - pipeline = dynamic_cast<const Pipeline *>(itsTask); - if (pipeline) { - tabs << TAB_SCHEDULE << TAB_STORAGE; - if (pipeline->isPulsarPipeline()) { - tabs << TAB_PULSAR_PIPELINE; - } - else if (pipeline->isLongBaselinePipeline()) { - tabs << TAB_LONGBASELINE_PIPELINE; - } - else { - tabs << TAB_PIPELINE; - } - } - tabs << TAB_EXTRA_INFO; - break; - case Task::SYSTEM: - tabs << TAB_SCHEDULE << TAB_EXTRA_INFO; - break; - default: // unknown task type enable all tabs - tabs << TAB_SCHEDULE << TAB_STATION_SETTINGS << TAB_STATION_BEAMS << TAB_PROCESSING << TAB_STORAGE - << TAB_PIPELINE << TAB_PULSAR_PIPELINE << TAB_LONGBASELINE_PIPELINE << TAB_EXTRA_INFO; - - break; - } - } - setVisibleTabs(tabs); - - ui.tabWidgetMain->blockSignals(false); - blockSignals(false); - setUpdatesEnabled(true); -} - -void TaskDialog::addTask(unsigned taskID) { - addingTask = true; - blockChangeDetection = true; - addingReservation = false; - delete itsTask; - itsTask = new Observation(taskID); // initializes the internal task object with a clean observation - itsOutputDataTypes.correlated = false; - itsOutputDataTypes.coherentStokes = false; - itsOutputDataTypes.incoherentStokes = false; - itsOutputDataTypes.instrumentModel = false; - itsOutputDataTypes.skyImage = false; - processTypeChanged(0); - ui.comboBoxStorageDataType->clear(); - itsTask->setStatus(Task::PRESCHEDULED); // set the status of newly added tasks in the scheduler directly to PRESCHEDULED - isMultiTasks = false; - ui.pushButtonOk->setEnabled(true); - this->setWindowTitle(QString("Add task ") + QString::number(taskID)); - ui.pushButtonOk->setText("Add"); - - ui.pushButtonApply->hide(); - - setNormalTaskMode(); // enable/disable specific settings - enableTabs(); - - loadReservations(); - setExistingProjects(Controller::theSchedulerSettings.getCampaignList()); - - ui.checkBoxCorrelatedData->setTristate(false); - ui.checkBoxCoherentStokes->setTristate(false); - ui.checkBoxIncoherentStokes->setTristate(false); - ui.checkBox_DelayCompensation->setTristate(false); - ui.checkBox_BandpassCorrection->setTristate(false); - ui.checkBoxPencilFlysEye->setTristate(false); - ui.checkBox_CoherentDedispersion->setTristate(false); - - ui.pushButtonShowDataSlots->setEnabled(false); - - ui.dateEditFirstPossibleDate->setUndefined(false); - ui.timeEditFirstPossibleTime->setUndefined(false); - ui.dateEditLastPossibleDate->setUndefined(false); - ui.timeEditLastPossibleTime->setUndefined(false); - ui.dateTimeEditScheduledStart->setUndefined(false); - ui.dateTimeEditScheduledEnd->setUndefined(false); - - ui.comboBoxTaskStatus->blockSignals(true); - ui.comboBoxTaskStatus->clear(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::SCHEDULED]); - ui.comboBoxTaskStatus->setCurrentIndex(1); // PRESCHEDULED - ui.comboBoxTaskStatus->blockSignals(false); - - ui.lineEditPredecessors->setText(""); - ui.lineEditGroupID->setText(""); - enablePredecessorSettings(false); - - // set project info to "no campaign" - ui.lineEdit_ProjectName->clear(); - ui.lineEdit_ProjectCOI->clear(); - ui.lineEdit_ProjectPI->clear(); - ui.lineEdit_ContactEmail->clear(); - ui.lineEdit_ContactPhone->clear(); - ui.lineEdit_ContactName->clear(); - ui.comboBoxProjectID->setFromString("no campaign"); - ui.lineEditTaskName->clear(); - ui.lineEditTaskDescription->clear(); - ui.lineEditTotalSubbands->clear(); - ui.lineEditTaskID->setText(QString::number(taskID)); - - ui.comboBoxStationClock->setCurrentIndex(0); - - ui.comboBoxStationAntennaMode->blockSignals(true); - ui.comboBoxStationAntennaMode->setCurrentIndex(0); - ui.comboBoxStationAntennaMode->blockSignals(false); - - ui.comboBoxStationFilter->setCurrentIndex(0); - - ui.spinBoxDataslotsPerRSPboard->setValue(MAX_DATASLOT_PER_RSP_16_BITS + 1); - - //stations - loadAvailableStations(); - ui.labelAssignedStations->setText("Assigned stations (0)"); - ui.treeWidgetUsedStations->clear(); - - // processType - itsTask->setProcessType(task_types_str[Task::OBSERVATION]); - itsTask->setProcessSubtype(PST_BEAM_OBSERVATION); - itsTask->setStrategy("default"); - setProcessSubProcessStrategy(itsTask); - - ui.comboBoxProcessType->setEnabled(true); - ui.comboBoxProcessSubType->setEnabled(true); - ui.comboBoxStrategies->setEnabled(true); - - ui.comboBoxProcessType->setToolTip(""); - ui.comboBoxProcessSubType->setToolTip(""); - ui.comboBoxStrategies->setToolTip(""); - - QDateTime startTime = QDateTime::currentDateTime().toUTC(); - startTime = startTime.addSecs(630); // add the task 10.5 minutes from now and round to start at complete minutes - startTime.setTime(QTime(startTime.time().hour(), startTime.time().minute())); - AstroDateTime stime(startTime); - const AstroDate &earliestDay = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - if ((stime < earliestDay) | (stime > Controller::theSchedulerSettings.getLatestSchedulingDay())) { - startTime = QDateTime(QDate(earliestDay.getYear(), earliestDay.getMonth(), earliestDay.getDay()), QTime()); - } - setScheduledStart(startTime); - ui.lineEditDuration->setText("0001:00:00"); - setScheduledEnd(startTime.addSecs(3600)); - - const AstroDate &fdate = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - ui.dateEditFirstPossibleDate->setDate(QDate(fdate.getYear(), fdate.getMonth(), fdate.getDay())); - const AstroDate &ldate = Controller::theSchedulerSettings.getLatestSchedulingDay(); - ui.dateEditLastPossibleDate->setDate(QDate(ldate.getYear(), ldate.getMonth(), ldate.getDay())); - ui.timeEditFirstPossibleTime->setTime(QTime(0,0,0)); - ui.timeEditLastPossibleTime->setTime(QTime(23,59,59)); - - ui.checkBoxFixedDate->setTristate(false); - ui.checkBoxFixedDate->setChecked(false); - ui.checkBoxFixedTime->setTristate(false); - ui.checkBoxFixedTime->setChecked(false); - - ui.lineEditPriority->setText("1.0"); - - // clear analog beam settings - itsAnalogBeamSettings.angle1.setRadianAngle(0.0); - itsAnalogBeamSettings.angle2.setRadianAngle(0.0); - itsAnalogBeamSettings.directionType = DIR_TYPE_J2000; - itsAnalogBeamAnglePair = ANGLE_PAIRS_HMS_DMS; - itsAnalogBeamSettings.duration.clearTime(); - itsAnalogBeamSettings.startTime.clearTime(); - setAnalogBeamSettings(itsAnalogBeamSettings); - - // clear digital beam settings - clearAllDigitalBeams(); - itsDigitalBeams.clear(); - ui.tableWidgetDigitalBeams->clearContents(); - ui.tableWidgetDigitalBeams->setRowCount(0); - ui.pushButtonEditBeam->setText("Edit"); - ui.pushButtonEditBeam->setEnabled(false); - ui.pushButtonAddBeam->setEnabled(true); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - itsDigitalBeamDialog->setReadOnly(false); - - // clear tied array beam setings -// itsTiedArrayBeams.clear(); - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - itsTiedArrayBeamDialog->setReadOnly(false); - - // processing tab default settings - ui.checkBoxCorrelatedData->setChecked(false); - ui.checkBoxCoherentStokes->setChecked(false); - ui.checkBoxIncoherentStokes->setChecked(false); - ui.checkBox_BandpassCorrection->setChecked(true); - ui.checkBox_DelayCompensation->setChecked(true); - ui.checkBox_CoherentDedispersion->setEnabled(false); - ui.checkBox_CoherentDedispersion->setChecked(true); - ui.checkBoxPencilFlysEye->setEnabled(false); - ui.checkBoxPencilFlysEye->setChecked(false); - ui.checkBoxTBBPiggybackAllowed->setChecked(true); - ui.checkBoxAartfaacPiggybackAllowed->setChecked(true); - ui.comboBoxBitsPerSample->setCurrentIndex(2); // 16 bits per sample - ui.comboBoxCoherentStokesType->blockSignals(true); - ui.comboBoxCoherentStokesType->setCurrentIndex(0); // I - type - ui.comboBoxCoherentStokesType->setEnabled(false); - ui.comboBoxCoherentStokesType->blockSignals(false); - ui.comboBoxIncoherentStokesType->blockSignals(true); - ui.comboBoxIncoherentStokesType->setCurrentIndex(0); // I - type - ui.comboBoxIncoherentStokesType->setEnabled(false); - ui.comboBoxIncoherentStokesType->blockSignals(false); - ui.spinBoxCoherentTimeIntegration->blockSignals(true); - ui.spinBoxCoherentTimeIntegration->setValue(1); - ui.spinBoxCoherentTimeIntegration->setEnabled(false); - ui.spinBoxCoherentTimeIntegration->blockSignals(false); - ui.spinBoxIncoherentTimeIntegration->blockSignals(true); - ui.spinBoxIncoherentTimeIntegration->setValue(1); - ui.spinBoxIncoherentTimeIntegration->setEnabled(false); - ui.spinBoxIncoherentTimeIntegration->blockSignals(false); - ui.spinBoxCoherentChannelsPerSubband->blockSignals(true); - ui.spinBoxCoherentChannelsPerSubband->setMinimum(1); - ui.spinBoxCoherentChannelsPerSubband->setValue(1); - ui.spinBoxCoherentChannelsPerSubband->setEnabled(false); - ui.spinBoxCoherentChannelsPerSubband->blockSignals(false); - ui.spinBoxIncoherentChannelsPerSubband->blockSignals(true); - ui.spinBoxIncoherentChannelsPerSubband->setEnabled(false); - ui.spinBoxIncoherentChannelsPerSubband->setMinimum(1); - ui.spinBoxIncoherentChannelsPerSubband->setValue(1); - ui.spinBoxIncoherentChannelsPerSubband->blockSignals(false); - ui.spinBoxCoherentSubbandsPerFile->blockSignals(true); - ui.spinBoxCoherentSubbandsPerFile->setValue(MAX_DATASLOTS_16_BITS); - ui.spinBoxCoherentSubbandsPerFile->setEnabled(false); - ui.spinBoxCoherentSubbandsPerFile->blockSignals(false); - ui.spinBoxIncoherentSubbandsPerFile->blockSignals(true); - ui.spinBoxIncoherentSubbandsPerFile->setValue(MAX_DATASLOTS_16_BITS); - ui.spinBoxIncoherentSubbandsPerFile->setEnabled(false); - ui.spinBoxIncoherentSubbandsPerFile->blockSignals(false); - ui.lineEditCorrelatorIntegrationTime->setText("1.0"); - ui.spinBoxChannelsPerSubband->setValue(64); // defaults to 64 channels per subband - ui.tabWidgetMain->setCurrentWidget(ui.tab_TaskSettings); - - ui.pushButtonOk->setEnabled(true); - ui.pushButtonCancelClose->setText("Cancel"); - ui.pushButtonCancelClose->setEnabled(true); - - // storage - itsTmpStorage.clear(); - updateStorageTree(); - ui.lineEditStorageAssigned->setText("No storage set"); - ui.lineEditStorageAssigned->setPalette(palette()); - ui.treeWidgetInputDataProducts->clear(); - ui.treeWidgetOutputDataProducts->clear(); - ui.comboBoxStorageSelectionMode->setCurrentIndex(1); - this->hide(); - this->setModal(true); - this->showNormal(); - this->raise(); - this->activateWindow(); - blockChangeDetection = true; -} - -/* -void TaskDialog::addReservation(unsigned taskID) { - addingReservation = true; - setReservationTaskMode(); - - if (!itsStationsLoaded) { - loadAvailableStations(); - } - ui.tabWidgetMain->setCurrentWidget(ui.tab_TaskSettings); - - ui.pushButtonApply->hide(); - ui.pushButtonOk->setText("Add"); - ui.pushButtonOk->setEnabled(true); - ui.pushButtonCancelClose->setText("Cancel"); - ui.pushButtonCancelClose->setEnabled(true); - - blockChangeDetection = true; -} -*/ - -void TaskDialog::setReservationTaskMode(void) { - isMultiTasks = false; - - ui.groupBoxAnalogBeam->setEnabled(false); - ui.tab_TaskSettings->setEnabled(true); - ui.tab_ExtraInfo->setEnabled(true); - - ui.comboBoxTaskStatus->clear(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); // PRESCHEDULED - - ui.lineEditPriority->setEnabled(false); - ui.labelPriority->setEnabled(false); - ui.lineEditPredecessors->setEnabled(false); - ui.labelPredecessor->setEnabled(false); - enablePredecessorSettings(false); - ui.dateEditFirstPossibleDate->setEnabled(false); - ui.labelFirstPossibleDate->setEnabled(false); - ui.dateEditLastPossibleDate->setEnabled(false); - ui.labelLastPossibleDate->setEnabled(false); - ui.timeEditFirstPossibleTime->setEnabled(false); - ui.labelFirstPossibleTime->setEnabled(false); - ui.timeEditLastPossibleTime->setEnabled(false); - ui.labelLastPossibleTime->setEnabled(false); - ui.checkBoxFixedDate->setEnabled(false); - ui.checkBoxFixedTime->setEnabled(false); - ui.comboBoxReservation->setEnabled(false); - ui.labelBindToReservation->setEnabled(false); - ui.pushButtonUnBindReservation->setEnabled(false); - - ui.comboBoxStorageSelectionMode->setEnabled(false); - ui.comboBoxStorageDataType->setEnabled(false); - - // tab stations - ui.checkBoxTBBPiggybackAllowed->setEnabled(false); - ui.checkBoxAartfaacPiggybackAllowed->setEnabled(false); - ui.tab_StationSettings->setEnabled(true); - ui.comboBoxStationAntennaMode->setEnabled(true); - ui.comboBoxStationClock->setEnabled(true); - ui.comboBoxStationFilter->setEnabled(true); - ui.listWidgetAvailableStations->setEnabled(true); - ui.treeWidgetUsedStations->setEnabled(true); - ui.pushButtonAddSuperStation->setEnabled(true); -} - -void TaskDialog::setNormalTaskMode(void) { - loadReservations(); - - // tab Schedule - ui.lineEditTaskName->setEnabled(true); - ui.pushButtonUpdateCampaigns->setEnabled(true); - ui.labelTaskName->setEnabled(true); - ui.comboBoxProjectID->setEnabled(true); - ui.labelProjectName->setEnabled(true); - ui.labelDuration->setEnabled(true); - ui.lineEditDuration->setEnabled(true); - ui.dateTimeEditScheduledStart->setEnabled(true); - ui.labelScheduledStart->setEnabled(true); - ui.dateTimeEditScheduledEnd->setEnabled(true); - ui.labelScheduledEnd->setEnabled(true); - ui.lineEditPriority->setEnabled(true); - ui.labelPriority->setEnabled(true); - ui.lineEditGroupID->setEnabled(true); - ui.lineEditPredecessors->setEnabled(true); - ui.lineEditPredecessors->setPalette(QPalette()); // sets the default palette - ui.labelPredecessor->setEnabled(true); - enablePredecessorSettings(true); - ui.dateEditFirstPossibleDate->setEnabled(true); - ui.labelFirstPossibleDate->setEnabled(true); - ui.dateEditLastPossibleDate->setEnabled(true); - ui.labelLastPossibleDate->setEnabled(true); - ui.timeEditFirstPossibleTime->setEnabled(true); - ui.labelFirstPossibleTime->setEnabled(true); - ui.timeEditLastPossibleTime->setEnabled(true); - ui.labelLastPossibleTime->setEnabled(true); - ui.checkBoxFixedDate->setEnabled(true); - ui.checkBoxFixedTime->setEnabled(true); - ui.comboBoxReservation->setEnabled(true); - ui.labelBindToReservation->setEnabled(true); - ui.tab_TaskSettings->setEnabled(true); - ui.groupBoxAnalogBeam->setEnabled(true); - ui.tableWidgetDigitalBeams->setEnabled(true); - ui.comboBoxStorageSelectionMode->setEnabled(true); - ui.comboBoxStorageDataType->setEnabled(true); - // tab stations - ui.checkBoxTBBPiggybackAllowed->setEnabled(true); - ui.checkBoxAartfaacPiggybackAllowed->setEnabled(true); - ui.tab_StationSettings->setEnabled(true); - ui.comboBoxStationAntennaMode->setEnabled(true); - ui.comboBoxStationClock->setEnabled(true); - ui.comboBoxStationFilter->setEnabled(true); - ui.listWidgetAvailableStations->setEnabled(true); - ui.treeWidgetUsedStations->setEnabled(true); - ui.pushButtonAddSuperStation->setEnabled(true); - - ui.tab_Processing->setEnabled(true); - ui.tab_Pipeline->setEnabled(true); -} - -void TaskDialog::setScheduledTaskMode(void) { - // tab Schedule - ui.tab_TaskSettings->setEnabled(true); - ui.comboBoxTaskStatus->setEnabled(true); - ui.lineEditTaskName->setEnabled(false); - ui.pushButtonUpdateCampaigns->setEnabled(false); - ui.labelTaskName->setEnabled(false); - ui.comboBoxProjectID->setEnabled(false); - ui.labelProjectName->setEnabled(false); - ui.labelDuration->setEnabled(false); - ui.lineEditDuration->setEnabled(false); - ui.dateTimeEditScheduledStart->setEnabled(false); - ui.labelScheduledStart->setEnabled(false); - ui.dateTimeEditScheduledEnd->setEnabled(false); - ui.labelScheduledEnd->setEnabled(false); - ui.lineEditPriority->setEnabled(false); - ui.labelPriority->setEnabled(false); - ui.lineEditGroupID->setEnabled(false); - ui.lineEditPredecessors->setEnabled(false); - ui.lineEditPredecessors->setPalette(QPalette()); // sets the default palette - ui.labelPredecessor->setEnabled(false); - enablePredecessorSettings(false); - ui.comboBoxProcessType->setEnabled(false); - ui.comboBoxProcessSubType->setEnabled(false); - ui.comboBoxStrategies->setEnabled(false); - ui.dateEditFirstPossibleDate->setEnabled(false); - ui.labelFirstPossibleDate->setEnabled(false); - ui.dateEditLastPossibleDate->setEnabled(false); - ui.labelLastPossibleDate->setEnabled(false); - ui.timeEditFirstPossibleTime->setEnabled(false); - ui.labelFirstPossibleTime->setEnabled(false); - ui.timeEditLastPossibleTime->setEnabled(false); - ui.labelLastPossibleTime->setEnabled(false); - ui.checkBoxFixedDate->setEnabled(false); - ui.checkBoxFixedTime->setEnabled(false); - ui.comboBoxReservation->setEnabled(false); - ui.labelBindToReservation->setEnabled(true); - ui.pushButtonUnBindReservation->setEnabled(false); - ui.groupBoxAnalogBeam->setEnabled(false); - // tab Station Beams - ui.groupBoxAnalogBeam->setEnabled(false); - itsDigitalBeamDialog->setReadOnly(true); - ui.pushButtonEditBeam->setText("Show"); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - ui.comboBoxStorageSelectionMode->setEnabled(false); - // tab stations - ui.checkBoxTBBPiggybackAllowed->setEnabled(false); - ui.checkBoxAartfaacPiggybackAllowed->setEnabled(false); - - ui.tab_StationSettings->setEnabled(true); - ui.comboBoxStationAntennaMode->setEnabled(false); - ui.comboBoxStationClock->setEnabled(false); - ui.comboBoxStationFilter->setEnabled(false); - ui.listWidgetAvailableStations->setEnabled(false); - ui.treeWidgetUsedStations->setEnabled(false); - ui.pushButtonAddSuperStation->setEnabled(false); - ui.tab_Processing->setEnabled(false); - ui.tab_Pipeline->setEnabled(false); -} - -void TaskDialog::setActiveTaskMode(void) { - // tab Schedule - ui.tab_TaskSettings->setEnabled(true); - ui.comboBoxTaskStatus->setEnabled(true); - ui.lineEditTaskName->setEnabled(false); - ui.pushButtonUpdateCampaigns->setEnabled(false); - ui.labelTaskName->setEnabled(false); - ui.comboBoxProjectID->setEnabled(false); - ui.labelProjectName->setEnabled(false); - ui.labelDuration->setEnabled(false); - ui.lineEditDuration->setEnabled(false); - ui.dateTimeEditScheduledStart->setEnabled(false); - ui.labelScheduledStart->setEnabled(false); - ui.dateTimeEditScheduledEnd->setEnabled(false); - ui.labelScheduledEnd->setEnabled(false); - ui.lineEditPriority->setEnabled(false); - ui.labelPriority->setEnabled(false); - ui.lineEditGroupID->setEnabled(false); - ui.lineEditPredecessors->setEnabled(false); - ui.lineEditPredecessors->setPalette(QPalette()); // sets the default palette - ui.labelPredecessor->setEnabled(false); - enablePredecessorSettings(false); - ui.comboBoxProcessType->setEnabled(false); - ui.comboBoxProcessSubType->setEnabled(false); - ui.comboBoxStrategies->setEnabled(false); - ui.dateEditFirstPossibleDate->setEnabled(false); - ui.labelFirstPossibleDate->setEnabled(false); - ui.dateEditLastPossibleDate->setEnabled(false); - ui.labelLastPossibleDate->setEnabled(false); - ui.timeEditFirstPossibleTime->setEnabled(false); - ui.labelFirstPossibleTime->setEnabled(false); - ui.timeEditLastPossibleTime->setEnabled(false); - ui.labelLastPossibleTime->setEnabled(false); - ui.checkBoxFixedDate->setEnabled(false); - ui.checkBoxFixedTime->setEnabled(false); - ui.comboBoxReservation->setEnabled(false); - ui.labelBindToReservation->setEnabled(true); - ui.groupBoxAnalogBeam->setEnabled(false); - // tab Station Beams - ui.groupBoxAnalogBeam->setEnabled(false); - itsDigitalBeamDialog->setReadOnly(true); - ui.pushButtonEditBeam->setText("Show"); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - ui.comboBoxStorageSelectionMode->setEnabled(false); - // tab stations - ui.tab_StationSettings->setEnabled(false); - ui.tab_Processing->setEnabled(false); - ui.tab_Pipeline->setEnabled(false); -} - -void TaskDialog::setFinishedTaskMode(void) { - ui.lineEditPredecessors->setPalette(QPalette()); // sets the default palette - ui.groupBoxAnalogBeam->setEnabled(false); - ui.comboBoxStorageSelectionMode->setEnabled(false); - ui.tab_TaskSettings->setEnabled(false); - ui.tab_StationSettings->setEnabled(false); - ui.tab_Processing->setEnabled(false); - ui.tab_Pipeline->setEnabled(false); -} - -void TaskDialog::countSelectedStorageLocations(void) { - int count(0); - for (QList<QTreeWidgetItem *>::const_iterator it = itsStorageTreeLocationsItems.begin(); it != itsStorageTreeLocationsItems.end(); ++it) { - if ((*it)->checkState(0) == Qt::Checked) ++count; - } - ui.lineEditAssignedStorageNodes->setText(QString::number(count)); -} - -void TaskDialog::setStorageTreeMixed(bool enableOverride) { - ui.treeWidgetStorageNodes->clear(); - itsStorageTreeLocationsItems.clear(); - QStringList treeText; - ui.treeWidgetStorageNodes->removeAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->removeAction(itsActionStorageUncheckSelected); - ui.treeWidgetStorageNodes->addAction(itsActionStorageOverride); - - if (enableOverride) { - connect(itsActionStorageOverride, SIGNAL(triggered()), this, SLOT(doManualStorageOverride())); - treeText << "MIXED\nRight-click and choose 'Manual override'\nto manual set storage for all selected tasks"; -// ui.treeWidgetStorageNodes->setToolTip("right-click and choose 'Manual override' to manual set storage for all tasks"); - itsActionStorageOverride->setEnabled(true); - } - else { - treeText << "MIXED\nSome tasks are not in the PRESCHEDULED state\nManual override is not possible"; - itsActionStorageOverride->setEnabled(false); -// itsActionStorageOverride->setToolTip("some tasks have status above PRESCHEDULED\nStorage node assignment may only be changed for tasks that have status lower or equal to PRESCHEDULED\nManual override is not possible"); - } - new QTreeWidgetItem(ui.treeWidgetStorageNodes, treeText); - ui.treeWidgetStorageNodes->resizeColumnToContents(0); - ui.lineEditMinNrStorageNodes->clear(); - ui.lineEditAssignedStorageNodes->clear(); -} - -void TaskDialog::doManualStorageOverride(void) { - if (itsActionStorageOverride) { - disconnect(itsActionStorageOverride); - } - ui.treeWidgetStorageNodes->removeAction(itsActionStorageOverride); - ui.treeWidgetStorageNodes->addAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->addAction(itsActionStorageUncheckSelected); -// itsTmpStorage.clear(); - ui.comboBoxStorageSelectionMode->blockSignals(true); - ui.comboBoxStorageSelectionMode->setCurrentIndex(STORAGE_MODE_MANUAL); - ui.comboBoxStorageSelectionMode->blockSignals(false); - setStorageSettings(true); - enableApplyButtons(true); - itsStorageOverride = true; -} - -void TaskDialog::doCheckSelectedStorage(void) { - for (QList<QTreeWidgetItem *>::iterator it = itsStorageTreeLocationsItems.begin(); it != itsStorageTreeLocationsItems.end(); ++it) { - if ((*it)->isSelected()) { - (*it)->setCheckState(0, Qt::Checked); - } - } -} - -void TaskDialog::doUnCheckSelectedStorage(void) { - for (QList<QTreeWidgetItem *>::iterator it = itsStorageTreeLocationsItems.begin(); it != itsStorageTreeLocationsItems.end(); ++it) { - if ((*it)->isSelected()) { - (*it)->setCheckState(0, Qt::Unchecked); - } - } -} - -void TaskDialog::updateStorageTree(void) { - // add the storage nodes info - itsStorageTreeLocationsItems.clear(); - itsStorageTreeNodeItems.clear(); - ui.treeWidgetStorageNodes->clear(); - QTreeWidgetItem *nodeItem, *childItem; - QStringList itemValues; - const hostPartitionsMap &partitions = itsController->getStoragePartitions(); - const storageHostsMap &storageNodes = itsController->getStorageNodes(); // should get the actual status of the storage nodes from the datamonitor class through the controller - const statesMap & states = itsController->getStorageNodesStates(); - hostPartitionsMap::const_iterator pit; - checkStorageSettingsEnable(); - - // ************************************** - // **** FILL THE STORAGE TREE WIDGET **** - // ************************************** - std::string hostName, hostStatus(" (Status unknown)"); - int nodeStatus; - bool enableStorageSelection, enableNode; - storage_selection_mode mode = static_cast<storage_selection_mode>(ui.comboBoxStorageSelectionMode->currentIndex()); - - (mode == STORAGE_MODE_MANUAL) ? enableStorageSelection = true : enableStorageSelection = false; - - statesMap::const_iterator statit; - dataProductTypes displayedDataProduct(getSelectedStorageDataProduct()); - - for (storageHostsMap::const_iterator sit = storageNodes.begin(); sit != storageNodes.end(); ++sit) { - // node name and status - hostName = sit->second.itsName; - nodeStatus = sit->second.itsStatus; - statit = states.find(nodeStatus); - if (statit != states.end()) - hostStatus = " (" + statit->second + ")"; - // node name and status - hostName += hostStatus; - nodeItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(hostName.c_str())); - if (nodeStatus == 0) { // inactive status - nodeItem->setTextColor(0,Qt::red); - } - if (sit->second.itsMayBeUsed) { - enableNode = true; - nodeItem->setFlags(Qt::ItemIsEnabled); - } - else { - nodeItem->setFlags(Qt::NoItemFlags); - enableNode = false; - } - - pit = partitions.find(sit->first); - if (pit != partitions.end()) { - bool checked(false); - for (dataPathsMap::const_iterator dpit = pit->second.begin(); dpit != pit->second.end(); ++dpit) { // loop through raid sets (partitions) - checked = false; - itemValues << "" << dpit->second.first.c_str() /*partition name */ - << humanReadableUnits(dpit->second.second[0], SIZE_UNITS).c_str() /*total space*/ << humanReadableUnits(dpit->second.second[3], SIZE_UNITS).c_str() /*free space*/; - childItem = new QTreeWidgetItem(nodeItem, itemValues); - itemValues.clear(); - - if (enableNode) { - childItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); - } - else { - childItem->setFlags(Qt::ItemIsSelectable); - } - childItem->setData(0,STORAGE_NODE_ID_ROLE,sit->first); // store the storage node ID in the child's data - childItem->setData(1,STORAGE_RAID_ID_ROLE,dpit->first); // store the raid ID in the child's data - itsStorageTreeLocationsItems.append(childItem); - childItem->setDisabled(!enableStorageSelection); - if (nodeStatus == 0) { // inactive status - childItem->setTextColor(1,Qt::red); - childItem->setTextColor(2,Qt::red); - childItem->setTextColor(3,Qt::red); - } - // now check if the current storage location (=childItem) is selected for the task shown - // if so set the check state of the childItem - storageMap::const_iterator stit = itsTmpStorage.find(displayedDataProduct); - if (stit != itsTmpStorage.end()) { - for (storageVector::const_iterator vit = stit->second.begin(); vit != stit->second.end(); ++vit) { - if ((vit->first == sit->first) & (vit->second == dpit->first)) { - childItem->setCheckState(0,Qt::Checked); - checked = true; - break; - } - } - } - if (!checked) { - childItem->setCheckState(0,Qt::Unchecked); - } - - // also go through the the storage check results to see if this partition needs to be marked as conflicting (not enough storage capacity/bandwidth) - // WHY? but only mark the raid arrays as conflicting if the storage was manually chosen, otherwise the storage check results of the task should not be shown. - const TaskStorage *task_storage(itsTask->storage()); - if (task_storage) { - const std::vector<storageResult> &storageCheck = task_storage->getStorageCheckResult(); - for (std::vector<storageResult>::const_iterator scrit = storageCheck.begin(); scrit != storageCheck.end(); ++scrit) { - if (scrit->storageRaidID == sit->first) { - for (short i = 0; i<=3; ++i) { - childItem->setBackgroundColor(i,Qt::red); - childItem->setTextColor(i,Qt::white); - } - if (scrit->conflict == CONFLICT_STORAGE_NODE_SPACE){ - for (short i = 0; i<=3; ++i) { - childItem->setToolTip(i,"At the task's scheduled time there will not be enough free space on this raid array"); - } - } - else if (scrit->conflict == CONFLICT_STORAGE_NODE_BANDWIDTH) { - for (short i = 0; i<=3; ++i) { - childItem->setToolTip(i,"At the task's scheduled time there will not be enough network bandwidth to this raid array"); - } - } - else if (scrit->conflict == CONFLICT_STORAGE_TIME_TOO_EARLY) { - for (short i = 0; i<=3; ++i) { - childItem->setToolTip(i,"This task is scheduled too early (before now)"); - } - } - else if (scrit->conflict == CONFLICT_STORAGE_WRITE_SPEED) { - for (short i = 0; i<=3; ++i) { - childItem->setToolTip(i,"At the task's scheduled time the maximum write speed for this raid set is exceeded"); - } - } - } - else if (sit->first == scrit->storageNodeID) { // the current storage node has a conflict - for (short i = 0; i<=3; ++i) { - nodeItem->setBackgroundColor(i,Qt::red); - nodeItem->setTextColor(i,Qt::white); - } - if (scrit->conflict == CONFLICT_STORAGE_NODE_BANDWIDTH) { - for (short i = 0; i<=3; ++i) { - nodeItem->setToolTip(i,"The total required network bandwidth exceeds the network bandwidth of this storage node"); - } - } - } - } - } - } - } - itsStorageTreeNodeItems.append(nodeItem); - } - ui.treeWidgetStorageNodes->insertTopLevelItems(0, itsStorageTreeNodeItems); - - for (QList<QTreeWidgetItem *>::const_iterator eit = itsStorageTreeNodeItems.begin(); eit != itsStorageTreeNodeItems.end(); ++eit) { - if (!(*eit)->isDisabled()) { - ui.treeWidgetStorageNodes->expandItem(*eit); - } - } - - ui.treeWidgetStorageNodes->header()->resizeSection(0, 150); - ui.treeWidgetStorageNodes->header()->resizeSection(1, 70); - ui.treeWidgetStorageNodes->header()->resizeSection(2, 55); - ui.treeWidgetStorageNodes->header()->resizeSection(3, 55); - - countSelectedStorageLocations(); - - std::map<dataProductTypes, int>::const_iterator minNodesIt(itsMinNrOfRequiredNodes.find(displayedDataProduct)); - if (minNodesIt != itsMinNrOfRequiredNodes.end()) { - ui.lineEditMinNrStorageNodes->setText(QString::number(minNodesIt->second)); - } - else { - ui.lineEditMinNrStorageNodes->setText("0"); - } -} - -// get the displayed storage locations for the data product currently selected by comboBoxStorageDataType and store in tmpStorage -void TaskDialog::getDisplayedStorageLocations(void) { - itsTmpStorage.clear(); - dataProductTypes dp(getSelectedStorageDataProduct()); - countSelectedStorageLocations(); - for (QList<QTreeWidgetItem *>::const_iterator it = itsStorageTreeLocationsItems.begin(); it != itsStorageTreeLocationsItems.end(); ++it) { - if ((*it)->checkState(0) == Qt::Checked) { - itsTmpStorage[dp].push_back(std::pair<int,int>((*it)->data(0,STORAGE_NODE_ID_ROLE).toInt(),(*it)->data(1,STORAGE_RAID_ID_ROLE).toInt())); - } - } -} - -void TaskDialog::disableAnalogBeamSettings(void) { - ui.groupBoxAnalogBeam->setEnabled(false); - ui.comboBoxAnalogBeamUnits->setCurrentIndex(0); - ui.comboBoxAnalogBeamCoordinates->setCurrentIndex(0); - ui.timeEditAnalogBeamStartTime->clear(); - ui.lineEditAnalogBeamDuration->clear(); - ui.lineEditAnalogBeamAngle1->setText(""); - ui.lineEditAnalogBeamAngle2->setText(""); -} - - -// disables or enables the user possibility to check storage locations in the storage locations tree widget -void TaskDialog::setStorageEditable(bool enable) { - if (enable) { - // enable right click actions - ui.treeWidgetStorageNodes->removeAction(itsActionStorageOverride); // remove the right click action from the storage view - ui.treeWidgetStorageNodes->addAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->addAction(itsActionStorageUncheckSelected); - for (QList<QTreeWidgetItem *>::iterator it = itsStorageTreeLocationsItems.begin(); it != itsStorageTreeLocationsItems.end(); ++it) { - (*it)->setDisabled(false); - } - } - else { - // disable all right click actions - ui.treeWidgetStorageNodes->removeAction(itsActionStorageOverride); // remove the right click action from the storage view - ui.treeWidgetStorageNodes->removeAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->removeAction(itsActionStorageUncheckSelected); - ui.treeWidgetStorageNodes->setBackgroundRole(QPalette::Dark); - for (QList<QTreeWidgetItem *>::iterator it = itsStorageTreeLocationsItems.begin(); it != itsStorageTreeLocationsItems.end(); ++it) { - (*it)->setDisabled(true); - } - } -} - -void TaskDialog::setStations(const StationTask *task) { - ui.listWidgetAvailableStations->clearSelection(); // also clear selection from available stations - ui.treeWidgetUsedStations->clear(); - const taskStationsMap &stations = task->getStations(); - taskStationsMap::const_iterator stationMappingit; - std::vector<unsigned>::const_iterator stationIDit; - std::vector<unsigned> addedStations; - - if (task->isObservation()) { - const superStationMap &superStations = static_cast<const Observation *>(task)->getSuperStations(); - // now iterate over the super stations that have to be added - superStationMap::const_iterator it = superStations.begin(); - while (it != superStations.end()) { - QTreeWidgetItem * superStation = ui.treeWidgetUsedStations->addSuperStation(); - stationIDit = it->second.begin(); // iterate over the station IDs that have to be added to this superstation - while (stationIDit != it->second.end()) { - stationMappingit = stations.begin(); - while (stationMappingit != stations.end()) { - if (stationMappingit->second == *stationIDit) { // found the station in the station name - id map - QTreeWidgetItem * stationItem = new QTreeWidgetItem(superStation, QStringList(stationMappingit->first.c_str())); // add the station item (by name) to this superstation - ui.listWidgetAvailableStations->removeStation(stationMappingit->first.c_str()); // also remove the station from the list of available stations - stationItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled); - addedStations.push_back(*stationIDit); // remember the stations that have been added - ++stationIDit; // goto next station that has to be added to this superstation - break; - } - ++stationMappingit; // increase station mapping search iterator - } - } - ++it; // next superstation - } - } - - stationMappingit = stations.begin(); - QStringList usedStations; - while (stationMappingit != stations.end()) { // add the stations that have not already been added as part of a superstation - if (std::find(addedStations.begin(), addedStations.end(), stationMappingit->second) == addedStations.end()) { - usedStations.append(stationMappingit->first.c_str()); - // remove the station from the available station list - ui.listWidgetAvailableStations->removeStation(stationMappingit->first.c_str()); - } - ++stationMappingit; - } - ui.treeWidgetUsedStations->addStations(usedStations); - ui.treeWidgetUsedStations->resetHasChangedFlag(); -} - -/* -void TaskDialog::showStorageConflict(const QString &conflictText) { - ui.lineEditStorageConflict->setText(conflictText); - ui.lineEditStorageConflict->show(); - ui.checkBox_AutomaticSelectionStorageNodes->setEnabled(false); - ui.treeWidgetStorageNodes->setEnabled(false); -} -*/ - - -void TaskDialog::clearDemixAlways(void) { - const QStringList &demixSources(Controller::theSchedulerSettings.getDemixSources()); - ui.listWidgetDemixAlways->addItems(demixSources); -} - -void TaskDialog::clearDemixIfNeeded(void) { - const QStringList &demixSources(Controller::theSchedulerSettings.getDemixSources()); - ui.listWidgetDemixIfNeeded->addItems(demixSources); -} -/* -void TaskDialog::disableAveragingSettings(void) { - ui.spinBoxAveragingFreqStep->clear(); - ui.spinBoxAveragingTimeStep->clear(); - ui.groupBoxAveraging->setEnabled(false); -} - -void TaskDialog::setAveragingSettings(const Pipeline *pTask) { - if (pTask) { - const DemixingSettings &demixing(pTask->getDemixingSettings()); - ui.spinBoxAveragingFreqStep->setValue(demixing.freqStep); - ui.spinBoxAveragingTimeStep->setValue(demixing.timeStep); - } - else { - ui.spinBoxAveragingFreqStep->setValue(1); - ui.spinBoxAveragingTimeStep->setValue(1); - } - ui.groupBoxAveraging->setEnabled(true); -} -*/ - -void TaskDialog::disableDemixSettings(void) { - ui.listWidgetDemixAlways->clear(); - ui.listWidgetDemixIfNeeded->clear(); - ui.lineEditDemixSkyModel->clear(); - ui.spinBoxDemixFreqStep->clear(); - ui.spinBoxDemixTimeStep->clear(); - ui.spinBoxAveragingFreqStep->clear(); - ui.spinBoxAveragingTimeStep->clear(); - ui.groupBoxDemixing->setEnabled(false); - ui.groupBoxAveraging->setEnabled(false); -} - -void TaskDialog::setDemixSettings(const DemixingSettings &demixing) { - ui.listWidgetDemixAlways->blockSignals(true); - ui.listWidgetDemixIfNeeded->blockSignals(true); - ui.listWidgetDemixIfNeeded->blockSignals(true); - ui.lineEditDemixSkyModel->blockSignals(true); - ui.spinBoxDemixFreqStep->blockSignals(true); - ui.spinBoxDemixTimeStep->blockSignals(true); - ui.spinBoxAveragingFreqStep->blockSignals(true); - ui.spinBoxAveragingTimeStep->blockSignals(true); - - ui.listWidgetDemixAlways->clear(); - ui.listWidgetDemixIfNeeded->clear(); - const QStringList &demixSources(Controller::theSchedulerSettings.getDemixSources()); - QStringList demixAlwaysChecked, demixIfNeededChecked; - demixAlwaysChecked = demixing.demixAlways().split(','); - demixIfNeededChecked = demixing.demixIfNeeded().split(','); - ui.lineEditDemixSkyModel->setText(demixing.skyModel()); - ui.spinBoxDemixFreqStep->setValue(demixing.demixFreqStep()); - ui.spinBoxDemixTimeStep->setValue(demixing.demixTimeStep()); - ui.spinBoxAveragingFreqStep->setValue(demixing.freqStep()); - ui.spinBoxAveragingTimeStep->setValue(demixing.timeStep()); - ui.listWidgetDemixAlways->addItems(demixSources, demixAlwaysChecked); - ui.listWidgetDemixIfNeeded->addItems(demixSources, demixIfNeededChecked); - ui.groupBoxDemixing->setEnabled(true); - ui.groupBoxAveraging->setEnabled(true); - - ui.listWidgetDemixAlways->blockSignals(false); - ui.listWidgetDemixIfNeeded->blockSignals(false); - ui.listWidgetDemixIfNeeded->blockSignals(false); - ui.lineEditDemixSkyModel->blockSignals(false); - ui.spinBoxDemixFreqStep->blockSignals(false); - ui.spinBoxDemixTimeStep->blockSignals(false); - ui.spinBoxAveragingFreqStep->blockSignals(false); - ui.spinBoxAveragingTimeStep->blockSignals(false); -} - -void TaskDialog::setCalibrationPipelineSettings(const CalibrationPipeline *pTask) { - ui.lineEditCalibrationSkyModel->setText(pTask->skyModel()); - ui.groupBoxCalibration->setEnabled(true); -} - -void TaskDialog::disableCalibrationPipelineSettings(void) { - ui.lineEditCalibrationSkyModel->clear(); - ui.groupBoxCalibration->setEnabled(false); -} - -void TaskDialog::disableImagingPipelineSettings(void) { - ui.spinBoxSubbandsPerImage->clear(); - ui.spinBoxSlicesPerImage->clear(); - ui.spinBoxNumberOfPixels->clear(); - ui.lineEditFieldOfView->clear(); - ui.lineEditCellSize->clear(); - ui.groupBoxImaging->setEnabled(false); -} - -void TaskDialog::setImagingPipelineSettings(const ImagingPipeline *pPipe) { - ui.spinBoxSubbandsPerImage->setValue(pPipe->subbandsPerImage()); - ui.spinBoxSlicesPerImage->setValue(pPipe->slicesPerImage()); - ui.checkBoxSpecifyFOV->setTristate(false); - ui.checkBoxSpecifyFOV->setChecked(pPipe->specifyFov()); - ui.lineEditFieldOfView->setText(QString::number(pPipe->fov(),'g',10)); - ui.spinBoxNumberOfPixels->setValue(pPipe->nrOfPixels()); - ui.lineEditCellSize->setText(pPipe->cellSize()); - ui.groupBoxImaging->setEnabled(true); -} - -void TaskDialog::setLongBaselinePipelineSettings(const LongBaselinePipeline *lbpipe) { - ui.spinBoxSubbandGroupsPerMS->setValue(lbpipe->subbandGroupsPerMS()); - ui.spinBoxSubbandsPerSubbandGroup->setValue(lbpipe->subbandsPerSubbandGroup()); -} - -void TaskDialog::setPulsarPipelineSettings(const PulsarPipeline *pPipe) { - ui.checkBox_NoRFI->setChecked(pPipe->noRFI()); - ui.checkBox_No_DSPSR->setChecked(pPipe->skipDspsr()); - ui.checkBox_No_fold->setChecked(pPipe->noFold()); - ui.checkBox_No_pdmp->setChecked(pPipe->noPdmp()); - ui.checkBox_RawTo8Bit->setChecked(pPipe->rawTo8Bit()); - ui.checkBox_rrats->setChecked(pPipe->rrats()); - ui.checkBox_Single_pulse->setChecked(pPipe->singlePulse()); - ui.checkBox_Skip_dynamic_spectrum->setChecked(pPipe->skipDynamicSpectrum()); - ui.checkBox_Skip_prepfold->setChecked(pPipe->skipPrepfold()); - ui.lineEdit2bf2fitsExtraOptions->setText(pPipe->twoBf2fitsExtra()); - ui.lineEditDigifilExtraOptions->setText(pPipe->digifilExtra()); - ui.lineEditDSPSRextraOptions->setText(pPipe->dspsrExtra()); - ui.lineEditPrepdataExtraOptions->setText(pPipe->prepDataExtra()); - ui.lineEditPrepfoldExtraOptions->setText(pPipe->prepFoldExtra()); - ui.lineEditPrepsubbandExtraOptions->setText(pPipe->prepSubbandExtra()); - ui.lineEditPulsarName->setText(pPipe->pulsarName()); - ui.lineEditRfiFindExtraOptions->setText(pPipe->rfiFindExtra()); - ui.spinBoxDecodeNblocks->setValue(pPipe->decodeNblocks()); - ui.spinBoxDecodeSigma->setValue(pPipe->decodeSigma()); - ui.spinBoxTsubint->setValue(pPipe->tsubInt()); - ui.doubleSpinBox8BitConversionSigma->setValue(pPipe->eightBitConversionSigma()); - ui.doubleSpinBoxDynamicSpectrumTimeAverage->setValue(pPipe->dynamicSpectrumAvg()); - ui.doubleSpinBoxRratsDmRange->setValue(pPipe->rratsDmRange()); -} - -bool TaskDialog::askForApplyChanges(void) { - QApplication::beep(); - QMessageBox questionBox(this); - questionBox.setWindowTitle(tr("Changes made to task")); - questionBox.setText(tr("Changes were made to this task, do you want to apply these changes?")); - questionBox.setIcon(QMessageBox::Question); - QAbstractButton *applyButton = questionBox.addButton(tr("Apply"), QMessageBox::ApplyRole); - QAbstractButton *discardButton = questionBox.addButton(tr("Discard"), QMessageBox::RejectRole); - questionBox.addButton(tr("Cancel"), QMessageBox::NoRole); - questionBox.exec(); - if (questionBox.clickedButton() == applyButton) { - if (itsTask->isReservation() || itsTask->isMaintenance()) { - if (!commitReservation(NOSTORE)) { - return false; - } - } - else { - if (!commitChanges(NOSTORE)) { - return false; - } - } - } - else if (questionBox.clickedButton() == discardButton) { - resetChangeDetection(); - } - else return false; // Cancel was clicked -> return false - return true; -} - -void TaskDialog::clearMultiTasks(void) { - for (std::vector<Task *>::iterator it = itsMultiTasks.begin(); it != itsMultiTasks.end(); ++it) { - delete *it; - } - itsMultiTasks.clear(); -} - -void TaskDialog::show(const Task *task, tabIndex tab) { - const AstroDate &edate = Controller::theSchedulerSettings.getEarliestSchedulingDay(); - QDate earliestDate(edate.getYear(), edate.getMonth(), edate.getDay()); - const AstroDate &ldate = Controller::theSchedulerSettings.getLatestSchedulingDay(); - QDate latestDate(ldate.getYear(), ldate.getMonth(), ldate.getDay()); - QString multipleStr(MULTIPLE_VALUE_TEXT); - - isMultiTasks = false; - itsDataSlotDialog.clear(); - clearMultiTasks(); // clear the vector of task pointers used for multi-edit of tasks. Clearing is done here to make sure no old pointers are left dangling - - if (this->isVisible() && ifSettingsChanged()) { - if (!askForApplyChanges()) return; - } - this->blockSignals(true); - blockChangeDetection = true; - addingTask = false; - addingReservation = false; - addingPipeline = false; - - // common properties both for reservations as for regular tasks - ui.pushButtonApply->show(); - enableApplyButtons(false); - - setExistingProjects(Controller::theSchedulerSettings.getCampaignList()); - - ui.pushButtonOk->setText("Ok"); - - if (task) { // here only properties that have to be set for both reservations and regular tasks! - Task::task_status status = task->getStatus(); - delete itsTask; - itsTask = cloneTask(task); // create an exact copy of the supplied task shown - enableTabs(); // enable/disable the correct tabs depending on itsTask type - const TaskStorage *task_storage(task->storage()); - if (task_storage) { - itsOutputDataTypes = task_storage->getOutputDataProductsEnabled(); - itsTmpStorage = task_storage->getStorageLocations(); - ui.comboBoxStorageSelectionMode->setCurrentIndex(task_storage->getStorageSelectionMode()); - } - ui.lineEdit_ProjectName->setText(task->getProjectName()); - ui.lineEdit_ProjectCOI->setText(task->getProjectCO_I()); - ui.comboBoxProjectID->setFromString(task->getProjectID()); - ui.lineEditSASID->setText(QString::number(task->getSASTreeID())); - ui.lineEditGroupID->setText(QString::number(task->getGroupID())); - - ui.lineEditCreationDate->setText(task->SASTree().creationDate().toString().c_str()); - ui.lineEditModificationDate->setText(task->SASTree().modificationDate().toString().c_str()); - - ui.lineEdit_ProjectPI->setText(task->getProjectPI()); - ui.lineEditTaskName->setText(task->getTaskName()); - // contact details - ui.lineEdit_ContactName->setText(task->getContactName()); - ui.lineEdit_ContactPhone->setText(task->getContactPhone()); - ui.lineEdit_ContactEmail->setText(task->getContactEmail()); - - ui.lineEditTaskDescription->setText(task->SASTree().description().c_str()); - - ui.lineEditTaskID->setText(QString::number(task->getID())); - - // earliest and latest scheduling dates - ui.dateEditFirstPossibleDate->blockSignals(true); - ui.dateEditLastPossibleDate->blockSignals(true); - ui.dateEditFirstPossibleDate->setMinimumDate(earliestDate); - ui.dateEditFirstPossibleDate->setMaximumDate(latestDate); - ui.dateEditLastPossibleDate->setMinimumDate(earliestDate); - ui.dateEditLastPossibleDate->setMaximumDate(latestDate); - ui.dateEditFirstPossibleDate->blockSignals(false); - ui.dateEditLastPossibleDate->blockSignals(false); - - // scheduled start and end - // ui.dateTimeEditScheduledStart->setMaximumDate(latestDate); - ui.dateTimeEditScheduledEnd->setMinimumDate(earliestDate); - // ui.dateTimeEditScheduledEnd->setMaximumDate(latestDate); - const AstroDateTime &sd = task->getScheduledStart(); - ui.dateTimeEditScheduledStart->blockSignals(true); // prevents automatic update - if (sd.isSet()) { - QDate sdate(sd.getYear(), sd.getMonth(), sd.getDay()); - QTime stime(sd.getHours(), sd.getMinutes(), sd.getSeconds()); - if (task->isObservation()) { - unsigned reservation_id(static_cast<const Observation *>(task)->getReservation()); - if (reservation_id) { - const Task* reservation(itsController->getTask(reservation_id)); - if (reservation) { - AstroDateTime rd(reservation->getScheduledStart()); - ui.dateTimeEditScheduledStart->setMinimumDateTime(QDateTime(QDate(rd.getYear(),rd.getMonth(),rd.getDay()), QTime(rd.getHours(),rd.getMinutes(),rd.getSeconds()))); - } - else ui.dateTimeEditScheduledStart->setMinimumDate(earliestDate); - } - else { - ui.dateTimeEditScheduledStart->setMinimumDate(earliestDate); - } - } - else { - ui.dateTimeEditScheduledStart->setMinimumDate(earliestDate); - } - ui.dateTimeEditScheduledStart->setDateTime(QDateTime(sdate, stime)); - } - else { - ui.dateTimeEditScheduledStart->setNotSetValue(); - } - ui.dateTimeEditScheduledStart->blockSignals(false); - - const AstroDateTime &enddate = task->getScheduledEnd(); - if (enddate.isSet()) { - QDate ed(enddate.getYear(), enddate.getMonth(), enddate.getDay()); - QTime et(enddate.getHours(), enddate.getMinutes(), enddate.getSeconds()); - setScheduledEnd(QDateTime(ed, et)); - } - else { - ui.dateTimeEditScheduledEnd->blockSignals(true); // prevents automatic update - ui.dateTimeEditScheduledEnd->setNotSetValue(); - ui.dateTimeEditScheduledEnd->blockSignals(false); - } - // duration - ui.lineEditDuration->blockSignals(true); // have to block signals to prevent scheduled end from being updated. Scheduled end would be displayed incorrectly the first time - ui.lineEditDuration->setText(task->getDuration().toString()); - ui.lineEditDuration->blockSignals(false); - - // fixed day and time - ui.checkBoxFixedDate->setTristate(false); - ui.checkBoxFixedDate->setChecked(task->getFixedDay()); - ui.checkBoxFixedTime->setTristate(false); - ui.checkBoxFixedTime->setChecked(task->getFixedTime()); - - setProcessSubProcessStrategy(task); - - ui.lineEditOriginalTreeID->setText(QString::number(task->getOriginalTreeID())); - // disable the possibility to change the task its processType, processSubtype and strategy if it is already created in SAS - if (task->getSASTreeID()) { - ui.comboBoxProcessType->setEnabled(false); - ui.comboBoxProcessSubType->setEnabled(false); - ui.comboBoxStrategies->setEnabled(false); - QString tt(tr("This task is already created in SAS.\nIts processType, processSubType and strategy cannot be changed anymore")); - ui.comboBoxProcessType->setToolTip(tt); - ui.comboBoxProcessSubType->setToolTip(tt); - ui.comboBoxStrategies->setToolTip(tt); - } - else { - ui.comboBoxProcessType->setEnabled(true); - ui.comboBoxProcessSubType->setEnabled(true); - ui.comboBoxStrategies->setEnabled(true); - ui.comboBoxProcessType->setToolTip(""); - ui.comboBoxProcessSubType->setToolTip(""); - ui.comboBoxStrategies->setToolTip(""); - } - - // predecessor - if (task->hasPredecessors()) { - ui.lineEditPredecessors->setText(task->getPredecessorsString()); - ui.lineEditMinPredDistance->setText(task->getPredecessorMinTimeDif().toString()); - ui.lineEditMaxPredDistance->setText(task->getPredecessorMaxTimeDif().toString()); - } - else { - ui.lineEditPredecessors->setPalette(QPalette()); // sets the default palette - ui.lineEditPredecessors->setText(""); - ui.lineEditMinPredDistance->setText(""); - ui.lineEditMaxPredDistance->setText(""); - enablePredecessorSettings(false); - } - - const AstroDate &fdate = task->getWindowFirstDay(); - if (fdate.isSet()) { - ui.dateEditFirstPossibleDate->setDate(QDate(fdate.getYear(), fdate.getMonth(), fdate.getDay())); - } - else { - ui.dateEditFirstPossibleDate->setDate(earliestDate); - } - const AstroDate &ldate = task->getWindowLastDay(); - if (ldate.isSet()) { - ui.dateEditLastPossibleDate->setDate(QDate(ldate.getYear(), ldate.getMonth(), ldate.getDay())); - } - else { - ui.dateEditLastPossibleDate->setDate(latestDate); - } - const AstroTime &ftime = task->getWindowMinTime(); - ui.timeEditFirstPossibleTime->setTime(QTime(ftime.getHours(), ftime.getMinutes(), ftime.getSeconds())); - const AstroTime <ime = task->getWindowMaxTime(); - ui.timeEditLastPossibleTime->setTime(QTime(ltime.getHours(), ltime.getMinutes(), ltime.getSeconds())); - // priority - ui.lineEditPriority->setInputMask("00.00;"); - ui.lineEditPriority->setText(QString::number(task->getPriority())); - - // settings for tasks running on stations (i.e. StationTask) - const StationTask *statTask = dynamic_cast<const StationTask *>(task); - if (statTask) { - // load available stations - loadAvailableStations(); - ui.comboBoxStationAntennaMode->blockSignals(true); - ui.comboBoxStationClock->blockSignals(true); - ui.comboBoxStationFilter->blockSignals(true); - ui.comboBoxStationAntennaMode->setCurrentIndex(statTask->getAntennaMode()); - - if (ui.comboBoxStationClock->itemText(ui.comboBoxStationClock->count()-1).compare(multipleStr) == 0) { - ui.comboBoxStationClock->removeItem(ui.comboBoxStationClock->count()-1); - } - ui.comboBoxStationClock->setCurrentIndex(statTask->getStationClock()); - - if (ui.comboBoxStationFilter->itemText(ui.comboBoxStationFilter->count()-1).compare(multipleStr) == 0) { - ui.comboBoxStationFilter->removeItem(ui.comboBoxStationFilter->count()-1); - } - ui.comboBoxStationFilter->setCurrentIndex(statTask->getFilterType()); - ui.comboBoxStationAntennaMode->blockSignals(false); - ui.comboBoxStationClock->blockSignals(false); - ui.comboBoxStationFilter->blockSignals(false); - - //stations - setStations(statTask); - ui.labelAssignedStations->setText("Assigned stations (" + QString::number(countStations()) + ")"); - - const Observation *obs = dynamic_cast<const Observation *>(statTask); - if (obs) { - this->setWindowTitle(QString("Observation ") + QString::number(obs->getID()) + " '" + obs->getTaskName() + "'"); - - loadReservations(); // loads all defined reservation tasks into the reservation selection puldown box - - itsDataSlotDialog.loadData(obs->getDataSlots()); - - ui.checkBoxTBBPiggybackAllowed->blockSignals(true); - ui.checkBoxTBBPiggybackAllowed->setChecked(obs->getTBBPiggybackAllowed()); - ui.checkBoxTBBPiggybackAllowed->blockSignals(false); - ui.checkBoxAartfaacPiggybackAllowed->blockSignals(true); - ui.checkBoxAartfaacPiggybackAllowed->setChecked(obs->getAartfaacPiggybackAllowed()); - ui.checkBoxAartfaacPiggybackAllowed->blockSignals(false); - // RTCP settings (have to be set correctly before setStorage is called) - setRTCPSettings(obs->getRTCPsettings()); - checkEnableDataTypeSettings(); - - itsDataSlotDialog.loadData(obs->getDataSlots()); - ui.pushButtonShowDataSlots->setEnabled(true); - - // digital and pencil beams - ui.tableWidgetDigitalBeams->setToolTip("This task's digital station beams"); - setDigitalBeamSettings(obs); - itsTempDigitalBeams = obs->getDigitalBeams(); // for change detection - checkEnableBeamButtons(); - // NrDataslotsPerRSPboard - ui.spinBoxDataslotsPerRSPboard->setValue(obs->getNrOfDataslotsPerRSPboard()); - // analog beam settings - if (QString(obs->getAntennaModeStr()).startsWith("LBA")) { - disableAnalogBeamSettings(); - } - else { - if (status < Task::STARTING) { - ui.groupBoxAnalogBeam->setEnabled(true); - } - const Observation::analogBeamSettings &beamSettings = obs->getAnalogBeam(); - if (beamSettings.directionType == DIR_TYPE_J2000) - itsAnalogBeamAnglePair = ANGLE_PAIRS_HMS_DMS; - else - itsAnalogBeamAnglePair = ANGLE_PAIRS_RADIANS; - setAnalogBeamSettings(beamSettings); - } - itsTempAnalogBeamSettings = getAnalogBeamSettings(); // itsTempAnalogBeamSettings is used for change detection - - } - // properties specific for reservations - else if (task->isReservation() || task->isMaintenance()) { // is this a reservation/maintenance task that has to be shown? - if (task->isReservation()) { - this->setWindowTitle(QString("Reservation ") + QString::number(task->getID()) + " '" + task->getTaskName() + "'"); - } - else { // Maintenance - this->setWindowTitle(QString("Maintenance ") + QString::number(task->getID()) + " '" + task->getTaskName() + "'"); - } - setReservationTaskMode(); - // load status options for reservation and maintenance tasks - ui.comboBoxTaskStatus->clear(); - ui.lineEditPredecessors->setPalette(QPalette()); // sets the default palette - ui.lineEditPredecessors->setText(""); - ui.lineEditMinPredDistance->setText(""); - ui.lineEditMaxPredDistance->setText(""); - enablePredecessorSettings(false); - if (status == Task::ERROR) { - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ERROR]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - if (status == Task::CONFLICT) { - ui.comboBoxTaskStatus->addItem(task_states_str[Task::CONFLICT]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - else { - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - if (status == Task::PRESCHEDULED) { - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - else { - ui.comboBoxTaskStatus->setCurrentIndex(1); - } - } - } - ui.treeWidgetInputDataProducts->clear(); - } - else if (task->isPipeline()) { - this->setWindowTitle(QString("Pipeline ") + QString::number(task->getID()) + " '" + task->getTaskName() + "'"); - setPipelineProperties(); - } - - // set the possible statusses for all task types (except reservations and maintenance) - if (!(task->isReservation() || task->isMaintenance())) { - // task status combo box - ui.comboBoxTaskStatus->blockSignals(true); - ui.comboBoxTaskStatus->clear(); - switch (status) { - case Task::ERROR: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ERROR]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::SCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - break; - case Task::COMPLETING: - case Task::FINISHED: - case Task::ABORTED: - setFinishedTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[status]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - break; - case Task::CONFLICT: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::CONFLICT]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - break; - case Task::UNSCHEDULED: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - break; - case Task::PRESCHEDULED: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::SCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(1); - break; - case Task::SCHEDULED: - setScheduledTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::SCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(2); - break; - case Task::ACTIVE: - setActiveTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ACTIVE]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ABORTED]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - break; - case Task::STARTING: - setActiveTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::STARTING]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ABORTED]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - break; - case Task::ON_HOLD: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(2); - break; - case Task::OBSOLETE: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::OBSOLETE]); - ui.comboBoxTaskStatus->setCurrentIndex(3); - break; - default: - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[status]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - ui.comboBoxTaskStatus->blockSignals(false); - } - - // storage properties - updateStorageTab(); - setStorageSettings(true); - checkStorageSettingsEnable(); - } - - - StoreValues(); - - ui.treeWidgetStorageNodes->removeAction(itsActionStorageOverride); // remove the right click action from the storage view - ui.treeWidgetStorageNodes->removeAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->removeAction(itsActionStorageUncheckSelected); - if (static_cast<storage_selection_mode>(ui.comboBoxStorageSelectionMode->currentIndex()) == STORAGE_MODE_MANUAL) { - ui.treeWidgetStorageNodes->addAction(itsActionStorageCheckSelected); - ui.treeWidgetStorageNodes->addAction(itsActionStorageUncheckSelected); - } - - setCurrentTab(tab); - this->blockSignals(false); - this->hide(); - this->setModal(false); - this->showNormal(); - this->raise(); - this->activateWindow(); - blockChangeDetection = false; -} - -void TaskDialog::setCurrentTab(tabIndex tab) { - switch (tab) { - default: - case TAB_SCHEDULE: - ui.tabWidgetMain->setCurrentWidget(ui.tab_TaskSettings); - return; - case TAB_STATION_SETTINGS: - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationSettings); - return; - case TAB_STATION_BEAMS: - ui.tabWidgetMain->setCurrentWidget(ui.tab_StationBeams); - return; - case TAB_PROCESSING: - ui.tabWidgetMain->setCurrentWidget(ui.tab_Processing); - return; - case TAB_STORAGE: - ui.tabWidgetMain->setCurrentWidget(ui.tab_Storage); - return; - case TAB_PIPELINE: - ui.tabWidgetMain->setCurrentWidget(ui.tab_Pipeline); - return; - } -} - -// make copies of the original supplied tasks -// make changes in the copies -// then for each task notify the controller that the task has changed so it can take the necessary actions and update the GUI -// reservation tasks cannot be multi-edited, these are already filtered out by the controller -void TaskDialog::showMultiEdit(std::vector<Task *> &tasks) { - itsStorageOverride = false; - blockChangeDetection = true; - blockSignals(true); - ui.checkBoxCorrelatedData->blockSignals(true); - ui.checkBoxCoherentStokes->blockSignals(true); - ui.checkBoxIncoherentStokes->blockSignals(true); - addingTask = false; - addingReservation = false; - isMultiTasks = true; - enableTabs(); - - // SW-933 - clearMultiTasks(); - - itsDataSlotDialog.clear(); - - ui.lineEditCreationDate->clear(); - ui.lineEditModificationDate->clear(); - - ui.lineEditStorageConflict->hide(); - QString multipleStr(MULTIPLE_VALUE_TEXT); - - ui.groupBoxCalibration->setEnabled(true); - ui.groupBoxDemixing->setEnabled(true); - ui.groupBoxAveraging->setEnabled(true); - ui.groupBoxImaging->setEnabled(true); - ui.groupBoxDigitalBeams->setEnabled(false); // multi-edit of digital beams not possible - ui.tableWidgetDigitalBeams->setToolTip("Digital beams cannot be multi-edited"); - ui.tableWidgetDigitalBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->clearContents(); - - this->setWindowTitle("Multi-edit tasks"); - if (!tasks.empty()) { -// connect(this,SIGNAL(QApplication::focusChanged (QWidget *, QWidget *)),this,SLOT(focusCheck(QWidget *, QWidget *))); - // make copies of the original tasks (used when changes are applied to these tasks) - for (std::vector<Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - itsMultiTasks.push_back(cloneTask(*it)); - } - - if (this->isVisible() && ifSettingsChanged()) { - if (!askForApplyChanges()) return; - } - - - // load available stations - loadAvailableStations(); - // update project combobox - setExistingProjects(Controller::theSchedulerSettings.getCampaignList()); - - bool difProcessType(false), difProcessSubtype(false), difStrategy(false), difStatus(false), difProjectID(false), difTaskName(false), difContactName(false), - difGroupID(false), difContactPhone(false), difContactEmail(false), difTaskDescription(false), - difFirstPossibleDate(false), difWindowMinTime(false), difLastPossibleDate(false), difWindowMaxTime(false), - difScheduledStart(false), difScheduledEnd(false), difReservation(false), - difDuration(false), difAntennaMode(false), difStationClock(false), difFilterType(false), - difPriority(false), difNrDataSlotsPerRSP(false), difTBBpiggyback(false), difAartfaacPiggyback(false), difoutputCorrelated(false), - difOutputCoherentStokes(false), difOutputIncoherentStokes(false), - difFixedDay(false), difFixedTime(false), difPredecessor(false), difpredMinTimeDif(false), difpredMaxTimeDif(false), - difStations(false), difDelayCompensation(false), difCorrectBandPass(false), /*difDigitalBeams(false),*/ - difAnalogAngle1(false), difAnalogAngle2(false), difAnalogDirectionType(false), difAnalogDuration(false), - difAnalogStartTime(false), onlyLBA(true), allNewTasks(true), - difFlysEye(false), difBitsPerSample(false), difChannelsPerSubband(false), - difCorrelatorIntegrationTime(false), difStorageSelectionMode(false), difStorageLocations(false), - difCoherentStokesType(false), difIncoherentStokesType(false), /*difTiedArrayBeams(false),*/ - difCoherentDedispersion(false), difCoherentTimeIntegration(false), difIncoherentTimeIntegration(false), - difCoherentChannelsPerSubband(false), difIncoherentChannelsPerSubband(false), difCoherentSubbandsPerFile(false), difIncoherentSubbandsPerFile(false), - difDemixAlways(false), difDemixIfNeeded(false), difDemixFreqStep(false), difDemixTimeStep(false), difAvgFreqStep(false), - difAvgTimeStep(false), difCalibrationSkyModel(false), difDemixSkyModel(false), difSpecifyFOV(false), difFOV(false), - difCellSize(false), difNrOfPixels(false), difSlicesPerImage(false), difSubbandsPerImage(false), difSubbandGroupsPerMS(false), difSubbandsPerSubbandGroup(false), - difPulsar_noRFI(false), difPulsar_noDSPSR(false), difPulsar_noFold(false), difPulsar_noPDMP(false), difPulsar_rawTo8Bit(false), difPulsar_RRATS(false), - difPulsar_singlePulse(false), difPulsar_skipDynamicSpectrum(false), difPulsar_skipPrepfold(false), difPulsar_twoBf2fitsExtra(false), difPulsar_digifilExtra(false), - difPulsar_dsprExtra(false), difPulsar_prepDataExtra(false), difPulsar_prepFoldExtra(false), difPulsar_prepSubbandExtra(false), difPulsar_PulsarName(false), - difPulsar_rfiFindExtra(false), difPulsar_decodeNblocks(false), difPulsar_decodeSigma(false), difPulsar_tsubint(false), difPulsar_8bitconvSigma(false), - difPulsar_dynamicSpectrumAvg(false), difPulsar_rratsDMRange(false); - delete itsTask; - itsTask = cloneTask(tasks.front()); // used for change detection in commitMultiTask - Task::task_type type = itsTask->getType(); - QString processType = itsTask->getProcessType(); - QString processSubtypeStr = itsTask->getProcessSubtypeStr(); - processSubTypes processSubtype = itsTask->getProcessSubtype(); - QString strategy = itsTask->getStrategy(); - const QString &predecessors(itsTask->getPredecessorsString()); - AstroTime predecessorMinTimeDif(itsTask->getPredecessorMinTimeDif()); - AstroTime predecessorMaxTimeDif(itsTask->getPredecessorMaxTimeDif()); - - Task::task_status status = itsTask->getStatus(), status2; - std::string projectID = itsTask->getProjectID(); - std::string taskName = itsTask->getTaskName(); - std::string contactName = itsTask->getContactName(); - std::string contactPhone = itsTask->getContactPhone(); - std::string contactEmail = itsTask->getContactEmail(); - std::string taskDescription = itsTask->SASTree().description(); - - // for each specific task type save a pointer to the first task (in the multitasks) that will be used to - // compare for differences between the mutlti tasks - const StationTask *firstStationTask(0); - const Observation *firstObservation(0); - const ImagingPipeline *firstImagingPipeline(0); - const PulsarPipeline *firstPulsarPipeline(0); - const CalibrationPipeline *firstCalibrationPipeline(0); - const LongBaselinePipeline *firstLongBaselinePipeline(0); - const DemixingSettings *firstDemixingSettings(0); - const TaskStorage *firstStorage(0); - TaskStorage::enableDataProdukts outputDataTypes; - - for (std::vector<Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - if (!firstStationTask && (*it)->isStationTask()) { - firstStationTask = static_cast<const StationTask *>(*it); - if (!firstObservation && (*it)->isObservation()) { - firstObservation = static_cast<const Observation *>(*it); - } - } - else if ((*it)->isPipeline()) { - const Pipeline *pipe(static_cast<Pipeline *>(*it)); - if (!firstCalibrationPipeline && pipe->isCalibrationPipeline()) { - firstCalibrationPipeline = static_cast<const CalibrationPipeline *>(pipe); - firstDemixingSettings = &firstCalibrationPipeline->demixingSettings(); - } - else if (!firstImagingPipeline && pipe->isImagingPipeline()) { - firstImagingPipeline = static_cast<const ImagingPipeline *>(pipe); - } - else if (!firstPulsarPipeline && pipe->isPulsarPipeline()) { - firstPulsarPipeline = static_cast<const PulsarPipeline *>(pipe); - } - else if (!firstLongBaselinePipeline && pipe->isLongBaselinePipeline()) { - firstLongBaselinePipeline = static_cast<const LongBaselinePipeline *>(pipe); - } - } - if (!firstStorage && (*it)->hasStorage()) { - firstStorage = (*it)->storage(); - outputDataTypes = firstStorage->getOutputDataProductsEnabled(); - itsTmpStorage = firstStorage->getStorageLocations(); - } - } - -// if (firstObservation) { -// if (firstObservation->getDigitalBeams().empty()) difTiedArrayBeams = true; // no need to check tied array beams for differences if there are none (no digital beams, so no tied array beams) -// } - - bool hasSAStreeID(itsTask->getSASTreeID()); - - bool containsNonEditableTasks(false), statusNotPreScheduled(false); - bool all_storage_assigned(true), all_storage_set(true), no_storage_set(true); - - for (std::vector<Task *>::const_iterator taskit = tasks.begin(); taskit != tasks.end(); ++taskit) { - Task *pTask = *taskit; - - if (!difProcessType) { // not yet different task types? - if (pTask->getType() != type) { - difProcessType = true; - } - } - if (!difProcessSubtype) { - if (pTask->getProcessSubtype() != processSubtype) { - difProcessSubtype = true; - } - } - if (!difStrategy) { - if (pTask->getStrategy() != strategy) { - difStrategy = true; - } - } - if (!difStatus) { - status2 = pTask->getStatus(); - if (status2 >= Task::SCHEDULED) containsNonEditableTasks = true; - if (status2 != status) { - difStatus = true; - } - if (!statusNotPreScheduled) { - if (status2 != Task::PRESCHEDULED) statusNotPreScheduled = true; - } - } - if (!difProjectID) { - if (pTask->getProjectID() != projectID) { - difProjectID = true; - } - } - if (!difGroupID) { - if (pTask->getGroupID() != itsTask->getGroupID()) { - difGroupID = true; - } - } - if (!difTaskName) { - if (pTask->getTaskName() != taskName) { - difTaskName = true; - } - } - if (!difContactName) { - if (pTask->getContactName() != contactName) { - difContactName = true; - } - } - if (!difContactPhone) { - if (pTask->getContactPhone() != contactPhone) { - difContactPhone = true; - } - } - if (!difContactEmail) { - if (pTask->getContactEmail() != contactEmail) { - difContactEmail = true; - } - } - if (!difTaskDescription) { - if (pTask->SASTree().description() != taskDescription) { - difTaskDescription = true; - } - } - if (!difFirstPossibleDate) { - if (pTask->getWindowFirstDay() != itsTask->getWindowFirstDay()) { - difFirstPossibleDate = true; - } - } - if (!difWindowMinTime) { - if (pTask->getWindowMinTime() != itsTask->getWindowMinTime()) { - difWindowMinTime = true; - } - } - if (!difLastPossibleDate) { - if (pTask->getWindowLastDay() != itsTask->getWindowLastDay()) { - difLastPossibleDate = true; - } - } - if (!difWindowMaxTime) { - if (pTask->getWindowMaxTime() != itsTask->getWindowMaxTime()) { - difWindowMaxTime = true; - } - } - if (!difScheduledStart) { - if (pTask->getScheduledStart() != itsTask->getScheduledStart()) { - difScheduledStart= true; - } - } - if (!difScheduledEnd) { - if (pTask->getScheduledEnd() != itsTask->getScheduledEnd()) { - difScheduledEnd= true; - } - } - if (!difDuration) { - if (pTask->getDuration() != itsTask->getDuration()) { - difDuration = true; - } - } - if (!difPriority) { - if (fabs(pTask->getPriority() - itsTask->getPriority()) > std::numeric_limits<double>::epsilon()) { - difPriority = true; - } - } - if (!difFixedDay) { - if (pTask->getFixedDay() != itsTask->getFixedDay()) { - difFixedDay = true; - } - } - if (!difFixedTime) { - if (pTask->getFixedTime() != itsTask->getFixedTime()) { - difFixedTime = true; - } - } - if (!difPredecessor) { - if (pTask->getPredecessorsString() != predecessors) { - difPredecessor = true; - } - } - if (!difpredMinTimeDif) { - if (pTask->getPredecessorMinTimeDif() != predecessorMinTimeDif) { - difpredMinTimeDif = true; - } - } - if (!difpredMaxTimeDif) { - if (pTask->getPredecessorMaxTimeDif() != predecessorMaxTimeDif) { - difpredMaxTimeDif = true; - } - } - if (!hasSAStreeID) { - if (pTask->SASTree().treeID()) { - hasSAStreeID = true; - } - } - - if (firstStationTask && pTask->isStationTask()) { - const StationTask *pStatTask(static_cast<const StationTask *>(pTask)); - //station settings - if (!difStations) { - if (pStatTask->getStations() != firstStationTask->getStations()) { - difStations = true; - } - } - // antenna mode - if (!difAntennaMode) { - if (pStatTask->getAntennaMode() != firstStationTask->getAntennaMode()) { - difAntennaMode = true; - } - } - // station clock - if (!difStationClock) { - if (pStatTask->getStationClock() != firstStationTask->getStationClock()) { - difStationClock = true; - } - } - // filter type - if (!difFilterType) { - if (pStatTask->getFilterType() != firstStationTask->getFilterType()) { - difFilterType = true; - } - } - - if (firstObservation && pTask->isObservation()) { - const Observation *pObs(static_cast<const Observation *>(pTask)); - if (!difReservation) { - if (pObs->getReservation() != firstObservation->getReservation()) { - difReservation = true; - } - } - if (!difNrDataSlotsPerRSP) { - if (pObs->getNrOfDataslotsPerRSPboard() != firstObservation->getNrOfDataslotsPerRSPboard()) { - difNrDataSlotsPerRSP = true; - } - } - if (!difTBBpiggyback) { - if (pObs->getTBBPiggybackAllowed() != firstObservation->getTBBPiggybackAllowed()) { - difTBBpiggyback = true; - } - } - - if (!difAartfaacPiggyback) { - if (pObs->getAartfaacPiggybackAllowed() != firstObservation->getAartfaacPiggybackAllowed()) { - difAartfaacPiggyback = true; - } - } - - // analog beam - if (onlyLBA) { - if (QString(pObs->getAntennaModeStr()).startsWith("HBA")) { - onlyLBA = false; - } - } - const Observation::analogBeamSettings &analogBeam(firstObservation->getAnalogBeam()); - const Observation::analogBeamSettings &otherAnalogBeam(pObs->getAnalogBeam()); - if (!difAnalogAngle1) { - if (analogBeam.angle1 != otherAnalogBeam.angle1) { - difAnalogAngle1 = true; - } - } - if (!difAnalogAngle2) { - if (analogBeam.angle2 != otherAnalogBeam.angle2) { - difAnalogAngle2 = true; - } - } - if (!difAnalogDirectionType) { - if (analogBeam.directionType != otherAnalogBeam.directionType) { - difAnalogDirectionType = true; - } - } - if (!difAnalogDuration) { - if (analogBeam.duration != otherAnalogBeam.duration) { - difAnalogDuration = true; - } - } - if (!difAnalogStartTime) { - if (analogBeam.startTime != otherAnalogBeam.startTime) { - difAnalogStartTime = true; - } - } - - // RTCP settings - const Observation::RTCPsettings &rtcp(firstObservation->getRTCPsettings()); - const Observation::RTCPsettings &rtcp2(pObs->getRTCPsettings()); - - const TaskStorage::enableDataProdukts &edp2(pObs->storage()->getOutputDataProductsEnabled()); - if (!difOutputCoherentStokes) { - if (outputDataTypes.coherentStokes != edp2.coherentStokes) { - difOutputCoherentStokes = true; - } - } - if (!difoutputCorrelated) { - if (outputDataTypes.correlated != edp2.correlated) { - difoutputCorrelated = true; - } - } - if (!difOutputIncoherentStokes) { - if (outputDataTypes.incoherentStokes != edp2.incoherentStokes) { - difOutputIncoherentStokes = true; - } - } - if (!difDelayCompensation) { - if (rtcp.delayCompensation != rtcp2.delayCompensation) { - difDelayCompensation = true; - } - } - if (!difCorrectBandPass) { - if (rtcp.correctBandPass != rtcp2.correctBandPass) { - difCorrectBandPass = true; - } - } - if (!difFlysEye) { - if (rtcp.flysEye != rtcp2.flysEye) { - difFlysEye = true; - } - } - if (!difCoherentStokesType) { - if (rtcp.coherentType != rtcp2.coherentType) { -// itsTask->setCoherentDataType(DATA_TYPE_UNDEFINED); - difCoherentStokesType = true; - } - } - if (!difIncoherentStokesType) { - if (rtcp.incoherentType != rtcp2.incoherentType) { -// itsTask->setIncoherentDataType(DATA_TYPE_UNDEFINED); - difIncoherentStokesType = true; - } - } - if (!difCoherentDedispersion) { - if (rtcp.coherentDedisperseChannels != rtcp2.coherentDedisperseChannels) { - difCoherentDedispersion = true; - } - } - - if (!difCoherentTimeIntegration) { - if (rtcp.coherentTimeIntegrationFactor != rtcp2.coherentTimeIntegrationFactor) { - difCoherentTimeIntegration = true; - } - } - if (!difIncoherentTimeIntegration) { - if (rtcp.incoherentTimeIntegrationFactor != rtcp2.incoherentTimeIntegrationFactor) { - difIncoherentTimeIntegration = true; - } - } - if (!difCoherentChannelsPerSubband) { - if (rtcp.coherentChannelsPerSubband != rtcp2.coherentChannelsPerSubband) { - difCoherentChannelsPerSubband = true; - } - } - if (!difIncoherentChannelsPerSubband) { - if (rtcp.incoherentChannelsPerSubband != rtcp2.incoherentChannelsPerSubband) { - difIncoherentChannelsPerSubband = true; - } - } - if (!difCoherentSubbandsPerFile) { - if (rtcp.coherentSubbandsPerFile != rtcp2.coherentSubbandsPerFile) { - difCoherentSubbandsPerFile = true; - } - } - if (!difIncoherentSubbandsPerFile) { - if (rtcp.incoherentSubbandsPerFile != rtcp2.incoherentSubbandsPerFile) { - difIncoherentSubbandsPerFile = true; - } - } - if (!difBitsPerSample) { - if (rtcp.nrBitsPerSample != rtcp2.nrBitsPerSample) { -// itsTask->setBitsPerSample(0); - difBitsPerSample = true; - } - } - if (!difChannelsPerSubband) { - if (rtcp.channelsPerSubband != rtcp2.channelsPerSubband) { -// itsTask->setChannelsPerSubband(0); - difChannelsPerSubband = true; - } - } - - if (!difCorrelatorIntegrationTime) { - if (fabs(rtcp.correlatorIntegrationTime - rtcp2.correlatorIntegrationTime) > 0.01) { -// itsTask->setCorrelatorIntegrationTime(0.0); - difCorrelatorIntegrationTime = true; - } - } - } // end if firstObservation - } // end if firstStationTask - else if (pTask->isPipeline()) { - const Pipeline *pipe(static_cast<Pipeline *>(pTask)); - if (pipe->isCalibrationPipeline()) { - const CalibrationPipeline *calpipe(static_cast<const CalibrationPipeline *>(pipe)); - const DemixingSettings &otherDemixSettings(calpipe->demixingSettings()); - if (!difDemixAlways) { - if (otherDemixSettings.demixAlways() != firstDemixingSettings->demixAlways()) { - difDemixAlways = true; - } - } - if (!difDemixIfNeeded) { - if (otherDemixSettings.demixIfNeeded() != firstDemixingSettings->demixIfNeeded()) { - difDemixIfNeeded = true; - } - } - if (!difDemixFreqStep) { - if (otherDemixSettings.demixFreqStep() != firstDemixingSettings->demixFreqStep()) { - difDemixFreqStep = true; - } - } - if (!difDemixTimeStep) { - if (otherDemixSettings.demixTimeStep() != firstDemixingSettings->demixTimeStep()) { - difDemixTimeStep = true; - } - } - if (!difAvgFreqStep) { - if (otherDemixSettings.freqStep() != firstDemixingSettings->freqStep()) { - difAvgFreqStep = true; - } - } - if (!difAvgTimeStep) { - if (otherDemixSettings.timeStep() != firstDemixingSettings->timeStep()) { - difAvgTimeStep = true; - } - } - if (!difDemixSkyModel) { - if (otherDemixSettings.skyModel() != firstDemixingSettings->skyModel()) { - difDemixSkyModel = true; - } - } - if (!difCalibrationSkyModel) { - if (firstCalibrationPipeline->skyModel() != calpipe->skyModel()) { - difCalibrationSkyModel = true; - } - } - } - else if (pipe->isImagingPipeline()) { - const ImagingPipeline *impipe(static_cast<const ImagingPipeline *>(pipe)); - if (!difSpecifyFOV) { - if (firstImagingPipeline->specifyFov() != impipe->specifyFov()) { - difSpecifyFOV = true; - } - } - - if (!difFOV) { - if (firstImagingPipeline->fov() != impipe->fov()) { - difFOV = true; - } - } - - if (!difCellSize) { - if (firstImagingPipeline->cellSize() != impipe->cellSize()) { - difCellSize = true; - } - } - - if (!difNrOfPixels) { - if (firstImagingPipeline->nrOfPixels() != impipe->nrOfPixels()) { - difNrOfPixels = true; - } - } - - if (!difSlicesPerImage) { - if (firstImagingPipeline->slicesPerImage() != impipe->slicesPerImage()) { - difSlicesPerImage = true; - } - } - - if (!difSubbandsPerImage) { - if (firstImagingPipeline->subbandsPerImage() != impipe->subbandsPerImage()) { - difSubbandsPerImage = true; - } - } - } - else if (pipe->isPulsarPipeline()) { - const PulsarPipeline *pulspipe(static_cast<const PulsarPipeline *>(pipe)); - - if (!difPulsar_noRFI && (pulspipe->noRFI() != firstPulsarPipeline->noRFI())) { - difPulsar_noRFI = true; - } - if (!difPulsar_noDSPSR && (pulspipe->skipDspsr() != firstPulsarPipeline->skipDspsr())) { - difPulsar_noDSPSR = true; - } - if (!difPulsar_noFold && (pulspipe->noFold() != firstPulsarPipeline->noFold())) { - difPulsar_noFold = true; - } - if (!difPulsar_noPDMP && (pulspipe->noPdmp() != firstPulsarPipeline->noPdmp())) { - difPulsar_noPDMP = true; - } - if (!difPulsar_rawTo8Bit && (pulspipe->rawTo8Bit() != firstPulsarPipeline->rawTo8Bit())) { - difPulsar_rawTo8Bit = true; - } - if (!difPulsar_RRATS && (pulspipe->rrats() != firstPulsarPipeline->rrats())) { - difPulsar_RRATS = true; - } - if (!difPulsar_singlePulse && (pulspipe->singlePulse() != firstPulsarPipeline->singlePulse())) { - difPulsar_singlePulse = true; - } - if (!difPulsar_skipDynamicSpectrum && (pulspipe->skipDynamicSpectrum() != firstPulsarPipeline->skipDynamicSpectrum())) { - difPulsar_skipDynamicSpectrum = true; - } - if (!difPulsar_skipPrepfold && (pulspipe->skipPrepfold() != firstPulsarPipeline->skipPrepfold())) { - difPulsar_skipPrepfold = true; - } - if (!difPulsar_twoBf2fitsExtra && (pulspipe->twoBf2fitsExtra() != firstPulsarPipeline->twoBf2fitsExtra())) { - difPulsar_twoBf2fitsExtra = true; - } - if (!difPulsar_digifilExtra && (pulspipe->digifilExtra() != firstPulsarPipeline->digifilExtra())) { - difPulsar_digifilExtra = true; - } - if (!difPulsar_dsprExtra && (pulspipe->dspsrExtra() != firstPulsarPipeline->dspsrExtra())) { - difPulsar_dsprExtra = true; - } - if (!difPulsar_prepDataExtra && (pulspipe->prepDataExtra() != firstPulsarPipeline->prepDataExtra())) { - difPulsar_prepDataExtra = true; - } - if (!difPulsar_prepFoldExtra && (pulspipe->prepFoldExtra() != firstPulsarPipeline->prepFoldExtra())) { - difPulsar_prepFoldExtra = true; - } - if (!difPulsar_prepSubbandExtra && (pulspipe->prepSubbandExtra() != firstPulsarPipeline->prepSubbandExtra())) { - difPulsar_prepSubbandExtra = true; - } - if (!difPulsar_PulsarName && (pulspipe->pulsarName() != firstPulsarPipeline->pulsarName())) { - difPulsar_PulsarName = true; - } - if (!difPulsar_rfiFindExtra && (pulspipe->rfiFindExtra() != firstPulsarPipeline->rfiFindExtra())) { - difPulsar_rfiFindExtra = true; - } - if (!difPulsar_decodeNblocks && (pulspipe->decodeNblocks() != firstPulsarPipeline->decodeNblocks())) { - difPulsar_decodeNblocks = true; - } - if (!difPulsar_decodeSigma && (pulspipe->decodeSigma() != firstPulsarPipeline->decodeSigma())) { - difPulsar_decodeSigma = true; - } - if (!difPulsar_tsubint && (pulspipe->tsubInt() != firstPulsarPipeline->tsubInt())) { - difPulsar_tsubint = true; - } - if (!difPulsar_8bitconvSigma && (pulspipe->eightBitConversionSigma() != firstPulsarPipeline->eightBitConversionSigma())) { - difPulsar_8bitconvSigma = true; - } - if (!difPulsar_dynamicSpectrumAvg && (pulspipe->dynamicSpectrumAvg() != firstPulsarPipeline->dynamicSpectrumAvg())) { - difPulsar_dynamicSpectrumAvg = true; - } - if (!difPulsar_rratsDMRange && (pulspipe->rratsDmRange() != firstPulsarPipeline->rratsDmRange())) { - difPulsar_rratsDMRange = true; - } - } - else if (pipe->isLongBaselinePipeline()) { - const LongBaselinePipeline *lbpipe(static_cast<const LongBaselinePipeline *>(pipe)); - if (!difSubbandGroupsPerMS && (lbpipe->subbandGroupsPerMS() != firstLongBaselinePipeline->subbandGroupsPerMS())) { - difSubbandGroupsPerMS = true; - } - if (!difSubbandsPerSubbandGroup && (lbpipe->subbandsPerSubbandGroup() != firstLongBaselinePipeline->subbandsPerSubbandGroup())) { - difSubbandsPerSubbandGroup = true; - } - } - } - - const TaskStorage *tStorage(pTask->storage()); - if (tStorage) { - if (!difStorageSelectionMode) { - if (tStorage->getStorageSelectionMode() != firstStorage->getStorageSelectionMode()) { - difStorageSelectionMode = true; - } - } - - if (!difStorageLocations) { - if (tStorage->getStorageLocations() != itsTmpStorage) { - difStorageLocations = true; - } - } - - if (all_storage_assigned && !tStorage->checkStorageAssigned()) { - all_storage_assigned = false; - } - if (all_storage_set || no_storage_set) { - bool hasStorage(tStorage->hasStorageLocations()); - if (all_storage_set && !hasStorage) { - all_storage_set = false; - } - if (no_storage_set && hasStorage) { - no_storage_set = false; - } - } - } - - if (allNewTasks) { - if (pTask->getSASTreeID() != 0) allNewTasks = false; - } - - // IF (all_storage_assigned) -> storage assigned - // ELSEIF (all_storage_set) -> storage set - // ELSEIF (no_storage_set) -> storage not set - // ELSE -> MIXED - } - - this->blockSignals(true); - - - if (all_storage_assigned) { - ui.lineEditStorageAssigned->setText("Storage is assigned"); - QPalette palet; - palet.setColor( QPalette::Base, Qt::green ); - ui.lineEditStorageAssigned->setPalette(palet); - } - else if (all_storage_set) { - ui.lineEditStorageAssigned->setText("Storage not assigned"); - QPalette palet; - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditStorageAssigned->setPalette(palet); - } - else if (no_storage_set) { - ui.lineEditStorageAssigned->setText("No storage set"); - ui.lineEditStorageAssigned->setPalette(palette()); - } - else { - ui.lineEditStorageAssigned->setText("MIXED"); - ui.lineEditStorageAssigned->setPalette(palette()); - } - - ui.lineEditTaskID->setText("multiple"); - ui.lineEditSASID->setText("multiple"); - - // fill taskDialog properties - // *** processType, processSubtype, strategy *** - -// checkEnableDataTypeSettings(); - - ui.comboBoxProcessType->blockSignals(true); - ui.comboBoxProcessSubType->blockSignals(true); - ui.comboBoxStrategies->blockSignals(true); - - ui.comboBoxProcessType->setEnabled(allNewTasks); - ui.comboBoxProcessSubType->setEnabled(allNewTasks); - ui.comboBoxStrategies->setEnabled(allNewTasks); - - if (!allNewTasks) { - QString tt(tr("Some tasks are already created in SAS.\nThe processType, processSubType and strategy cannot be changed anymore")); - ui.comboBoxProcessType->setToolTip(tt); - ui.comboBoxProcessSubType->setToolTip(tt); - ui.comboBoxStrategies->setToolTip(tt); - } - else { - ui.comboBoxProcessType->setToolTip(""); - ui.comboBoxProcessSubType->setToolTip(""); - ui.comboBoxStrategies->setToolTip(""); - } - - if (difProcessType) { // tasks of different type - ui.comboBoxProcessType->setUndefined(true); - ui.comboBoxProcessSubType->setUndefined(true); - ui.comboBoxStrategies->setUndefined(true); - } - else { - ui.comboBoxProcessType->setCurrentIndex(type); - updateProcessSubtypes(processType); - if (difProcessSubtype) { - ui.comboBoxProcessSubType->setUndefined(true); - ui.comboBoxStrategies->setUndefined(true); - } - else { - int idx(ui.comboBoxProcessSubType->findText(processSubtypeStr)); - if (idx != -1) { - ui.comboBoxProcessSubType->setCurrentIndex(idx); - } - else { - ui.comboBoxProcessSubType->addItem(processSubtypeStr); - ui.comboBoxProcessSubType->setCurrentIndex(ui.comboBoxProcessSubType->count()-1); - } - if (difStrategy) { - ui.comboBoxStrategies->setUndefined(true); - } - else { - idx = ui.comboBoxStrategies->findText(strategy); - if (idx != -1) { - ui.comboBoxStrategies->setCurrentIndex(idx); - } - else { - ui.comboBoxStrategies->addItem(strategy); - ui.comboBoxStrategies->setCurrentIndex(ui.comboBoxStrategies->count()-1); - } - } - } - } - ui.comboBoxProcessType->blockSignals(false); - ui.comboBoxProcessSubType->blockSignals(false); - ui.comboBoxStrategies->blockSignals(false); - - - // *** task status *** - ui.comboBoxTaskStatus->blockSignals(true); - ui.comboBoxTaskStatus->clear(); - if (!difStatus) { - if (status == Task::SCHEDULED) { - setFinishedTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::SCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::OBSOLETE]); - ui.comboBoxTaskStatus->setCurrentIndex(3); - } - else if (status == Task::ERROR) { - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ERROR]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - else if ((status >= Task::STARTING) && (status <= Task::FINISHED)) { - setFinishedTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[status]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - else if (status == Task::ABORTED) { - setFinishedTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ABORTED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - else if (status == Task::PRESCHEDULED) { - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::SCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::OBSOLETE]); - ui.comboBoxTaskStatus->setCurrentIndex(1); - } - else { - setNormalTaskMode(); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::OBSOLETE]); - if (status == Task::UNSCHEDULED) { - ui.comboBoxTaskStatus->setCurrentIndex(0); - } - else if (status == Task::PRESCHEDULED) { - ui.comboBoxTaskStatus->setCurrentIndex(1); - } - else if (status == Task::ON_HOLD) { - ui.comboBoxTaskStatus->setCurrentIndex(2); - } - else if (status == Task::OBSOLETE) { - ui.comboBoxTaskStatus->setCurrentIndex(3); - } - } - } - else { // tasks have different status - if (containsNonEditableTasks) { - QMessageBox::warning(0, tr("Selection contains non editable tasks"), - tr("The selection contains finished/aborted/starting tasks which may not be edited.\nAny changes you make will not be applied to these finished tasks")); - } - setNormalTaskMode(); -// ui.comboBoxTaskStatus->addItem(task_states_str[Task::PREPARED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::UNSCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::PRESCHEDULED]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::OBSOLETE]); - ui.comboBoxTaskStatus->addItem(task_states_str[Task::ON_HOLD]); - ui.comboBoxTaskStatus->setUndefined(true); - } - ui.comboBoxTaskStatus->blockSignals(false); - - // *** stations *** - if (difStations) { - ui.labelAssignedStations->setText("Assigned stations " + multipleStr); - ui.treeWidgetUsedStations->setMixed(); - } - else if (firstStationTask) { - setStations(firstStationTask); - ui.labelAssignedStations->setText("Assigned stations (" + QString::number(countStations()) + ")"); - } - - // *** projectID, project name *** - if (difProjectID) { - ui.comboBoxProjectID->setUndefined(true); - ui.lineEdit_ProjectName->setText(multipleStr); - ui.lineEdit_ProjectCOI->setText(multipleStr); - ui.lineEdit_ProjectPI->setText(multipleStr); - } - else { - ui.comboBoxProjectID->setFromString(projectID.c_str()); - ui.lineEdit_ProjectName->setText(itsTask->getProjectName()); - ui.lineEdit_ProjectCOI->setText(itsTask->getProjectCO_I()); - ui.lineEdit_ProjectPI->setText(itsTask->getProjectPI()); - } - - if (difGroupID) { - ui.lineEditGroupID->setUndefined(true); - } - else { - ui.lineEditGroupID->setText(QString::number(itsTask->getGroupID())); - } - - // *** taskName *** - if (difTaskName) { - ui.lineEditTaskName->setUndefined(true); - } - else { - ui.lineEditTaskName->setText(taskName); - } - - // *** contactName *** - if (difContactName) { - ui.lineEdit_ContactName->setText(multipleStr); - } - else { - ui.lineEdit_ContactName->setText(contactName.c_str()); - } - itsTask->setContactName(ui.lineEdit_ContactName->text().toStdString()); // change detection - - // *** contactPhone *** - if (difContactPhone) { - ui.lineEdit_ContactPhone->setText(multipleStr); - } - else { - ui.lineEdit_ContactPhone->setText(contactPhone.c_str()); - } - itsTask->setContactPhone(ui.lineEdit_ContactPhone->text().toStdString()); // change detection - - // *** contactEmail *** - if (difContactEmail) { - ui.lineEdit_ContactEmail->setText(multipleStr); - } - else { - ui.lineEdit_ContactEmail->setText(contactEmail.c_str()); - } - itsTask->setContactEmail(ui.lineEdit_ContactEmail->text().toStdString()); // change detection - - // *** taskDescription *** - if (difTaskDescription) { - ui.lineEditTaskDescription->setText(multipleStr); - } - else { - ui.lineEditTaskDescription->setText(taskDescription.c_str()); - } - itsTask->setTaskDescription(ui.lineEditTaskDescription->text().toStdString()); // change detection - - - // reservation - loadReservations(); - if (difReservation) { - ui.comboBoxReservation->setUndefined(); - ui.comboBoxReservation->setEnabled(false); - } - else { - ui.comboBoxReservation->setEnabled(true); - } - - // *** firstPossibleDate *** - ui.dateEditFirstPossibleDate->blockSignals(true); - const AstroDate &fdate(Controller::theSchedulerSettings.getEarliestSchedulingDay()); - ui.dateEditFirstPossibleDate->setDefaultDate(fdate); - ui.dateEditFirstPossibleDate->setMinimumDate(QDate(fdate.getYear(),fdate.getMonth(),fdate.getDay())); - if (difFirstPossibleDate) { - ui.dateEditFirstPossibleDate->setUndefined(true); - } - else { - ui.dateEditFirstPossibleDate->setUndefined(false); - const AstroDate &date = itsTask->getWindowFirstDay(); - ui.dateEditFirstPossibleDate->setDate(QDate(date.getYear(), date.getMonth(), date.getDay())); - } - ui.dateEditFirstPossibleDate->blockSignals(false); - - // *** lastPossibleDate *** - ui.dateEditLastPossibleDate->blockSignals(true); - const AstroDate &ldate(Controller::theSchedulerSettings.getLatestSchedulingDay()); - ui.dateEditLastPossibleDate->setDefaultDate(ldate); - ui.dateEditLastPossibleDate->setMaximumDate(QDate(ldate.getYear(),ldate.getMonth(),ldate.getDay())); - if (difLastPossibleDate) { - ui.dateEditLastPossibleDate->setUndefined(true); - } - else { - ui.dateEditLastPossibleDate->setUndefined(false); - const AstroDate &date = itsTask->getWindowLastDay(); - ui.dateEditLastPossibleDate->setDate(QDate(date.getYear(), date.getMonth(), date.getDay())); - } - ui.dateEditLastPossibleDate->blockSignals(false); - - // *** firstPossibleTime *** - ui.timeEditFirstPossibleTime->blockSignals(true); - if (difWindowMinTime) { - ui.timeEditFirstPossibleTime->setMultipleValue(); - } - else { - const AstroTime &time = itsTask->getWindowMinTime(); - ui.timeEditFirstPossibleTime->setTime(QTime(time.getHours(), time.getMinutes(), time.getSeconds())); - } - ui.timeEditFirstPossibleTime->blockSignals(false); - - // *** lastPossibleTime *** - ui.timeEditLastPossibleTime->blockSignals(true); - if (difWindowMaxTime) { - ui.timeEditLastPossibleTime->setDefaultTime(AstroTime("23:59:59")); - ui.timeEditLastPossibleTime->setMultipleValue(); - } - else { - const AstroTime &time = itsTask->getWindowMaxTime(); - ui.timeEditLastPossibleTime->setTime(QTime(time.getHours(), time.getMinutes(), time.getSeconds())); - } - ui.timeEditLastPossibleTime->blockSignals(false); - - // scheduledStart - ui.dateTimeEditScheduledStart->blockSignals(true); - if (difScheduledStart) { - ui.dateTimeEditScheduledStart->setMultipleValue(); - } - else { - const AstroDate &date(Controller::theSchedulerSettings.getEarliestSchedulingDay()); - ui.dateTimeEditScheduledStart->setMinimumDate(QDate(date.getYear(),date.getMonth(),date.getDay())); - const AstroDateTime &start = itsTask->getScheduledStart(); - setScheduledStart(QDateTime(QDate(start.getYear(), start.getMonth(), start.getDay()), - QTime(start.getHours(), start.getMinutes(), start.getSeconds()))); - } - ui.dateTimeEditScheduledStart->blockSignals(false); - - // scheduledEnd - ui.dateTimeEditScheduledEnd->blockSignals(true); - if (difScheduledEnd) { - ui.dateTimeEditScheduledEnd->setMultipleValue(); - } - else { - const AstroDateTime &end = itsTask->getScheduledEnd(); - setScheduledEnd(QDateTime(QDate(end.getYear(), end.getMonth(), end.getDay()), - QTime(end.getHours(), end.getMinutes(), end.getSeconds()))); - } - ui.dateTimeEditScheduledEnd->blockSignals(false); - - // duration - ui.lineEditDuration->blockSignals(true); - if (difDuration) { - ui.lineEditDuration->setUndefined(true); - } - else { - ui.lineEditDuration->setText(itsTask->getDuration().toString()); - } - ui.lineEditDuration->blockSignals(false); - - // priority - ui.lineEditPriority->blockSignals(true); - if (difPriority) { - ui.lineEditPriority->setUndefined(true); - } - else { - ui.lineEditPriority->setText(QString::number(itsTask->getPriority())); - } - ui.lineEditPriority->blockSignals(false); - - // predecessor - ui.lineEditPredecessors->blockSignals(true); - ui.lineEditMaxPredDistance->blockSignals(true); - ui.lineEditMinPredDistance->blockSignals(true); - - if (predecessors.isEmpty()) { - if (difPredecessor) { - ui.lineEditPredecessors->setUndefined(true); - } - else { - ui.lineEditPredecessors->setText(predecessors); - } - - // predecessor min time dif - if (difpredMinTimeDif) { - ui.lineEditMinPredDistance->setUndefined(true); - } - else { - ui.lineEditMinPredDistance->setText(predecessorMinTimeDif.toString()); - } - - // predecessor max time dif - if (difpredMaxTimeDif) { - ui.lineEditMaxPredDistance->setUndefined(true); - } - else { - ui.lineEditMaxPredDistance->setText(predecessorMaxTimeDif.toString()); - } - - } - else { - ui.lineEditPredecessors->setPalette(QPalette()); - ui.lineEditPredecessors->setText(""); - ui.lineEditMinPredDistance->setText(""); - ui.lineEditMaxPredDistance->setText(""); - } - ui.lineEditMaxPredDistance->blockSignals(false); - ui.lineEditPredecessors->blockSignals(false); - ui.lineEditMinPredDistance->blockSignals(false); - - // nrOFDataSlots - ui.spinBoxDataslotsPerRSPboard->blockSignals(true); - if (difNrDataSlotsPerRSP) { - ui.spinBoxDataslotsPerRSPboard->setUndefined(true); - } - else if (firstStationTask) { - ui.spinBoxDataslotsPerRSPboard->setValue(firstStationTask->getNrOfDataslotsPerRSPboard()); - } - ui.spinBoxDataslotsPerRSPboard->blockSignals(false); - - // TBB piggyback allowed - ui.checkBoxTBBPiggybackAllowed->blockSignals(true); - if (difTBBpiggyback) { - ui.checkBoxTBBPiggybackAllowed->setToolTip("Allow TBB to piggyback on the stations " + multipleStr); - ui.checkBoxTBBPiggybackAllowed->setUndefined(true); - } - else { - ui.checkBoxTBBPiggybackAllowed->setTristate(false); - ui.checkBoxTBBPiggybackAllowed->setToolTip("Allow TBB to piggyback on the stations"); - if (firstObservation) { - ui.checkBoxTBBPiggybackAllowed->setChecked(firstObservation->getTBBPiggybackAllowed()); - } - } - ui.checkBoxTBBPiggybackAllowed->blockSignals(false); - - // Aartfaac piggyback allowed - ui.checkBoxAartfaacPiggybackAllowed->blockSignals(true); - if (difAartfaacPiggyback) { - ui.checkBoxAartfaacPiggybackAllowed->setToolTip("Allow AARTFAAC to piggyback on the stations " + multipleStr); - ui.checkBoxAartfaacPiggybackAllowed->setUndefined(true); - } - else { - ui.checkBoxAartfaacPiggybackAllowed->setTristate(false); - ui.checkBoxAartfaacPiggybackAllowed->setToolTip("Allow AARTFAAC to piggyback on the stations"); - if (firstObservation) { - ui.checkBoxAartfaacPiggybackAllowed->setChecked(firstObservation->getAartfaacPiggybackAllowed()); - } - } - ui.checkBoxAartfaacPiggybackAllowed->blockSignals(false); - - // antenna mode - if (difAntennaMode) { - ui.comboBoxStationAntennaMode->setUndefined(true); - } - else if (firstStationTask) { - ui.comboBoxStationAntennaMode->setCurrentIndex(firstStationTask->getAntennaMode()); - } - - // station clock - if (difStationClock) { - ui.comboBoxStationClock->setUndefined(true); - } - else if (firstStationTask) { - ui.comboBoxStationClock->setCurrentIndex(firstStationTask->getStationClock()); - } - - // filter type - if (difFilterType) { - ui.comboBoxStationFilter->setUndefined(true); - } - else if (firstStationTask) { - ui.comboBoxStationFilter->setCurrentIndex(firstStationTask->getFilterType()); - } - - if (difOutputCoherentStokes) { - ui.checkBoxCoherentStokes->setToolTip("Store coherent Stokes data " + multipleStr); - ui.checkBoxCoherentStokes->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBoxCoherentStokes->setToolTip("Store coherent Stokes data"); - ui.checkBoxCoherentStokes->setChecked(outputDataTypes.coherentStokes/* || itsOutputDataTypes.complexVoltages*/); - } - - if (difoutputCorrelated) { - ui.checkBoxCorrelatedData->setToolTip("Store correlated visibilities " + multipleStr); - ui.checkBoxCorrelatedData->setCheckState(Qt::PartiallyChecked); - } - else { -// ui.checkBoxCorrelatedData->setTristate(false); - ui.checkBoxCorrelatedData->setToolTip("Store correlated visibilities"); - ui.checkBoxCorrelatedData->setChecked(outputDataTypes.correlated); - } - - if (difOutputIncoherentStokes) { - ui.checkBoxIncoherentStokes->setToolTip("Store incoherent Stokes data " + multipleStr); - ui.checkBoxIncoherentStokes->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBoxIncoherentStokes->setToolTip("Store incoherent Stokes data"); - ui.checkBoxIncoherentStokes->setChecked(outputDataTypes.incoherentStokes); - } - - if (firstObservation) { - // RTCP settings - const Observation::RTCPsettings &rtcp(firstObservation->getRTCPsettings()); - if (difCorrelatorIntegrationTime) { - ui.lineEditCorrelatorIntegrationTime->setUndefined(true); - } - else { - ui.lineEditCorrelatorIntegrationTime->setText(QString::number(rtcp.correlatorIntegrationTime)); - } - - if (difDelayCompensation) { - ui.checkBox_DelayCompensation->setToolTip("perform delay compensation between stations " + multipleStr); - ui.checkBox_DelayCompensation->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_DelayCompensation->setToolTip("perform delay compensation between stations"); - ui.checkBox_DelayCompensation->setChecked(rtcp.delayCompensation); - } - - if (difCorrectBandPass) { - ui.checkBox_BandpassCorrection->setToolTip("apply the bandpass filter " + multipleStr); - ui.checkBox_BandpassCorrection->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_BandpassCorrection->setToolTip("apply the bandpass filter"); - ui.checkBox_BandpassCorrection->setChecked(rtcp.correctBandPass); - } - - if (difFlysEye) { - ui.checkBoxPencilFlysEye->setToolTip("transforms every station into its own beam " + multipleStr); - ui.checkBoxPencilFlysEye->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBoxPencilFlysEye->setToolTip("transforms every station into its own beam"); - ui.checkBoxPencilFlysEye->setChecked(rtcp.flysEye); - } - - if (difCoherentDedispersion) { - ui.checkBox_CoherentDedispersion->setToolTip("turn on online coherent dedispersion " + multipleStr); - ui.checkBox_CoherentDedispersion->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_CoherentDedispersion->setToolTip("turn on online coherent dedispersion"); - ui.checkBox_CoherentDedispersion->setChecked(rtcp.coherentDedisperseChannels); - } - - if (difCoherentStokesType) { - ui.comboBoxCoherentStokesType->setUndefined(true); - } - else { - ui.comboBoxCoherentStokesType->setCurrentIndex(static_cast<int>(rtcp.coherentType)); - } - - if (difIncoherentStokesType) { - ui.comboBoxIncoherentStokesType->setUndefined(true); - } - else { - ui.comboBoxIncoherentStokesType->setCurrentIndex(static_cast<int>(rtcp.incoherentType)); - } - - if (difCoherentTimeIntegration) { - ui.spinBoxCoherentTimeIntegration->setUndefined(true); - } - else { - ui.spinBoxCoherentTimeIntegration->setValue(rtcp.coherentTimeIntegrationFactor); - } - if (difIncoherentTimeIntegration) { - ui.spinBoxIncoherentTimeIntegration->setUndefined(true); - } - else { - ui.spinBoxIncoherentTimeIntegration->setValue(rtcp.incoherentTimeIntegrationFactor); - } - - if (difCoherentChannelsPerSubband) { - ui.spinBoxCoherentChannelsPerSubband->setUndefined(true); - } - else { - ui.spinBoxCoherentChannelsPerSubband->setValue(rtcp.coherentChannelsPerSubband); - } - - if (difIncoherentChannelsPerSubband) { - ui.spinBoxIncoherentChannelsPerSubband->setUndefined(true); - } - else { - ui.spinBoxIncoherentChannelsPerSubband->setValue(rtcp.incoherentChannelsPerSubband); - } - if (difCoherentSubbandsPerFile) { - ui.spinBoxCoherentSubbandsPerFile->setUndefined(true); - } - else { - ui.spinBoxCoherentSubbandsPerFile->setValue(rtcp.coherentSubbandsPerFile); - } - - if (difIncoherentSubbandsPerFile) { - ui.spinBoxIncoherentSubbandsPerFile->setUndefined(true); - } - else { - ui.spinBoxIncoherentSubbandsPerFile->setValue(rtcp.incoherentSubbandsPerFile); - } - - if (difBitsPerSample) { - ui.comboBoxBitsPerSample->setUndefined(true); - } - else { - setBitsPerSample(rtcp.nrBitsPerSample); - } - - if (difChannelsPerSubband) { - ui.spinBoxChannelsPerSubband->setUndefined(true); - } - else { - ui.spinBoxChannelsPerSubband->setValue(rtcp.channelsPerSubband); - } - } - - // fixed day - if (difFixedDay) { - ui.checkBoxFixedDate->setToolTip("Fix scheduled date " + multipleStr); - ui.checkBoxFixedDate->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBoxFixedDate->setTristate(false); - ui.checkBoxFixedDate->setToolTip("Fix scheduled date"); - ui.checkBoxFixedDate->setChecked(itsTask->getFixedDay()); - } - - // fixed time - if (difFixedTime) { - ui.checkBoxFixedTime->setToolTip("Fix scheduled time " + multipleStr); - ui.checkBoxFixedTime->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBoxFixedTime->setTristate(false); - ui.checkBoxFixedTime->setToolTip("Fix scheduled time"); - ui.checkBoxFixedTime->setChecked(itsTask->getFixedTime()); - } - - /* - // digital beams - if (difDigitalBeams) { - ui.tableWidgetDigitalBeams->clearContents(); - ui.tableWidgetDigitalBeams->setRowCount(1); - QTableWidgetItem *newItem = new QTableWidgetItem(multipleStr); - ui.tableWidgetDigitalBeams->setItem(0, 0, newItem); - ui.lineEditTotalSubbands->clear(); - ui.pushButtonAddBeam->setEnabled(false); - ui.pushButtonEditBeam->setEnabled(false); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(true); - // disable tied array beam settings as long as digital beams are different - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - } - else { // digital beams are the same or no beams have been defined yet - itsDigitalBeams.clear(); - ui.tableWidgetDigitalBeams->clearContents(); - ui.tableWidgetDigitalBeams->setRowCount(digitalBeams.size()); - int row(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = digitalBeams.begin(); it != digitalBeams.end(); ++it) { - setDigitalBeam(row++, it->second); - } - // set appropriate column widths - ui.tableWidgetDigitalBeams->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); - // set the total number of subbands - ui.lineEditTotalSubbands->setText(QString::number(itsTask->getNrOfSubbands())); - // enable/disable beam buttons depending on if the task has a SAS tree ID already (VIC tree) - ui.pushButtonAddBeam->setEnabled(!hasSAStreeID); - if (!digitalBeams.empty()) { // if beams are defined - ui.pushButtonEditBeam->setEnabled(true); // edit is also show button and should be enabled - if (containsNonEditableTasks) { - itsDigitalBeamDialog->setReadOnly(true); - ui.pushButtonEditBeam->setText("Show"); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - } - else { // digital beams are the same and editable - itsDigitalBeamDialog->setReadOnly(false); - ui.pushButtonEditBeam->setText("Edit"); - ui.pushButtonDeleteBeams->setEnabled(!hasSAStreeID); // depends on VIC tree or template tree - ui.pushButtonClearAllBeams->setEnabled(!hasSAStreeID); - } - } - else { // if no beams have been defined yet - itsDigitalBeamDialog->setReadOnly(false); - ui.pushButtonEditBeam->setText("Edit"); - ui.pushButtonEditBeam->setEnabled(false); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonClearAllBeams->setEnabled(false); - } - } - - // tied array beam (of the first digital beam) - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(digitalBeams.find(0)->second.tiedArrayBeams()); - if (difTiedArrayBeams) { // tells us if the tied array beams of the first digital beams are different or not - if (tiedArrayBeams.empty()) { - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - } - else { // tied array beams of the first digital beam are different - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(1); - QTableWidgetItem *newItem = new QTableWidgetItem(multipleStr); - ui.tableWidgetTiedArrayBeams->setItem(0, 0, newItem); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - } - } - else { // tied array beams of the first digital beam are the same, show it - updateTiedArrayBeams(digitalBeams.find(0)->second); - if (containsNonEditableTasks) { - itsTiedArrayBeamDialog->setReadOnly(true); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - } - else { - itsTiedArrayBeamDialog->setReadOnly(false); - ui.pushButtonAddTiedArrayBeam->setEnabled(!hasSAStreeID); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(!hasSAStreeID); - ui.pushButtonEditTiedArrayBeam->setEnabled(true); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(!hasSAStreeID); - } - } - */ - - // analog beam - ui.comboBoxAnalogBeamCoordinates->blockSignals(true); - if (onlyLBA) { // disable analog beam editing - disableAnalogBeamSettings(); - } - else { -// itsAnalogBeamSettings.directionType = DIR_TYPE_J2000; // for multi-edit set to J2000 - if (status < Task::SCHEDULED) { - ui.groupBoxAnalogBeam->setEnabled(true); - } - if (difAnalogDirectionType) { // coordinate system different - ui.comboBoxAnalogBeamCoordinates->setUndefined(true); - } - else { // coordinate system the same - ui.comboBoxAnalogBeamCoordinates->setCurrentIndex(itsAnalogBeamSettings.directionType); - setAnalogBeamUnitsComboBox(); - } - - ui.comboBoxAnalogBeamUnits->blockSignals(true); - ui.comboBoxAnalogBeamUnits->setCurrentIndex(0); - ui.comboBoxAnalogBeamUnits->blockSignals(false); - - bool setAngles(false); - if (difAnalogAngle1) { - ui.lineEditAnalogBeamAngle1->setUndefined(true); - } - else { - setAngles = true; - } - - if (difAnalogAngle2) { - ui.lineEditAnalogBeamAngle2->setUndefined(true); - } - else { - setAngles = true; - } - if (setAngles) { - AnalogBeamAngleUnitChanged(ui.comboBoxAnalogBeamUnits->currentText()); - } - - if (difAnalogStartTime) { - ui.timeEditAnalogBeamStartTime->setTime(QTime(0,0,0)); - - } - else { - ui.timeEditAnalogBeamStartTime->setTime(QTime(itsAnalogBeamSettings.startTime.getHours(), - itsAnalogBeamSettings.startTime.getMinutes(), itsAnalogBeamSettings.startTime.getSeconds())); - } - if (difAnalogDuration) { - ui.lineEditAnalogBeamDuration->setToolTip("Active duration of this beam (hhhh:mm:ss) " + multipleStr); - ui.lineEditAnalogBeamDuration->setUndefined(true); - } - else { - ui.lineEditAnalogBeamDuration->setToolTip("Active duration of this beam (hh:mm:ss)"); - ui.lineEditAnalogBeamDuration->setText(itsAnalogBeamSettings.duration.toString()); - } -// setAnalogBeamSettings(analogBeam); - } - ui.comboBoxAnalogBeamCoordinates->blockSignals(false); - - if (firstDemixingSettings) { - const QStringList &demixSources(Controller::theSchedulerSettings.getDemixSources()); - if (difDemixAlways) { - ui.listWidgetDemixAlways->setUndefined(true); - } - else { - ui.listWidgetDemixAlways->addItems(demixSources, firstDemixingSettings->demixAlwaysList()); - } - - if (difDemixIfNeeded) { - ui.listWidgetDemixIfNeeded->setUndefined(true); - } - else { - ui.listWidgetDemixIfNeeded->addItems(demixSources, firstDemixingSettings->demixIfNeededList()); - } - - if (difDemixFreqStep) { - ui.spinBoxDemixFreqStep->setUndefined(true); - } - else { - ui.spinBoxDemixFreqStep->setValue(firstDemixingSettings->demixFreqStep()); - } - - if (difDemixTimeStep) { - ui.spinBoxDemixTimeStep->setUndefined(true); - } - else { - ui.spinBoxDemixTimeStep->setValue(firstDemixingSettings->demixTimeStep()); - } - - if (difAvgFreqStep) { - ui.spinBoxAveragingFreqStep->setUndefined(true); - } - else { - ui.spinBoxAveragingFreqStep->setValue(firstDemixingSettings->freqStep()); - } - - if (difAvgTimeStep) { - ui.spinBoxAveragingTimeStep->setUndefined(true); - } - else { - ui.spinBoxAveragingTimeStep->setValue(firstDemixingSettings->timeStep()); - } - - if (difDemixSkyModel) { - ui.lineEditDemixSkyModel->setUndefined(true); - } - else { - ui.lineEditDemixSkyModel->setText(firstDemixingSettings->skyModel()); - } - } - - if (firstCalibrationPipeline) { - if (difCalibrationSkyModel) { - ui.lineEditCalibrationSkyModel->setUndefined(true); - } - else { - ui.lineEditCalibrationSkyModel->setText(firstCalibrationPipeline->skyModel()); - } - } - - if (firstImagingPipeline) { - if (difSpecifyFOV) { - ui.checkBoxSpecifyFOV->setToolTip("Specify Field Of View instead of Cell size & npix " + multipleStr); - ui.checkBoxSpecifyFOV->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBoxSpecifyFOV->setTristate(false); - ui.checkBoxSpecifyFOV->setToolTip("Specify Field Of View instead of Cell size & npix"); - ui.checkBoxSpecifyFOV->setChecked(firstImagingPipeline->specifyFov()); - } - - if (difFOV) { - ui.lineEditFieldOfView->setUndefined(true); - } - else { - ui.lineEditFieldOfView->setText(QString::number(firstImagingPipeline->fov(),'g',16)); - } - - if (difCellSize) { - ui.lineEditCellSize->setUndefined(true); - } - else { - ui.lineEditCellSize->setText(firstImagingPipeline->cellSize()); - } - - if (difNrOfPixels) { - ui.spinBoxNumberOfPixels->setUndefined(true); - } - else { - ui.spinBoxNumberOfPixels->setValue(firstImagingPipeline->nrOfPixels()); - } - - if (difSlicesPerImage) { - ui.spinBoxSlicesPerImage->setUndefined(true); - } - else { - ui.spinBoxSlicesPerImage->setValue(firstImagingPipeline->slicesPerImage()); - } - - if (difSubbandsPerImage) { - ui.spinBoxSubbandsPerImage->setUndefined(true); - } - else { - ui.spinBoxSubbandsPerImage->setValue(firstImagingPipeline->subbandsPerImage()); - } - } - - if (firstPulsarPipeline) { - if (difPulsar_noRFI) { - ui.checkBox_NoRFI->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_NoRFI->setTristate(false); - ui.checkBox_NoRFI->setChecked(firstPulsarPipeline->noRFI()); - } - - if (difPulsar_noDSPSR) { - ui.checkBox_No_DSPSR->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_No_DSPSR->setTristate(false); - ui.checkBox_No_DSPSR->setChecked(firstPulsarPipeline->skipDspsr()); - } - - if (difPulsar_noFold) { - ui.checkBox_No_fold->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_No_fold->setTristate(false); - ui.checkBox_No_fold->setChecked(firstPulsarPipeline->noFold()); - } - - if (difPulsar_noPDMP) { - ui.checkBox_No_pdmp->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_No_pdmp->setTristate(false); - ui.checkBox_No_pdmp->setChecked(firstPulsarPipeline->noPdmp()); - } - - if (difPulsar_rawTo8Bit) { - ui.checkBox_RawTo8Bit->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_RawTo8Bit->setTristate(false); - ui.checkBox_RawTo8Bit->setChecked(firstPulsarPipeline->rawTo8Bit()); - } - - if (difPulsar_RRATS) { - ui.checkBox_rrats->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_rrats->setTristate(false); - ui.checkBox_rrats->setChecked(firstPulsarPipeline->rrats()); - } - if (difPulsar_singlePulse) { - ui.checkBox_Single_pulse->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_Single_pulse->setTristate(false); - ui.checkBox_Single_pulse->setChecked(firstPulsarPipeline->singlePulse()); - } - - if (difPulsar_skipDynamicSpectrum) { - ui.checkBox_Skip_dynamic_spectrum->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_Skip_dynamic_spectrum->setTristate(false); - ui.checkBox_Skip_dynamic_spectrum->setChecked(firstPulsarPipeline->skipDynamicSpectrum()); - } - - if (difPulsar_skipPrepfold) { - ui.checkBox_Skip_prepfold->setCheckState(Qt::PartiallyChecked); - } - else { - ui.checkBox_Skip_prepfold->setTristate(false); - ui.checkBox_Skip_prepfold->setChecked(firstPulsarPipeline->skipPrepfold()); - } - - if (difPulsar_twoBf2fitsExtra) { - ui.lineEdit2bf2fitsExtraOptions->setUndefined(true); - } - else { - ui.lineEdit2bf2fitsExtraOptions->setText(firstPulsarPipeline->twoBf2fitsExtra()); - } - - if (difPulsar_digifilExtra) { - ui.lineEditDigifilExtraOptions->setUndefined(true); - } - else { - ui.lineEditDigifilExtraOptions->setText(firstPulsarPipeline->digifilExtra()); - } - - if (difPulsar_dsprExtra) { - ui.lineEditDSPSRextraOptions->setUndefined(true); - } - else { - ui.lineEditDSPSRextraOptions->setText(firstPulsarPipeline->dspsrExtra()); - } - - if (difPulsar_prepDataExtra) { - ui.lineEditPrepdataExtraOptions->setUndefined(true); - } - else { - ui.lineEditPrepdataExtraOptions->setText(firstPulsarPipeline->prepDataExtra()); - } - - if (difPulsar_prepFoldExtra) { - ui.lineEditPrepfoldExtraOptions->setUndefined(true); - } - else { - ui.lineEditPrepfoldExtraOptions->setText(firstPulsarPipeline->prepFoldExtra()); - } - - if (difPulsar_prepSubbandExtra) { - ui.lineEditPrepsubbandExtraOptions->setUndefined(true); - } - else { - ui.lineEditPrepsubbandExtraOptions->setText(firstPulsarPipeline->prepSubbandExtra()); - } - - if (difPulsar_PulsarName) { - ui.lineEditPulsarName->setUndefined(true); - } - else { - ui.lineEditPulsarName->setText(firstPulsarPipeline->pulsarName()); - } - - if (difPulsar_rfiFindExtra) { - ui.lineEditRfiFindExtraOptions->setUndefined(true); - } - else { - ui.lineEditRfiFindExtraOptions->setText(firstPulsarPipeline->rfiFindExtra()); - } - - if (difPulsar_decodeNblocks) { - ui.spinBoxDecodeNblocks->setUndefined(true); - } - else { - ui.spinBoxDecodeNblocks->setValue(firstPulsarPipeline->decodeNblocks()); - } - - if (difPulsar_decodeSigma) { - ui.spinBoxDecodeSigma->setUndefined(true); - } - else { - ui.spinBoxDecodeSigma->setValue(firstPulsarPipeline->decodeSigma()); - } - - if (difPulsar_tsubint) { - ui.spinBoxTsubint->setUndefined(true); - } - else { - ui.spinBoxTsubint->setValue(firstPulsarPipeline->tsubInt()); - } - - if (difPulsar_8bitconvSigma) { - ui.doubleSpinBox8BitConversionSigma->setUndefined(true); - } - else { - ui.doubleSpinBox8BitConversionSigma->setValue(firstPulsarPipeline->eightBitConversionSigma()); - } - - if (difPulsar_dynamicSpectrumAvg) { - ui.doubleSpinBoxDynamicSpectrumTimeAverage->setUndefined(true); - } - else { - ui.doubleSpinBoxDynamicSpectrumTimeAverage->setValue(firstPulsarPipeline->dynamicSpectrumAvg()); - } - - if (difPulsar_rratsDMRange) { - ui.doubleSpinBoxRratsDmRange->setUndefined(true); - } - else { - ui.doubleSpinBoxRratsDmRange->setValue(firstPulsarPipeline->rratsDmRange()); - } - } - if (firstLongBaselinePipeline) { - if (difSubbandGroupsPerMS) { - ui.spinBoxSubbandGroupsPerMS->setUndefined(true); - } - else { - ui.spinBoxSubbandGroupsPerMS->setValue(firstLongBaselinePipeline->subbandGroupsPerMS()); - } - - if (difSubbandsPerSubbandGroup) { - ui.spinBoxSubbandsPerSubbandGroup->setUndefined(true); - } - else { - ui.spinBoxSubbandsPerSubbandGroup->setValue(firstLongBaselinePipeline->subbandsPerSubbandGroup()); - } - } - - if (firstStorage) { - if (difStorageSelectionMode) { - ui.comboBoxStorageSelectionMode->setUndefined(true); - } - else { - ui.comboBoxStorageSelectionMode->setCurrentIndex(static_cast<int>(firstStorage->getStorageSelectionMode())); - } - } - - if (difStorageLocations) { - setStorageTreeMixed(!statusNotPreScheduled); // override will be enabled only if all tasks have status lower than PRESCHEDULED - } - else { - updateStorageTree(); - } - - } - - // common properties both for reservations as for regular tasks - ui.pushButtonApply->show(); - enableApplyButtons(false); - ui.pushButtonOk->setText("Ok"); - - blockChangeDetection = false; - ui.checkBoxCorrelatedData->blockSignals(false); - ui.checkBoxCoherentStokes->blockSignals(false); - ui.checkBoxIncoherentStokes->blockSignals(false); - this->blockSignals(false); - this->setVisible(true); -} - -void TaskDialog::updateStatus(Task::task_status status) { - ui.comboBoxTaskStatus->blockSignals(true); - - QString stateStr(task_states_str[status]); - for (int i = 0; i < ui.comboBoxTaskStatus->count(); ++i) { - if (ui.comboBoxTaskStatus->itemText(i).compare(stateStr) == 0) { - ui.comboBoxTaskStatus->setCurrentIndex(i); - return; - } - } - // status not found in combobox -> add it and set it as current - ui.comboBoxTaskStatus->addItem(stateStr); - ui.comboBoxTaskStatus->setCurrentIndex(ui.comboBoxTaskStatus->count()-1); - - ui.comboBoxTaskStatus->blockSignals(false); -} - - -void TaskDialog::update(const Task *task) { // dangerous function -> be aware it might change it task copies. This was a major and difficult to find problem when multi-editing - if (this->isVisible() && (!isMultiTasks)) { - if (task) { - if (itsTask->getID() == task->getID()) { // only do the update if task is the task currently shown - show(task); - } - } - else show(itsController->getTask(itsTask->getID())); - } -} - -void TaskDialog::setRTCPSettings(const Observation::RTCPsettings &rtcp) { - this->blockSignals(true); - ui.checkBoxCorrelatedData->setTristate(false); - ui.checkBoxCoherentStokes->setTristate(false); - ui.checkBoxIncoherentStokes->setTristate(false); - ui.checkBox_DelayCompensation->setTristate(false); - ui.checkBox_BandpassCorrection->setTristate(false); - ui.checkBoxPencilFlysEye->setTristate(false); - ui.checkBox_CoherentDedispersion->setTristate(false); - - ui.checkBoxCorrelatedData->blockSignals(true); - ui.checkBoxCoherentStokes->blockSignals(true); - ui.checkBoxIncoherentStokes->blockSignals(true); - ui.lineEditCorrelatorIntegrationTime->blockSignals(true); - ui.spinBoxChannelsPerSubband->blockSignals(true); - ui.checkBoxCorrelatedData->setChecked(itsOutputDataTypes.correlated); - if (ui.checkBoxCorrelatedData->isChecked()) { - ui.label_CorrelatorIntTime->setEnabled(true); - ui.lineEditCorrelatorIntegrationTime->setEnabled(true); - ui.labelChannelsPerSubband->setEnabled(true); - ui.spinBoxChannelsPerSubband->setEnabled(true); - } - else { - ui.label_CorrelatorIntTime->setEnabled(false); - ui.lineEditCorrelatorIntegrationTime->setEnabled(false); - ui.labelChannelsPerSubband->setEnabled(false); - ui.spinBoxChannelsPerSubband->setEnabled(false); - } - ui.checkBoxCoherentStokes->setChecked(itsOutputDataTypes.coherentStokes); - ui.checkBoxIncoherentStokes->setChecked(itsOutputDataTypes.incoherentStokes); - ui.checkBoxCorrelatedData->blockSignals(false); - ui.checkBoxCoherentStokes->blockSignals(false); - ui.checkBoxIncoherentStokes->blockSignals(false); - ui.lineEditCorrelatorIntegrationTime->blockSignals(false); - ui.spinBoxChannelsPerSubband->blockSignals(false); - - ui.checkBox_CoherentDedispersion->blockSignals(true); - ui.checkBox_CoherentDedispersion->setChecked(rtcp.coherentDedisperseChannels); - ui.checkBox_CoherentDedispersion->blockSignals(false); - ui.checkBox_BandpassCorrection->blockSignals(true); - ui.checkBox_BandpassCorrection->setChecked(rtcp.correctBandPass); - ui.checkBox_BandpassCorrection->blockSignals(false); - ui.checkBox_DelayCompensation->blockSignals(true); - ui.checkBox_DelayCompensation->setChecked(rtcp.delayCompensation); - ui.checkBox_DelayCompensation->blockSignals(false); - ui.comboBoxCoherentStokesType->blockSignals(true); - ui.comboBoxCoherentStokesType->setCurrentIndex(rtcp.coherentType); - ui.comboBoxCoherentStokesType->blockSignals(false); - ui.comboBoxIncoherentStokesType->blockSignals(true); - ui.comboBoxIncoherentStokesType->setCurrentIndex(rtcp.incoherentType); - ui.comboBoxIncoherentStokesType->blockSignals(false); - ui.spinBoxCoherentTimeIntegration->blockSignals(true); - ui.spinBoxCoherentTimeIntegration->setValue(rtcp.coherentTimeIntegrationFactor); - ui.spinBoxCoherentTimeIntegration->blockSignals(false); - ui.spinBoxIncoherentTimeIntegration->blockSignals(true); - ui.spinBoxIncoherentTimeIntegration->setValue(rtcp.incoherentTimeIntegrationFactor); - ui.spinBoxIncoherentTimeIntegration->blockSignals(false); - ui.spinBoxCoherentChannelsPerSubband->blockSignals(true); - if (rtcp.coherentChannelsPerSubband == 0) { - ui.spinBoxCoherentChannelsPerSubband->setMinimum(0); // this is not a valid value but if the task has it set to 0 then it should be shown as zero - } - else { - ui.spinBoxCoherentChannelsPerSubband->setMinimum(1); - } - ui.spinBoxCoherentChannelsPerSubband->setValue(rtcp.coherentChannelsPerSubband); - ui.spinBoxCoherentChannelsPerSubband->blockSignals(false); - ui.spinBoxIncoherentChannelsPerSubband->blockSignals(true); - if (rtcp.incoherentChannelsPerSubband == 0) { - ui.spinBoxIncoherentChannelsPerSubband->setMinimum(0); // this is not a valid value but if the task has it set to 0 then it should be shown as zero - } - else { - ui.spinBoxIncoherentChannelsPerSubband->setMinimum(1); - } - ui.spinBoxIncoherentChannelsPerSubband->setValue(rtcp.incoherentChannelsPerSubband); - ui.spinBoxIncoherentChannelsPerSubband->blockSignals(false); - ui.spinBoxCoherentSubbandsPerFile->blockSignals(true); - ui.spinBoxCoherentSubbandsPerFile->setValue(rtcp.coherentSubbandsPerFile); - ui.spinBoxCoherentSubbandsPerFile->blockSignals(false); - ui.spinBoxIncoherentSubbandsPerFile->blockSignals(true); - ui.spinBoxIncoherentSubbandsPerFile->setValue(rtcp.incoherentSubbandsPerFile); - ui.spinBoxIncoherentSubbandsPerFile->blockSignals(false); - - ui.lineEditCorrelatorIntegrationTime->setText(QString::number(rtcp.correlatorIntegrationTime)); - // bits per sample 2,4,8,16 bits - setBitsPerSample(rtcp.nrBitsPerSample); - ui.spinBoxChannelsPerSubband->setValue(rtcp.channelsPerSubband); - - ui.checkBoxPencilFlysEye->setChecked(rtcp.flysEye); - this->blockSignals(false); -} - -void TaskDialog::setBitsPerSample(unsigned short bitsPerSample) { - switch (bitsPerSample) { - case 4: - ui.comboBoxBitsPerSample->setCurrentIndex(0); - break; - case 8: - ui.comboBoxBitsPerSample->setCurrentIndex(1); - break; - default: // default 16 bits - ui.comboBoxBitsPerSample->setCurrentIndex(2); - break; - } - - // also set maximum nr of dataslots per RSP board - setMaxNrDataslotsPerRSPboard(bitsPerSample); -} - -void TaskDialog::setMaxNrDataslotsPerRSPboard(unsigned short bitsPerSample) { - ui.spinBoxDataslotsPerRSPboard->blockSignals(true); - switch (bitsPerSample) { - case 4: - ui.spinBoxDataslotsPerRSPboard->setMaximum(MAX_DATASLOT_PER_RSP_4_BITS + 1); - break; - case 8: - ui.spinBoxDataslotsPerRSPboard->setMaximum(MAX_DATASLOT_PER_RSP_8_BITS + 1); - break; - default: - ui.spinBoxDataslotsPerRSPboard->setMaximum(MAX_DATASLOT_PER_RSP_16_BITS + 1); - break; - } - ui.spinBoxDataslotsPerRSPboard->blockSignals(false); -} - -void TaskDialog::updateMaxDataslotsPerRSP(void) { - setMaxNrDataslotsPerRSPboard(ui.comboBoxBitsPerSample->currentText().toUInt()); - ui.spinBoxDataslotsPerRSPboard->blockSignals(true); - ui.spinBoxDataslotsPerRSPboard->setValue(ui.spinBoxDataslotsPerRSPboard->maximum()); - ui.spinBoxDataslotsPerRSPboard->blockSignals(false); - detectChanges(); -} - -void TaskDialog::StoreValues(void) { - // save current values for comparison to detect changes - itsStationClockIdx = ui.comboBoxStationClock->currentIndex(); - itsStationAntennaMode = ui.comboBoxStationClock->currentIndex(); - itsStationFilterType = ui.comboBoxStationFilter->currentIndex(); - - // beam settings - itsAnalogBeamSettings = getAnalogBeamSettings(); -} - -void TaskDialog::addDigitalBeam(void) { - itsDigitalBeamDialog->reset(); - itsDigitalBeamDialog->exec(); -} - -void TaskDialog::editDigitalBeam(void) { - // load the currently selected beam in the digital beam dialog - int row = ui.tableWidgetDigitalBeams->currentRow(); - if (row >= 0) { - if (ui.tableWidgetDigitalBeams->item(row, 0)->text().toStdString().compare(MULTIPLE_VALUE_TEXT) != 0) { - itsDigitalBeamDialog->loadBeamSettings(row, itsDigitalBeams.at(row)); - itsDigitalBeamDialog->exec(); - } - else QApplication::beep(); - } - else { - itsDigitalBeamDialog->loadBeamSettings(0, itsDigitalBeams.at(0)); - itsDigitalBeamDialog->exec(); - } -} - -void TaskDialog::deleteDigitalBeam(void) { - int row = ui.tableWidgetDigitalBeams->currentRow(); - if (row >= 0) { - ui.tableWidgetDigitalBeams->removeRow(row); - itsDigitalBeams.erase(row); - // important! renumber beam numbers in itsDigitalBeam map, to keep track of digital beams - int i(0); - std::map<unsigned, DigitalBeam> newBeams; - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - newBeams[i++] = it->second; - } - itsDigitalBeams = newBeams; - - if (itsDigitalBeams.empty()) { - ui.pushButtonClearAllBeams->setEnabled(false); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonEditBeam->setEnabled(false); - // also remove the tied array beams from the tied array beam table - // and update the tied array beam table and buttons - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - } - else { // show the tied array beams of the now selected digital beam - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); -// updateTiedArrayBeams(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()]); - checkEnableBeamButtons(); - - } - enableApplyButtons(true); - } - else { - QMessageBox::warning(this, tr("No beam selected"), - tr("No digital beam is selected for deletion.")); - } - countDigitalBeamSubbands(); -} - -void TaskDialog::clearAllDigitalBeams(void) { -// if (!itsDigitalBeams.empty()) { - itsDigitalBeams.clear(); - ui.tableWidgetDigitalBeams->clearContents(); - ui.tableWidgetDigitalBeams->setRowCount(0); - countDigitalBeamSubbands(); - changeBeams = true; - ui.pushButtonClearAllBeams->setEnabled(false); - ui.pushButtonDeleteBeams->setEnabled(false); - ui.pushButtonEditBeam->setEnabled(false); - // also clear the tied array beams (they are part of the digital beam) -// itsTiedArrayBeams.clear(); - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - ui.pushButtonAddTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - enableApplyButtons(true); -// } -} - -// function used a.o. by DigitalBeamDialog to add or update a beam -void TaskDialog::setDigitalBeam(int beamNr, const DigitalBeam &beam, bool change) { - // update the beam in the dialog's digital beam table - - if (beamNr == -1) { // -1 : add new beam - beamNr = itsDigitalBeams.size(); - ui.tableWidgetDigitalBeams->insertRow(beamNr); - ui.pushButtonEditBeam->setEnabled(true); // only enable these when a new beam is added - ui.pushButtonDeleteBeams->setEnabled(true); - ui.pushButtonClearAllBeams->setEnabled(true); - ui.pushButtonAddTiedArrayBeam->setEnabled(true); - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - } - - QTableWidgetItem *newItem = new QTableWidgetItem(beam.target().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 0, newItem); - newItem = new QTableWidgetItem(BEAM_DIRECTION_TYPES[beam.directionType()]); - ui.tableWidgetDigitalBeams->setItem(beamNr, 1, newItem); - // angle units - newItem = new QTableWidgetItem(ANGLE_PAIRS[beam.units()]); - ui.tableWidgetDigitalBeams->setItem(beamNr, 2, newItem); - // angle1 - switch (beam.units()) { - case ANGLE_PAIRS_HMS_DMS: - newItem = new QTableWidgetItem(beam.angle1().HMSstring().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 3, newItem); - // angle2 - newItem = new QTableWidgetItem(beam.angle2().DMSstring().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 4, newItem); - break; - case ANGLE_PAIRS_DMS_DMS: - newItem = new QTableWidgetItem(beam.angle1().DMSstring().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 3, newItem); - // angle2 - newItem = new QTableWidgetItem(beam.angle2().DMSstring().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 4, newItem); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - newItem = new QTableWidgetItem(QString::number(beam.angle1().degree(),'g',16)); - ui.tableWidgetDigitalBeams->setItem(beamNr, 3, newItem); - // angle2 - newItem = new QTableWidgetItem(QString::number(beam.angle2().degree(),'g',16)); - ui.tableWidgetDigitalBeams->setItem(beamNr, 4, newItem); - break; - case ANGLE_PAIRS_RADIANS: - newItem = new QTableWidgetItem(QString::number(beam.angle1().radian(),'g',16)); - ui.tableWidgetDigitalBeams->setItem(beamNr, 3, newItem); - // angle2 - newItem = new QTableWidgetItem(QString::number(beam.angle2().radian(),'g',16)); - ui.tableWidgetDigitalBeams->setItem(beamNr, 4, newItem); - break; - default: - break; - } - // subband list - newItem = new QTableWidgetItem(Vector2StringList(beam.subbandList())); - ui.tableWidgetDigitalBeams->setItem(beamNr, 5, newItem); - // number of subbands - newItem = new QTableWidgetItem(QString::number(beam.subbandList().size())); - ui.tableWidgetDigitalBeams->setItem(beamNr, 6, newItem); - // start time - newItem = new QTableWidgetItem(beam.startTime().toString().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 7, newItem); - // duration - newItem = new QTableWidgetItem(beam.duration().toString().c_str()); - ui.tableWidgetDigitalBeams->setItem(beamNr, 8, newItem); - // nr TAB rings - newItem = new QTableWidgetItem(QString::number(beam.nrTabRings())); - ui.tableWidgetDigitalBeams->setItem(beamNr, 9, newItem); - // duration - newItem = new QTableWidgetItem(QString::number(beam.tabRingSize(),'g',10)); - ui.tableWidgetDigitalBeams->setItem(beamNr, 10, newItem); - - // update the beam settings in itsDigitalBeams map - if (change) { - itsDigitalBeams[beamNr] = beam; -// enableApplyButtons(true); - detectChanges(); - countDigitalBeamSubbands(); - } - // select the just edited or added beam (needed to be able to edit its tied array beams) - ui.tableWidgetDigitalBeams->selectRow(beamNr); -} - -void TaskDialog::countDigitalBeamSubbands(void) { - unsigned totalSubbands(0); - for (unsigned i = 0; i < itsDigitalBeams.size(); ++i) { - totalSubbands += itsDigitalBeams[i].nrSubbands(); - } - // set the total number of subbands - ui.lineEditTotalSubbands->setText(QString::number(totalSubbands)); -} - -// sets the task's digital beam settings in the dialog and stores them in a local copy -void TaskDialog::setDigitalBeamSettings(const Observation *obs) { - ui.tableWidgetDigitalBeams->blockSignals(true); - ui.tableWidgetDigitalBeams->clearContents(); - // store the beam settings in a local copy - itsDigitalBeams = obs->getDigitalBeams(); - ui.tableWidgetDigitalBeams->setRowCount(itsDigitalBeams.size()); - int row(0); - for (std::map<unsigned, DigitalBeam>::const_iterator it = itsDigitalBeams.begin(); it != itsDigitalBeams.end(); ++it) { - setDigitalBeam(row++, it->second); - } - // set appropriate column widths - ui.tableWidgetDigitalBeams->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); - // set the total number of subbands - ui.lineEditTotalSubbands->setText(QString::number(obs->getNrOfSubbands())); - //also update the tied array beams - if (!itsDigitalBeams.empty()) { - ui.tableWidgetDigitalBeams->selectRow(0); - updateTiedArrayBeams(itsDigitalBeams.begin()->second); - } - ui.tableWidgetDigitalBeams->blockSignals(false); -} - -// obtains the current digital beam settings from the dialog and stores them in itsDigitalBeams -void TaskDialog::getDigitalBeamSettings(void) { - itsDigitalBeams.clear(); - DigitalBeam beam; - QTableWidgetItem * item; - QString coordUnits; - for (int row = 0; row < ui.tableWidgetDigitalBeams->rowCount(); ++row) { - // target name - item = ui.tableWidgetDigitalBeams->item(row, 0); - beam.setTarget(item->text().toStdString()); - // coordinate types - item = ui.tableWidgetDigitalBeams->item(row, 1); - beam.setDirectionType(stringToBeamDirectionType(item->text().toStdString())); - // angle units - item = ui.tableWidgetDigitalBeams->item(row, 2); - coordUnits = item->text(); - // now read angles according to current coordinate units - if (coordUnits == ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS]) { - // angle 1 - item = ui.tableWidgetDigitalBeams->item(row, 3); - beam.setAngle1HMS(item->text().toStdString()); - // angle 2 - item = ui.tableWidgetDigitalBeams->item(row, 4); - beam.setAngle2DMS(item->text().toStdString()); - // units - beam.setUnits(ANGLE_PAIRS_HMS_DMS); - } - else if (coordUnits == ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS]) { - // angle 1 - item = ui.tableWidgetDigitalBeams->item(row, 3); - beam.setAngle1DMS(item->text().toStdString()); - // angle 2 - item = ui.tableWidgetDigitalBeams->item(row, 4); - beam.setAngle2DMS(item->text().toStdString()); - // units - beam.setUnits(ANGLE_PAIRS_DMS_DMS); - } - else if (coordUnits == ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES]) { - // angle 1 - item = ui.tableWidgetDigitalBeams->item(row, 3); - beam.setAngle1Degree(item->text().toDouble()); - // angle 2 - item = ui.tableWidgetDigitalBeams->item(row, 4); - beam.setAngle2Degree(item->text().toDouble()); - // units - beam.setUnits(ANGLE_PAIRS_DECIMAL_DEGREES); - } - else if (coordUnits == ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]) { - // angle 1 - item = ui.tableWidgetDigitalBeams->item(row, 3); - beam.setAngle1Radian(item->text().toDouble()); - // angle 2 - item = ui.tableWidgetDigitalBeams->item(row, 4); - beam.setAngle2Radian(item->text().toDouble()); - // units - beam.setUnits(ANGLE_PAIRS_RADIANS); - } - // subband list - item = ui.tableWidgetDigitalBeams->item(row, 5); - beam.setSubbandList(item->text()); - - // data slots is on column 6 but cannot be changed by user, is determined automatically by the scheduler only shown for info - - // start time - item = ui.tableWidgetDigitalBeams->item(row, 7); - beam.setStartTime(AstroTime(item->text().toStdString())); - - // duration - item = ui.tableWidgetDigitalBeams->item(row, 8); - beam.setDuration(AstroTime(item->text().toStdString())); - - item = ui.tableWidgetDigitalBeams->item(row, 9); - beam.setNrTabRings(item->text().toUInt()); - - item = ui.tableWidgetDigitalBeams->item(row, 10); - beam.setTabRingSize(item->text().toDouble()); - - // store in itsDigitalBeams - itsDigitalBeams[row] = beam; - } -} - -void TaskDialog::addTiedArrayBeam(void) { - itsTiedArrayBeamDialog->setAddMode(); -// itsTiedArrayBeamDialog->setWindowTitle("Add Tied Array Beam " + QString::number(itsTiedArrayBeams.size())); - itsTiedArrayBeamDialog->setMultiEdit(true); - itsTiedArrayBeamDialog->exec(); -} - - -void TaskDialog::addNewTiedArrayBeams(int nrBeams, const TiedArrayBeam &TAB) { - int digiBeamNr(ui.tableWidgetDigitalBeams->currentRow()); - std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(itsDigitalBeams[digiBeamNr].getTiedArrayBeamsForChange()); - int newTABstartNr(tiedArrayBeams.size()); - for (int tabNr = newTABstartNr; tabNr < newTABstartNr + nrBeams; ++tabNr) { - tiedArrayBeams[tabNr].setAngle1(TAB.angle1()); - tiedArrayBeams[tabNr].setAngle2(TAB.angle2()); - tiedArrayBeams[tabNr].setDispersionMeasure(TAB.dispersionMeasure()); - tiedArrayBeams[tabNr].setCoherent(TAB.isCoherent()); - } - // update the tied array beams in itsDigitalBeams -// itsDigitalBeams[digiBeamNr].setTiedArrayBeams(itsTiedArrayBeams); - // update the tied array beam table to reflect the changes - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(tiedArrayBeams.size()); - int row(0); - for (std::map<unsigned, TiedArrayBeam>::const_iterator it = tiedArrayBeams.begin(); it != tiedArrayBeams.end(); ++it) { - setTiedArrayBeam(row++, it->second); - } - checkEnableBeamButtons(); - enableApplyButtons(true); -} - -void TaskDialog::deleteTiedArrayBeam(void) { - std::vector<unsigned> selectedRows; - for (int row = 0; row < ui.tableWidgetTiedArrayBeams->rowCount(); ++row) { - if (ui.tableWidgetTiedArrayBeams->item(row,0)->isSelected()) { - selectedRows.push_back(row); - } - } - std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()].getTiedArrayBeamsForChange()); - if (selectedRows.size() != 0) { - for (std::vector<unsigned>::const_iterator it = selectedRows.begin(); it != selectedRows.end(); ++it) { - tiedArrayBeams.erase(*it); - } - // re-enumerate the tied array beams - unsigned cnt(0); - std::map<unsigned, TiedArrayBeam> newTABs; - for(std::map<unsigned, TiedArrayBeam>::iterator it = tiedArrayBeams.begin(); it != tiedArrayBeams.end(); ++it ) { - newTABs[cnt++] = it->second; - } - tiedArrayBeams = newTABs; - - // remove the selected tied array beams from the tied array beams table - for (std::vector<unsigned>::reverse_iterator it = selectedRows.rbegin(); it != selectedRows.rend(); ++it) { - ui.tableWidgetTiedArrayBeams->removeRow(*it); - } - checkEnableBeamButtons(); - enableApplyButtons(true); - } - else { - QMessageBox::warning(this, tr("No tied array beam selected"), - tr("To delete, select one or more tied array beams in the table first.")); - } -} - -void TaskDialog::clearAllTiedArrayBeams(void) { - std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()].getTiedArrayBeamsForChange()); - tiedArrayBeams.clear(); - ui.pushButtonDeleteTiedArrayBeam->setEnabled(false); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(false); - ui.pushButtonEditTiedArrayBeam->setEnabled(false); - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - enableApplyButtons(true); -} - -void TaskDialog::editTiedArrayBeam(void) { - // load the currently selected beam in the tied array beam dialog - std::vector<unsigned> selectedRows; - for (int row = 0; row < ui.tableWidgetTiedArrayBeams->rowCount(); ++row) { - if (ui.tableWidgetTiedArrayBeams->item(row,0)->isSelected()) { - selectedRows.push_back(row); - } - } - unsigned nrSelectedRows(selectedRows.size()); - std::map<unsigned, TiedArrayBeam> tmpTiedArrays; - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()].tiedArrayBeams()); - if (nrSelectedRows == 1) { // single row edit - itsTiedArrayBeamDialog->setMultiEdit(false); - std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.find(selectedRows.front()); - if (tit != tiedArrayBeams.end()) { - tmpTiedArrays[selectedRows.front()] = tit->second; - itsTiedArrayBeamDialog->loadTiedArrayBeam(tmpTiedArrays); - itsTiedArrayBeamDialog->exec(); - } - } - else if (nrSelectedRows > 1) { // multi row edit - for (std::vector<unsigned>::const_iterator rit = selectedRows.begin(); rit != selectedRows.end(); ++rit) { - std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.find(*rit); - tmpTiedArrays[*rit] = tit->second; - } - itsTiedArrayBeamDialog->loadTiedArrayBeam(tmpTiedArrays); - itsTiedArrayBeamDialog->exec(); - } - else { - QMessageBox::warning(this, tr("No tied array beam selected"), - tr("To edit, select one or more tied array beams in the table first.")); - } -} - -void TaskDialog::applyChangeToTiedArrayBeams(const std::vector<unsigned> &tabNrs, const TiedArrayBeam &TAB, const tabProps &applyTABprop) { - bool change(false); -// std::map<unsigned, TiedArrayBeam> tiedArrayBeams; - std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()].getTiedArrayBeamsForChange()); - for (std::vector<unsigned>::const_iterator it = tabNrs.begin(); it != tabNrs.end(); ++it) { - if (applyTABprop.angle1) { // apply settings for angle1 ? - tiedArrayBeams[*it].setAngle1(TAB.angle1()); - change = true; - } - if (applyTABprop.angle2) { - tiedArrayBeams[*it].setAngle2(TAB.angle2()); - change = true; - } - if (applyTABprop.dispersion_measure) { - tiedArrayBeams[*it].setDispersionMeasure(TAB.dispersionMeasure()); - change = true; - } - if (applyTABprop.coherent) { - tiedArrayBeams[*it].setCoherent(TAB.isCoherent()); - change = true; - } - } - if (change) { - // update the tied array beam table to reflect the changes - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(tiedArrayBeams.size()); - int row(0); - for (std::map<unsigned, TiedArrayBeam>::const_iterator it = tiedArrayBeams.begin(); it != tiedArrayBeams.end(); ++it) { - setTiedArrayBeam(row++, it->second); - } - detectChanges(); - } -} - -// sets the task's tied array beam settings in the dialog and stores them in a local copy -void TaskDialog::updateTiedArrayBeams(const DigitalBeam &digiBeam) { - ui.tableWidgetTiedArrayBeams->clearContents(); - ui.tableWidgetTiedArrayBeams->setRowCount(0); - - // store the beam settings in a local copy - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(digiBeam.tiedArrayBeams()); - ui.tableWidgetTiedArrayBeams->setRowCount(tiedArrayBeams.size()); - for (std::map<unsigned, TiedArrayBeam>::const_iterator it = tiedArrayBeams.begin(); it != tiedArrayBeams.end(); ++it) { - setTiedArrayBeam(it->first, it->second); - } -} - -// SLOT showTiedArrayBeams used when clicking in the digital beam dialog to show the digital's beam its tied array beams -void TaskDialog::showTiedArrayBeams(int digitalBeamNr) { - updateTiedArrayBeams(itsDigitalBeams[digitalBeamNr]); -} - -void TaskDialog::setTiedArrayBeam(int TABnr, const TiedArrayBeam &TAB) { - bool change(false), newTiedArrayBeam(false); - std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(itsDigitalBeams[ui.tableWidgetDigitalBeams->currentRow()].getTiedArrayBeamsForChange()); - if (TABnr == -1) { // beam = -1 means add a new beam - newTiedArrayBeam = true; - TABnr = tiedArrayBeams.size(); - ui.tableWidgetTiedArrayBeams->insertRow(TABnr); - ui.pushButtonEditTiedArrayBeam->setEnabled(true); // only enable these when a new beam is added - ui.pushButtonDeleteTiedArrayBeam->setEnabled(true); - ui.pushButtonClearAllTiedArrayBeam->setEnabled(true); - } - // angle1 - QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(TAB.angle1(),'g',16)); - ui.tableWidgetTiedArrayBeams->setItem(TABnr, 0, newItem); - // angle2 - newItem = new QTableWidgetItem(QString::number(TAB.angle2(),'g',16)); - ui.tableWidgetTiedArrayBeams->setItem(TABnr, 1, newItem); - // type (coherent/incoherent) - QString coherent; - TAB.isCoherent() ? coherent = "coherent" : coherent = "incoherent"; - newItem = new QTableWidgetItem(coherent); - ui.tableWidgetTiedArrayBeams->setItem(TABnr, 2, newItem); - // dispersion measure - newItem = new QTableWidgetItem(QString::number(TAB.dispersionMeasure(),'g',16)); - ui.tableWidgetTiedArrayBeams->setItem(TABnr, 3, newItem); - - // update the TABs - if (newTiedArrayBeam) { - change = true; - } - else if (TAB != tiedArrayBeams[TABnr]) change = true; // TODO: itsTiedArrayBeams have not been set when called from show(), therefore change is always set true here - // should this not be changed so that a compare is made with the tiedarraybeams from tsTask ? But of which digital beam then? - - if (change) { - tiedArrayBeams[TABnr] = TAB; - enableApplyButtons(true); -// changeBeams = true; - } -} - - -void TaskDialog::FilterTypeChanged(int newFilter) { - switch (newFilter) { - case 1: - case 2: - case 6: - ui.comboBoxStationClock->setCurrentIndex(1); // 160 Mhz - break; - case 3: - case 4: - case 5: - case 7: - ui.comboBoxStationClock->setCurrentIndex(2); // 200 Mhz - break; - } - if ((newFilter >= 1) & (newFilter <=4)) { - ui.groupBoxAnalogBeam->setEnabled(false); // for LBA antenna modes the Analog beam settings are not relevant - if (ui.comboBoxStationAntennaMode->currentText().startsWith("HBA")) { // discrepancy between new filter type choosen and antenna mode - ui.comboBoxStationAntennaMode->setCurrentIndex(0, false); // UNSPECIFIED antenna mode - } - } - else { - ui.groupBoxAnalogBeam->setEnabled(true); // for HBA antenna modes the Analog beam settings need to be specified - if (newFilter > 4) { // HBA filter type - if (ui.comboBoxStationAntennaMode->currentText().startsWith("LBA")) { // discrepancy between new filter type choosen and antenna mode - ui.comboBoxStationAntennaMode->setCurrentIndex(0, false); // UNSPECIFIED antenna mode - } - } - } - - if (!addingReservation && !addingTask) { // disable/enable apply and cancel buttons only when changing a task not when adding a new task - if (itsStationFilterType != newFilter) { - enableApplyButtons(true); - changeStations = true; - } - else { - changeStations = false; - detectChanges(); - } - } -} - -void TaskDialog::AntennaModeChanged(int newMode) { - if ((newMode >= 1) & (newMode <=6)) { // LBA modes - ui.groupBoxAnalogBeam->setEnabled(false); // for LBA antenna modes the Analog beam settings are not relevant - if (ui.comboBoxStationFilter->currentText().startsWith("HBA")) { // discrepancy between new antenna mode choosen and filter type - ui.comboBoxStationFilter->setCurrentIndex(0); // UNSPECIFIED filter type - } - } - else { - ui.groupBoxAnalogBeam->setEnabled(true); // for HBA antenna modes the Analog beam settings need to be specified - if (newMode > 6) { // HBA antenna mode was chosen - if (ui.comboBoxStationFilter->currentText().startsWith("LBA")) { // discrepancy between new antenna mode choosen and filter type - ui.comboBoxStationFilter->setCurrentIndex(0); // UNSPECIFIED filter type - } - } - } - - if (!addingReservation && !addingTask) { // disable/enable apply and cancel buttons only when changing a task not when adding a new task - if (itsStationAntennaMode != newMode) { - enableApplyButtons(true); - changeStations = true; - } - else { - changeStations = false; - detectChanges(); - } - } -} - -void TaskDialog::StationClockModeChanged(int newClockMode) { - if (newClockMode) { // 0 = UNSPECIFIED - const QString &filter = ui.comboBoxStationFilter->currentText(); - if (newClockMode == clock_160Mhz) { - if ((filter == filter_types_str[LBA_10_70]) | - (filter == filter_types_str[LBA_30_70]) | // 160MHz filter types - (filter == filter_types_str[HBA_170_230])) { } - else { // 200MHz filter types - // clock mode chosen that is not compatible with the current station filter - ui.comboBoxStationFilter->setCurrentIndex(0, false); - } - } - } - if (!addingReservation && !addingTask) { // disable/enable apply and cancel buttons only when changing a task not when adding a new task - if (itsStationClockIdx != newClockMode) { - enableApplyButtons(true); - changeStations = true; - } - else { - changeStations = false; - detectChanges(); - } - } -} - -void TaskDialog::setAnalogBeamUnitsComboBox(void) { - QStringList items; - beamDirectionType newCoordinateSystem = static_cast<beamDirectionType>(ui.comboBoxAnalogBeamCoordinates->currentIndex()); - switch (newCoordinateSystem) { - default: - case DIR_TYPE_J2000: // Right ascension & declination - case DIR_TYPE_B1950: - case DIR_TYPE_ICRS: - case DIR_TYPE_ITRF: - case DIR_TYPE_TOPO: - case DIR_TYPE_APP: - ui.labelBeamAngle1->setText("Right Asc.:"); - ui.labelBeamAngle2->setText("Declination:"); - ui.labelAngleNotation->setText("Units (ra,dec):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_HADEC: - ui.labelBeamAngle1->setText("Hour angle:"); - ui.labelBeamAngle2->setText("Declination:"); - ui.labelAngleNotation->setText("Units (ha,dec):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_AZELGEO: - ui.labelBeamAngle1->setText("Azimuth:"); - ui.labelBeamAngle2->setText("Elevation:"); - ui.labelAngleNotation->setText("Units (az,el):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_SUN: - case DIR_TYPE_MOON: - case DIR_TYPE_PLUTO: - case DIR_TYPE_NEPTUNE: - case DIR_TYPE_URANUS: - case DIR_TYPE_SATURN: - case DIR_TYPE_JUPITER: - case DIR_TYPE_MARS: - case DIR_TYPE_VENUS: - case DIR_TYPE_MERCURY: - ui.labelBeamAngle1->setText("Angle 1:"); - ui.labelBeamAngle2->setText("Angle 2:"); - ui.labelAngleNotation->setText("Units (ang1,ang2):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - break; - case DIR_TYPE_GALACTIC: - case DIR_TYPE_ECLIPTIC: - case DIR_TYPE_COMET: - ui.labelBeamAngle1->setText("Longitude:"); - ui.labelBeamAngle2->setText("Latitude:"); - ui.labelAngleNotation->setText("Units (long,lat):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - } - ui.comboBoxAnalogBeamUnits->blockSignals(true); - ui.comboBoxAnalogBeamUnits->clear(); - ui.comboBoxAnalogBeamUnits->addItems(items); - ui.comboBoxAnalogBeamUnits->blockSignals(false); -} - -void TaskDialog::AnalogBeamDirectionTypeChanged(void) { - beamDirectionType newCoordinateSystem = static_cast<beamDirectionType>(ui.comboBoxAnalogBeamCoordinates->currentIndex()); - - if (newCoordinateSystem != itsAnalogBeamSettings.directionType) { - - setAnalogBeamUnitsComboBox(); - - itsAnalogBeamSettings.directionType = newCoordinateSystem; - - changeBeams = true; - enableApplyButtons(true); - } - else detectChanges(); -} - - -void TaskDialog::setAnalogBeamAngle1(void) { - switch (itsAnalogBeamAnglePair) { - case ANGLE_PAIRS_HMS_DMS: - if (!itsAnalogBeamSettings.angle1.setHMSangleStr(ui.lineEditAnalogBeamAngle1->text().toStdString())) { - QPalette palet = ( ui.lineEditAnalogBeamAngle1->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditAnalogBeamAngle1->setPalette(palet); - QMessageBox::warning(this, tr("Wrong HMS angle"), tr("The entered HMS angle is invalid")); - QApplication::beep(); - } - else { - ui.lineEditAnalogBeamAngle1->setPalette(QPalette()); - } - break; - case ANGLE_PAIRS_DMS_DMS: - if (!itsAnalogBeamSettings.angle1.setDMSangleStr(ui.lineEditAnalogBeamAngle1->text().toStdString())) { - QPalette palet = ( ui.lineEditAnalogBeamAngle1->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditAnalogBeamAngle1->setPalette(palet); - QMessageBox::warning(this, tr("Wrong DMS angle"), tr("The entered DMS angle is invalid")); - QApplication::beep(); - } - else { - ui.lineEditAnalogBeamAngle1->setPalette(QPalette()); - } - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - itsAnalogBeamSettings.angle1.setDegreeAngle(ui.lineEditAnalogBeamAngle1->text().toDouble()); - ui.lineEditAnalogBeamAngle1->setPalette(QPalette()); - break; - case ANGLE_PAIRS_RADIANS: - itsAnalogBeamSettings.angle1.setRadianAngle(ui.lineEditAnalogBeamAngle1->text().toDouble()); - ui.lineEditAnalogBeamAngle1->setPalette(QPalette()); - break; - default: - break; - } -} - -void TaskDialog::setAnalogBeamAngle2(void) { - switch (itsAnalogBeamAnglePair) { - case ANGLE_PAIRS_HMS_DMS: - if (!itsAnalogBeamSettings.angle2.setDMSangleStr(ui.lineEditAnalogBeamAngle2->text().toStdString())) { - QPalette palet = ( ui.lineEditAnalogBeamAngle2->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditAnalogBeamAngle2->setPalette(palet); - QMessageBox::warning(this, tr("Wrong DMS angle"), tr("The entered DMS angle is invalid")); - QApplication::beep(); - } - else { - ui.lineEditAnalogBeamAngle2->setPalette(QPalette()); - } - break; - case ANGLE_PAIRS_DMS_DMS: - if (!itsAnalogBeamSettings.angle2.setDMSangleStr(ui.lineEditAnalogBeamAngle2->text().toStdString())) { - QPalette palet = ( ui.lineEditAnalogBeamAngle2->palette() ); - palet.setColor( QPalette::Base, Qt::red ); - ui.lineEditAnalogBeamAngle2->setPalette(palet); - QMessageBox::warning(this, tr("Wrong DMS angle"), tr("The entered DMS angle is invalid")); - QApplication::beep(); - } - else { - ui.lineEditAnalogBeamAngle2->setPalette(QPalette()); - } - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - itsAnalogBeamSettings.angle2.setDegreeAngle(ui.lineEditAnalogBeamAngle2->text().toDouble()); - ui.lineEditAnalogBeamAngle2->setPalette(QPalette()); - break; - case ANGLE_PAIRS_RADIANS: - itsAnalogBeamSettings.angle2.setRadianAngle(ui.lineEditAnalogBeamAngle2->text().toDouble()); - ui.lineEditAnalogBeamAngle2->setPalette(QPalette()); - break; - default: - break; - } -} - - -void TaskDialog::AnalogBeamAngleUnitChanged(const QString &unitStr) { - anglePairs newDisplayUnits; - - if (unitStr.compare(ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS]) == 0) newDisplayUnits = ANGLE_PAIRS_HMS_DMS; - else if (unitStr.compare(ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS]) == 0) newDisplayUnits = ANGLE_PAIRS_DMS_DMS; - else if (unitStr.compare(ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES]) == 0) newDisplayUnits = ANGLE_PAIRS_DECIMAL_DEGREES; - else newDisplayUnits = ANGLE_PAIRS_RADIANS; - - if (newDisplayUnits != itsAnalogBeamAnglePair) { - setAnalogBeamAnglePair(newDisplayUnits); - itsAnalogBeamAnglePair = newDisplayUnits; - } -} - -void TaskDialog::setComboBoxAnalogBeamUnits(void) const { - QStringList items; - ui.comboBoxAnalogBeamUnits->clear(); - switch (itsAnalogBeamSettings.directionType) { - default: - case DIR_TYPE_J2000: // Right ascension & declination - case DIR_TYPE_B1950: - case DIR_TYPE_ICRS: - case DIR_TYPE_ITRF: - case DIR_TYPE_TOPO: - case DIR_TYPE_APP: - ui.labelBeamAngle1->setText("Right Asc.:"); - ui.labelBeamAngle2->setText("Declination:"); - ui.labelAngleNotation->setText("Units (ra,dec):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_HADEC: - ui.labelBeamAngle1->setText("Hour angle:"); - ui.labelBeamAngle2->setText("Declination:"); - ui.labelAngleNotation->setText("Units (ha,dec):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_HMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_AZELGEO: - ui.labelBeamAngle1->setText("Azimuth:"); - ui.labelBeamAngle2->setText("Elevation:"); - ui.labelAngleNotation->setText("Units (az,el):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - case DIR_TYPE_SUN: - case DIR_TYPE_MOON: - case DIR_TYPE_PLUTO: - case DIR_TYPE_NEPTUNE: - case DIR_TYPE_URANUS: - case DIR_TYPE_SATURN: - case DIR_TYPE_JUPITER: - case DIR_TYPE_MARS: - case DIR_TYPE_VENUS: - case DIR_TYPE_MERCURY: - ui.labelBeamAngle1->setText("Angle 1:"); - ui.labelBeamAngle2->setText("Angle 2:"); - ui.labelAngleNotation->setText("Units (ang1,ang2):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - break; - case DIR_TYPE_GALACTIC: - case DIR_TYPE_ECLIPTIC: - case DIR_TYPE_COMET: - ui.labelBeamAngle1->setText("Longitude:"); - ui.labelBeamAngle2->setText("Latitude:"); - ui.labelAngleNotation->setText("Units (long,lat):"); - items << ANGLE_PAIRS[ANGLE_PAIRS_DMS_DMS] - << ANGLE_PAIRS[ANGLE_PAIRS_DECIMAL_DEGREES] - << ANGLE_PAIRS[ANGLE_PAIRS_RADIANS]; - break; - } - ui.comboBoxAnalogBeamUnits->addItems(items); -} - -void TaskDialog::setAnalogBeamAnglePair(const anglePairs &anglepair) { - ui.lineEditAnalogBeamAngle1->blockSignals(true); // to prevent false detection of changes - ui.lineEditAnalogBeamAngle2->blockSignals(true); - switch (anglepair) { - case ANGLE_PAIRS_HMS_DMS: - ui.lineEditAnalogBeamAngle1->setInputMask("00:00:00.000000"); - ui.lineEditAnalogBeamAngle2->setInputMask("#00:00:00.000000"); - ui.lineEditAnalogBeamAngle1->setText(itsAnalogBeamSettings.angle1.HMSstring().c_str()); - ui.lineEditAnalogBeamAngle2->setText(itsAnalogBeamSettings.angle2.DMSstring().c_str()); - break; - case ANGLE_PAIRS_DMS_DMS: - ui.lineEditAnalogBeamAngle1->setInputMask("000:00:00.000000"); - ui.lineEditAnalogBeamAngle2->setInputMask("#00:00:00.000000"); - ui.lineEditAnalogBeamAngle1->setText(itsAnalogBeamSettings.angle1.DMSstring().c_str()); - ui.lineEditAnalogBeamAngle2->setText(itsAnalogBeamSettings.angle2.DMSstring().c_str()); - break; - case ANGLE_PAIRS_RADIANS: - ui.lineEditAnalogBeamAngle1->setInputMask("0.0000000000"); - ui.lineEditAnalogBeamAngle2->setInputMask("#0.0000000000"); - ui.lineEditAnalogBeamAngle1->setText(QString::number(itsAnalogBeamSettings.angle1.radian(),'g',16)); - ui.lineEditAnalogBeamAngle2->setText(QString::number(itsAnalogBeamSettings.angle2.radian(),'g',16)); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - ui.lineEditAnalogBeamAngle1->setInputMask("000.0000000000"); - ui.lineEditAnalogBeamAngle2->setInputMask("#00.0000000000"); - ui.lineEditAnalogBeamAngle1->setText(QString::number(itsAnalogBeamSettings.angle1.degree(),'g',16)); - ui.lineEditAnalogBeamAngle2->setText(QString::number(itsAnalogBeamSettings.angle2.degree(),'g',16)); - break; - default: - break; - } - itsAnalogBeamAngle1Str = ui.lineEditAnalogBeamAngle1->text(); // for change detection - itsAnalogBeamAngle2Str = ui.lineEditAnalogBeamAngle2->text(); - ui.lineEditAnalogBeamAngle1->blockSignals(false); // to prevent false detection of changes - ui.lineEditAnalogBeamAngle2->blockSignals(false); // to prevent false detection of changes -} - -Observation::analogBeamSettings TaskDialog::getAnalogBeamSettings(void) const { - Observation::analogBeamSettings beamSettings; - switch (itsAnalogBeamAnglePair) { - case ANGLE_PAIRS_HMS_DMS: - beamSettings.angle1.setHMSangleStr(ui.lineEditAnalogBeamAngle1->text().toStdString()); - beamSettings.angle2.setDMSangleStr(ui.lineEditAnalogBeamAngle2->text().toStdString()); - break; - case ANGLE_PAIRS_DMS_DMS: - beamSettings.angle1.setDMSangleStr(ui.lineEditAnalogBeamAngle1->text().toStdString()); - beamSettings.angle2.setDMSangleStr(ui.lineEditAnalogBeamAngle2->text().toStdString()); - break; - case ANGLE_PAIRS_RADIANS: - beamSettings.angle1.setRadianAngle(ui.lineEditAnalogBeamAngle1->text().toDouble()); - beamSettings.angle2.setRadianAngle(ui.lineEditAnalogBeamAngle2->text().toDouble()); - break; - case ANGLE_PAIRS_DECIMAL_DEGREES: - beamSettings.angle1.setDegreeAngle(ui.lineEditAnalogBeamAngle1->text().toDouble()); - beamSettings.angle2.setDegreeAngle(ui.lineEditAnalogBeamAngle2->text().toDouble()); - break; - default: - break; - } - beamSettings.directionType = static_cast<beamDirectionType>(ui.comboBoxAnalogBeamCoordinates->currentIndex()); - beamSettings.duration = AstroTime(ui.lineEditAnalogBeamDuration->text().toStdString()); - QTime timeVal = ui.timeEditAnalogBeamStartTime->time(); - beamSettings.startTime = AstroTime(timeVal.hour(), timeVal.minute(), timeVal.second()); - return beamSettings; -} - -void TaskDialog::setAnalogBeamSettings(const Observation::analogBeamSettings &beamSettings) { - itsAnalogBeamSettings = beamSettings; - itsAnalogBeamSettings = beamSettings; - ui.comboBoxAnalogBeamCoordinates->blockSignals(true); - ui.comboBoxAnalogBeamCoordinates->setCurrentIndex(itsAnalogBeamSettings.directionType); - ui.comboBoxAnalogBeamCoordinates->blockSignals(false); - setComboBoxAnalogBeamUnits(); - setAnalogBeamAnglePair(itsAnalogBeamAnglePair); - ui.timeEditAnalogBeamStartTime->setTime(QTime(itsAnalogBeamSettings.startTime.getHours(), - itsAnalogBeamSettings.startTime.getMinutes(),itsAnalogBeamSettings.startTime.getSeconds())); - ui.lineEditAnalogBeamDuration->setText(itsAnalogBeamSettings.duration.toString()); -} - -void TaskDialog::analogBeamStartTimeChanged(const QTime &starttime) { - AstroTime newStartTime(starttime.hour(), starttime.minute(), starttime.second()); - if (itsAnalogBeamSettings.startTime != newStartTime) { - itsAnalogBeamSettings.startTime = AstroTime(starttime.hour(), starttime.minute(), starttime.second()); - } - else detectChanges(); -} - -void TaskDialog::analogBeamDurationChanged(const QString &duration) { - itsAnalogBeamSettings.duration = duration; - if (itsTask->isObservation()) { - if (itsAnalogBeamSettings.duration != static_cast<const Observation *>(itsTask)->getAnalogBeam().duration) { - enableApplyButtons(true); - changeBeams = true; - } - else detectChanges(); - } -} - -void TaskDialog::loadReservations(void) { - ui.comboBoxReservation->blockSignals(true); - ui.comboBoxReservation->clear(); - ui.comboBoxReservation->addItem("no reservation", 0); - ui.comboBoxReservation->setEnabled(true); - bool selectReservation(false), foundReservation(false); - unsigned reservationID(0); - if (itsTask->isObservation()) { - reservationID = static_cast<const Observation *>(itsTask)->getReservation(); - } - - if (reservationID) selectReservation = true; - reservationsMap reservations = itsController->getReservations(); - reservationsMap::const_iterator rit = reservations.begin(); - int idx(1); - while (rit != reservations.end()) { - if (rit->second->isReservation()) { - ui.comboBoxReservation->addItem(QString(rit->second->getTaskName()) + " (" + QString::number(rit->second->getSASTreeID()) + ")", rit->first); - if (selectReservation) { - if (rit->first == reservationID) { - ui.comboBoxReservation->setCurrentIndex(idx); - ui.comboBoxReservation->setEnabled(false); - ui.pushButtonUnBindReservation->setEnabled(true); - foundReservation = true; - selectReservation = false; - } - else { - ++idx; - } - } - } - ++rit; - } - if (!foundReservation) { - ui.pushButtonUnBindReservation->setEnabled(false); - } - ui.comboBoxReservation->blockSignals(false); -} - -void TaskDialog::bindToReservation(int currentIndex) { - if (itsTask->isObservation()) { - Observation *obs(static_cast<Observation *>(itsTask)); - unsigned reservationID = ui.comboBoxReservation->itemData(currentIndex).toUInt(); - if (obs->getReservation() != reservationID) { - //do checks on task for compatibility with reservation and show needed changes if necessary - std::pair<bool, std::pair<QString, Observation> > reservationCheck = itsController->doReservationChecks(obs, reservationID); - if (reservationCheck.first) { // changes to the task are needed to be compatible with the reservation, warn user about changes - - if (QMessageBox::question(this, tr("Task changes needed"), reservationCheck.second.first + "\nDo you want to continue with these changes?", - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - obs->clone(&reservationCheck.second.second); - obs->setReservation(reservationID); - // update the dialog with the accepted changes - ui.lineEditDuration->blockSignals(true); - ui.dateTimeEditScheduledStart->blockSignals(true); - ui.dateTimeEditScheduledEnd->blockSignals(true); - ui.comboBoxStationClock->blockSignals(true); - ui.comboBoxStationFilter->blockSignals(true); - ui.lineEditDuration->setText(itsTask->getDuration().toString()); - const AstroDate &fdate(itsTask->getWindowFirstDay()); - const AstroTime &ftime(itsTask->getWindowMinTime()); - const AstroDate &ldate(itsTask->getWindowLastDay()); - const AstroTime <ime(itsTask->getWindowMaxTime()); - const AstroDateTime &start(itsTask->getScheduledStart()); - const AstroDateTime &stop(itsTask->getScheduledEnd()); - ui.dateTimeEditScheduledStart->setMinimumDateTime(QDateTime(QDate(fdate.getYear(), fdate.getMonth(), fdate.getDay()), QTime(ftime.getHours(), ftime.getMinutes(), ftime.getSeconds()))); - // ui.dateTimeEditScheduledEnd->setMaximumDateTime(QDateTime(QDate(ldate.getYear(), ldate.getMonth(), ldate.getDay()), QTime(ltime.getHours(), ltime.getMinutes(), ltime.getSeconds()))); - setScheduledStart(QDateTime(QDate(start.getYear(), start.getMonth(), start.getDay()), QTime(start.getHours(), start.getMinutes(), start.getSeconds()))); - setScheduledEnd(QDateTime(QDate(stop.getYear(), stop.getMonth(), stop.getDay()), QTime(stop.getHours(), stop.getMinutes(), stop.getSeconds()))); - ui.dateEditFirstPossibleDate->setDate(QDate(fdate.getYear(), fdate.getMonth(), fdate.getDay())); - ui.timeEditFirstPossibleTime->setTime(QTime(ftime.getHours(), ftime.getMinutes(), ftime.getSeconds())); - ui.dateEditLastPossibleDate->setDate(QDate(ldate.getYear(), ldate.getMonth(), ldate.getDay())); - ui.timeEditLastPossibleTime->setTime(QTime(ltime.getHours(), ltime.getMinutes(), ltime.getSeconds())); - setStations(obs); - ui.comboBoxStationClock->setCurrentIndex(obs->getStationClock()); - ui.comboBoxStationFilter->setCurrentIndex(obs->getFilterType()); - ui.comboBoxStationAntennaMode->setCurrentIndex(obs->getAntennaMode()); - ui.lineEditDuration->blockSignals(false); - ui.dateTimeEditScheduledStart->blockSignals(false); - ui.dateTimeEditScheduledEnd->blockSignals(false); - ui.comboBoxStationClock->blockSignals(false); - ui.comboBoxStationFilter->blockSignals(false); - - changeSchedule = true; - enableApplyButtons(true); - } - else { - ui.comboBoxReservation->blockSignals(true); - ui.comboBoxReservation->setCurrentIndex(0); - ui.comboBoxReservation->blockSignals(false); - } - } - } - } -} - -void TaskDialog::unbindReservation(void) { - if (itsTask->isObservation()) { - static_cast<Observation *>(itsTask)->setReservation(0); - changeSchedule = true; - ui.pushButtonUnBindReservation->blockSignals(true); - ui.comboBoxReservation->blockSignals(true); - ui.pushButtonUnBindReservation->setEnabled(false); - ui.comboBoxReservation->setCurrentIndex(0); - ui.comboBoxReservation->setEnabled(true); - ui.pushButtonUnBindReservation->blockSignals(false); - ui.comboBoxReservation->blockSignals(false); - enableApplyButtons(true); - } -} diff --git a/SAS/Scheduler/src/taskdialog.h b/SAS/Scheduler/src/taskdialog.h deleted file mode 100644 index 860f1c80a03c8e6a7a61ca0a423721c5ea808e39..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskdialog.h +++ /dev/null @@ -1,278 +0,0 @@ -/* - * taskdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Nov 2009 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/taskdialog.h $ - * - */ - -#ifndef TASKDIALOG_H -#define TASKDIALOG_H - -#include <QDialog> -#include <vector> -#include <string> -#include "lofar_scheduler.h" -#include "ui_taskdialog.h" -#include "task.h" -#include "observation.h" -#include "Angle.h" -#include "digitalbeamdialog.h" -#include "tiedarraybeamdialog.h" -#include "dataslotdialog.h" -#include "DigitalBeam.h" - -class Task; -class StationTreeWidget; -class StationListWidget; -class Controller; -class DateEdit; -class TimeEdit; -class LineEdit; -class SpinBox; -class ListWidget; -class DateTimeEdit; -class ComboBox; -class QSpacerItem; -class SpinBox; -class DoubleSpinBox; -class TiedArrayBeamDialog; -class Pipeline; -class CalibrationPipeline; -class ImagingPipeline; -class PulsarPipeline; -class LongBaselinePipeline; -class DemixingSettings; - -enum tabIndex { - TAB_SCHEDULE, - TAB_STATION_SETTINGS, - TAB_STATION_BEAMS, - TAB_PROCESSING, - TAB_STORAGE, - TAB_PIPELINE, - TAB_PULSAR_PIPELINE, - TAB_LONGBASELINE_PIPELINE, - TAB_EXTRA_INFO, - NR_TABS -}; - -extern const char *tab_names[NR_TABS]; - -#define STORE true -#define NOSTORE false - -class TaskDialog : public QDialog -{ - Q_OBJECT - -public: - TaskDialog(QWidget *parentGUI, Controller *controller); - ~TaskDialog(); - -// bool stationsLoaded(void) const {return itsStationsLoaded;} - void show(const Task *task = 0, tabIndex tab = TAB_SCHEDULE); - void showMultiEdit(std::vector<Task *> &tasks); - void update(const Task *task); - void updateStatus(Task::task_status status); - void addTask(unsigned taskID); -// void addReservation(unsigned taskID); -// void addPipeline(unsigned taskID); - bool commitChanges(bool storeValues); - bool commitReservation(bool storeValues); - bool commitPipeline(void); - bool commitMultiTasks(void); -// void updatePredecessor(bool isValid) const; - void loadAvailableStations(void); - void setDigitalBeam(int beamNr, const DigitalBeam &beam, bool change = false); -// void setPencilBeam(int pencilNr, const std::pair<Angle, Angle> &angles); - void addNewTiedArrayBeams(int nrBeams, const TiedArrayBeam &TAB); - void applyChangeToTiedArrayBeams(const std::vector<unsigned>& TABnrs,const TiedArrayBeam &, const tabProps &applyTABprop); - void setExistingProjects(const campaignMap &projects); - // load the existing process types in the processType ComboBox - void loadProcessTypes(void); -// void loadStorageNodesTable(void); - -private: - void apply(bool close); - void resetChangeDetection(void); - void enableTabs(void); // enables/disables the correct tabs depending on itsTask type - void enablePredecessorSettings(bool enable); - void StoreValues(void); - void loadTask(const Task *task); // will load the task properties in my embedded task object - void setReservationTaskMode(void); - void setNormalTaskMode(void); - void setFinishedTaskMode(void); - void setActiveTaskMode(void); - void setScheduledTaskMode(void); - void setScheduledStart(const QDateTime &start); // used to set the scheduled start without triggering an end update - void setScheduledEnd(const QDateTime &end); // used to set the scheduled end without triggering a duration update - void setAnalogBeamAnglePair(const anglePairs &anglepair); - void setAnalogBeamUnitsComboBox(void); - Observation::analogBeamSettings getAnalogBeamSettings(void) const; // returns the beamsettings from the dialog - void setAnalogBeamSettings(const Observation::analogBeamSettings &); - void getDigitalBeamSettings(void); // obtains the current digital beam settings from the dialog and stores them in isTmpDigitalBeams - void setDigitalBeamSettings(const Observation *obs); // sets the current digital beam settings in the dialog -// void setPencilBeamSettings(const Task *task); // sets the current pencils beam settings in the dialog - void updateTiedArrayBeams(const DigitalBeam &digiBeam); - void setRTCPSettings(const Observation::RTCPsettings &rtcp); // sets the RTCP settings in the dialog - void setComboBoxAnalogBeamUnits(void) const; - std::vector<std::string> getAssignedStationNames(void) const; - unsigned countStations(void) const; - superStationMap getSuperStations(const Observation *task) const; - void setStations(const StationTask *task); - std::map<int, QStringList> getSuperStationChildNames(void) const; - Observation::RTCPsettings getRTCPSettings(void); - // update the comboBoxStorageDataType for selecting the displayed storage tree - // and checks if the storage tree itself needsd to be updated as well. - void setStorageSettings(bool forceUpdate = false); - void storeStorageSettings(void); // stores the storage locations from the dialog into itsTask - void setStorageTreeMixed(bool enableOverride); - void countDigitalBeamSubbands(void); // count the current total nr of subbands and sets them in the dialog -// void showStorageConflict(const QString &conflictText); - // returns the currently selected data product type in the combox datatype on the storage tab - dataProductTypes getSelectedStorageDataProduct(void); - // get the displayed storage location for the data product currently selected by comboBoxStorageDataType and store in tmpStorage - void getDisplayedStorageLocations(void); - void checkStorageSettingsEnable(void); // checks multiple storage requirements and enables storage settings if these requirements are fulfilled - bool askForApplyChanges(void); - void checkEnableBeamButtons(void); - void checkEnableDataTypeSettings(void); - void updateStorageTab(void); - void checkForRemovalOfDataProducts(const TaskStorage::enableDataProdukts &edp); - void setInputDataProductsTree(const Task &task); - std::map<dataProductTypes, std::vector<bool> > getInputDataFilesCheckState(void); - void generateFileList(const Task *task, bool noWarnings); - void loadReservations(void); - void enableApplyButtons(bool enable); - void setBitsPerSample(unsigned short bitsPerSample); - void setMaxNrDataslotsPerRSPboard(unsigned short bitsPerSample); - void disableAnalogBeamSettings(void); - void setCurrentTab(tabIndex tab); - void setDemixSettings(const DemixingSettings &demixing); -// void setAveragingSettings(const Pipeline *pTask = 0); - void disableDemixSettings(void); -// void disableAveragingSettings(void); - void disableCalibrationPipelineSettings(void); - void disableImagingPipelineSettings(void); - void setCalibrationPipelineSettings(const CalibrationPipeline *); - void setImagingPipelineSettings(const ImagingPipeline *); - void setPulsarPipelineSettings(const PulsarPipeline *); - void setLongBaselinePipelineSettings(const LongBaselinePipeline *); - void updateOriginalTreeID(void); - void setProcessSubProcessStrategy(const Task *); - void updateEnabledInputDataTypes(void); - void clearMultiTasks(void); - bool ifSettingsChanged(void) const { - return changeBeams || changeExtraInfo || changeProcessing || changeSchedule - || changeStorage || changeStations || changePipeline || changePulsar || changeLongBaseline - || changeEnabledInputFiles; - } - void updateProcessSubtypes(const QString &processType); - void setPipelineProperties(void); - void setTabModified(tabIndex tabIdx, bool modified); - void setAllTabsUnmodified(void); - void setVisibleTabs(const QVector<tabIndex> &tabs); -signals: - void abortTask(unsigned int) const; - void addNewTask(const Task &task) const; - void checkPredecessor(unsigned int predecessorID) const; - -private slots: - void statusChanged(void); - void showTiedArrayBeams(int); - void setAnalogBeamAngle1(void); - void setAnalogBeamAngle2(void); - void detectChanges(void); - void ApplyFirstPossibleDateChange(void); - void ApplyFirstPossibleTimeChange(void); - void ApplyLastPossibleTimeChange(void); - void applyProjectChange(const QString &); - void updateScheduledEnd(void); - void updateDuration(void); - void applyClicked(void); - void cancelClicked(void); - void okClicked(void); - void enableFOVedit(int); - bool checkEmail(); -// void checkForSpecialType(int); - void AntennaModeChanged(int); - void FilterTypeChanged(int); - void StationClockModeChanged(int); - void AnalogBeamAngleUnitChanged(const QString &unitStr); - void AnalogBeamDirectionTypeChanged(void); - void analogBeamStartTimeChanged(const QTime &starttime); - void analogBeamDurationChanged(const QString &duration); - void addDigitalBeam(void); - void deleteDigitalBeam(void); - void editDigitalBeam(void); - void clearAllDigitalBeams(void); - void addTiedArrayBeam(void); - void deleteTiedArrayBeam(void); - void editTiedArrayBeam(void); - void setTiedArrayBeam(int row, const TiedArrayBeam &TAB); - void clearAllTiedArrayBeams(void); - void updateMaxDataslotsPerRSP(void); - void setPipelineType(void); - void setCorrelatorIntegrationTime(void); - void addSuperStation(void); - void addAvailableStations(const QStringList &stations); - void checkIfStationChanged(); - void applyStationsRemoved(void); - void addStationsToUsedStations(const QStringList &stations); - void showDataSlots(void) {itsDataSlotDialog.exec();} - void setStorageEditable(bool); - void doManualStorageOverride(void); - void doCheckSelectedStorage(void); - void doUnCheckSelectedStorage(void); - void countSelectedStorageLocations(void); - void doTabChangeUpdate(int); - void outputDataTypesChanged(); - void detectStorageLocationChanges(void); - void strategyChanged(void); - void updateProjects(void); // fetch the list of campaigns from SAS and update itsTaskDialog accordingly - void updateStorageTree(void); // sets the storage locations in the dialog according to itsTask - void displayDigitalBeamContextMenu(const QPoint &pos); - void bindToReservation(int); - void unbindReservation(void); - void updateStorageSelectionMode(int); - void processTypeChanged(int ptype); - void updateStrategiesComboBox(void); - void detectInputFilesEnabledChanges(void); - void clearDemixAlways(void); - void clearDemixIfNeeded(void); - -private: - Ui::TaskDialogClass ui; - Controller *itsController; - Task *itsTask; // contains an exact copy of the task currently shown and will contain the changes when user chooses to commit the task changes - std::vector<Task *> itsMultiTasks; // only used for multi-edit of tasks - QVector<QWidget *> itsTabs; // pointer to all tabs (for enabling/disabling) - TaskStorage::enableDataProdukts itsOutputDataTypes; - bool itsStorageOverflow; - bool changeSchedule, changeStations, changeBeams, changeProcessing, changeStorage, changePipeline, changePulsar, changeLongBaseline, changeExtraInfo, - changeEnabledInputFiles, itsNoUnschedule; - Observation::analogBeamSettings itsAnalogBeamSettings, itsTempAnalogBeamSettings; - std::map<unsigned, DigitalBeam> itsDigitalBeams, itsTempDigitalBeams; - DigitalBeamDialog *itsDigitalBeamDialog; - TiedArrayBeamDialog *itsTiedArrayBeamDialog; - QString itsAnalogBeamAngle1Str, itsAnalogBeamAngle2Str; - anglePairs itsAnalogBeamAnglePair; // the current units displayed for the analog beam angles - int itsStationClockIdx, itsStationAntennaMode, itsStationFilterType; - bool itsStationsLoaded; - bool addingTask, addingPipeline, addingReservation, isMultiTasks, blockChangeDetection; - DataSlotDialog itsDataSlotDialog; - storageMap itsTmpStorage; // where to store for this task (temporary settings to compare for changes) - QList<QTreeWidgetItem *> itsStorageTreeLocationsItems, itsStorageTreeNodeItems; - - QAction * itsActionStorageOverride, *itsActionStorageCheckSelected, *itsActionStorageUncheckSelected; - bool itsStorageOverride; - std::map<dataProductTypes, int> itsMinNrOfRequiredNodes; -}; - -#endif // TASKDIALOG_H diff --git a/SAS/Scheduler/src/taskdialog.ui b/SAS/Scheduler/src/taskdialog.ui deleted file mode 100644 index ec96d189c5c36da09322a47eaa070ce3fcfbabdc..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskdialog.ui +++ /dev/null @@ -1,4899 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>TaskDialogClass</class> - <widget class="QDialog" name="TaskDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>850</width> - <height>613</height> - </rect> - </property> - <property name="minimumSize"> - <size> - <width>850</width> - <height>600</height> - </size> - </property> - <property name="windowTitle"> - <string>Task Properties</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="4" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pushButtonCancelClose"> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButtonApply"> - <property name="text"> - <string>Apply</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButtonOk"> - <property name="text"> - <string>Ok</string> - </property> - </widget> - </item> - </layout> - </item> - <item row="2" column="0"> - <widget class="QTabWidget" name="tabWidgetMain"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="font"> - <font> - <weight>50</weight> - <bold>false</bold> - </font> - </property> - <property name="toolTip"> - <string/> - </property> - <property name="currentIndex"> - <number>0</number> - </property> - <widget class="QWidget" name="tab_TaskSettings"> - <attribute name="title"> - <string>Schedule</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="2" column="0"> - <widget class="QFrame" name="frame_3"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="frameShape"> - <enum>QFrame::StyledPanel</enum> - </property> - <property name="frameShadow"> - <enum>QFrame::Raised</enum> - </property> - <layout class="QGridLayout" name="gridLayout_5"> - <item row="5" column="3"> - <widget class="QLineEdit" name="lineEditModificationDate"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="palette"> - <palette> - <active> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </active> - <inactive> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>48</red> - <green>48</green> - <blue>48</blue> - </color> - </brush> - </colorrole> - </inactive> - <disabled> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>88</red> - <green>88</green> - <blue>88</blue> - </color> - </brush> - </colorrole> - </disabled> - </palette> - </property> - <property name="toolTip"> - <string>the last modification date in SAS</string> - </property> - <property name="text"> - <string/> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelFirstPossibleDate"> - <property name="text"> - <string>First possible date:</string> - </property> - </widget> - </item> - <item row="5" column="2"> - <widget class="QLabel" name="labelModificationDate"> - <property name="text"> - <string>Last modified:</string> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QLabel" name="labelLastPossibleTime"> - <property name="text"> - <string>Last possible time:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="DateTimeEdit" name="dateTimeEditScheduledStart"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>the planned start time of the task</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd hh:mm:ss</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="DateTimeEdit" name="dateTimeEditScheduledEnd"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the planned end time of the task</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd hh:mm:ss</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelFirstPossibleTime"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>First possible time:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelScheduledStart"> - <property name="text"> - <string>Scheduled start:</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="labelCreationDate"> - <property name="text"> - <string>Creation date:</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QLabel" name="labelScheduledEnd"> - <property name="text"> - <string>Scheduled end:</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelDuration"> - <property name="text"> - <string>Duration:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="LineEdit" name="lineEditDuration"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>The duration of the task (hhhh:mm:ss)</string> - </property> - <property name="inputMask"> - <string>0000:00:00; </string> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QLabel" name="labelLastPossibleDate"> - <property name="text"> - <string>Last possible date:</string> - </property> - </widget> - </item> - <item row="2" column="4"> - <widget class="CheckBox" name="checkBoxFixedTime"> - <property name="toolTip"> - <string>fix the task's start date</string> - </property> - <property name="text"> - <string>Fixed time</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="QLineEdit" name="lineEditCreationDate"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="palette"> - <palette> - <active> - <colorrole role="WindowText"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>34</red> - <green>31</green> - <blue>30</blue> - </color> - </brush> - </colorrole> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </active> - <inactive> - <colorrole role="WindowText"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>34</red> - <green>31</green> - <blue>30</blue> - </color> - </brush> - </colorrole> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>48</red> - <green>48</green> - <blue>48</blue> - </color> - </brush> - </colorrole> - </inactive> - <disabled> - <colorrole role="WindowText"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>0</red> - <green>0</green> - <blue>0</blue> - </color> - </brush> - </colorrole> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>88</red> - <green>88</green> - <blue>88</blue> - </color> - </brush> - </colorrole> - </disabled> - </palette> - </property> - <property name="toolTip"> - <string>the date this task was created in SAS</string> - </property> - <property name="text"> - <string/> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="4"> - <widget class="CheckBox" name="checkBoxFixedDate"> - <property name="toolTip"> - <string>fix the task's start date</string> - </property> - <property name="text"> - <string>Fixed date</string> - </property> - </widget> - </item> - <item row="4" column="2"> - <spacer name="verticalSpacer_6"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="1"> - <widget class="DateEdit" name="dateEditFirstPossibleDate"> - <property name="toolTip"> - <string>The earliest date at which this task may be scheduled</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="DateEdit" name="dateEditLastPossibleDate"> - <property name="toolTip"> - <string>The latest date at which this task may be scheduled</string> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd</string> - </property> - <property name="calendarPopup"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="TimeEdit" name="timeEditFirstPossibleTime"> - <property name="toolTip"> - <string>the earliest time on any given date that this task may be scheduled</string> - </property> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="TimeEdit" name="timeEditLastPossibleTime"> - <property name="toolTip"> - <string>the latest time on any given date that this task may be scheduled</string> - </property> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="0" column="0"> - <widget class="QFrame" name="frameScheduleGeneral"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="frameShape"> - <enum>QFrame::StyledPanel</enum> - </property> - <property name="frameShadow"> - <enum>QFrame::Raised</enum> - </property> - <layout class="QGridLayout" name="gridLayout_3"> - <item row="5" column="4"> - <widget class="LineEdit" name="lineEditPredecessors"> - <property name="toolTip"> - <string>comma separates list of predecessor task(s) that have to be scheduled before this task</string> - </property> - </widget> - </item> - <item row="4" column="4"> - <widget class="LineEdit" name="lineEditPriority"> - <property name="toolTip"> - <string>The priority of this task (floating point from low 0.0 to high 10.0)</string> - </property> - <property name="inputMask"> - <string>00.00; </string> - </property> - </widget> - </item> - <item row="6" column="4"> - <widget class="LineEdit" name="lineEditMinPredDistance"> - <property name="toolTip"> - <string>The minimum distance to all predecessors (hhhh:mm:ss)</string> - </property> - <property name="inputMask"> - <string>0000:00:00; </string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="ComboBox" name="comboBoxReservation"> - <property name="toolTip"> - <string>the reservation to which this task belongs</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="ComboBox" name="comboBoxProcessType"> - <property name="toolTip"> - <string>the task's ProcessType</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="ComboBox" name="comboBoxProcessSubType"> - <property name="toolTip"> - <string>the task's ProcessSubType</string> - </property> - </widget> - </item> - <item row="6" column="1"> - <widget class="ComboBox" name="comboBoxStrategies"> - <property name="toolTip"> - <string>the task's strategy</string> - </property> - </widget> - </item> - <item row="3" column="4"> - <widget class="LineEdit" name="lineEditGroupID"> - <property name="toolTip"> - <string>the group ID (to assign grouped storage resources)</string> - </property> - </widget> - </item> - <item row="0" column="3"> - <widget class="QLabel" name="label_20"> - <property name="text"> - <string>ID:</string> - </property> - </widget> - </item> - <item row="0" column="4"> - <widget class="QLineEdit" name="lineEditTaskID"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="minimumSize"> - <size> - <width>50</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="palette"> - <palette> - <active> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </active> - <inactive> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </inactive> - <disabled> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>88</red> - <green>88</green> - <blue>88</blue> - </color> - </brush> - </colorrole> - </disabled> - </palette> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QLabel" name="label_10"> - <property name="text"> - <string>SAS ID:</string> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QPushButton" name="pushButtonUnBindReservation"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>Unbind from reservation</string> - </property> - <property name="text"> - <string>unbind</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelTaskName"> - <property name="text"> - <string>Task name:</string> - </property> - </widget> - </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_9"> - <property name="text"> - <string>Strategy:</string> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="QLabel" name="label_13"> - <property name="text"> - <string>Group ID:</string> - </property> - </widget> - </item> - <item row="2" column="4"> - <widget class="QLineEdit" name="lineEditOriginalTreeID"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="palette"> - <palette> - <active> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </active> - <inactive> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </inactive> - <disabled> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>88</red> - <green>88</green> - <blue>88</blue> - </color> - </brush> - </colorrole> - </disabled> - </palette> - </property> - </widget> - </item> - <item row="4" column="3"> - <widget class="QLabel" name="labelPriority"> - <property name="text"> - <string>Priority:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="labelStatus"> - <property name="text"> - <string>Status:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="LineEdit" name="lineEditTaskName"> - <property name="toolTip"> - <string>The name of the task</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="ComboBox" name="comboBoxTaskStatus"> - <property name="toolTip"> - <string>The status of the task</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="ComboBox" name="comboBoxProjectID"> - <property name="toolTip"> - <string>The project to which this task belongs</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelBindToReservation"> - <property name="text"> - <string>Bind to reservation:</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelProjectName"> - <property name="text"> - <string>Project ID:</string> - </property> - </widget> - </item> - <item row="7" column="3"> - <widget class="QLabel" name="labelMaxPredDistance"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Max. distance:</string> - </property> - </widget> - </item> - <item row="1" column="4"> - <widget class="QLineEdit" name="lineEditSASID"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="palette"> - <palette> - <active> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </active> - <inactive> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>31</red> - <green>28</green> - <blue>27</blue> - </color> - </brush> - </colorrole> - </inactive> - <disabled> - <colorrole role="Text"> - <brush brushstyle="SolidPattern"> - <color alpha="255"> - <red>88</red> - <green>88</green> - <blue>88</blue> - </color> - </brush> - </colorrole> - </disabled> - </palette> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="QLabel" name="label_11"> - <property name="text"> - <string>Parent template ID:</string> - </property> - </widget> - </item> - <item row="6" column="3"> - <widget class="QLabel" name="labelMinPredDistance"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Min. distance:</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelTaskType"> - <property name="text"> - <string>Process Type:</string> - </property> - </widget> - </item> - <item row="5" column="3"> - <widget class="QLabel" name="labelPredecessor"> - <property name="text"> - <string>Predecessors:</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_8"> - <property name="text"> - <string>Process Subtype:</string> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QPushButton" name="pushButtonUpdateCampaigns"> - <property name="maximumSize"> - <size> - <width>50</width> - <height>16777215</height> - </size> - </property> - <property name="statusTip"> - <string>fetches all defined projects from the SAS database</string> - </property> - <property name="text"> - <string>update</string> - </property> - </widget> - </item> - <item row="7" column="4"> - <widget class="LineEdit" name="lineEditMaxPredDistance"> - <property name="toolTip"> - <string>The maximum distance to all predecessors (hhhh:mm:ss)</string> - </property> - <property name="inputMask"> - <string>0000:00:00; </string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_StationSettings"> - <attribute name="title"> - <string>Station settings</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_4"> - <item row="1" column="0"> - <widget class="QLabel" name="labelStationFilter"> - <property name="maximumSize"> - <size> - <width>120</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Station filter:</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelStationClock"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Station clock frequency:</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelStations"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>20</height> - </size> - </property> - <property name="text"> - <string>Available stations</string> - </property> - </widget> - </item> - <item row="4" column="2"> - <widget class="QLabel" name="labelAssignedStations"> - <property name="text"> - <string>Assigned stations</string> - </property> - </widget> - </item> - <item row="4" column="4"> - <widget class="QPushButton" name="pushButtonAddSuperStation"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>Adds a superstation (a collection of beamformed stations)</string> - </property> - <property name="text"> - <string>Add Super station</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelStationAntennaMode"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Station antenna mode:</string> - </property> - </widget> - </item> - <item row="5" column="2" colspan="3"> - <widget class="StationTreeWidget" name="treeWidgetUsedStations"> - <property name="toolTip"> - <string>the list of used stations. -Drag them back to available stations (or push delete) to remove them from this task</string> - </property> - <property name="headerHidden"> - <bool>true</bool> - </property> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - <item row="0" column="3"> - <widget class="SpinBox" name="spinBoxDataslotsPerRSPboard"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>the number of dataslots per RSP board for all stations used by this task</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QLabel" name="labelDataslotsPerRPSBoard"> - <property name="text"> - <string># dataslots per RSP board:</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="ComboBox" name="comboBoxStationClock"> - <property name="toolTip"> - <string>the station clock frequency for all stations used by this task</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="CheckBox" name="checkBoxTBBPiggybackAllowed"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>is TBB piggybacking allowed during this observation?</string> - </property> - <property name="text"> - <string>TBB Piggyback allowed</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="ComboBox" name="comboBoxStationFilter"> - <property name="toolTip"> - <string>the station bandpass filter for all stations used by this task</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="1"> - <widget class="ComboBox" name="comboBoxStationAntennaMode"> - <property name="toolTip"> - <string>the antenna mode for all stations used by this task</string> - </property> - </widget> - </item> - <item row="0" column="4"> - <widget class="QPushButton" name="pushButtonShowDataSlots"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>show the task's assigned dataslots for every station individually</string> - </property> - <property name="whatsThis"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Shows task's assigned dataslots for every station individually.</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Dataslots are only assigned to (PRE)SCHEDULED tasks. They are determined automatically by the scheduler when the scheduler is uploaded to SAS. After the upload you can view the assigned dataslots for each scheduled task.</span></p></body></html></string> - </property> - <property name="text"> - <string>Show dataslots</string> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="CheckBox" name="checkBoxAartfaacPiggybackAllowed"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>is AARTFAAC piggybacking allowed during this observation?</string> - </property> - <property name="text"> - <string>Aartfaac Piggyback allowed</string> - </property> - </widget> - </item> - <item row="5" column="0" colspan="2"> - <widget class="StationListWidget" name="listWidgetAvailableStations"> - <property name="toolTip"> - <string>the list of available stations. -Drag them to the used station list to assign them to this task</string> - </property> - <property name="dragDropMode"> - <enum>QAbstractItemView::DragDrop</enum> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_StationBeams"> - <attribute name="title"> - <string>Station beams</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_8"> - <item row="0" column="0"> - <widget class="QGroupBox" name="groupBoxAnalogBeam"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>90</height> - </size> - </property> - <property name="title"> - <string>Analog Beam</string> - </property> - <layout class="QGridLayout" name="gridLayout_20"> - <property name="topMargin"> - <number>9</number> - </property> - <item row="0" column="4"> - <widget class="QLabel" name="labelBeamStartTime"> - <property name="text"> - <string>Start time</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="labelAngleNotation"> - <property name="text"> - <string>Units</string> - </property> - </widget> - </item> - <item row="0" column="3"> - <widget class="QLabel" name="labelBeamAngle2"> - <property name="text"> - <string>Declination</string> - </property> - </widget> - </item> - <item row="0" column="5"> - <widget class="QLabel" name="labelBeamDuration"> - <property name="text"> - <string>Duration</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QLabel" name="labelBeamAngle1"> - <property name="text"> - <string>Right Ascension</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelBeamCoordinateSystem"> - <property name="text"> - <string>Coordinates</string> - </property> - </widget> - </item> - <item row="1" column="4"> - <widget class="TimeEdit" name="timeEditAnalogBeamStartTime"> - <property name="toolTip"> - <string>the start time of the analog beam relative to the observation start time</string> - </property> - <property name="displayFormat"> - <string>hh:mm:ss</string> - </property> - </widget> - </item> - <item row="1" column="5"> - <widget class="LineEdit" name="lineEditAnalogBeamDuration"> - <property name="toolTip"> - <string>the duration of the analog beam -(leave at zero means equal to observation duration)</string> - </property> - <property name="inputMask"> - <string>0000:00:00; </string> - </property> - <property name="text"> - <string>0000:00:00</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="LineEdit" name="lineEditAnalogBeamAngle1"> - <property name="toolTip"> - <string>The right ascension or azimuth angle of the analog HBA beam</string> - </property> - <property name="inputMask"> - <string>00:00:00.000000; </string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="LineEdit" name="lineEditAnalogBeamAngle2"> - <property name="toolTip"> - <string>The declination or elevation angle of the analog HBA beam</string> - </property> - <property name="inputMask"> - <string>#00:00:00.000000; </string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="ComboBox" name="comboBoxAnalogBeamCoordinates"> - <property name="minimumSize"> - <size> - <width>110</width> - <height>0</height> - </size> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="ComboBox" name="comboBoxAnalogBeamUnits"> - <property name="minimumSize"> - <size> - <width>110</width> - <height>0</height> - </size> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="0"> - <widget class="QGroupBox" name="groupBoxDigitalBeams"> - <property name="title"> - <string>Digital beams and Tied Array Beams</string> - </property> - <layout class="QGridLayout" name="gridLayout_9"> - <item row="1" column="0" rowspan="8"> - <widget class="QTableWidget" name="tableWidgetDigitalBeams"> - <property name="toolTip"> - <string>This task's digital station beams</string> - </property> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - <property name="showDropIndicator" stdset="0"> - <bool>true</bool> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - </widget> - </item> - <item row="6" column="1"> - <widget class="QLineEdit" name="lineEditTotalSubbands"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>the total number of subbands over all beams</string> - </property> - <property name="text"> - <string/> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QPushButton" name="pushButtonDeleteBeams"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Delete</string> - </property> - </widget> - </item> - <item row="10" column="1"> - <widget class="QPushButton" name="pushButtonAddTiedArrayBeam"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Add</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QPushButton" name="pushButtonClearAllBeams"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Clear all</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButtonAddBeam"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Add</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="QLabel" name="labelTotalSubbands"> - <property name="text"> - <string>Subbands:</string> - </property> - </widget> - </item> - <item row="10" column="0" rowspan="4"> - <widget class="QTableWidget" name="tableWidgetTiedArrayBeams"> - <property name="toolTip"> - <string>Shows the tied array beams of the currently selected digital beam</string> - </property> - </widget> - </item> - <item row="12" column="1"> - <widget class="QPushButton" name="pushButtonDeleteTiedArrayBeam"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Delete</string> - </property> - </widget> - </item> - <item row="13" column="1"> - <widget class="QPushButton" name="pushButtonClearAllTiedArrayBeam"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Clear all</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QPushButton" name="pushButtonEditBeam"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Edit</string> - </property> - </widget> - </item> - <item row="11" column="1"> - <widget class="QPushButton" name="pushButtonEditTiedArrayBeam"> - <property name="maximumSize"> - <size> - <width>75</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Edit</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Processing"> - <attribute name="title"> - <string>Processing</string> - </attribute> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QGroupBox" name="groupBox_Correlated"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>90</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="title"> - <string>Correlated data</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - <property name="flat"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout_17"> - <item row="0" column="3"> - <spacer name="horizontalSpacer_6"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="2"> - <widget class="LineEdit" name="lineEditCorrelatorIntegrationTime"> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>the correlator integration time in seconds</string> - </property> - <property name="inputMask"> - <string>00.00; </string> - </property> - <property name="text"> - <string>1.0</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="labelChannelsPerSubband"> - <property name="text"> - <string>Channels per subband:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="CheckBox" name="checkBoxCorrelatedData"> - <property name="minimumSize"> - <size> - <width>200</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Store correlated visibilities</string> - </property> - <property name="text"> - <string>Correlated Visibilities</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QLabel" name="label_CorrelatorIntTime"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Integration time:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="SpinBox" name="spinBoxChannelsPerSubband"> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>number of channels per subband used for the correlator</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>4096</number> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBox_Stokes"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>210</height> - </size> - </property> - <property name="title"> - <string>Complex Voltages data, Coherent Stokes, Incoherent Stokes</string> - </property> - <property name="flat"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout_21"> - <item row="1" column="4"> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="4" column="3"> - <widget class="SpinBox" name="spinBoxIncoherentSubbandsPerFile"> - <property name="toolTip"> - <string>incoherent Stokes number of subbands per file</string> - </property> - <property name="maximum"> - <number>512</number> - </property> - </widget> - </item> - <item row="3" column="3"> - <widget class="SpinBox" name="spinBoxIncoherentChannelsPerSubband"> - <property name="toolTip"> - <string>incoherent Stokes number of channels per subband</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>4096</number> - </property> - </widget> - </item> - <item row="4" column="2"> - <widget class="SpinBox" name="spinBoxCoherentSubbandsPerFile"> - <property name="toolTip"> - <string>coherent Stokes number of subbands per file</string> - </property> - <property name="maximum"> - <number>512</number> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="CheckBox" name="checkBoxCoherentStokes"> - <property name="toolTip"> - <string>Store coherent Stokes data</string> - </property> - <property name="text"> - <string>Coherent</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="ComboBox" name="comboBoxIncoherentStokesType"> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>which Incoherent Stokes parameters to produce</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLabel" name="label_StokesChannelsPerSubband"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Channels per subband:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="SpinBox" name="spinBoxCoherentTimeIntegration"> - <property name="toolTip"> - <string>coherent Stokes time integration factor</string> - </property> - <property name="maximum"> - <number>99999</number> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QLabel" name="label_Coherent"> - <property name="text"> - <string>Coherent</string> - </property> - </widget> - </item> - <item row="0" column="3"> - <widget class="QLabel" name="label_Incoherent"> - <property name="text"> - <string>Incoherent</string> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="SpinBox" name="spinBoxIncoherentTimeIntegration"> - <property name="toolTip"> - <string>incoherent Stokes time integration factor</string> - </property> - <property name="maximum"> - <number>99999</number> - </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="SpinBox" name="spinBoxCoherentChannelsPerSubband"> - <property name="toolTip"> - <string>coherent Stokes number of channels per subband</string> - </property> - <property name="minimum"> - <number>1</number> - </property> - <property name="maximum"> - <number>4096</number> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLabel" name="label_StokesTimeIntegration"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Time integration:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="CheckBox" name="checkBoxIncoherentStokes"> - <property name="toolTip"> - <string>Store incoherent Stokes data</string> - </property> - <property name="text"> - <string>Incoherent</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QLabel" name="label_StokesSubbandsPerFile"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>Subbands per file:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="ComboBox" name="comboBoxCoherentStokesType"> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>which Coherent Stokes parameters to produce</string> - </property> - </widget> - </item> - <item row="6" column="0"> - <widget class="CheckBox" name="checkBoxPencilFlysEye"> - <property name="toolTip"> - <string>tranforms every station into its own beam</string> - </property> - <property name="text"> - <string>Fly's eye</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLabel" name="label_StokesType"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string>(Stokes) type:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="CheckBox" name="checkBox_CoherentDedispersion"> - <property name="minimumSize"> - <size> - <width>200</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>turn on online coherent dedispersion</string> - </property> - <property name="text"> - <string>Coherent Dedispersion</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBox_ProcessingGeneric"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>120</height> - </size> - </property> - <property name="title"> - <string>Central Processing generic settings</string> - </property> - <property name="flat"> - <bool>true</bool> - </property> - <layout class="QGridLayout" name="gridLayout_22"> - <item row="2" column="5"> - <spacer name="horizontalSpacer_7"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="3"> - <widget class="QLabel" name="label_BitsPerSample"> - <property name="minimumSize"> - <size> - <width>146</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>Bits per sample:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="CheckBox" name="checkBox_DelayCompensation"> - <property name="toolTip"> - <string>perform delay compensation between stations</string> - </property> - <property name="text"> - <string>Delay compensation</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="CheckBox" name="checkBox_BandpassCorrection"> - <property name="minimumSize"> - <size> - <width>200</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Apply the bandpass filter</string> - </property> - <property name="text"> - <string>Bandpass correction</string> - </property> - </widget> - </item> - <item row="2" column="4"> - <widget class="ComboBox" name="comboBoxBitsPerSample"> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>number of bits per sample</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <spacer name="verticalSpacer_7"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - <item> - <spacer name="verticalSpacer_4"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>30</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Storage"> - <attribute name="title"> - <string>Storage</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_12"> - <item row="1" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Total storage size:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="0" column="0" colspan="6"> - <widget class="QLineEdit" name="lineEditStorageConflict"> - <property name="font"> - <font> - <weight>75</weight> - <bold>true</bold> - </font> - </property> - <property name="acceptDrops"> - <bool>false</bool> - </property> - <property name="frame"> - <bool>false</bool> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Total bandwidth required:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="lineEditTotalBandwidth"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>Total network bandwidth required -(Total storage size / observation duration)</string> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="lineEditTotalStorageSize"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>the total size of all dataproducts written to the storage nodes</string> - </property> - <property name="statusTip"> - <string/> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string># Nodes Minimum:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="2" column="3"> - <widget class="QLineEdit" name="lineEditMinNrStorageNodes"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">the most optimistic minimum number of storage nodes required to obtain the required total network bandwidth. The automatic selection might select more nodes depending on storage space available.</span></p></body></html></string> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="2" column="4"> - <widget class="QLabel" name="label_12"> - <property name="text"> - <string># Nodes Selected:</string> - </property> - </widget> - </item> - <item row="2" column="5"> - <widget class="QLineEdit" name="lineEditAssignedStorageNodes"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the selected nodes for the displayed data produkt type</string> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="2" rowspan="4" colspan="4"> - <widget class="QTreeWidget" name="treeWidgetStorageNodes"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="baseSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the storage nodes and raid arrays used</string> - </property> - <property name="autoFillBackground"> - <bool>true</bool> - </property> - <property name="animated"> - <bool>false</bool> - </property> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - <item row="1" column="4" colspan="2"> - <widget class="QComboBox" name="comboBoxStorageDataType"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>Select the data product type for which to display the storage selection</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLineEdit" name="lineEditNrOfDataFiles"> - <property name="minimumSize"> - <size> - <width>250</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>the number of data products that are written</string> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string># of data files:</string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_DataProducts"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>14</height> - </size> - </property> - <property name="text"> - <string>Data products:</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="QLineEdit" name="lineEditStorageAssigned"> - <property name="text"> - <string>Storage not assigned</string> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="5" column="0" rowspan="2" colspan="2"> - <widget class="QTabWidget" name="tabWidgetDataProdukts"> - <property name="currentIndex"> - <number>1</number> - </property> - <widget class="QWidget" name="tabInput"> - <attribute name="title"> - <string>Input</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_6"> - <item row="0" column="0"> - <widget class="QTreeWidget" name="treeWidgetInputDataProducts"> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tabOutput"> - <attribute name="title"> - <string>Output</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_10"> - <item row="0" column="0"> - <widget class="QTreeWidget" name="treeWidgetOutputDataProducts"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <column> - <property name="text"> - <string notr="true">1</string> - </property> - </column> - </widget> - </item> - </layout> - </widget> - </widget> - </item> - <item row="1" column="2" colspan="2"> - <widget class="ComboBox" name="comboBoxStorageSelectionMode"> - <property name="toolTip"> - <string>the method for selecting storage nodes</string> - </property> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_Pipeline"> - <attribute name="title"> - <string>Imaging Pipeline</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_11"> - <item row="0" column="0" rowspan="4"> - <widget class="QGroupBox" name="groupBoxDemixing"> - <property name="title"> - <string>Demixing</string> - </property> - <layout class="QGridLayout" name="gridLayout_14"> - <item row="7" column="0"> - <widget class="QLabel" name="labelDemixFreqStep"> - <property name="text"> - <string>Demix freq. step:</string> - </property> - </widget> - </item> - <item row="8" column="0"> - <widget class="QLabel" name="label_15"> - <property name="text"> - <string>Demix time step:</string> - </property> - </widget> - </item> - <item row="6" column="0"> - <spacer name="verticalSpacer_5"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="5" column="0"> - <widget class="QPushButton" name="pushButtonClearDemixIfNeeded"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Clear</string> - </property> - </widget> - </item> - <item row="9" column="0"> - <widget class="QLabel" name="label_14"> - <property name="text"> - <string>Demixing SkyModel:</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <spacer name="verticalSpacer_3"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelDemixAlways"> - <property name="minimumSize"> - <size> - <width>130</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>Demix always:</string> - </property> - </widget> - </item> - <item row="4" column="1" rowspan="3"> - <widget class="ListWidget" name="listWidgetDemixIfNeeded"> - <property name="toolTip"> - <string>mark the sources for which the pipeline has to decide if demixing is needed</string> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::NoSelection</enum> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelDemixIfNeeded"> - <property name="text"> - <string>Demix if needed:</string> - </property> - </widget> - </item> - <item row="0" column="1" rowspan="3"> - <widget class="ListWidget" name="listWidgetDemixAlways"> - <property name="toolTip"> - <string>mark the sources thatmust be demixed</string> - </property> - <property name="selectionMode"> - <enum>QAbstractItemView::NoSelection</enum> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QPushButton" name="pushButtonClearDemixAlways"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Clear</string> - </property> - </widget> - </item> - <item row="9" column="1"> - <widget class="LineEdit" name="lineEditDemixSkyModel"> - <property name="toolTip"> - <string>the (user-supplied) SkyModel used for demixing -specified as a SkyModel file name omitting the extension .skymodel, e.g. 3C295 -or as a fully specified path to a SkyModel file</string> - </property> - </widget> - </item> - <item row="7" column="1"> - <widget class="SpinBox" name="spinBoxDemixFreqStep"> - <property name="toolTip"> - <string>the number of frequency channels to average in the demixing result</string> - </property> - <property name="maximum"> - <number>999999</number> - </property> - </widget> - </item> - <item row="8" column="1"> - <widget class="SpinBox" name="spinBoxDemixTimeStep"> - <property name="toolTip"> - <string>the number of time steps to average in the demixing result</string> - </property> - <property name="maximum"> - <number>999999</number> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="0" column="2"> - <widget class="QGroupBox" name="groupBoxCalibration"> - <property name="title"> - <string>Calibration</string> - </property> - <layout class="QGridLayout" name="gridLayout_13"> - <item row="0" column="0"> - <widget class="QLabel" name="label_18"> - <property name="text"> - <string>Calibration SkyModel:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="LineEdit" name="lineEditCalibrationSkyModel"> - <property name="toolTip"> - <string>the SkyModel used by BBS for calibration (e.g. 3C295)</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="4" column="0"> - <widget class="QGroupBox" name="groupBoxAveraging"> - <property name="title"> - <string>Averaging</string> - </property> - <layout class="QGridLayout" name="gridLayout_15"> - <item row="0" column="0"> - <widget class="QLabel" name="label_16"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>130</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Averaging freq. step:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_17"> - <property name="text"> - <string>Averaging time step:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="SpinBox" name="spinBoxAveragingFreqStep"> - <property name="toolTip"> - <string>the number of frequency channels to average</string> - </property> - <property name="maximum"> - <number>999999</number> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="SpinBox" name="spinBoxAveragingTimeStep"> - <property name="toolTip"> - <string>the number of time steps to average</string> - </property> - <property name="maximum"> - <number>999999</number> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="2" rowspan="3"> - <widget class="QGroupBox" name="groupBoxImaging"> - <property name="title"> - <string>Imaging</string> - </property> - <layout class="QFormLayout" name="formLayout_2"> - <property name="fieldGrowthPolicy"> - <enum>QFormLayout::AllNonFixedFieldsGrow</enum> - </property> - <item row="0" column="0"> - <widget class="QLabel" name="label_19"> - <property name="text"> - <string>Slices per Image:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_21"> - <property name="text"> - <string>Subbands per Image:</string> - </property> - </widget> - </item> - <item row="2" column="0" colspan="2"> - <widget class="CheckBox" name="checkBoxSpecifyFOV"> - <property name="toolTip"> - <string>Specify Field Of View instead of Cell size & npix</string> - </property> - <property name="text"> - <string>Specify FOV</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelFOV"> - <property name="text"> - <string>Field Of View (degrees):</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelCellSize"> - <property name="text"> - <string>Cell size:</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="labelNpix"> - <property name="text"> - <string>Number of pixels:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="SpinBox" name="spinBoxSlicesPerImage"> - <property name="toolTip"> - <string>the number of slices that are grouped in to a single image</string> - </property> - <property name="maximum"> - <number>99999</number> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="SpinBox" name="spinBoxSubbandsPerImage"> - <property name="toolTip"> - <string>the number of subbands that are grouped in to a single image</string> - </property> - <property name="maximum"> - <number>99999</number> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="LineEdit" name="lineEditFieldOfView"> - <property name="toolTip"> - <string>field of view in degrees</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="LineEdit" name="lineEditCellSize"> - <property name="toolTip"> - <string>the pixel width in x and y direction, specify units (arcsec/arcmin/rad/deg)</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="SpinBox" name="spinBoxNumberOfPixels"> - <property name="toolTip"> - <string>the number of image pixels in x and y direction</string> - </property> - <property name="maximum"> - <number>99999999</number> - </property> - </widget> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_LongBaselinePipeline"> - <attribute name="title"> - <string>Long-Baseline Pipeline</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_19"> - <item row="0" column="0"> - <widget class="QGroupBox" name="groupBoxConcatenation"> - <property name="title"> - <string>Concatenation</string> - </property> - <layout class="QGridLayout" name="gridLayout_18"> - <item row="0" column="0"> - <widget class="QLabel" name="label_SubbandsPerSubbandGroup_2"> - <property name="text"> - <string>Subbands per Subband Group:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_SubbandGroupsPerMS_2"> - <property name="text"> - <string>Subband Groups per MS:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="SpinBox" name="spinBoxSubbandGroupsPerMS"> - <property name="minimumSize"> - <size> - <width>75</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the number of subband-groups to write to a single measurement set</string> - </property> - <property name="maximum"> - <number>99999</number> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="SpinBox" name="spinBoxSubbandsPerSubbandGroup"> - <property name="minimumSize"> - <size> - <width>75</width> - <height>0</height> - </size> - </property> - <property name="toolTip"> - <string>the number of subbands concatenated into a single subband-group</string> - </property> - <property name="maximum"> - <number>99999</number> - </property> - </widget> - </item> - <item row="0" column="2"> - <spacer name="horizontalSpacer_5"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </item> - <item row="1" column="0"> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_PulsarPipeline"> - <attribute name="title"> - <string>Pulsar Pipeline</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_16"> - <item row="1" column="1"> - <widget class="QGroupBox" name="groupBoxPulsarCV"> - <property name="title"> - <string>CV specific settings</string> - </property> - <layout class="QFormLayout" name="formLayout_4"> - <item row="0" column="0"> - <widget class="QLabel" name="label_34"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Digifil extra options:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="LineEdit" name="lineEditDigifilExtraOptions"> - <property name="toolTip"> - <string>Additional options for digifil. -Only for CV data and only when Single pulse analysis is enabled</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="0" column="1"> - <widget class="QGroupBox" name="groupBoxPulsarCSIS"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - <property name="title"> - <string>CS/IS specific settings</string> - </property> - <layout class="QFormLayout" name="formLayout_3"> - <item row="2" column="0"> - <widget class="QLabel" name="label_35"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>2bf2fits extra options:</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_36"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Decode sigma:</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_37"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Decode nblocks:</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_38"> - <property name="toolTip"> - <string/> - </property> - <property name="statusTip"> - <string/> - </property> - <property name="text"> - <string>RFI find extra options:</string> - </property> - </widget> - </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_39"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Prepfold extra options:</string> - </property> - </widget> - </item> - <item row="7" column="0"> - <widget class="QLabel" name="label_40"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Prepsubband extra options:</string> - </property> - </widget> - </item> - <item row="9" column="0"> - <widget class="QLabel" name="label_41"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Dynamic spectrum time avg.:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="CheckBox" name="checkBox_rrats"> - <property name="toolTip"> - <string>Run rrats analysis i.e. running prepsubband for a range of DMs around nominal DM of the RRAT followed by single pulse search. -Zero-DM time series is also created with prepdata.</string> - </property> - <property name="text"> - <string>rrats</string> - </property> - </widget> - </item> - <item row="8" column="1"> - <widget class="CheckBox" name="checkBox_Skip_dynamic_spectrum"> - <property name="toolTip"> - <string>Skip creation of the dynamic spectrum of the observation</string> - </property> - <property name="text"> - <string>Skip dynamic spectrum</string> - </property> - </widget> - </item> - <item row="10" column="1"> - <widget class="CheckBox" name="checkBox_Skip_prepfold"> - <property name="toolTip"> - <string>Skip execxution of prepfold.</string> - </property> - <property name="text"> - <string>Skip prepfold</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_23"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>rrats DM range:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="LineEdit" name="lineEdit2bf2fitsExtraOptions"> - <property name="toolTip"> - <string>Additional options for 2bf2fits</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="LineEdit" name="lineEditRfiFindExtraOptions"> - <property name="toolTip"> - <string>Additional options for rfifind</string> - </property> - </widget> - </item> - <item row="6" column="1"> - <widget class="LineEdit" name="lineEditPrepfoldExtraOptions"> - <property name="toolTip"> - <string>Additional options for prepfold</string> - </property> - </widget> - </item> - <item row="7" column="1"> - <widget class="LineEdit" name="lineEditPrepsubbandExtraOptions"> - <property name="toolTip"> - <string>Additional options for prepsubband -Only used when rrats is enabled</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="SpinBox" name="spinBoxDecodeSigma"> - <property name="toolTip"> - <string>Sigma limit value used for packing in 2bf2fits</string> - </property> - <property name="maximum"> - <number>9999999</number> - </property> - <property name="value"> - <number>3</number> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="SpinBox" name="spinBoxDecodeNblocks"> - <property name="toolTip"> - <string>Number of blocks to read at a time in 2bf2fits</string> - </property> - <property name="maximum"> - <number>9999999</number> - </property> - <property name="value"> - <number>100</number> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="DoubleSpinBox" name="doubleSpinBoxRratsDmRange"> - <property name="toolTip"> - <string>The range between the lowest DM value in the prepsubband and the nominal DM of a RRAT</string> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="maximum"> - <double>99999.000000000000000</double> - </property> - <property name="value"> - <double>5.000000000000000</double> - </property> - </widget> - </item> - <item row="9" column="1"> - <widget class="DoubleSpinBox" name="doubleSpinBoxDynamicSpectrumTimeAverage"> - <property name="toolTip"> - <string>Averaging time in seconds for dynamic spectrum of the observation</string> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="maximum"> - <double>99999.000000000000000</double> - </property> - <property name="value"> - <double>0.500000000000000</double> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="0" column="0"> - <widget class="QGroupBox" name="groupBoxPulsarCSISCV"> - <property name="title"> - <string>General CS/IS/CV</string> - </property> - <layout class="QFormLayout" name="formLayout"> - <property name="fieldGrowthPolicy"> - <enum>QFormLayout::AllNonFixedFieldsGrow</enum> - </property> - <item row="0" column="0"> - <widget class="QLabel" name="label_22"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Pulsar:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="CheckBox" name="checkBox_RawTo8Bit"> - <property name="toolTip"> - <string>Convert raw 32-bit data to 8 bits</string> - </property> - <property name="text"> - <string>Raw to 8 bit</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_25"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>DSPSR extra options:</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_26"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>Prepdata extra options:</string> - </property> - </widget> - </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_27"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>8 bit conversion sigma:</string> - </property> - </widget> - </item> - <item row="6" column="0"> - <widget class="QLabel" name="label_28"> - <property name="toolTip"> - <string/> - </property> - <property name="text"> - <string>tsubint:</string> - </property> - </widget> - </item> - <item row="7" column="1"> - <widget class="CheckBox" name="checkBox_NoRFI"> - <property name="toolTip"> - <string>Skip all RFI excision or inspection tools.</string> - </property> - <property name="text"> - <string>No RFI</string> - </property> - </widget> - </item> - <item row="8" column="1"> - <widget class="CheckBox" name="checkBox_No_fold"> - <property name="toolTip"> - <string>No data folding.</string> - </property> - <property name="text"> - <string>No Folding</string> - </property> - </widget> - </item> - <item row="11" column="1"> - <widget class="CheckBox" name="checkBox_No_DSPSR"> - <property name="toolTip"> - <string>Skip execution of DSPSR.</string> - </property> - <property name="text"> - <string>No DSPSR</string> - </property> - </widget> - </item> - <item row="10" column="1"> - <widget class="CheckBox" name="checkBox_No_pdmp"> - <property name="toolTip"> - <string>Skip execution of PDMP</string> - </property> - <property name="text"> - <string>No PDMP</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="CheckBox" name="checkBox_Single_pulse"> - <property name="toolTip"> - <string>Do single pulse analysis.</string> - </property> - <property name="text"> - <string>Single pulse analysis</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="LineEdit" name="lineEditPulsarName"> - <property name="toolTip"> - <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Pulsar name or comma separated list of pulsars. In addition to pulsar names can also have several special keywords: </p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">parset - to take pulsar name from the source field for each SAP separately from the parset file.</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">meta - same as 'parset' but only from the HDF5 metadata</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">sapfind - to find the best (brightest) pulsars in FOV of the particular SAP</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">sapfind3 - to find 3 best (brighters) pulsars in FOV of the particular SAP</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">tabfind - to find the brightest pulsar for each TAB individually</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">tabfind+ - to first get pulsar from the parset (meta) if pulsar name there is legitimate, then find the brightest one in the SAP (same as 'sapfind'), and then get another pulsar from the TAB (same as 'tabfind')</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">By default (i.e. when pulsar option is empty), pipeline will take pulsar name from the parset (or meta). If pulsar names are not legitimate (i.e. not known, not in the catalog), then find the brightest pulsar in the SAP (same as 'sapfind').</p></body></html></string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="LineEdit" name="lineEditDSPSRextraOptions"> - <property name="toolTip"> - <string>Additional options for dspsr</string> - </property> - </widget> - </item> - <item row="4" column="1"> - <widget class="LineEdit" name="lineEditPrepdataExtraOptions"> - <property name="toolTip"> - <string>Additional options for prepdata</string> - </property> - </widget> - </item> - <item row="6" column="1"> - <widget class="SpinBox" name="spinBoxTsubint"> - <property name="toolTip"> - <string>Set the length (in seconds) of each subintegration. Default is 60 secs for CS/IS and 5 secs for CV mode</string> - </property> - <property name="minimum"> - <number>-1</number> - </property> - <property name="maximum"> - <number>99999999</number> - </property> - <property name="value"> - <number>-1</number> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="DoubleSpinBox" name="doubleSpinBox8BitConversionSigma"> - <property name="toolTip"> - <string>Clip raw data above this threshold (in sigmas) for conversion raw data from 32 to 8 bits</string> - </property> - <property name="decimals"> - <number>5</number> - </property> - <property name="maximum"> - <double>99999.000000000000000</double> - </property> - <property name="value"> - <double>5.000000000000000</double> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="2" column="1"> - <spacer name="verticalSpacer_8"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - <widget class="QWidget" name="tab_ExtraInfo"> - <attribute name="title"> - <string>Extra Info</string> - </attribute> - <layout class="QGridLayout" name="gridLayout_7"> - <item row="6" column="0"> - <widget class="QLabel" name="labelContactName"> - <property name="minimumSize"> - <size> - <width>80</width> - <height>0</height> - </size> - </property> - <property name="text"> - <string>Contact name:</string> - </property> - </widget> - </item> - <item row="6" column="1"> - <widget class="QLineEdit" name="lineEdit_ContactName"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>Contact person for this task</string> - </property> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="7" column="0"> - <widget class="QLabel" name="labelContactPhone"> - <property name="text"> - <string>Phone:</string> - </property> - </widget> - </item> - <item row="7" column="1"> - <widget class="QLineEdit" name="lineEdit_ContactPhone"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>Phone number of the contact person</string> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="8" column="0"> - <widget class="QLabel" name="labelContactEmail"> - <property name="text"> - <string>E-mail:</string> - </property> - </widget> - </item> - <item row="8" column="1"> - <widget class="QLineEdit" name="lineEdit_ContactEmail"> - <property name="maximumSize"> - <size> - <width>16777215</width> - <height>16777215</height> - </size> - </property> - <property name="toolTip"> - <string>E-mail of the contact person</string> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="7" column="2"> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="10" column="1"> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelDescription"> - <property name="text"> - <string>Description</string> - </property> - </widget> - </item> - <item row="0" column="1" colspan="2"> - <widget class="LineEdit" name="lineEditTaskDescription"> - <property name="toolTip"> - <string>The task description</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>Principal Investigator(s):</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="lineEdit_ProjectPI"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>Co Investigator(s):</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLineEdit" name="lineEdit_ProjectCOI"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>Project name:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="lineEdit_ProjectName"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <customwidgets> - <customwidget> - <class>CheckBox</class> - <extends>QCheckBox</extends> - <header>CheckBox.h</header> - </customwidget> - <customwidget> - <class>LineEdit</class> - <extends>QLineEdit</extends> - <header>LineEdit.h</header> - </customwidget> - <customwidget> - <class>ComboBox</class> - <extends>QComboBox</extends> - <header>ComboBox.h</header> - </customwidget> - <customwidget> - <class>DateTimeEdit</class> - <extends>QDateTimeEdit</extends> - <header>DateTimeEdit.h</header> - </customwidget> - <customwidget> - <class>DateEdit</class> - <extends>QDateEdit</extends> - <header>DateEdit.h</header> - </customwidget> - <customwidget> - <class>TimeEdit</class> - <extends>QTimeEdit</extends> - <header>TimeEdit.h</header> - </customwidget> - <customwidget> - <class>SpinBox</class> - <extends>QSpinBox</extends> - <header>SpinBox.h</header> - </customwidget> - <customwidget> - <class>StationListWidget</class> - <extends>QListWidget</extends> - <header>stationlistwidget.h</header> - </customwidget> - <customwidget> - <class>StationTreeWidget</class> - <extends>QTreeWidget</extends> - <header>stationtreewidget.h</header> - </customwidget> - <customwidget> - <class>ListWidget</class> - <extends>QListWidget</extends> - <header>ListWidget.h</header> - </customwidget> - <customwidget> - <class>DoubleSpinBox</class> - <extends>QDoubleSpinBox</extends> - <header>doublespinbox.h</header> - </customwidget> - </customwidgets> - <tabstops> - <tabstop>tabWidgetMain</tabstop> - <tabstop>lineEditTaskName</tabstop> - <tabstop>comboBoxTaskStatus</tabstop> - <tabstop>comboBoxProjectID</tabstop> - <tabstop>pushButtonUpdateCampaigns</tabstop> - <tabstop>comboBoxReservation</tabstop> - <tabstop>pushButtonUnBindReservation</tabstop> - <tabstop>comboBoxProcessType</tabstop> - <tabstop>comboBoxProcessSubType</tabstop> - <tabstop>comboBoxStrategies</tabstop> - <tabstop>lineEditTaskID</tabstop> - <tabstop>lineEditSASID</tabstop> - <tabstop>lineEditOriginalTreeID</tabstop> - <tabstop>lineEditGroupID</tabstop> - <tabstop>lineEditPriority</tabstop> - <tabstop>lineEditPredecessors</tabstop> - <tabstop>lineEditMinPredDistance</tabstop> - <tabstop>lineEditMaxPredDistance</tabstop> - <tabstop>lineEditDuration</tabstop> - <tabstop>dateTimeEditScheduledStart</tabstop> - <tabstop>dateEditFirstPossibleDate</tabstop> - <tabstop>timeEditFirstPossibleTime</tabstop> - <tabstop>dateTimeEditScheduledEnd</tabstop> - <tabstop>dateEditLastPossibleDate</tabstop> - <tabstop>timeEditLastPossibleTime</tabstop> - <tabstop>checkBoxFixedDate</tabstop> - <tabstop>checkBoxFixedTime</tabstop> - <tabstop>lineEditCreationDate</tabstop> - <tabstop>lineEditModificationDate</tabstop> - <tabstop>pushButtonCancelClose</tabstop> - <tabstop>pushButtonApply</tabstop> - <tabstop>pushButtonOk</tabstop> - <tabstop>comboBoxStationAntennaMode</tabstop> - <tabstop>comboBoxStationFilter</tabstop> - <tabstop>comboBoxStationClock</tabstop> - <tabstop>checkBoxTBBPiggybackAllowed</tabstop> - <tabstop>checkBoxAartfaacPiggybackAllowed</tabstop> - <tabstop>pushButtonShowDataSlots</tabstop> - <tabstop>listWidgetAvailableStations</tabstop> - <tabstop>treeWidgetUsedStations</tabstop> - <tabstop>pushButtonAddSuperStation</tabstop> - <tabstop>comboBoxAnalogBeamCoordinates</tabstop> - <tabstop>comboBoxAnalogBeamUnits</tabstop> - <tabstop>lineEditAnalogBeamAngle1</tabstop> - <tabstop>lineEditAnalogBeamAngle2</tabstop> - <tabstop>timeEditAnalogBeamStartTime</tabstop> - <tabstop>lineEditAnalogBeamDuration</tabstop> - <tabstop>tableWidgetDigitalBeams</tabstop> - <tabstop>pushButtonAddBeam</tabstop> - <tabstop>pushButtonEditBeam</tabstop> - <tabstop>pushButtonDeleteBeams</tabstop> - <tabstop>pushButtonClearAllBeams</tabstop> - <tabstop>lineEditTotalSubbands</tabstop> - <tabstop>tableWidgetTiedArrayBeams</tabstop> - <tabstop>pushButtonAddTiedArrayBeam</tabstop> - <tabstop>pushButtonEditTiedArrayBeam</tabstop> - <tabstop>pushButtonDeleteTiedArrayBeam</tabstop> - <tabstop>pushButtonClearAllTiedArrayBeam</tabstop> - <tabstop>checkBoxCorrelatedData</tabstop> - <tabstop>checkBoxCoherentStokes</tabstop> - <tabstop>checkBoxIncoherentStokes</tabstop> - <tabstop>checkBox_CoherentDedispersion</tabstop> - <tabstop>checkBoxPencilFlysEye</tabstop> - <tabstop>checkBox_DelayCompensation</tabstop> - <tabstop>checkBox_BandpassCorrection</tabstop> - <tabstop>lineEditCorrelatorIntegrationTime</tabstop> - <tabstop>spinBoxChannelsPerSubband</tabstop> - <tabstop>comboBoxCoherentStokesType</tabstop> - <tabstop>comboBoxIncoherentStokesType</tabstop> - <tabstop>spinBoxCoherentTimeIntegration</tabstop> - <tabstop>spinBoxIncoherentTimeIntegration</tabstop> - <tabstop>spinBoxCoherentChannelsPerSubband</tabstop> - <tabstop>spinBoxIncoherentChannelsPerSubband</tabstop> - <tabstop>spinBoxCoherentSubbandsPerFile</tabstop> - <tabstop>spinBoxIncoherentSubbandsPerFile</tabstop> - <tabstop>comboBoxBitsPerSample</tabstop> - <tabstop>lineEditStorageConflict</tabstop> - <tabstop>lineEditTotalStorageSize</tabstop> - <tabstop>comboBoxStorageSelectionMode</tabstop> - <tabstop>lineEditTotalBandwidth</tabstop> - <tabstop>lineEditNrOfDataFiles</tabstop> - <tabstop>lineEditStorageAssigned</tabstop> - <tabstop>tabWidgetDataProdukts</tabstop> - <tabstop>treeWidgetOutputDataProducts</tabstop> - <tabstop>listWidgetDemixAlways</tabstop> - <tabstop>listWidgetDemixIfNeeded</tabstop> - <tabstop>pushButtonClearDemixAlways</tabstop> - <tabstop>pushButtonClearDemixIfNeeded</tabstop> - <tabstop>spinBoxDemixFreqStep</tabstop> - <tabstop>spinBoxDemixTimeStep</tabstop> - <tabstop>lineEditDemixSkyModel</tabstop> - <tabstop>spinBoxAveragingFreqStep</tabstop> - <tabstop>spinBoxAveragingTimeStep</tabstop> - <tabstop>lineEditCalibrationSkyModel</tabstop> - <tabstop>spinBoxSlicesPerImage</tabstop> - <tabstop>spinBoxSubbandsPerImage</tabstop> - <tabstop>checkBoxSpecifyFOV</tabstop> - <tabstop>lineEditFieldOfView</tabstop> - <tabstop>lineEditCellSize</tabstop> - <tabstop>spinBoxNumberOfPixels</tabstop> - <tabstop>spinBoxSubbandsPerSubbandGroup</tabstop> - <tabstop>spinBoxSubbandGroupsPerMS</tabstop> - <tabstop>lineEditPulsarName</tabstop> - <tabstop>checkBox_Single_pulse</tabstop> - <tabstop>checkBox_RawTo8Bit</tabstop> - <tabstop>lineEditDSPSRextraOptions</tabstop> - <tabstop>lineEditPrepdataExtraOptions</tabstop> - <tabstop>doubleSpinBox8BitConversionSigma</tabstop> - <tabstop>spinBoxTsubint</tabstop> - <tabstop>checkBox_NoRFI</tabstop> - <tabstop>checkBox_No_fold</tabstop> - <tabstop>checkBox_No_pdmp</tabstop> - <tabstop>checkBox_No_DSPSR</tabstop> - <tabstop>checkBox_rrats</tabstop> - <tabstop>doubleSpinBoxRratsDmRange</tabstop> - <tabstop>lineEdit2bf2fitsExtraOptions</tabstop> - <tabstop>spinBoxDecodeSigma</tabstop> - <tabstop>spinBoxDecodeNblocks</tabstop> - <tabstop>lineEditRfiFindExtraOptions</tabstop> - <tabstop>lineEditPrepfoldExtraOptions</tabstop> - <tabstop>lineEditPrepsubbandExtraOptions</tabstop> - <tabstop>checkBox_Skip_dynamic_spectrum</tabstop> - <tabstop>doubleSpinBoxDynamicSpectrumTimeAverage</tabstop> - <tabstop>checkBox_Skip_prepfold</tabstop> - <tabstop>lineEditDigifilExtraOptions</tabstop> - <tabstop>lineEditTaskDescription</tabstop> - <tabstop>lineEdit_ProjectName</tabstop> - <tabstop>lineEdit_ProjectPI</tabstop> - <tabstop>lineEdit_ProjectCOI</tabstop> - <tabstop>lineEdit_ContactName</tabstop> - <tabstop>lineEdit_ContactPhone</tabstop> - <tabstop>lineEdit_ContactEmail</tabstop> - <tabstop>lineEditAssignedStorageNodes</tabstop> - <tabstop>spinBoxDataslotsPerRSPboard</tabstop> - <tabstop>comboBoxStorageDataType</tabstop> - <tabstop>treeWidgetStorageNodes</tabstop> - <tabstop>treeWidgetInputDataProducts</tabstop> - <tabstop>lineEditMinNrStorageNodes</tabstop> - </tabstops> - <resources/> - <connections> - <connection> - <sender>pushButtonApply</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>applyClicked()</slot> - <hints> - <hint type="sourcelabel"> - <x>748</x> - <y>589</y> - </hint> - <hint type="destinationlabel"> - <x>507</x> - <y>386</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEdit_ContactEmail</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>202</x> - <y>227</y> - </hint> - <hint type="destinationlabel"> - <x>5</x> - <y>104</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEdit_ContactPhone</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>202</x> - <y>196</y> - </hint> - <hint type="destinationlabel"> - <x>1</x> - <y>71</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonCancelClose</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>cancelClicked()</slot> - <hints> - <hint type="sourcelabel"> - <x>657</x> - <y>589</y> - </hint> - <hint type="destinationlabel"> - <x>346</x> - <y>397</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonOk</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>okClicked()</slot> - <hints> - <hint type="sourcelabel"> - <x>839</x> - <y>589</y> - </hint> - <hint type="destinationlabel"> - <x>618</x> - <y>386</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEdit_ContactName</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>202</x> - <y>165</y> - </hint> - <hint type="destinationlabel"> - <x>132</x> - <y>0</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_DelayCompensation</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>130</x> - <y>422</y> - </hint> - <hint type="destinationlabel"> - <x>5</x> - <y>319</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_BandpassCorrection</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>163</x> - <y>451</y> - </hint> - <hint type="destinationlabel"> - <x>30</x> - <y>373</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBoxPencilFlysEye</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>130</x> - <y>358</y> - </hint> - <hint type="destinationlabel"> - <x>618</x> - <y>168</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditTaskDescription</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>208</x> - <y>41</y> - </hint> - <hint type="destinationlabel"> - <x>374</x> - <y>0</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonShowDataSlots</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>showDataSlots()</slot> - <hints> - <hint type="sourcelabel"> - <x>829</x> - <y>66</y> - </hint> - <hint type="destinationlabel"> - <x>619</x> - <y>145</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBoxStorageDataType</sender> - <signal>currentIndexChanged(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>updateStorageTree()</slot> - <hints> - <hint type="sourcelabel"> - <x>660</x> - <y>68</y> - </hint> - <hint type="destinationlabel"> - <x>626</x> - <y>0</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonUnBindReservation</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>unbindReservation()</slot> - <hints> - <hint type="sourcelabel"> - <x>450</x> - <y>171</y> - </hint> - <hint type="destinationlabel"> - <x>736</x> - <y>75</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_CoherentDedispersion</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>216</x> - <y>331</y> - </hint> - <hint type="destinationlabel"> - <x>5</x> - <y>183</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBoxTBBPiggybackAllowed</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>639</x> - <y>95</y> - </hint> - <hint type="destinationlabel"> - <x>447</x> - <y>527</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_Single_pulse</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>118</y> - </hint> - <hint type="destinationlabel"> - <x>182</x> - <y>7</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_RawTo8Bit</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>145</y> - </hint> - <hint type="destinationlabel"> - <x>199</x> - <y>-5</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_NoRFI</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>296</y> - </hint> - <hint type="destinationlabel"> - <x>6</x> - <y>232</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_No_fold</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>323</y> - </hint> - <hint type="destinationlabel"> - <x>4</x> - <y>265</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_No_pdmp</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>356</y> - </hint> - <hint type="destinationlabel"> - <x>4</x> - <y>296</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_No_DSPSR</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>383</y> - </hint> - <hint type="destinationlabel"> - <x>4</x> - <y>344</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_rrats</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>87</y> - </hint> - <hint type="destinationlabel"> - <x>849</x> - <y>95</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_Skip_dynamic_spectrum</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>331</y> - </hint> - <hint type="destinationlabel"> - <x>852</x> - <y>242</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_Skip_prepfold</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>389</y> - </hint> - <hint type="destinationlabel"> - <x>851</x> - <y>293</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBoxAartfaacPiggybackAllowed</sender> - <signal>clicked()</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>639</x> - <y>126</y> - </hint> - <hint type="destinationlabel"> - <x>480</x> - <y>580</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditTaskName</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>292</x> - <y>62</y> - </hint> - <hint type="destinationlabel"> - <x>184</x> - <y>-4</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBoxProjectID</sender> - <signal>currentIndexChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>198</x> - <y>122</y> - </hint> - <hint type="destinationlabel"> - <x>3</x> - <y>136</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBoxReservation</sender> - <signal>currentIndexChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>bindToReservation(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>186</x> - <y>162</y> - </hint> - <hint type="destinationlabel"> - <x>5</x> - <y>164</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBoxProcessType</sender> - <signal>currentIndexChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>processTypeChanged(int)</slot> - <hints> - <hint type="sourcelabel"> - <x>179</x> - <y>190</y> - </hint> - <hint type="destinationlabel"> - <x>4</x> - <y>215</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBoxProcessSubType</sender> - <signal>currentIndexChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>updateStrategiesComboBox()</slot> - <hints> - <hint type="sourcelabel"> - <x>197</x> - <y>221</y> - </hint> - <hint type="destinationlabel"> - <x>-5</x> - <y>242</y> - </hint> - </hints> - </connection> - <connection> - <sender>comboBoxStrategies</sender> - <signal>currentIndexChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>strategyChanged()</slot> - <hints> - <hint type="sourcelabel"> - <x>371</x> - <y>251</y> - </hint> - <hint type="destinationlabel"> - <x>841</x> - <y>263</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditGroupID</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>808</x> - <y>159</y> - </hint> - <hint type="destinationlabel"> - <x>845</x> - <y>156</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditPriority</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>814</x> - <y>188</y> - </hint> - <hint type="destinationlabel"> - <x>844</x> - <y>189</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditPredecessors</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>808</x> - <y>218</y> - </hint> - <hint type="destinationlabel"> - <x>846</x> - <y>219</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditMinPredDistance</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>814</x> - <y>248</y> - </hint> - <hint type="destinationlabel"> - <x>845</x> - <y>139</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditMaxPredDistance</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>800</x> - <y>281</y> - </hint> - <hint type="destinationlabel"> - <x>848</x> - <y>325</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditDuration</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>updateScheduledEnd()</slot> - <hints> - <hint type="sourcelabel"> - <x>168</x> - <y>332</y> - </hint> - <hint type="destinationlabel"> - <x>-6</x> - <y>328</y> - </hint> - </hints> - </connection> - <connection> - <sender>dateTimeEditScheduledStart</sender> - <signal>dateTimeChanged(QDateTime)</signal> - <receiver>TaskDialogClass</receiver> - <slot>updateScheduledEnd()</slot> - <hints> - <hint type="sourcelabel"> - <x>161</x> - <y>363</y> - </hint> - <hint type="destinationlabel"> - <x>-8</x> - <y>355</y> - </hint> - </hints> - </connection> - <connection> - <sender>dateTimeEditScheduledEnd</sender> - <signal>dateTimeChanged(QDateTime)</signal> - <receiver>TaskDialogClass</receiver> - <slot>updateDuration()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>370</y> - </hint> - <hint type="destinationlabel"> - <x>848</x> - <y>370</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBoxFixedDate</sender> - <signal>stateChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>801</x> - <y>374</y> - </hint> - <hint type="destinationlabel"> - <x>848</x> - <y>355</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBoxFixedTime</sender> - <signal>stateChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>767</x> - <y>398</y> - </hint> - <hint type="destinationlabel"> - <x>846</x> - <y>405</y> - </hint> - </hints> - </connection> - <connection> - <sender>dateEditFirstPossibleDate</sender> - <signal>dateChanged(QDate)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>167</x> - <y>400</y> - </hint> - <hint type="destinationlabel"> - <x>4</x> - <y>395</y> - </hint> - </hints> - </connection> - <connection> - <sender>dateEditLastPossibleDate</sender> - <signal>dateChanged(QDate)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>701</x> - <y>397</y> - </hint> - <hint type="destinationlabel"> - <x>843</x> - <y>436</y> - </hint> - </hints> - </connection> - <connection> - <sender>timeEditFirstPossibleTime</sender> - <signal>timeChanged(QTime)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>162</x> - <y>433</y> - </hint> - <hint type="destinationlabel"> - <x>3</x> - <y>438</y> - </hint> - </hints> - </connection> - <connection> - <sender>timeEditLastPossibleTime</sender> - <signal>timeChanged(QTime)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>690</x> - <y>433</y> - </hint> - <hint type="destinationlabel"> - <x>847</x> - <y>481</y> - </hint> - </hints> - </connection> - <connection> - <sender>timeEditAnalogBeamStartTime</sender> - <signal>timeChanged(QTime)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>663</x> - <y>119</y> - </hint> - <hint type="destinationlabel"> - <x>845</x> - <y>89</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditAnalogBeamAngle1</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>362</x> - <y>119</y> - </hint> - <hint type="destinationlabel"> - <x>274</x> - <y>4</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditAnalogBeamAngle2</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>517</x> - <y>119</y> - </hint> - <hint type="destinationlabel"> - <x>487</x> - <y>-2</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditAnalogBeamDuration</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>769</x> - <y>119</y> - </hint> - <hint type="destinationlabel"> - <x>713</x> - <y>-2</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditCorrelatorIntegrationTime</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>488</x> - <y>91</y> - </hint> - <hint type="destinationlabel"> - <x>849</x> - <y>55</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxChannelsPerSubband</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>488</x> - <y>122</y> - </hint> - <hint type="destinationlabel"> - <x>851</x> - <y>127</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxCoherentTimeIntegration</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>488</x> - <y>242</y> - </hint> - <hint type="destinationlabel"> - <x>844</x> - <y>288</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxIncoherentTimeIntegration</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>594</x> - <y>242</y> - </hint> - <hint type="destinationlabel"> - <x>843</x> - <y>215</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxCoherentChannelsPerSubband</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>488</x> - <y>273</y> - </hint> - <hint type="destinationlabel"> - <x>845</x> - <y>350</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxIncoherentChannelsPerSubband</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>594</x> - <y>273</y> - </hint> - <hint type="destinationlabel"> - <x>856</x> - <y>176</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxCoherentSubbandsPerFile</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>488</x> - <y>304</y> - </hint> - <hint type="destinationlabel"> - <x>423</x> - <y>602</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxIncoherentSubbandsPerFile</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>594</x> - <y>304</y> - </hint> - <hint type="destinationlabel"> - <x>546</x> - <y>599</y> - </hint> - </hints> - </connection> - <connection> - <sender>listWidgetDemixAlways</sender> - <signal>clicked(QModelIndex)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>96</y> - </hint> - <hint type="destinationlabel"> - <x>6</x> - <y>131</y> - </hint> - </hints> - </connection> - <connection> - <sender>listWidgetDemixIfNeeded</sender> - <signal>clicked(QModelIndex)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>243</y> - </hint> - <hint type="destinationlabel"> - <x>5</x> - <y>290</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxAveragingFreqStep</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>516</y> - </hint> - <hint type="destinationlabel"> - <x>4</x> - <y>489</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxAveragingTimeStep</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>547</y> - </hint> - <hint type="destinationlabel"> - <x>3</x> - <y>536</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxDemixFreqStep</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>386</y> - </hint> - <hint type="destinationlabel"> - <x>7</x> - <y>391</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxDemixTimeStep</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>417</y> - </hint> - <hint type="destinationlabel"> - <x>3</x> - <y>425</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditCalibrationSkyModel</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>689</x> - <y>110</y> - </hint> - <hint type="destinationlabel"> - <x>849</x> - <y>42</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxSlicesPerImage</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>703</x> - <y>198</y> - </hint> - <hint type="destinationlabel"> - <x>445</x> - <y>594</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxSubbandsPerImage</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>703</x> - <y>229</y> - </hint> - <hint type="destinationlabel"> - <x>295</x> - <y>592</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditFieldOfView</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>703</x> - <y>287</y> - </hint> - <hint type="destinationlabel"> - <x>581</x> - <y>574</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditCellSize</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>703</x> - <y>318</y> - </hint> - <hint type="destinationlabel"> - <x>321</x> - <y>578</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxNumberOfPixels</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>703</x> - <y>349</y> - </hint> - <hint type="destinationlabel"> - <x>847</x> - <y>318</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxSubbandsPerSubbandGroup</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>305</x> - <y>91</y> - </hint> - <hint type="destinationlabel"> - <x>360</x> - <y>584</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxSubbandGroupsPerMS</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>305</x> - <y>122</y> - </hint> - <hint type="destinationlabel"> - <x>195</x> - <y>576</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditPulsarName</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>91</y> - </hint> - <hint type="destinationlabel"> - <x>132</x> - <y>593</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditDSPSRextraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>176</y> - </hint> - <hint type="destinationlabel"> - <x>501</x> - <y>584</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditPrepdataExtraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>207</y> - </hint> - <hint type="destinationlabel"> - <x>72</x> - <y>573</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEdit2bf2fitsExtraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>149</y> - </hint> - <hint type="destinationlabel"> - <x>845</x> - <y>123</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditRfiFindExtraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>242</y> - </hint> - <hint type="destinationlabel"> - <x>843</x> - <y>184</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditPrepfoldExtraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>273</y> - </hint> - <hint type="destinationlabel"> - <x>770</x> - <y>571</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditPrepsubbandExtraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>304</y> - </hint> - <hint type="destinationlabel"> - <x>355</x> - <y>574</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditDigifilExtraOptions</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>668</x> - <y>457</y> - </hint> - <hint type="destinationlabel"> - <x>156</x> - <y>588</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxTsubint</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>269</y> - </hint> - <hint type="destinationlabel"> - <x>457</x> - <y>600</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxDecodeSigma</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>180</y> - </hint> - <hint type="destinationlabel"> - <x>845</x> - <y>27</y> - </hint> - </hints> - </connection> - <connection> - <sender>spinBoxDecodeNblocks</sender> - <signal>valueChanged(int)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>211</y> - </hint> - <hint type="destinationlabel"> - <x>844</x> - <y>396</y> - </hint> - </hints> - </connection> - <connection> - <sender>doubleSpinBoxRratsDmRange</sender> - <signal>valueChanged(double)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>118</y> - </hint> - <hint type="destinationlabel"> - <x>753</x> - <y>4</y> - </hint> - </hints> - </connection> - <connection> - <sender>doubleSpinBoxDynamicSpectrumTimeAverage</sender> - <signal>valueChanged(double)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>724</x> - <y>362</y> - </hint> - <hint type="destinationlabel"> - <x>846</x> - <y>466</y> - </hint> - </hints> - </connection> - <connection> - <sender>doubleSpinBox8BitConversionSigma</sender> - <signal>valueChanged(double)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>285</x> - <y>238</y> - </hint> - <hint type="destinationlabel"> - <x>5</x> - <y>210</y> - </hint> - </hints> - </connection> - <connection> - <sender>lineEditDemixSkyModel</sender> - <signal>textEdited(QString)</signal> - <receiver>TaskDialogClass</receiver> - <slot>detectChanges()</slot> - <hints> - <hint type="sourcelabel"> - <x>266</x> - <y>448</y> - </hint> - <hint type="destinationlabel"> - <x>13</x> - <y>591</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <signal>applied()</signal> - <slot>apply()</slot> - <slot>applyClicked()</slot> - <slot>cancelClicked()</slot> - <slot>okClicked()</slot> - <slot>detectChanges()</slot> - <slot>updateScheduledStart()</slot> - <slot>updateScheduledEnd()</slot> - <slot>updateDuration()</slot> - <slot>checkForSpecialType(QString)</slot> - <slot>ApplyFirstPossibleDateChange()</slot> - <slot>ApplyLastPossibleDateChange()</slot> - <slot>ApplyFirstPossibleTimeChange()</slot> - <slot>ApplyLastPossibleTimeChange()</slot> - <slot>AnalogBeamDirectionTypeChanged()</slot> - <slot>calculateAnalogAngle1()</slot> - <slot>calculateAnalogAngle2()</slot> - <slot>AnalogBeamAngleUnitChanged(QString)</slot> - <slot>analogBeamStartTimeChanged(QTime)</slot> - <slot>analogBeamDurationChanged(QTime)</slot> - <slot>AntennaModeChanged(int)</slot> - <slot>showDataSlots()</slot> - <slot>FilterTypeChanged(int)</slot> - <slot>setStorageEditable(int)</slot> - <slot>detectStorageLocationChanges(QTreeWidgetItem*,int)</slot> - <slot>outputDataTypesChanged()</slot> - <slot>updateStorageTree()</slot> - <slot>applyProjectChange(QString)</slot> - <slot>bindToReservation(int)</slot> - <slot>unbindReservation()</slot> - <slot>processTypeChanged(int)</slot> - <slot>updateStrategiesComboBox()</slot> - <slot>strategyChanged()</slot> - </slots> -</ui> diff --git a/SAS/Scheduler/src/taskstorage.cpp b/SAS/Scheduler/src/taskstorage.cpp deleted file mode 100644 index a26e85e235f286b78418b03d8cbbb4b131b2443c..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskstorage.cpp +++ /dev/null @@ -1,1120 +0,0 @@ -/* - * taskstorage.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/taskstorage.cpp $ - * - */ - -#include "task.h" -#include "taskstorage.h" -#include "observation.h" -#include "pipeline.h" -#include "pulsarpipeline.h" -#include "Controller.h" - -//const char *storage_cluster_mode_str[NR_STORAGE_CLUSTERING_MODES] = {"Project preferred nodes", "Data type preferred nodes"}; - -const char *storage_select_mode_str[NR_STORAGE_SELECTION_MODES] = {"Maximum - data type preferred", "Maximum - project preferred", - "Minimum - data type preferred", "Minimum - project preferred", "Manual selection"}; - -TaskStorage::TaskStorage(const Task *owner, const TaskStorage *other) - : itsOwner(owner), itsRecalcStorageNeeded(true), itsStorageSelectionMode(STORAGE_MODE_MAXIMUM_PROJECT_PREFERRED), itsTotalDataSizekBytes(0.0), itsTotalBandWidth(0.0) -{ - if (other) { - itsRecalcStorageNeeded = other->itsRecalcStorageNeeded; - itsStorageSelectionMode = other->itsStorageSelectionMode; - itsOutputDataFiles = other->itsOutputDataFiles; - itsInputDataFiles = other->itsInputDataFiles; - itsEnabledInputData = other->itsEnabledInputData; - itsEnabledOutputData = other->itsEnabledOutputData; - itsInputDataProducts = other->itsInputDataProducts; - itsOutputDataProducts = other->itsOutputDataProducts; - itsTotalDataSizekBytes = other->itsTotalDataSizekBytes; - itsTotalBandWidth = other->itsTotalBandWidth; - itsStorage = other->itsStorage; - itsInputStorageLocations = other->itsInputStorageLocations; - itsStorageCheckResult = other->itsStorageCheckResult; - itsOwner = owner; - } -} - - -QDataStream& operator<< (QDataStream &out, const TaskStorage &storage) { - if (out.status() == QDataStream::Ok) { - - // itsOwner is already set by the parent task - out << storage.itsRecalcStorageNeeded; - // itsStorageSelectionMode - out << (quint8) storage.itsStorageSelectionMode; - - // itsStorage - out << (quint32) storage.itsStorage.size(); - for (storageMap::const_iterator it = storage.itsStorage.begin(); it != storage.itsStorage.end(); ++it) { - out << (quint8) it->first - << (quint32) it->second.size(); - for (storageVector::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { - out << (quint16) sit->first // storage node ID - << (quint16) sit->second; // storage raid ID - } - } - - // input data product specifications - // itsEnabledInputData - out << storage.itsEnabledInputData.coherentStokes << storage.itsEnabledInputData.correlated - << storage.itsEnabledInputData.incoherentStokes << storage.itsEnabledInputData.instrumentModel; - - // itsInputDataProducts - out << (quint32) storage.itsInputDataProducts.size(); - for (std::map<dataProductTypes, TaskStorage::inputDataProduct>::const_iterator it = storage.itsInputDataProducts.begin(); it != storage.itsInputDataProducts.end(); ++it) { - out << (quint8) it->first; - - out << (quint32) it->second.identifications.size(); - for (QStringList::const_iterator strit = it->second.identifications.begin(); strit != it->second.identifications.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.locations.size(); - for (QStringList::const_iterator strit = it->second.locations.begin(); strit != it->second.locations.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.filenames.size(); - for (QStringList::const_iterator strit = it->second.filenames.begin(); strit != it->second.filenames.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.skip.size(); - for (std::vector<bool>::const_iterator strit = it->second.skip.begin(); strit != it->second.skip.end(); ++strit) { - out << *strit; - } - - } - - // input data files (number of files and file size for each input data product) - // itsInputDataFiles - out << (quint32) storage.itsInputDataFiles.size(); - for (dataFileMap::const_iterator it = storage.itsInputDataFiles.begin(); it != storage.itsInputDataFiles.end(); ++it) { - out << (quint8) it->first << it->second.first << it->second.second; - } - - // output data files (number of files and file size for each output data product) - // itsOutputDataFiles - out << (quint32) storage.itsOutputDataFiles.size(); - for (dataFileMap::const_iterator it = storage.itsOutputDataFiles.begin(); it != storage.itsOutputDataFiles.end(); ++it) { - out << (quint8) it->first << it->second.first << it->second.second; - } - - // output data product specifications - - // itsEnabledOutputData - out << storage.itsEnabledOutputData.coherentStokes << storage.itsEnabledOutputData.correlated - << storage.itsEnabledOutputData.incoherentStokes << storage.itsEnabledOutputData.instrumentModel - << storage.itsEnabledOutputData.pulsar << storage.itsEnabledOutputData.skyImage - << storage.itsEnabledOutputData.coherentStokesAssigned << storage.itsEnabledOutputData.complexVoltagesAssigned - << storage.itsEnabledOutputData.correlatedAssigned << storage.itsEnabledOutputData.incoherentStokesAssigned - << storage.itsEnabledOutputData.instrumentModelAssigned << storage.itsEnabledOutputData.pulsarAssigned << storage.itsEnabledOutputData.skyImageAssigned; - - // itsOutputDataProducts - out << (quint32) storage.itsOutputDataProducts.size(); - for (std::map<dataProductTypes, TaskStorage::outputDataProduct>::const_iterator it = storage.itsOutputDataProducts.begin(); it != storage.itsOutputDataProducts.end(); ++it) { - out << (quint8) it->first; - - out << (quint32) it->second.identifications.size(); - for (QStringList::const_iterator strit = it->second.identifications.begin(); strit != it->second.identifications.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.locations.size(); - for (QStringList::const_iterator strit = it->second.locations.begin(); strit != it->second.locations.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.filenames.size(); - for (QStringList::const_iterator strit = it->second.filenames.begin(); strit != it->second.filenames.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.uniqueMointPoints.size(); - for (QStringList::const_iterator strit = it->second.uniqueMointPoints.begin(); strit != it->second.uniqueMointPoints.end(); ++strit) { - out << strit->toStdString(); - } - - out << (quint32) it->second.skip.size(); - for (std::vector<bool>::const_iterator strit = it->second.skip.begin(); strit != it->second.skip.end(); ++strit) { - out << *strit; - } - } - - out << storage.itsTotalDataSizekBytes << storage.itsTotalBandWidth; - -// storageMap itsInputStorageLocations; // itsStorage contains the 'asked' storage node IDs and raid IDs -// std::vector<storageResult> itsStorageCheckResult; - - } - return out; -} - -QDataStream& operator>> (QDataStream &in, TaskStorage &storage) { - if (in.status() == QDataStream::Ok) { - in >> storage.itsRecalcStorageNeeded; - // itsStorageSelectionMode - quint8 storagemode; - in >> storagemode; - storage.itsStorageSelectionMode = (storage_selection_mode) storagemode; - - // storage settings - storage.itsStorage.clear(); - std::pair<quint16,quint16> storagePair; - storageVector storageVec; - quint8 dptype; - quint32 nrOfObjects, nrOfObjects2; - - in >> nrOfObjects; - for (quint32 i = 0; i < nrOfObjects; ++i) { - in >> dptype - >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> storagePair.first // storage node ID - >> storagePair.second; // storage raid ID - storageVec.push_back(storagePair); - } - storage.itsStorage.insert(storageMap::value_type((dataProductTypes)dptype, storageVec)); - storageVec.clear(); - } - - // input data product specifications - - in >> storage.itsEnabledInputData.coherentStokes >> storage.itsEnabledInputData.correlated - >> storage.itsEnabledInputData.incoherentStokes >> storage.itsEnabledInputData.instrumentModel; - - storage.itsInputDataProducts.clear(); - quint8 dpType; - bool skip; - std::string tmpString; - in >> nrOfObjects; // itsInputDataProducts.size() - for (quint32 i = 0; i < nrOfObjects; ++i) { - TaskStorage::inputDataProduct tmpInputDP; - in >> dpType; - - // identifications - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpInputDP.identifications.push_back(tmpString.c_str()); - } - // locations - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpInputDP.locations.push_back(tmpString.c_str()); - } - // filenames - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpInputDP.filenames.push_back(tmpString.c_str()); - } - // skip vector - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> skip; - tmpInputDP.skip.push_back(skip); - } - - storage.itsInputDataProducts[static_cast<dataProductTypes>(dpType)] = tmpInputDP; - } - - // input data files (number of files and file size for each input data product) - in >> nrOfObjects; //(quint32) storage.itsInputDataFiles.size(); - std::pair<double, unsigned> files; - for (quint32 j = 0; j < nrOfObjects; ++j) { - in >> dpType >> files.first >> files.second; - storage.itsInputDataFiles[static_cast<dataProductTypes>(dpType)] = files; - } - - // output data files (number of files and file size for each input data product) - in >> nrOfObjects; //(quint32) storage.itsOutputDataFiles.size(); - for (quint32 j = 0; j < nrOfObjects; ++j) { - in >> dpType >> files.first >> files.second; - storage.itsOutputDataFiles[static_cast<dataProductTypes>(dpType)] = files; - } - // output data product specifications - - in >> storage.itsEnabledOutputData.coherentStokes >> storage.itsEnabledOutputData.correlated - >> storage.itsEnabledOutputData.incoherentStokes >> storage.itsEnabledOutputData.instrumentModel >> storage.itsEnabledOutputData.pulsar - >> storage.itsEnabledOutputData.skyImage >> storage.itsEnabledOutputData.coherentStokesAssigned - >> storage.itsEnabledOutputData.complexVoltagesAssigned >> storage.itsEnabledOutputData.correlatedAssigned - >> storage.itsEnabledOutputData.incoherentStokesAssigned >> storage.itsEnabledOutputData.instrumentModelAssigned >> storage.itsEnabledOutputData.pulsarAssigned - >> storage.itsEnabledOutputData.skyImageAssigned; - - storage.itsOutputDataProducts.clear(); - in >> nrOfObjects; // itsOutputDataProducts.size() - for (quint32 i = 0; i < nrOfObjects; ++i) { - TaskStorage::outputDataProduct tmpOutputDP; - in >> dpType; - - // identifications - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpOutputDP.identifications.push_back(tmpString.c_str()); - } - // locations - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpOutputDP.locations.push_back(tmpString.c_str()); - } - // filenames - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpOutputDP.filenames.push_back(tmpString.c_str()); - } - // mointpoints - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> tmpString; - tmpOutputDP.uniqueMointPoints.push_back(tmpString.c_str()); - } - // skip vector - in >> nrOfObjects2; - for (quint32 j = 0; j < nrOfObjects2; ++j) { - in >> skip; - tmpOutputDP.skip.push_back(skip); - } - storage.itsOutputDataProducts[static_cast<dataProductTypes>(dpType)] = tmpOutputDP; - } - - in >> storage.itsTotalDataSizekBytes >> storage.itsTotalBandWidth; - } - return in; -} - -//WK code commented out -// Returns True if the input and output node locations are equal for -// all the input and output products -// THis function should be moved to the pipeline class? -//bool TaskStorage::getEqualityInputOutputProducts()const -//{ -// // Check we have the same number of dataproduct types -// if (itsInputDataProducts.size() != itsOutputDataProducts.size()) -// return false; - -// //loop over the input and output data types -// std::map<dataProductTypes, inputDataProduct >::const_iterator inputTypePair; -// std::map<dataProductTypes, outputDataProduct >::const_iterator outputTypePair; -// for (inputTypePair = itsInputDataProducts.begin(), -// outputTypePair = itsOutputDataProducts.begin(); -// inputTypePair != itsInputDataProducts.end(); // length is the same -// ++inputTypePair, ++outputTypePair ) -// { -// // Check if we have the same number of input and output entries -// if (inputTypePair->second.locations.size() != -// outputTypePair->second.locations.size()) -// return false; - -// // Loop over all the input and output locations -// QStringList::const_iterator inputLoc; -// QStringList::const_iterator outputLoc; -// for (inputLoc = inputTypePair->second.locations.begin(), -// outputLoc = outputTypePair->second.locations.begin(); -// inputLoc != inputTypePair->second.locations.end(); -// ++inputLoc , ++outputLoc) -// { -// //return false if the nodes are not the same -// if (inputLoc->split(":").at(0) != outputLoc->split(":").at(0)) -// return false; -// } -// } -// return true; -//} - -void TaskStorage::setInputFileSizes(dataProductTypes dpType, const std::pair<double, unsigned> &inputFileSizes) { - itsInputDataFiles[dpType] = inputFileSizes; - itsRecalcStorageNeeded = true; -} - -unsigned TaskStorage::getNrFiles(void) const { - unsigned nrFiles(0); - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator it = itsOutputDataFiles.begin(); it != itsOutputDataFiles.end(); ++it) { - nrFiles += it->second.second; - } - return nrFiles; -} - -std::map<dataProductTypes, int> TaskStorage::getMinimumNrOfStorageNodes(void) const { - std::map<dataProductTypes, int> minNrOfNodesMap; - double bandwidthPerFile, storageNodeBW(Controller::theSchedulerSettings.getStorageNodeBandWidth()); - unsigned maxFilesToNode(0), maxFilesPerNode(Controller::theSchedulerSettings.getMaxNrOfFilesPerStorageNode()); - int durationSec = itsOwner->getDuration().totalSeconds(); - if (durationSec > 0) { - for (std::map<dataProductTypes, std::pair<double, unsigned> >::const_iterator mit = itsOutputDataFiles.begin(); mit != itsOutputDataFiles.end(); ++mit) { - bandwidthPerFile = mit->second.first * 8 / (double) durationSec; // kbit/sec - maxFilesToNode = std::min((unsigned)std::floor(storageNodeBW / bandwidthPerFile), maxFilesPerNode); - if (maxFilesToNode > 0) { - minNrOfNodesMap[mit->first] = (int)(std::ceil((float)(mit->second.second) / maxFilesToNode)); // ceil(total_nr_files / max_files_to_node) - } - else minNrOfNodesMap[mit->first] = -1; // the bandwidth required for a single file of this dataproduct exceeds the single storage node network bandwidth - } - } - return minNrOfNodesMap; -} - - -std::pair<double, unsigned> TaskStorage::getOutputFileSizes(dataProductTypes dpType) const { - dataFileMap::const_iterator it = itsOutputDataFiles.find(dpType); - if (it != itsOutputDataFiles.end()) { - return it->second; - } - else return std::pair<double, unsigned>(0,0); -} - - -storageVector TaskStorage::getStorageLocations(dataProductTypes dpType) const { - storageMap::const_iterator it = itsStorage.find(dpType); - if (it != itsStorage.end()) { - return it->second; - } - else return storageVector(); -} - -bool TaskStorage::setStorage(dataProductTypes dataProduct, const QStringList &nodeList, const QStringList &raidList) { - if (!nodeList.isEmpty() & (nodeList.size() == raidList.size())) { - std::string nodeName, raidName; - int nodeID, locationID; - bool stop(false), result(true); - storageVector tmpStorageVec; - for (int idx = 0; idx < nodeList.size(); ++idx) { // nodeList and raidList are of equal size (see check at beginning) - nodeName = nodeList.at(idx).toStdString(); - raidName = raidList.at(idx).toStdString(); - nodeID = Controller::theSchedulerSettings.getStorageNodeID(nodeName); - if (nodeID != 0) { - locationID = Controller::theSchedulerSettings.getStorageRaidID(nodeID, raidName); - if (locationID != 0) { - // look for this entry in storageMap, if it is already inserted then we can stop because of the repeating pattern - for (std::vector<std::pair<int, int> >::const_iterator vit = tmpStorageVec.begin(); vit != tmpStorageVec.end(); ++vit) { - if ((vit->first == nodeID) & (vit->second == locationID)) { - stop = true; - //result = true; - break; - } - } - if (stop) break; // break out of first for loop - tmpStorageVec.push_back(std::pair<int, int>(nodeID, locationID)); - } - else { - qWarning() << "TaskStorage::setStorage, SAS tree: " << itsOwner->getSASTreeID() << ", node: " << nodeName.c_str() << " raid: " << raidName.c_str() << " does not exist"; - result = false; - } - } - else { - qWarning() << "TaskStorage::setStorage, SAS tree: " << itsOwner->getSASTreeID() << " storage node:" << nodeName.c_str() << " does not exist"; - result = false; - } - } - if (result == true) { - itsStorage[dataProduct] = tmpStorageVec; - return true; - } - else return false; - } - else { - qWarning() << "TaskStorage::setStorage, SAS tree: " << itsOwner->getSASTreeID() << "data type: " << DATA_PRODUCTS[dataProduct] << " empty or not of equal length storage nodes and raid array keys!"; - return false; - } -} - - -void TaskStorage::addStorage(dataProductTypes dataProductType, const storageVector &storage) { - if (itsOwner->isObservation()) { - // sort the nodes for observations (which are not dependent on input data products) - storageVector cpy(storage); - sort(cpy.begin(), cpy.end(), cmp_intPairSecond()); // first sort on raid IDs - sort(cpy.begin(), cpy.end(), cmp_intPairFirst()); // then sort on node ID - itsStorage[dataProductType] = cpy; - } - else { - itsStorage[dataProductType] = storage; - } -} - - -void TaskStorage::unAssignStorage(void) { - itsEnabledOutputData.complexVoltagesAssigned = false; - itsEnabledOutputData.correlatedAssigned = false; - itsEnabledOutputData.coherentStokesAssigned = false; - itsEnabledOutputData.incoherentStokesAssigned = false; - itsEnabledOutputData.instrumentModelAssigned = false; - itsEnabledOutputData.pulsarAssigned = false; - itsEnabledOutputData.skyImageAssigned = false; -} - - - -void TaskStorage::setInputFilesToBeProcessed( - const std::map<dataProductTypes, std::vector<bool> > &files) -{ - for (std::map<dataProductTypes, std::vector<bool> >::const_iterator it = files.begin(); - it != files.end(); ++it) - { - std::map<dataProductTypes, inputDataProduct>::iterator - fit(itsInputDataProducts.find(it->first)); - if (fit != itsInputDataProducts.end()) - { - if (it->second.size() == (unsigned)fit->second.filenames.size()) - { - fit->second.skip = it->second; - } - } - } -} - -void TaskStorage::setInputDataProductEnabled(dataProductTypes dpType, bool enabled) { - switch (dpType) { - case DP_COHERENT_STOKES: - itsEnabledInputData.coherentStokes = enabled; - break; - case DP_CORRELATED_UV: - itsEnabledInputData.correlated = enabled; - break; - case DP_INCOHERENT_STOKES: - itsEnabledInputData.incoherentStokes = enabled; - break; - case DP_INSTRUMENT_MODEL: - itsEnabledInputData.instrumentModel = enabled; - break; - case DP_SKY_IMAGE: - itsEnabledInputData.skyImage = enabled; - break; - default: - break; - } -} - -void TaskStorage::setOutputDataProductEnabled(dataProductTypes dpType, bool enabled) { - switch (dpType) { - case DP_COHERENT_STOKES: - itsEnabledOutputData.coherentStokes = enabled; - break; - case DP_CORRELATED_UV: - itsEnabledOutputData.correlated = enabled; - break; - case DP_INCOHERENT_STOKES: - itsEnabledOutputData.incoherentStokes = enabled; - break; - case DP_INSTRUMENT_MODEL: - itsEnabledOutputData.instrumentModel = enabled; - break; - case DP_PULSAR: - itsEnabledOutputData.pulsar = enabled; - break; - case DP_SKY_IMAGE: - itsEnabledOutputData.skyImage = enabled; - break; - default: - break; - } -} - -void TaskStorage::setOutputDataProductAssigned(dataProductTypes dpType, bool assigned) { - switch (dpType) { - case DP_COHERENT_STOKES: - itsEnabledOutputData.coherentStokesAssigned = assigned; - break; - case DP_CORRELATED_UV: - itsEnabledOutputData.correlatedAssigned = assigned; - break; - case DP_INCOHERENT_STOKES: - itsEnabledOutputData.incoherentStokesAssigned = assigned; - break; - case DP_INSTRUMENT_MODEL: - itsEnabledOutputData.instrumentModelAssigned = assigned; - break; - case DP_PULSAR: - itsEnabledOutputData.pulsarAssigned = assigned; - break; - case DP_SKY_IMAGE: - itsEnabledOutputData.skyImageAssigned = assigned; - break; - default: - break; - } -} - -bool TaskStorage::isInputDataProduktEnabled(dataProductTypes dpType) const { - switch (dpType) { - case DP_COHERENT_STOKES: - return itsEnabledInputData.coherentStokes; - case DP_CORRELATED_UV: - return itsEnabledInputData.correlated; - case DP_INCOHERENT_STOKES: - return itsEnabledInputData.incoherentStokes; - case DP_INSTRUMENT_MODEL: - return itsEnabledInputData.instrumentModel; - case DP_SKY_IMAGE: - return itsEnabledInputData.skyImage; - default: - break; - } - return false; -} - -bool TaskStorage::isOutputDataProduktEnabled(dataProductTypes dpType) const { - switch (dpType) { - case DP_COHERENT_STOKES: - return itsEnabledOutputData.coherentStokes; - case DP_CORRELATED_UV: - return itsEnabledOutputData.correlated; - case DP_INCOHERENT_STOKES: - return itsEnabledOutputData.incoherentStokes; - case DP_INSTRUMENT_MODEL: - return itsEnabledOutputData.instrumentModel; - case DP_PULSAR: - return itsEnabledOutputData.pulsar; - case DP_SKY_IMAGE: - return itsEnabledOutputData.skyImage; - default: - break; - } - return false; -} - -bool TaskStorage::isOutputDataProduktAssigned(dataProductTypes dpType) const { - switch (dpType) { - case DP_COHERENT_STOKES: - return itsEnabledOutputData.coherentStokesAssigned; - case DP_CORRELATED_UV: - return itsEnabledOutputData.correlatedAssigned; - case DP_INCOHERENT_STOKES: - return itsEnabledOutputData.incoherentStokesAssigned; - case DP_INSTRUMENT_MODEL: - return itsEnabledOutputData.instrumentModelAssigned; - case DP_PULSAR: - return itsEnabledOutputData.pulsarAssigned; - case DP_SKY_IMAGE: - return itsEnabledOutputData.skyImageAssigned; - default: - break; - } - return false; -} - -bool TaskStorage::checkStorageAssigned(void) const { - if (itsEnabledOutputData.correlated && !itsEnabledOutputData.correlatedAssigned) return false; - else if (itsEnabledOutputData.coherentStokes && !itsEnabledOutputData.coherentStokesAssigned) return false; - else if (itsEnabledOutputData.incoherentStokes && !itsEnabledOutputData.incoherentStokesAssigned) return false; - else if (itsEnabledOutputData.instrumentModel && !itsEnabledOutputData.instrumentModelAssigned) return false; - else if (itsEnabledOutputData.pulsar && !itsEnabledOutputData.pulsarAssigned) return false; - else if (itsEnabledOutputData.skyImage && !itsEnabledOutputData.skyImageAssigned) return false; - else return true; -} - -bool TaskStorage::hasStorageLocations(void) const { - for (storageMap::const_iterator it = itsStorage.begin(); it != itsStorage.end(); ++it) { - if (!it->second.empty()) return true; - } - return false; -} - -const std::map<dataProductTypes, TaskStorage::outputDataProduct> &TaskStorage::generateFileList(void) { - // for some types of task we need some private information, cast a pointer if needed - QString nodeName,raidSet; - QString observationIDStr; - const QString & ObsIDPrefix(Controller::theSchedulerSettings.getObservationIDprefix()); - unsigned treeID(itsOwner->SASTree().treeID()); - if (treeID) { - observationIDStr = ObsIDPrefix + QString::number(treeID); // Lxxxxx, no padding - } - else { - observationIDStr = ObsIDPrefix + "?????"; - } - QString locationStr("/" + observationIDStr + "/"); - int nrFiles; - std::map<dataProductTypes, outputDataProduct>::iterator oit; - - const Observation *pObs(0); - const CalibrationPipeline *pCalPipe(0); - const ImagingPipeline *pImagingPipe(0); - const LongBaselinePipeline *pLongBasePipe(0); - const PulsarPipeline *pPulsarPipe(0); - - if ((pObs = dynamic_cast<const Observation *>(itsOwner))) { } - else if ((pCalPipe = dynamic_cast<const CalibrationPipeline *>(itsOwner))) { } - else if ((pLongBasePipe = dynamic_cast<const LongBaselinePipeline *>(itsOwner))) { } - else if ((pImagingPipe = dynamic_cast<const ImagingPipeline *>(itsOwner))) { } - else if ((pPulsarPipe = dynamic_cast<const PulsarPipeline *>(itsOwner))) { } - else { - qDebug() << "TaskStorage::generateFileList Unknown task type for task ID:" << itsOwner->getID() << ", cannot update the output file list"; - return itsOutputDataProducts; - } - - - for (dataProductTypes dp = _BEGIN_DATA_PRODUCTS_ENUM_; dp < _END_DATA_PRODUCTS_ENUM_-1; dp = dataProductTypes(dp + 1)) { - outputDataProduct dFile; - if (isOutputDataProduktEnabled(dp)) { - oit = itsOutputDataProducts.find(dp); - if (oit != itsOutputDataProducts.end()) { - if (!oit->second.identifications.empty()) { - // copy already existing information on the output data product which is already in the task (e.g. identifications array) - dFile.identifications = oit->second.identifications; - } - } - - storageMap::const_iterator it = itsStorage.find(dp); - dataFileMap::const_iterator dit = itsOutputDataFiles.find(dp); - if( dit != itsOutputDataFiles.end()) { - nrFiles = dit->second.second; - if (it != itsStorage.end()) { - if (!it->second.empty()) { - // generate stringlist of storage node names concatenated with raid sets for round-robin file distribution pattern - int firstNode(-1), firstRaid(-1); - if (it->second.size() > 1) { - firstNode = it->second.begin()->first; - firstRaid = it->second.begin()->second; - nodeName = Controller::theSchedulerSettings.getStorageNodeName(firstNode).c_str(); - raidSet = Controller::theSchedulerSettings.getStorageRaidName(firstNode, firstRaid).c_str(); - if (!nodeName.isEmpty() && !raidSet.isEmpty()) { - dFile.uniqueMointPoints.push_back(nodeName + ":" + raidSet); - } - } - else { - nodeName = Controller::theSchedulerSettings.getStorageNodeName(it->second.front().first).c_str(); - raidSet = Controller::theSchedulerSettings.getStorageRaidName(it->second.front().first, it->second.front().second).c_str(); - if (!nodeName.isEmpty() && !raidSet.isEmpty()) { - dFile.uniqueMointPoints.push_back(nodeName + ":" + raidSet); - } - } - for (storageVector::const_iterator sit = it->second.begin()+1; sit != it->second.end(); ++sit) { - if ((sit->first == firstNode) && (sit->second == firstRaid)) break; // stop if we are back at a previous location - nodeName = Controller::theSchedulerSettings.getStorageNodeName(sit->first).c_str(); - raidSet = Controller::theSchedulerSettings.getStorageRaidName(sit->first, sit->second).c_str(); - if (!nodeName.isEmpty() && !raidSet.isEmpty()) { - dFile.uniqueMointPoints.push_back(nodeName + ":" + raidSet); - } - } - } - else { - dFile.uniqueMointPoints.push_back("??:??"); - } - } - else { - dFile.uniqueMointPoints.push_back("??:??"); - } - - if (pObs) { - const Observation::RTCPsettings &RTCP(pObs->getRTCPsettings()); - - switch (dp) { - case DP_INCOHERENT_STOKES: - { - unsigned fileIdxCounter(0); - unsigned nrParts(0); - int sz(dFile.uniqueMointPoints.size()); - unsigned nrComponents = RTCP.incoherentType == DATA_TYPE_STOKES_IQUV ? 4 : 1; - QString fileName_p1, fileName_p2, fileName_p3, fileName_p4; - for (std::map<unsigned, DigitalBeam>::const_iterator dbit = pObs->itsDigitalBeams.begin(); dbit != pObs->itsDigitalBeams.end(); ++dbit) { - nrParts = static_cast<unsigned>(ceil((double)dbit->second.nrSubbands() / RTCP.incoherentSubbandsPerFile)); - // add the SAP identifier to the filename - fileName_p1 = observationIDStr + "_SAP" + QString("%1").arg(dbit->first, 3, 10, QChar('0')); - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(dbit->second.tiedArrayBeams()); - for (std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.begin(); tit != tiedArrayBeams.end(); ++tit) { - // add the tied array beam identifier to the filename - fileName_p2 = "_B" + QString("%1").arg(tit->first, 3, 10, QChar('0')); - if (!tit->second.isCoherent()) { - if (nrComponents == 1) { // only I is written - // add the part identifier to the filename - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p3 = "_S0_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - else { // QUIV is written - for (short unsigned which = 0; which < nrComponents; ++which) { - // add the which identifier _Sx to the filename - fileName_p3 = "_S" + QString("%1").arg(which, 1, 10, QChar('0')); - // add the part identifier to the filename - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p4 = "_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3 + fileName_p4); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - } - } - } - } - itsOutputDataProducts[dp] = dFile; - } - break; - - case DP_COHERENT_STOKES: - { - unsigned fileIdxCounter(0), nrParts(0); - int sz(dFile.uniqueMointPoints.size()); - unsigned nrComponents = RTCP.coherentType == DATA_TYPE_STOKES_IQUV || RTCP.coherentType == DATA_TYPE_XXYY ? 4 : 1; - QString fileName_p1, fileName_p2, fileName_p3, fileName_p4; - for (std::map<unsigned, DigitalBeam>::const_iterator dbit = pObs->itsDigitalBeams.begin(); dbit != pObs->itsDigitalBeams.end(); ++dbit) { - unsigned TABNr(0); - nrParts = static_cast<unsigned>(ceil((double)dbit->second.nrSubbands() / RTCP.coherentSubbandsPerFile)); - // add the SAP identifier to the filename - fileName_p1 = observationIDStr + "_SAP" + QString("%1").arg(dbit->first, 3, 10, QChar('0')); - - // generate files for MANUAL TABs - const std::map<unsigned, TiedArrayBeam> &tiedArrayBeams(dbit->second.tiedArrayBeams()); - for (std::map<unsigned, TiedArrayBeam>::const_iterator tit = tiedArrayBeams.begin(); tit != tiedArrayBeams.end(); ++tit) { - // add the tied array beam identifier to the filename - if (tit->second.isCoherent()) { - fileName_p2 = "_B" + QString("%1").arg(tit->first, 3, 10, QChar('0')); - if (nrComponents == 1) { // only I is written - // add the part identifier to the filename - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p3 = "_S0_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - else { // IQUV is written - for (short unsigned which = 0; which < nrComponents; ++which) { - // add the which identifier _Sx to the filename - fileName_p3 = "_S" + QString("%1").arg(which, 1, 10, QChar('0')); - // add the part identifier to the filename - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p4 = "_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3 + fileName_p4); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - } - } - } - - TABNr = tiedArrayBeams.size(); - - // generate files for NR_TAB_RINGS - if (dbit->second.nrTabRings() > 0) { - unsigned nrRingTabs(dbit->second.nrRingTABs()); - if (nrComponents == 1) { - for (unsigned t = 0; t < nrRingTabs; ++t) { - // add the part identifier to the filename - fileName_p2 = "_B" + QString("%1").arg(TABNr++, 3, 10, QChar('0')); - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p3 = "_S0_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - } - else { - for (unsigned t = 0; t < nrRingTabs; ++t) { - fileName_p2 = "_B" + QString("%1").arg(TABNr++, 3, 10, QChar('0')); - for (short unsigned which = 0; which < nrComponents; ++which) { - // add the which identifier _Sx to the filename - fileName_p3 = "_S" + QString("%1").arg(which, 1, 10, QChar('0')); - // add the part identifier to the filename - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p4 = "_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3 + fileName_p4); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - } - } - } - - // generate files for fly's eye - if (RTCP.flysEye) { - nrParts = static_cast<unsigned>(ceil((double)pObs->getNrOfSubbands() / RTCP.coherentSubbandsPerFile)); // here we use the total number of subbands of all SAP's together (is that ok?) - for (unsigned t = 0; t < pObs->getNrVirtualStations(); ++t) { - fileName_p2 = "_B" + QString("%1").arg(TABNr++, 3, 10, QChar('0')); - if (nrComponents == 1) { - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p3 = "_S0_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - else { - for (short unsigned which = 0; which < nrComponents; ++which) { - // add the which identifier _Sx to the filename - fileName_p3 = "_S" + QString("%1").arg(which, 1, 10, QChar('0')); - // add the part identifier to the filename - for (unsigned part = 0; part < nrParts; ++part) { - fileName_p4 = "_P" + QString("%1").arg(part, 3, 10, QChar('0')) + "_bf.h5"; - dFile.filenames.push_back(fileName_p1 + fileName_p2 + fileName_p3 + fileName_p4); - dFile.locations.push_back(dFile.uniqueMointPoints.at(fileIdxCounter++ % sz) + locationStr); // round-robin storage locations - } - } - } - } - } - } - - itsOutputDataProducts[dp] = dFile; - } - break; - - case DP_CORRELATED_UV: - { - if (!dFile.uniqueMointPoints.empty()) { - int sz(dFile.uniqueMointPoints.size()); - for (int i=0; i < nrFiles; ++i) { - dFile.locations.push_back(dFile.uniqueMointPoints.at(i % sz) + "/" + observationIDStr + "/"); // round-robin storage locations - } - - // generate the array for correlated uv data - int curDigiBeam(0), beamSBBorder(0); - QString SAPstr; - std::map<unsigned, DigitalBeam>::const_iterator dbit; - const std::map<unsigned, DigitalBeam> &digitalBeams(pObs->getDigitalBeams()); - for (int subIdx=0; subIdx < nrFiles; ++subIdx) { // one file per subband - if (subIdx == beamSBBorder) { - SAPstr = QString("_SAP%1").arg(curDigiBeam,3,10,QChar('0')); - dbit = digitalBeams.find(curDigiBeam++); - if (dbit != digitalBeams.end()) { - beamSBBorder += dbit->second.nrSubbands(); // next digital beam subband border - } - } - dFile.filenames.push_back(observationIDStr + SAPstr + "_SB" + QString("%1").arg(subIdx,3,10,QChar('0')) + "_uv.MS"); - } - } - itsOutputDataProducts[dp] = dFile; - } - break; - - default: - break; - } // end switch(dp) - } - else if (pCalPipe) { - if (dp == DP_CORRELATED_UV) { - outputDataProduct &output(itsOutputDataProducts[DP_CORRELATED_UV]); - output.locations.clear(); - output.filenames.clear(); - std::map<dataProductTypes, inputDataProduct>::iterator idpit(itsInputDataProducts.find(DP_CORRELATED_UV)); - if (idpit != itsInputDataProducts.end()) { - if (idpit->second.filenames.size() == nrFiles) { - if (dFile.uniqueMointPoints.empty()) { - dFile.uniqueMointPoints.push_back("??:??"); - } - int sz(dFile.uniqueMointPoints.size()); - output.uniqueMointPoints = dFile.uniqueMointPoints; - for (int i=0; i < nrFiles; ++i) { - output.filenames.push_back(QString(idpit->second.filenames.at(i)).remove(QRegExp("_SAP[0-9]{1,}")).replace(QRegExp(ObsIDPrefix + "[0-9]{1,}"), observationIDStr).replace("_uv.MS","_uv.dppp.MS")); - output.locations.push_back(dFile.uniqueMointPoints.at(i % sz) + "/" + observationIDStr + "/"); // round-robin storage locations - } - output.skip = idpit->second.skip; - } - } - } - // for the output data product type instrumentModel we now also determine the files if this output type is enabled - // it generates one file for each input correlated data product file. (i.e. the number of files is the same as the number of input correlated files - else if (dp == DP_INSTRUMENT_MODEL) { // is intrumentModel output data product enabled? - outputDataProduct &output(itsOutputDataProducts[DP_INSTRUMENT_MODEL]); - output.locations.clear(); - output.filenames.clear(); - std::map<dataProductTypes, inputDataProduct>::iterator idpit(itsInputDataProducts.find(DP_CORRELATED_UV)); - if (idpit != itsInputDataProducts.end()) { - if (idpit->second.filenames.size() == nrFiles) { - if (dFile.uniqueMointPoints.empty()) { - dFile.uniqueMointPoints.push_back("??:??"); - } - int sz(dFile.uniqueMointPoints.size()); - output.uniqueMointPoints = dFile.uniqueMointPoints; - for (int i=0; i < nrFiles; ++i) { - output.filenames.push_back(QString(idpit->second.filenames.at(i)).replace("_uv.MS","_inst.INST").replace(QRegExp(ObsIDPrefix + "[0-9]{1,}"), observationIDStr)); // replace _uv.MS extension of the correlated input files with _inst.INST extension to get the output instrument filenames - output.locations.push_back(dFile.uniqueMointPoints.at(i % sz) + "/" + observationIDStr + "/"); // round-robin storage locations - } - output.skip = idpit->second.skip; - } - } - } - } - else if (pPulsarPipe && dp == DP_PULSAR) { // is pulsar output data product enabled? - outputDataProduct &output(itsOutputDataProducts[DP_PULSAR]); - output.locations.clear(); - output.filenames.clear(); - output.skip.clear(); - std::vector<dataProductTypes> dpv; - dpv.push_back(DP_COHERENT_STOKES); - dpv.push_back(DP_INCOHERENT_STOKES); - std::map<dataProductTypes, TaskStorage::inputDataProduct>::iterator idpit; - for (std::vector<dataProductTypes>::const_iterator dpi = dpv.begin(); dpi != dpv.end(); ++dpi) { - if (isInputDataProduktEnabled(*dpi)) { - idpit = itsInputDataProducts.find(*dpi); - if (idpit != itsInputDataProducts.end()) { - if (idpit->second.filenames.size() == idpit->second.locations.size()) { - if (dFile.uniqueMointPoints.empty()) { - dFile.uniqueMointPoints.push_back("??:??"); - } - output.uniqueMointPoints = dFile.uniqueMointPoints; - - QString fileName, location, outFile, regexp; - // All file parts (_Pxxx) and polarizations (_Sy) are tarred into one output file for complex voltage (XXYY) - // for other coherent data types each input file gets its own output tar.gz file (so keep _Sn identifier in filenames) - // TODO: for Stokes IQUV with number of parts > 1 all files merge to one tarball so _P[0-9]+ should be removed - if (*dpi == DP_COHERENT_STOKES) { - regexp = (pPulsarPipe->coherentType() == DATA_TYPE_STOKES_IQUV) ? "_P[0-9]+" : "_S[0-9]_P[0-9]+"; - } - else { - regexp = (pPulsarPipe->incoherentType() == DATA_TYPE_STOKES_IQUV) ? "_P[0-9]+" : "_S[0-9]_P[0-9]+"; - } - for (int i=0; i < idpit->second.filenames.size(); ++i) { - fileName = idpit->second.filenames.at(i); - location = idpit->second.locations.at(i); - // replace _bf.h5 extension of the coherent stokes input files with _bf.tar.gz extension - outFile = fileName.replace("_bf.h5","_bf.tar.gz").replace(QRegExp(regexp),"").replace(QRegExp(ObsIDPrefix + "[0-9]+"), observationIDStr); - if (!output.filenames.contains(outFile)) { - output.filenames.push_back(outFile); - output.locations.push_back(location.replace(QRegExp(ObsIDPrefix + "[0-9]+"), observationIDStr)); - } - } - output.skip.assign(output.filenames.size(), false); - } - } - } - } - } - else if (pImagingPipe && dp == DP_SKY_IMAGE) { - outputDataProduct &output(itsOutputDataProducts[DP_SKY_IMAGE]); - output.locations.clear(); - output.filenames.clear(); - std::map<dataProductTypes, TaskStorage::inputDataProduct>::iterator idpit(itsInputDataProducts.find(DP_CORRELATED_UV)); - if (idpit != itsInputDataProducts.end()) { - if (dFile.uniqueMointPoints.empty()) { - dFile.uniqueMointPoints.push_back("??:??"); - } - int sz(dFile.uniqueMointPoints.size()); - output.uniqueMointPoints = dFile.uniqueMointPoints; - unsigned nrInputSubbands(idpit->second.filenames.size()); - // nr of skyImage files = nr_input_correlated files (= total subbands) / (slices_per_image * subbands_per_image) - // if the division above is not an integer value, that is an error, needs to be checked in Controller::doPrescheduleChecks - unsigned slicesPerImage(pImagingPipe->slicesPerImage()), subbandsPerImage(pImagingPipe->subbandsPerImage()); - if ((slicesPerImage != 0) && (subbandsPerImage != 0)) { - if (fmod((float)(nrInputSubbands), (float)subbandsPerImage * slicesPerImage) == 0) { - unsigned nrImages(nrInputSubbands / (subbandsPerImage * slicesPerImage)); - for (unsigned sbg = 0; sbg < nrImages; ++sbg) { - output.filenames.push_back(observationIDStr + "_SBG" + QString("%1").arg(sbg,3,10,QChar('0')) + "_sky.h5"); - output.locations.push_back(dFile.uniqueMointPoints.at(sbg % sz) + "/" + observationIDStr + "/"); // round-robin storage locations - } - output.skip.assign(output.filenames.size(), false); - } - } - } - } - else if (pLongBasePipe && dp == DP_CORRELATED_UV) { - outputDataProduct &output(itsOutputDataProducts[DP_CORRELATED_UV]); - output.locations.clear(); - output.filenames.clear(); - std::map<dataProductTypes, TaskStorage::inputDataProduct>::iterator idpit(itsInputDataProducts.find(DP_CORRELATED_UV)); - if (idpit != itsInputDataProducts.end()) { - if (dFile.uniqueMointPoints.empty()) { - dFile.uniqueMointPoints.push_back("??:??"); - } - int sz(dFile.uniqueMointPoints.size()); - output.uniqueMointPoints = dFile.uniqueMointPoints; - unsigned nrInputFiles(idpit->second.filenames.size()); - // nr of output MS = nr of input files (= total subbands) / (* ) - // if the division above is not an integer value, that is an error, needs to be checked in Controller::doPrescheduleChecks - unsigned subbandsPerSubbandGroup(pLongBasePipe->subbandsPerSubbandGroup()), subbandGroupsPerMS(pLongBasePipe->subbandGroupsPerMS()); - if ((subbandsPerSubbandGroup != 0) && (subbandGroupsPerMS != 0)) { - if (fmod((float)(nrInputFiles), (float)subbandsPerSubbandGroup * subbandGroupsPerMS) == 0) { - unsigned nrOutputFiles(nrInputFiles / (subbandsPerSubbandGroup * subbandGroupsPerMS)); - for (unsigned sbg = 0; sbg < nrOutputFiles; ++sbg) { - output.filenames.push_back(observationIDStr + "_SBG" + QString("%1").arg(sbg,3,10,QChar('0')) + "_uv.MS"); - output.locations.push_back(dFile.uniqueMointPoints.at(sbg % sz) + "/" + observationIDStr + "/"); // round-robin storage locations - } - output.skip.assign(output.filenames.size(), false); - } - } - } - } - } - else if (!itsOutputDataProducts.empty()) { // this output data product does not have output files defined (could be because of missing specification) - oit = itsOutputDataProducts.find(dp); - if (oit != itsOutputDataProducts.end()) { - if (oit->second.identifications.empty()) { // if an identification for this data product type exists then don't remove it - // if it doesn't exist, it is save to remove this output data product type altogether - itsOutputDataProducts.erase(dp); - } - else { - oit->second.filenames.clear(); - oit->second.locations.clear(); - oit->second.uniqueMointPoints.clear(); - } - } - } - } - else { // this output data product type is not enabled (anymore) - oit = itsOutputDataProducts.find(dp); - if (oit != itsOutputDataProducts.end()) { - if (oit->second.identifications.empty()) { // if an identification for this data product type exists then don't remove it - // if it doesn't exist, it is save to remove this output data product type altogether - itsOutputDataProducts.erase(dp); - } - else { - oit->second.filenames.clear(); - oit->second.locations.clear(); - oit->second.uniqueMointPoints.clear(); - } - } - } - } - - return itsOutputDataProducts; -} - -bool TaskStorage::diff(const TaskStorage *other, task_diff &dif) const { - // storage settings - itsEnabledOutputData != other->getOutputDataProductsEnabled() ? dif.output_data_types = true : dif.output_data_types = false; - itsOutputDataProducts != other->getOutputDataProducts() ? dif.output_data_products = true : dif.output_data_products = false; - if (itsStorageSelectionMode != other->getStorageSelectionMode()) dif.output_storage_settings = true; - else dif.output_storage_settings = false; - - // input data products - // w'll need a special compare for differences for input data products, where a file that has been disabled (in the enabled vector) - // is not marked different from that file not being there in the input data product list of the other task - - dif.input_data_products = false; - if (itsEnabledInputData != other->getInputDataProductsEnabled()) { - dif.input_data_products = true; - } - else { - std::map<dataProductTypes, inputDataProduct>::const_iterator odit; - const std::map<dataProductTypes, inputDataProduct> &otherInput(other->getInputDataProducts()); - for (std::map<dataProductTypes, inputDataProduct>::const_iterator it = itsInputDataProducts.begin(); it != itsInputDataProducts.end(); ++it) { - odit = otherInput.find(it->first); - if (odit != otherInput.end()) { - if (it->second.skip != odit->second.skip) dif.input_data_products = true; - if (itsOwner->getStatus() >= Task::PRESCHEDULED) { // input data products locations don't need to be saved (diff done) for tasks that have status < PRESCHEDULED - if (it->second.locations != odit->second.locations) dif.input_data_products = true; - } - if (it->second.filenames != odit->second.filenames) dif.input_data_products = true; - else if (it->second.identifications != odit->second.identifications) dif.input_data_products = true; - } - else dif.input_data_products = true; - } - } - return (dif.input_data_products || dif.output_data_types || dif.output_storage_settings || dif.output_data_products); -} - - -QString TaskStorage::diffString(const task_diff &dif) const { - QString difstr; - if (dif.input_data_products) difstr += QString(SAS_item_names[TP_INPUT_DATA_PRODUCTS]) + ","; - if (dif.output_data_types) difstr += QString(SAS_item_names[TP_OUTPUT_DATA_TYPES]) + ","; - if (dif.output_storage_settings) difstr += QString(SAS_item_names[TP_OUTPUT_STORAGE_SETTINGS]) + ","; - if (dif.output_data_products) difstr += QString(SAS_item_names[TP_OUTPUT_DATA_PRODUCTS]) + ","; - - if (difstr.endsWith(',')) { - difstr = difstr.remove(difstr.length()-1,1); - } - return difstr; -} diff --git a/SAS/Scheduler/src/taskstorage.h b/SAS/Scheduler/src/taskstorage.h deleted file mode 100644 index 202898a8f5ad3868fe5f516a6544362407a2dc27..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/taskstorage.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * taskstorage.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jul 18, 2014 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/taskstorage.h $ - * description : data class TaskStorage contains storage settings and calculation methods to store storage settings and is used by Tasks that generate storage - * - */ - -#ifndef TASKSTORAGE_H -#define TASKSTORAGE_H - -#include "storage_definitions.h" -#include "Storage.h" - -class Task; -class task_diff; - -extern const char * DATA_PRODUCTS[NR_DATA_PRODUCT_TYPES]; - -/* -enum storage_clustering_mode { - STORAGE_PROJECT_PREFERRED, - STORAGE_DATATYPE_PREFERRED, - END_STORAGE_CLUSTERING_MODES -}; -#define NR_STORAGE_CLUSTERING_MODES END_STORAGE_CLUSTERING_MODES -*/ - -enum storage_selection_mode { - STORAGE_MODE_MAXIMUM_DATA_TYPE_PREFERRED, - STORAGE_MODE_MAXIMUM_PROJECT_PREFERRED, - STORAGE_MODE_MINIMUM_DATA_TYPE_PREFERRED, - STORAGE_MODE_MINIMUM_PROJECT_PREFERRED, - STORAGE_MODE_MANUAL, - END_STORAGE_SELECTION_MODES -}; -#define NR_STORAGE_SELECTION_MODES END_STORAGE_SELECTION_MODES - -//extern const char *storage_cluster_mode_str[NR_STORAGE_CLUSTERING_MODES]; -extern const char *storage_select_mode_str[NR_STORAGE_SELECTION_MODES]; - -// dataFileMap: for each data product contains the size per file (kB) and the number of files to be written -typedef std::map<dataProductTypes, std::pair<double, unsigned> > dataFileMap; - -class TaskStorage -{ - // TODO: Friend class codesmell ( why does everybody need to look under my skirt?) - friend class Observation; - friend class Pipeline; - friend class PulsarPipeline; - friend class ImagingPipeline; - friend class LongBaselinePipeline; - friend class CalibrationPipeline; - - friend QDataStream& operator<< (QDataStream &out, const TaskStorage &task); // used for writing data to binary file - friend QDataStream& operator>> (QDataStream &in, TaskStorage &task); // used for reading data from binary file - -public: - - class enableDataProdukts { - public: - enableDataProdukts() : correlated(false), coherentStokes(false), incoherentStokes(false), - instrumentModel(false), pulsar(false), skyImage(false), correlatedAssigned(false), coherentStokesAssigned(false), incoherentStokesAssigned(false), - complexVoltagesAssigned(false), instrumentModelAssigned(false), pulsarAssigned(false), skyImageAssigned(false) - { } - bool operator!=(const enableDataProdukts &other) const { - return ((correlated != other.correlated) || - (coherentStokes != other.coherentStokes) || - (incoherentStokes != other.incoherentStokes) || - (instrumentModel != other.instrumentModel) || - (pulsar != other.pulsar) || - (skyImage != other.skyImage) - ); - } - - bool correlated, coherentStokes, incoherentStokes, instrumentModel, pulsar, skyImage; - bool correlatedAssigned, coherentStokesAssigned, incoherentStokesAssigned, complexVoltagesAssigned, instrumentModelAssigned, pulsarAssigned, skyImageAssigned; - }; - - class inputDataProduct { - public: - QStringList identifications; - QStringList locations; - QStringList filenames; - std::vector<bool> skip; - }; - - class outputDataProduct { - public: - QStringList identifications; - QStringList locations; - QStringList filenames; - QStringList uniqueMointPoints; - std::vector<bool> skip; - }; - - TaskStorage(const Task *owner, const TaskStorage *other = 0); - - // getters - const Task *owner(void) const {return itsOwner;} - unsigned getNrFiles(void) const; - std::map<dataProductTypes, int> getMinimumNrOfStorageNodes(void) const; - const storageMap &getStorageLocations(void) const {return itsStorage;} - storageVector getStorageLocations(dataProductTypes dpType) const; - storage_selection_mode getStorageSelectionMode(void) const {return itsStorageSelectionMode;} - bool checkStorageAssigned(void) const; - bool hasStorageLocations(void) const; - double getTotalStoragekBytes(void) const {return itsTotalDataSizekBytes;} - double getTotalBandWidth(void) const {return itsTotalBandWidth;} - const dataFileMap &getOutputFileSizes(void) const {return itsOutputDataFiles;} - std::pair<double, unsigned> getOutputFileSizes(dataProductTypes dp) const; - const std::vector<storageResult> &getStorageCheckResult(void) const {return itsStorageCheckResult;} - const std::map<dataProductTypes, outputDataProduct> &generateFileList(void); - const std::map<dataProductTypes, outputDataProduct> &getOutputDataProducts(void) const {return itsOutputDataProducts;} - const enableDataProdukts &getOutputDataProductsEnabled(void) const {return itsEnabledOutputData;} - std::map<dataProductTypes, outputDataProduct> &getOutputDataProductsForChange(void) {return itsOutputDataProducts;} - const std::map<dataProductTypes, inputDataProduct> &getInputDataProducts(void) const {return itsInputDataProducts;} - std::map<dataProductTypes, inputDataProduct> &getInputDataProductsForChange(void) {return itsInputDataProducts;} - const enableDataProdukts &getInputDataProductsEnabled(void) const {return itsEnabledInputData;} - const storageMap &getInputStorageLocations(void) const {return itsInputStorageLocations;} - bool isInputDataProduktEnabled(dataProductTypes dpType) const; - bool isOutputDataProduktEnabled(dataProductTypes dpType) const; - bool isOutputDataProduktAssigned(dataProductTypes dpType) const; - - // add all data products of a certain type (clears previous data products of that type if they where already added) - void addStorage(dataProductTypes dataProduct, const storageVector &storage); - void setStorage(const storageMap &storage) {itsStorage = storage;} - bool setStorage(dataProductTypes dataProduct, const QStringList &nodeList, const QStringList &raidList); - void unAssignStorage(void); - void setInputFilesForDataProduct(dataProductTypes dpType, const QStringList &filenames, const QStringList &locations, const std::vector<bool> &skipVector) { - itsInputDataProducts[dpType].filenames = filenames; - itsInputDataProducts[dpType].locations = locations; - itsInputDataProducts[dpType].skip = skipVector; - } - void setOutputFilesForDataProduct(dataProductTypes dpType, const QStringList &filenames, const QStringList &locations, const std::vector<bool> &skipVector) { - itsOutputDataProducts[dpType].filenames = filenames; - itsOutputDataProducts[dpType].locations = locations; - itsOutputDataProducts[dpType].skip = skipVector; - } - - // setters - void setOwner(const Task *owner) {itsOwner = owner;} - void addInputStorageLocations(dataProductTypes dpType, const storageVector &storage) {itsInputStorageLocations[dpType] = storage;} - // add an identifications list for a specific input data product type (creates a dependency on that dataproduct) - void addInputDataProductID(dataProductTypes dpType, const QStringList &identification_list) {itsInputDataProducts[dpType].identifications = identification_list;} - void setInputDataProductEnabled(dataProductTypes dpType, bool enabled); - void setInputFilesToBeProcessed(const std::map<dataProductTypes, std::vector<bool> > &files); - void setOutputDataProductEnabled(dataProductTypes dp_type, bool enabled); - void setEnabledOutputDataProducts(const enableDataProdukts &outputDataTypes) {itsEnabledOutputData = outputDataTypes;} - void setOutputDataProductAssigned(dataProductTypes dp_type, bool assigned); - void addOutputDataProductID(dataProductTypes dpType, const QStringList &identification_list) {itsOutputDataProducts[dpType].identifications = identification_list;} - void setInputFileSizes(dataProductTypes dpType, const std::pair<double, unsigned> &inputFileSizes); - void setOutputFileNames(dataProductTypes dpType, const QStringList &filenames) {itsOutputDataProducts[dpType].filenames = filenames;} - void setOutputFileLocations(dataProductTypes dpType, const QStringList &file_locations) {itsOutputDataProducts[dpType].locations = file_locations;} - void setOutputFileMountpoints(dataProductTypes dpType, const QStringList &mountPoints) {itsOutputDataProducts[dpType].uniqueMointPoints = mountPoints;} - void clearOutputFileMountpoints(dataProductTypes dpType) {itsOutputDataProducts[dpType].uniqueMointPoints.clear();} - - void setStorageCheckResult(const std::vector<storageResult> &result) {itsStorageCheckResult = result;} - void clearStorageCheckResults(void) {itsStorageCheckResult.clear();} - void setStorageSelectionMode(storage_selection_mode mode) {itsStorageSelectionMode = mode;} - void setRecalcStorageNeeded(void) {itsRecalcStorageNeeded = true;} - - bool diff(const TaskStorage *other, task_diff &dif) const; - QString diffString(const task_diff &dif) const; - -//WK code commented out -// bool getEqualityInputOutputProducts()const; - -private: - const Task *itsOwner; - bool itsRecalcStorageNeeded; - storage_selection_mode itsStorageSelectionMode; - dataFileMap itsOutputDataFiles, itsInputDataFiles; // for each data product contains the size per file and the number of files to be written - enableDataProdukts itsEnabledInputData, itsEnabledOutputData; - std::map<dataProductTypes, inputDataProduct> itsInputDataProducts; - std::map<dataProductTypes, outputDataProduct> itsOutputDataProducts; - double itsTotalDataSizekBytes; - double itsTotalBandWidth; // Gbit/sec - storageMap itsStorage, itsInputStorageLocations; // itsStorage contains the 'asked' storage node IDs and raid IDs - std::vector<storageResult> itsStorageCheckResult; -}; - -inline bool operator==(const TaskStorage::inputDataProduct &lhs, const TaskStorage::inputDataProduct &rhs) { - return ((lhs.identifications == rhs.identifications) && - (lhs.locations == rhs.locations) && - (lhs.filenames == rhs.filenames)); -} - -inline bool operator==(const TaskStorage::outputDataProduct &lhs, const TaskStorage::outputDataProduct &rhs) { - return ( - (lhs.identifications == rhs.identifications) && - (lhs.locations == rhs.locations) && - (lhs.filenames == rhs.filenames) && - (lhs.uniqueMointPoints == rhs.uniqueMointPoints)); -} - -#endif // TASKSTORAGE_H diff --git a/SAS/Scheduler/src/thrashbin.cpp b/SAS/Scheduler/src/thrashbin.cpp deleted file mode 100644 index 89cc39e6a2edb4dad1121c0ef5ca181067e5f9d6..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/thrashbin.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * thrashbin.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 18-March-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/thrashbin.cpp $ - * - */ - -#include "thrashbin.h" -#include <QStringList> - -Thrashbin::Thrashbin(QWidget *parent) - : QDialog(parent), itsSortColumn(0), itsSortOrder(Qt::AscendingOrder) -{ - ui.setupUi(this); - setupThrashBin(); -} - -Thrashbin::~Thrashbin() -{ - -} - -void Thrashbin::emptyThrashBin(void) { - itsTasks.clear(); - ui.tableWidgetThrash->clearContents(); - ui.tableWidgetThrash->setRowCount(0); -} - -void Thrashbin::setupThrashBin(void) { - QStringList labels; - labels << "ID" << tr("Task name") << tr("Project name") << tr("Task type") << tr("Status"); - ui.tableWidgetThrash->setColumnCount(5); - ui.tableWidgetThrash->horizontalHeader()->setDefaultSectionSize(75); - ui.tableWidgetThrash->verticalHeader()->setDefaultSectionSize(16); - ui.tableWidgetThrash->setHorizontalHeaderLabels(labels); - ui.tableWidgetThrash->setColumnWidth(0, 40); // task ID - ui.tableWidgetThrash->setColumnWidth(1, 150); // task name - ui.tableWidgetThrash->setColumnWidth(2, 150); // project name - ui.tableWidgetThrash->setColumnWidth(3, 100); // task type - ui.tableWidgetThrash->setColumnWidth(4, 80); // task status -// ui.tableWidgetThrash->verticalHeader()->setDefaultSectionSize(16); - ui.tableWidgetThrash->setSelectionMode(QAbstractItemView::MultiSelection); - ui.tableWidgetThrash->horizontalHeader()->setStretchLastSection(true); - ui.tableWidgetThrash->horizontalHeader()->setSortIndicatorShown(true); -// ui.tableWidgetThrash->setSortingEnabled(true); - connect(ui.tableWidgetThrash->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(sortTable(int))); -} - -void Thrashbin::sortTable(int column) { - itsSortColumn = column; - if (itsSortOrder == Qt::AscendingOrder) - itsSortOrder = Qt::DescendingOrder; - else - itsSortOrder = Qt::AscendingOrder; - ui.tableWidgetThrash->sortByColumn(itsSortColumn, itsSortOrder); -} - - -void Thrashbin::addTasks(const std::vector<Task *> &tasks) { - unsigned taskID; - for (std::vector<Task *>::const_iterator it = tasks.begin(); it != tasks.end(); ++it) { - taskID = (*it)->getID(); - std::pair<std::map<unsigned, Task *>::iterator, bool> ret = - itsTasks.insert(std::map<unsigned, Task *>::value_type (taskID, *it)); - if (ret.second) { - int row = ui.tableWidgetThrash->rowCount(); - ui.tableWidgetThrash->insertRow(row); - //task ID - QTableWidgetItem *item = new QTableWidgetItem(); - item->setData(0,taskID); // we have to use setData to get correct number sorting for this column - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 0, item); - // task name - item = new QTableWidgetItem((*it)->getTaskName()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 1, item); - // project name - item = new QTableWidgetItem((*it)->getProjectName()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 2, item); - // task type - item = new QTableWidgetItem((*it)->getTypeStr()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 3, item); - // task status - item = new QTableWidgetItem((*it)->getStatusStr()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 4, item); - } - } - ui.tableWidgetThrash->sortByColumn(itsSortColumn, itsSortOrder); - if (!itsTasks.empty()) - emit thrashBinContainsItems(); -} - -void Thrashbin::removeRestoredTasks(const std::vector<unsigned> &restoredTasks) { - for (std::vector<unsigned>::const_iterator it = restoredTasks.begin(); it != restoredTasks.end(); ++it) { - itsTasks.erase(*it); - } - updateThrashBin(); -} - -void Thrashbin::updateThrashBin(void) { - ui.tableWidgetThrash->clearContents(); - ui.tableWidgetThrash->setRowCount(itsTasks.size()); - int row(0); - QTableWidgetItem *item; - for (std::map<unsigned, Task *>::const_iterator it = itsTasks.begin(); it != itsTasks.end(); ++it) { - unsigned taskID = it->first; - //task ID - item = new QTableWidgetItem(); - item->setData(0,taskID); // we have to use setData to get correct number sorting for this column - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 0, item); - // task name - item = new QTableWidgetItem(it->second->getTaskName()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 1, item); - // project name - item = new QTableWidgetItem(it->second->getProjectName()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 2, item); - // task type - item = new QTableWidgetItem(it->second->getTypeStr()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 3, item); - // task status - item = new QTableWidgetItem(it->second->getStatusStr()); - item->setData(100, taskID); - ui.tableWidgetThrash->setItem(row, 4, item); - ++row; - } - if (itsTasks.empty()) { - ui.pushButtonDelete->setEnabled(false); - ui.pushButtonRestore->setEnabled(false); - emit thrashBinIsEmpty(); - } - else { - ui.tableWidgetThrash->sortByColumn(itsSortColumn, itsSortOrder); - emit thrashBinContainsItems(); - } -} - -void Thrashbin::checkSelection(void) { - if (ui.tableWidgetThrash->selectedItems().isEmpty()) { - ui.pushButtonDelete->setEnabled(false); - ui.pushButtonRestore->setEnabled(false); - } - else { - ui.pushButtonDelete->setEnabled(true); - ui.pushButtonRestore->setEnabled(true); - } -} - -void Thrashbin::restoreTasks(void) const { - std::vector<unsigned> tasks; - unsigned taskID; - QList<QTableWidgetItem *> list = ui.tableWidgetThrash->selectedItems(); - for (QList<QTableWidgetItem *>::const_iterator it = list.begin(); it != list.end(); ++it) { - if ((*it)->column() == 0) { - taskID = (*it)->data(100).toUInt(); - tasks.push_back(taskID); - } - } - emit restoreTasksRequest(tasks); -} - -void Thrashbin::deleteTasks(void) { - unsigned taskID; - std::vector<unsigned> tasksToDestroy; - std::map<unsigned, Task *>::iterator tit; - QList<QTableWidgetItem *> list = ui.tableWidgetThrash->selectedItems(); - for (QList<QTableWidgetItem *>::const_iterator it = list.begin(); it != list.end(); ++it) { - taskID = (*it)->data(100).toUInt(); - if ((tit = itsTasks.find(taskID)) != itsTasks.end()) { - itsTasks.erase(tit); - tasksToDestroy.push_back(taskID); - } - } - updateThrashBin(); - emit destroyTasks(tasksToDestroy); -} - -void Thrashbin::reject(void) { - ui.tableWidgetThrash->clearSelection(); - hide(); -} diff --git a/SAS/Scheduler/src/thrashbin.h b/SAS/Scheduler/src/thrashbin.h deleted file mode 100644 index 72e8ff88003c29d2fcca1bba6435c390b7340f14..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/thrashbin.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * thrashbin.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : 18-March-2010 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/thrashbin.h $ - * - */ - -#ifndef THRASHBIN_H -#define THRASHBIN_H - -#include <QDialog> -#include "ui_thrashbin.h" -#include <map> -#include <vector> -#include "task.h" - -class Thrashbin : public QDialog -{ - Q_OBJECT - -public: - Thrashbin(QWidget *parent = 0); - ~Thrashbin(); - - void addTasks(const std::vector<Task *> &tasks); - void emptyThrashBin(void);// {itsTasks.clear();ui.tableWidgetThrash->clear();} - void removeRestoredTasks(const std::vector<unsigned> &tasks); - -private: - void setupThrashBin(void); - void updateThrashBin(void); - -private slots: - void deleteTasks(void); - void restoreTasks(void) const; - void reject(void); - void checkSelection(void); - void sortTable(int column); - -signals: - void restoreTasksRequest(const std::vector<unsigned> &tasks) const; - void thrashBinIsEmpty(void) const; - void thrashBinContainsItems(void) const; - void destroyTasks(std::vector<unsigned>) const; - -private: - Ui::ThrashbinClass ui; - std::map<unsigned, Task *> itsTasks; - int itsSortColumn; - Qt::SortOrder itsSortOrder; -}; - -#endif // THRASHBIN_H diff --git a/SAS/Scheduler/src/thrashbin.ui b/SAS/Scheduler/src/thrashbin.ui deleted file mode 100644 index 5913ec93c2d2b725dbe8850fedc10705fc8dfa07..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/thrashbin.ui +++ /dev/null @@ -1,148 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>ThrashbinClass</class> - <widget class="QDialog" name="ThrashbinClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>552</width> - <height>284</height> - </rect> - </property> - <property name="windowTitle"> - <string>Scheduler Thrash Bin</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="1"> - <widget class="QPushButton" name="pushButtonDelete"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Delete</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QPushButton" name="pushButtonClose"> - <property name="text"> - <string>Close</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QPushButton" name="pushButtonRestore"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Restore</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0" colspan="4"> - <widget class="QTableWidget" name="tableWidgetThrash"> - <property name="selectionMode"> - <enum>QAbstractItemView::MultiSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - </widget> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <tabstops> - <tabstop>tableWidgetThrash</tabstop> - <tabstop>pushButtonDelete</tabstop> - <tabstop>pushButtonRestore</tabstop> - <tabstop>pushButtonClose</tabstop> - </tabstops> - <resources/> - <connections> - <connection> - <sender>pushButtonClose</sender> - <signal>clicked()</signal> - <receiver>ThrashbinClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>575</x> - <y>372</y> - </hint> - <hint type="destinationlabel"> - <x>586</x> - <y>385</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonDelete</sender> - <signal>clicked()</signal> - <receiver>ThrashbinClass</receiver> - <slot>deleteTasks()</slot> - <hints> - <hint type="sourcelabel"> - <x>383</x> - <y>363</y> - </hint> - <hint type="destinationlabel"> - <x>363</x> - <y>363</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonRestore</sender> - <signal>clicked()</signal> - <receiver>ThrashbinClass</receiver> - <slot>restoreTasks()</slot> - <hints> - <hint type="sourcelabel"> - <x>492</x> - <y>368</y> - </hint> - <hint type="destinationlabel"> - <x>491</x> - <y>381</y> - </hint> - </hints> - </connection> - <connection> - <sender>tableWidgetThrash</sender> - <signal>itemSelectionChanged()</signal> - <receiver>ThrashbinClass</receiver> - <slot>checkSelection()</slot> - <hints> - <hint type="sourcelabel"> - <x>140</x> - <y>302</y> - </hint> - <hint type="destinationlabel"> - <x>124</x> - <y>366</y> - </hint> - </hints> - </connection> - </connections> - <slots> - <slot>deleteTasks()</slot> - <slot>restoreTasks()</slot> - <slot>checkSelection()</slot> - </slots> -</ui> diff --git a/SAS/Scheduler/src/tiedarraybeamdialog.cpp b/SAS/Scheduler/src/tiedarraybeamdialog.cpp deleted file mode 100644 index 70d2b068d333446171f3f3c80d110b5f8a0a09c3..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tiedarraybeamdialog.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "tiedarraybeamdialog.h" -#include "ComboBox.h" -#include "LineEdit.h" - -#define COHERENT 0 -#define INCOHERENT 1 - -TiedArrayBeamDialog::TiedArrayBeamDialog(QWidget *parent) - : QDialog(parent), itsParentTaskDialog(static_cast<TaskDialog *>(parent)), itsMultiEdit(false) -{ - ui.setupUi(this); - - // angle1 - itsLineEditAngle1 = new LineEdit(this); - itsLineEditAngle1->setObjectName(QString::fromUtf8("itsLineEditAngle1")); - ui.gridLayout->addWidget(itsLineEditAngle1, 1, 1, 1, 2); - // angle2 - itsLineEditAngle2 = new LineEdit(this); - itsLineEditAngle2->setObjectName(QString::fromUtf8("itsLineEditAngle2")); - ui.gridLayout->addWidget(itsLineEditAngle2, 2, 1, 1, 2); - // type - itsComboBoxType = new ComboBox(this); - itsComboBoxType->setObjectName(QString::fromUtf8("itsComboBoxType")); - QStringList items; - items << "coherent" << "incoherent"; - itsComboBoxType->addItems(items); - ui.gridLayout->addWidget(itsComboBoxType, 3, 1, 1, 2); - // dispersion measure - itsLineEditDispersionMeasure = new LineEdit(this); - itsLineEditDispersionMeasure->setObjectName(QString::fromUtf8("itsLineEditDispersionMeasure")); - ui.gridLayout->addWidget(itsLineEditDispersionMeasure, 4, 1, 1, 2); - - // multi TAB edit off by default - ui.labelNrOfBeams->hide(); - ui.spinBoxNrOfBeams->hide(); -} - -TiedArrayBeamDialog::~TiedArrayBeamDialog() -{ - -} - -void TiedArrayBeamDialog::reset(void) { - itsTABNrs.clear(); - ui.spinBoxNrOfBeams->setValue(1); - itsTiedArrayBeam = TiedArrayBeam(); - itsLineEditAngle1->setText("0.0"); - itsLineEditAngle2->setText("0.0"); - itsLineEditDispersionMeasure->setText("0.0"); - setReadOnly(false); -} - -bool TiedArrayBeamDialog::changesMade(void) { - itsTABchanges.angle1 = itsLineEditAngle1->hasBeenChanged(); - itsTABchanges.angle2 = itsLineEditAngle2->hasBeenChanged(); - itsTABchanges.dispersion_measure = itsLineEditDispersionMeasure->hasBeenChanged(); - itsTABchanges.coherent = itsComboBoxType->hasBeenChanged(); - return itsTABchanges.angle1 || itsTABchanges.angle2 || itsTABchanges.dispersion_measure || itsTABchanges.coherent; -} - -void TiedArrayBeamDialog::accept(void) { - if (itsAddMode) { - itsTiedArrayBeam.setAngle1(itsLineEditAngle1->text().toDouble()); - itsTiedArrayBeam.setAngle2(itsLineEditAngle2->text().toDouble()); - itsTiedArrayBeam.setDispersionMeasure(itsLineEditDispersionMeasure->text().toDouble()); - itsTiedArrayBeam.setCoherent(itsComboBoxType->currentIndex() == COHERENT); - itsParentTaskDialog->addNewTiedArrayBeams(ui.spinBoxNrOfBeams->value(), itsTiedArrayBeam); - } - else if (changesMade()) { - if (itsTABchanges.angle1) itsTiedArrayBeam.setAngle1(itsLineEditAngle1->text().toDouble()); - if (itsTABchanges.angle2) itsTiedArrayBeam.setAngle2(itsLineEditAngle2->text().toDouble()); - if (itsTABchanges.dispersion_measure) itsTiedArrayBeam.setDispersionMeasure(itsLineEditDispersionMeasure->text().toDouble()); - if (itsTABchanges.coherent) itsTiedArrayBeam.setCoherent(itsComboBoxType->currentIndex() == COHERENT); - itsParentTaskDialog->applyChangeToTiedArrayBeams(itsTABNrs, itsTiedArrayBeam, itsTABchanges); - } - QDialog::accept(); -} - - -void TiedArrayBeamDialog::setMultiEdit(bool multi_edit) { - itsMultiEdit = multi_edit; - if (itsMultiEdit) { - ui.spinBoxNrOfBeams->setValue(1); - ui.labelNrOfBeams->show(); - ui.spinBoxNrOfBeams->show(); - } - else { - ui.labelNrOfBeams->hide(); - ui.spinBoxNrOfBeams->hide(); - } -} - - -void TiedArrayBeamDialog::setReadOnly(bool read_only) { - itsLineEditAngle1->setReadOnly(read_only); - itsLineEditAngle2->setReadOnly(read_only); - itsLineEditDispersionMeasure->setReadOnly(read_only); - itsComboBoxType->setEnabled(!read_only); - if (read_only) { - ui.pushButtonOk->hide(); - ui.pushButtonCancel->setText("Close"); - } - else { - ui.pushButtonOk->show(); - ui.pushButtonCancel->setText("Cancel"); - } -} - - -void TiedArrayBeamDialog::loadTiedArrayBeam(const std::map<unsigned, TiedArrayBeam> &TABs) { - itsAddMode = false; - itsTiedArrayBeam = TABs.begin()->second; - if (TABs.size() > 1) { - this->setWindowTitle("Tied Array Beams (multi)"); - setMultiEdit(true); - } - else { - this->setWindowTitle(QString("Tied Array Beam ") + QString::number(TABs.begin()->first)); - } - - itsTABchanges.angle1 = false; - itsTABchanges.angle2 = false; - itsTABchanges.dispersion_measure = false; - itsTABchanges.coherent = false; - itsTABNrs.clear(); - if (TABs.size() > 1) { - for (std::map<unsigned, TiedArrayBeam>::const_iterator it = TABs.begin(); it != TABs.end(); ++it) { - itsTABNrs.push_back(it->first); - if (!itsTABchanges.angle1) { - if (itsTiedArrayBeam.angle1() != it->second.angle1()) { - itsTABchanges.angle1 = true; - itsLineEditAngle1->setUndefined(true); - } - } - if (!itsTABchanges.angle2) { - if (itsTiedArrayBeam.angle2() != it->second.angle2()) { - itsTABchanges.angle2 = true; - itsLineEditAngle2->setUndefined(true); - } - } - if (!itsTABchanges.dispersion_measure) { - if (itsTiedArrayBeam.dispersionMeasure() != it->second.dispersionMeasure()) { - itsTABchanges.dispersion_measure = true; - itsLineEditDispersionMeasure->setUndefined(true); - } - } - if (!itsTABchanges.coherent) { - if (itsTiedArrayBeam.isCoherent() != it->second.isCoherent()) { - itsTABchanges.coherent = true; - itsComboBoxType->setUndefined(true); - } - } - } - } - else { - itsTABNrs.push_back(TABs.begin()->first); - } - - if (!itsTABchanges.angle1) { - itsLineEditAngle1->setText(QString::number(itsTiedArrayBeam.angle1(),'g',16)); - } - if (!itsTABchanges.angle2) { - itsLineEditAngle2->setText(QString::number(itsTiedArrayBeam.angle2(),'g',16)); - } - if (!itsTABchanges.coherent) { - if (itsTiedArrayBeam.isCoherent()) { - itsComboBoxType->setCurrentIndex(COHERENT); - } - else { - itsComboBoxType->setCurrentIndex(INCOHERENT); - } - } - if (!itsTABchanges.dispersion_measure) { - itsLineEditDispersionMeasure->setText(QString::number(itsTiedArrayBeam.dispersionMeasure(),'g',16)); - } -} diff --git a/SAS/Scheduler/src/tiedarraybeamdialog.h b/SAS/Scheduler/src/tiedarraybeamdialog.h deleted file mode 100644 index 19bba5856d0f174f3075dfc9bbf67109978318af..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tiedarraybeamdialog.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * tiedarraybeamdialog.h - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : feb-2012 - * URL : $URL: https://svn.astron.nl/ROD/trunk/LOFAR_Scheduler/tiedarraybeamdialog.h $ - * - */ - -#ifndef TIEDARRAYBEAMDIALOG_H -#define TIEDARRAYBEAMDIALOG_H - -struct tabProps { - bool angle1, angle2, dispersion_measure, coherent; -}; - -#include <QDialog> -#include "ui_tiedarraybeamdialog.h" -#include "TiedArrayBeam.h" -#include "taskdialog.h" - -class ComboBox; -class LineEdit; - -class TiedArrayBeamDialog : public QDialog -{ - Q_OBJECT - -public: - TiedArrayBeamDialog(QWidget *parent = 0); - ~TiedArrayBeamDialog(); - - void reset(void); - void setAddMode(bool add_mode = true) {reset(); itsAddMode = add_mode;} - void setMultiEdit(bool multi_edit); - void setReadOnly(bool read_only = true); - void loadTiedArrayBeam(const std::map<unsigned, TiedArrayBeam> &TABs); - -private: - bool changesMade(void); - -private slots: - void accept(void); - -private: - Ui::TiedArrayBeamDialogClass ui; - - TaskDialog *itsParentTaskDialog; - ComboBox *itsComboBoxType; - LineEdit *itsLineEditAngle1, *itsLineEditAngle2, *itsLineEditDispersionMeasure; - std::vector<unsigned> itsTABNrs; - TiedArrayBeam itsTiedArrayBeam; - bool itsAddMode, itsMultiEdit; - tabProps itsTABchanges; -}; - -#endif // TIEDARRAYBEAMDIALOG_H diff --git a/SAS/Scheduler/src/tiedarraybeamdialog.ui b/SAS/Scheduler/src/tiedarraybeamdialog.ui deleted file mode 100644 index fb01b31c272bf9d7005e9e54c90d50186194fde0..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/src/tiedarraybeamdialog.ui +++ /dev/null @@ -1,119 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>TiedArrayBeamDialogClass</class> - <widget class="QDialog" name="TiedArrayBeamDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>296</width> - <height>205</height> - </rect> - </property> - <property name="windowTitle"> - <string>TiedArrayBeamDialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="0"> - <widget class="QLabel" name="labelAngle1"> - <property name="text"> - <string>Angle 1:</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="labelAngle2"> - <property name="text"> - <string>Angle 2:</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="labelType"> - <property name="text"> - <string>Type:</string> - </property> - </widget> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="labelDispersionMeasure"> - <property name="text"> - <string>Dispersion measure:</string> - </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="QPushButton" name="pushButtonCancel"> - <property name="maximumSize"> - <size> - <width>70</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item row="5" column="2"> - <widget class="QPushButton" name="pushButtonOk"> - <property name="maximumSize"> - <size> - <width>70</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>Ok</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="labelNrOfBeams"> - <property name="text"> - <string>Number of TABs:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="spinBoxNrOfBeams"/> - </item> - </layout> - </widget> - <layoutdefault spacing="6" margin="11"/> - <resources/> - <connections> - <connection> - <sender>pushButtonCancel</sender> - <signal>clicked()</signal> - <receiver>TiedArrayBeamDialogClass</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>155</x> - <y>190</y> - </hint> - <hint type="destinationlabel"> - <x>124</x> - <y>189</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButtonOk</sender> - <signal>clicked()</signal> - <receiver>TiedArrayBeamDialogClass</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>281</x> - <y>184</y> - </hint> - <hint type="destinationlabel"> - <x>292</x> - <y>165</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/SAS/Scheduler/test/CMakeLists.txt b/SAS/Scheduler/test/CMakeLists.txt deleted file mode 100644 index b609eb0c222e357362b826a9ee5703a5eff1d733..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# $Id$ - -include(LofarCTest) - -add_subdirectory(unittest) -add_subdirectory(integrationTests) \ No newline at end of file diff --git a/SAS/Scheduler/test/integrationTests/CMakeLists.txt b/SAS/Scheduler/test/integrationTests/CMakeLists.txt deleted file mode 100644 index 1766fd8bcf3dd14b0d9735d1c6b44a1d859b78d5..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/integrationTests/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -# $Id$ - -add_subdirectory(TestSASConnection) diff --git a/SAS/Scheduler/test/integrationTests/TestSASConnection/CMakeLists.txt b/SAS/Scheduler/test/integrationTests/TestSASConnection/CMakeLists.txt deleted file mode 100644 index 077d7f243816ea984b5d35c6a213bddc96e76002..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/integrationTests/TestSASConnection/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -# $Id$ - -include (LofarCTest) - -lofar_add_test(TestSASConnection main.cpp) diff --git a/SAS/Scheduler/test/integrationTests/TestSASConnection/TestSASConnection.run b/SAS/Scheduler/test/integrationTests/TestSASConnection/TestSASConnection.run deleted file mode 100755 index f66928db8a851b51b4a21eb3adb3b0409b0f2f0b..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/integrationTests/TestSASConnection/TestSASConnection.run +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# For reasons beyond my comprehesion 'trap' is not executed if I replace -# /bin/bash with /bin/sh; so I surrendered and used /bin/bash. -# -# $Id$ - -# Kill all background jobs we've created -trap 'for pid in $(jobs -p); do kill $pid; done' 0 1 2 3 15 - -# Fake a display if envvar DISPLAY is not set. -if [ -z "$DISPLAY" ] -then - Xvfb :99 -ac & - export DISPLAY=:99 - sleep 0.1 # Give Xvfb time to start -fi - -# Run the test -./TestSASConnection diff --git a/SAS/Scheduler/test/integrationTests/TestSASConnection/TestSASConnection.sh b/SAS/Scheduler/test/integrationTests/TestSASConnection/TestSASConnection.sh deleted file mode 100755 index 24d70a3e7b6db5264ccefd87d3222c7c019fc2eb..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/integrationTests/TestSASConnection/TestSASConnection.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -x -./runctest.sh TestSASConnection diff --git a/SAS/Scheduler/test/integrationTests/TestSASConnection/main.cpp b/SAS/Scheduler/test/integrationTests/TestSASConnection/main.cpp deleted file mode 100644 index 68dadf7c91fa9ad098c7012d0bac3cedfc8bdcb9..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/integrationTests/TestSASConnection/main.cpp +++ /dev/null @@ -1,79 +0,0 @@ - -/* - * main.cpp - * - * Author : Alwin de Jong - * e-mail : jong@astron.nl - * Revision : $Revision$ - * Last change by : $Author$ - * Change date : $Date$ - * First creation : Jan 29, 2009 - * URL : $URL: https://svn.astron.nl/ROD/branches/LOFAR_Scheduler-Task6767/main.cpp $ - * - */ - -#include "Scheduler/schedulerLib.h" - -#include <time.h> -#include <string> -#include <iostream> -#include <QtCore> - -// Example scheduler integration test. -// We start the scheduler in the main thread but also start a thread containing -// A number of actions to be performed by the scheduler. -// TODO: The majority of this source is boilerplate. -// refactor to remove duplicate code between tests. - -// The exercising of the scheduler should happen in a thread. The gui runs in -// the main thread. TODO: This is the cause of errors: The event loop -// might get corrupted. -class TestThread : public QThread -{ - // Very shallow wrapper around the run function -private: - // Todo, rename to test or forward to function test? - void run() - { - // TODO: We use fragile wait here, if we have signal back we could - // make the next step conditional - sleep(3); - -// // Step 1: Press download button -// signalForward("DownloadSASSchedule",""); -// sleep(5); - -// // Step 2: Press close button -// signalForward("DownloadSASScheduleClose",""); -// sleep(3); - -// // Assert that the sas connection worked...? -// // We need faulty state then - - // step 4: Press close application button - signalForward("MainWindowClose",""); - sleep(2); - // step 5: press no button, do not save - signalForward("PresNoInSaveDialog", ","); - - // Assertain correct correct closure of program. - } -}; - -int main(int argc, char *argv[]) -{ - // Test thread - TestThread test1; - test1.start(); - - // The actual scheduler main function - // TODO: Should we validate the exit state? - int exit_value = main_function(argc, argv); - - test1.quit(); - test1.wait(); // It takes about 3 seconds for the thread to be distructed - - return exit_value; -} - - diff --git a/SAS/Scheduler/test/unittest/CMakeLists.txt b/SAS/Scheduler/test/unittest/CMakeLists.txt deleted file mode 100644 index dcf9cee91e3d58b7597b2682d0c3c1615064144d..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# $Id$ - -add_subdirectory(testGui) -add_subdirectory(testqstring) diff --git a/SAS/Scheduler/test/unittest/testGui/CMakeLists.txt b/SAS/Scheduler/test/unittest/testGui/CMakeLists.txt deleted file mode 100644 index d86d831f216a0c3aec4fa3f048e015d3a9ac6ee1..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testGui/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# $Id$ - -include(LofarCTest) - -qt4_generate_moc(testgui.cpp testgui.moc) -lofar_add_test(testGui testgui.cpp testgui.moc) diff --git a/SAS/Scheduler/test/unittest/testGui/testGui.run b/SAS/Scheduler/test/unittest/testGui/testGui.run deleted file mode 100755 index a962004bbb6571b6dbac26b7c8d3c710755cf0a5..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testGui/testGui.run +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# For reasons beyond my comprehesion 'trap' is not executed if I replace -# /bin/bash with /bin/sh; so I surrendered and used /bin/bash. -# -# $Id$ - -# Kill all background jobs we've created -trap 'for pid in $(jobs -p); do kill $pid; done' 0 1 2 3 15 - -# Fake a display if envvar DISPLAY is not set. -if [ -z "$DISPLAY" ] -then - Xvfb :99 -ac & - export DISPLAY=:99 - sleep 0.1 # Give Xvfb time to start -fi - -# Run the test -./testGui diff --git a/SAS/Scheduler/test/unittest/testGui/testGui.sh b/SAS/Scheduler/test/unittest/testGui/testGui.sh deleted file mode 100755 index 3808b2e8f125af3f3dd556a7c9e7fe8fe0ff2fb1..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testGui/testGui.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -x -./runctest.sh testGui diff --git a/SAS/Scheduler/test/unittest/testGui/testgui.cpp b/SAS/Scheduler/test/unittest/testGui/testgui.cpp deleted file mode 100644 index 9404ab9274c88286c90f3c6bd4c31f71da4189b7..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testGui/testgui.cpp +++ /dev/null @@ -1,20 +0,0 @@ - #include <QtGui> - #include <QtTest/QtTest> - - class TestGui: public QObject - { - Q_OBJECT - private slots: - void testGui(); - }; - - void TestGui::testGui() - { - QLineEdit lineEdit; - QTest::keyClicks(&lineEdit, "hello world"); - QCOMPARE(lineEdit.text(), QString("hello world")); - } - - QTEST_MAIN(TestGui) - #include "testgui.moc" - diff --git a/SAS/Scheduler/test/unittest/testqstring/CMakeLists.txt b/SAS/Scheduler/test/unittest/testqstring/CMakeLists.txt deleted file mode 100644 index e8a777704bf37c806d11a924fd187b497a524918..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testqstring/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# $Id$ - -include(LofarCTest) - -qt4_generate_moc(testqstring.cpp testqstring.moc) -lofar_add_test(testqstring testqstring.cpp testqstring.moc) diff --git a/SAS/Scheduler/test/unittest/testqstring/testqstring.cpp b/SAS/Scheduler/test/unittest/testqstring/testqstring.cpp deleted file mode 100644 index 188cb49f6a1b27d4334cdb2d12eba911c036cff8..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testqstring/testqstring.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include <QtTest/QtTest> - -class TestQString: public QObject -{ - Q_OBJECT - private slots: - void toUpper(); -}; - -void TestQString::toUpper() -{ - QString str = "Hello"; - QCOMPARE(str.toUpper(), QString("HELLO")); -} - -QTEST_MAIN(TestQString) -#include "testqstring.moc" - diff --git a/SAS/Scheduler/test/unittest/testqstring/testqstring.run b/SAS/Scheduler/test/unittest/testqstring/testqstring.run deleted file mode 100755 index c3f28ba9cd0afce0fc51ba6db037ace749551f94..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testqstring/testqstring.run +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# -# For reasons beyond my comprehesion 'trap' is not executed if I replace -# /bin/bash with /bin/sh; so I surrendered and used /bin/bash. -# -# $Id$ - -# Kill all background jobs we've created -trap 'for pid in $(jobs -p); do kill $pid; done' 0 1 2 3 15 - -# Fake a display if envvar DISPLAY is not set. -if [ -z "$DISPLAY" ] -then - Xvfb :99 -ac & - export DISPLAY=:99 - sleep 0.1 # Give Xvfb time to start -fi - -# Run the test -./testqstring diff --git a/SAS/Scheduler/test/unittest/testqstring/testqstring.sh b/SAS/Scheduler/test/unittest/testqstring/testqstring.sh deleted file mode 100755 index b94eef55db64b4c469133233aa8608b413fbc319..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/testqstring/testqstring.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -x -./runctest.sh testqstring diff --git a/SAS/Scheduler/test/unittest/tojunit.xslt b/SAS/Scheduler/test/unittest/tojunit.xslt deleted file mode 100644 index cc9d172e4b2991d6c11238ee0fd0e5282d3f4fe2..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/tojunit.xslt +++ /dev/null @@ -1,86 +0,0 @@ - -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> - -<!-- To convert on sas001: --> -<!-- xsltproc -o joutput.xml tojunit.xslt output.xml --> - -<xsl:output method="xml" indent="yes" /> -<xsl:decimal-format decimal-separator="." grouping-separator="," /> - -<!-- misc variables --> -<xsl:variable name="classname" select="/TestCase/@name" /> -<xsl:variable name="total-tests" select="count(/TestCase/TestFunction)" /> -<xsl:variable name="total-failures" select="count(/TestCase/TestFunction/Incident[@type='fail'])" /> - -<!-- main template call --> -<xsl:template match="/"> - <xsl:apply-templates select="TestCase"/> -</xsl:template> - -<xsl:template match="TestCase"> - <testsuite name="{$classname}" tests="{$total-tests}" failures="{$total-failures}" errors="0" time="0.0"> - <xsl:apply-templates select="Environment"/> - <xsl:apply-templates select="TestFunction" /> - <xsl:call-template name="display-system-out" /> - <xsl:call-template name="display-system-err" /> - </testsuite> -</xsl:template> - -<xsl:template match="Environment"> - <properties> - <xsl:for-each select="*"> - <property name="{name()}" value="{text()}" /> - </xsl:for-each> - </properties> -</xsl:template> - -<xsl:template match="TestFunction"> - <testcase classname="{$classname}" name="{@name}" time="0.0"> - <!-- handle fail --> - <xsl:if test="Incident/@type = 'fail'"> - <!-- will be used to generate "nice" error message --> - <xsl:variable name="file" select="Incident/@file" /> - <xsl:variable name="line" select="Incident/@line" /> - <xsl:variable name="description"> - <xsl:value-of select="Incident/Description" /> - </xsl:variable> - - <!-- display a reasonable error message --> - <xsl:element name="failure"> - <xsl:attribute name="type">Standard</xsl:attribute> - <xsl:attribute name="message"> - <xsl:value-of select="concat($file,':',$line,' :: ',$description)" /> - </xsl:attribute> - </xsl:element> - - </xsl:if> - - <!-- handle skip --> - <xsl:if test="Incident/@type = 'skip'"> - - </xsl:if> - </testcase> -</xsl:template> - -<xsl:template name="display-system-out"> - <system-out> - <xsl:for-each select="/TestCase/TestFunction/Incident[@type='fail'] | /TestCase/TestFunction/Message[@type='skip']"> - <xsl:choose> - <xsl:when test="@type='fail'"> - <xsl:value-of select="Description"/> - </xsl:when> - <xsl:when test="@type='skip'"> - <xsl:value-of select="Description"/> - </xsl:when> - </xsl:choose> - </xsl:for-each> - </system-out> -</xsl:template> - -<xsl:template name="display-system-err"> - <!-- do nothing for now --> - <system-err /> -</xsl:template> - - -</xsl:stylesheet> diff --git a/SAS/Scheduler/test/unittest/unittest_runner.py b/SAS/Scheduler/test/unittest/unittest_runner.py deleted file mode 100644 index f837c5ad07768c8ba1cb6094f64226fd1ef7b3c6..0000000000000000000000000000000000000000 --- a/SAS/Scheduler/test/unittest/unittest_runner.py +++ /dev/null @@ -1,176 +0,0 @@ -import os -import unittest -import getopt -import string -import inspect -import sys -import re -import subprocess -import shutil - -def discover(path, pattern): - """ - Discover class collects all unit test executable in <path> and recursive directories - Collects them in a single large string list - Start at supplied <path> an add all tests in files matching the supplied expression and - all individual tests matching the expression - """ - - failed_build = False - # match with all (used for a filename matches with expression: all individual test must be loaded - allMatcher = re.compile(".*") - # matcher for the expression - patternMatcher = re.compile(pattern) - # matcher for hidden dirs - hiddenMatcher = re.compile(".*/\..*") - - found_tests = [] - for root, dirs, files in os.walk(path): - # skip hidden directories - if hiddenMatcher.match(root): - continue - - for file_name in files: - - # find all pro files - parts = file_name.split(".") - if not (len(parts) == 2 and parts[1] == "pro"): - continue - - name = parts[0] - # the expression mechanism - testMatcher = None - if patternMatcher.match(name): - testMatcher = allMatcher # if current dir matches with expression include all tests - else: - testMatcher = patternMatcher - - # add all cases ending with test and match the regexp search string - if name.lower().endswith('test') or name.lower().startswith('test'): - if not testMatcher.match(name): # Continue of current testname does not match supplied expression - continue - - # Now we know that we want to build current pro file - full_file_path = os.path.join(root, file_name) - - print("*"*30) - print(root) - if os.system("cd %s; qmake %s" % (root, file_name)) != 0: - print("failed build detected!: qmake") - failed_build = True - - if os.system("cd %s; make clean" % (root)) != 0: - print("failed build detected!: make clean") - failed_build = True - - if os.system("cd %s; make" % (root)) != 0: - print("failed build detected!: make") - failed_build = True - - full_exec_path = full_file_path = os.path.join(root, parts[0]) - - # assert that the current file is executable - if not (os.path.isfile(full_file_path) and os.access(full_file_path, os.X_OK)): - continue - # else append the test program to be executed - found_tests.append(full_file_path) - - return failed_build, found_tests - -def usage(): - """ - Display a short overview of available arguments - """ - usage = r""" - Recursively look in path for executables and runs them as qt unittests. - Collect all results, convert to Junit xml and combine in a single large xml: - <path>/collected.xml - Returns 0 on all ok: returns #failures else - Collect in a single suite and run them - Usage: - python3 unittest_runner.py <path> <matchword> - <path> to start looking. - <matchword> matchword match with found classes to perform a subset of tests (shorthand for .*arg.* expression) - default is match all - """ - print(usage) - -def run_unit_tests(list_of_paths): - """ - Run all the unittest provided as an system call. - convert the produced qtxml to jxml and return if there were failed runs - and the xml files - """ - failed_run = False - jxml_files = [] - for path in list_of_paths: - - # run the executable write results to xml - command = "%s -xml -o %s.qtxml" - formatted_command = command % (path, path) - return_value = os.system(formatted_command) - if return_value != 0: - failed_run = True - print("failed unit test detected!!") - fp = open("%s.qtxml" % path) - print(fp.read()) - - # convert to jxml - os.system("xsltproc -o %s.xml %s/tojunit.xslt %s.qtxml " % ( - path, os.path.dirname(os.path.abspath(__file__)), path)) - - jxml_files.append("%s.xml" % path) - - return failed_run, jxml_files - -def bundle_jxml(jxml_files): - """ - collect all xml files in the dir results.xml - """ - target_dir = "%s/results.xml" % os.path.dirname(os.path.abspath(__file__)) - if not os.path.isdir(target_dir): - os.mkdir(target_dir) - - for path in jxml_files: - target_path = os.path.join(target_dir, os.path.basename(path)) - try: - shutil.copyfile(path, target_path) - except Exception as e: - print(str(e)) - -if __name__ == "__main__": - - path = None - expression = None - # Default parameters settings: (sas001 has very old python version: no arg parser...) - if len(sys.argv) == 1: - usage() - sys.exit(2) - if len(sys.argv) == 2: - path = sys.argv[1] - expression = ".*" # match all - if len(sys.argv) == 3: - path = sys.argv[1] - expression = sys.argv[2] - - # os.path.dirname(os.path.abspath(__file__)) - path = sys.argv[1] - failed_builds, found_tests = discover(path, expression) - - # skip if we cannot find any test matchin expression - if len(found_tests) == 0: - "no test matching the expression %s were found" % expression - sys.exit(0) - - exit_value, jxml_files = run_unit_tests(found_tests) - - bundle_jxml(jxml_files) - - if failed_builds: - print("ran all succesfull build unittests. BUT build error were found") - print("exiting error exit state: ") - sys.exit(1) - - print("exiting the unittest runner with exit state: %i " % exit_value) - sys.exit(exit_value) -