#include "BaseInteractive.h" #include "IndependentAlg.h" #include BaseInteractive::BaseInteractive() { } BaseInteractive::~BaseInteractive() { } void BaseInteractive::AddCtrlPoint(int x) { if(x < baseCtrl.rg_low || x > baseCtrl.rg_high) { qDebug() << "Can't insert Control Point out of range"; return; } int i = 0; for(; i= x) { if(baseCtrl.XCtrl[i] == x) { qDebug() << QString("The new control point in channel %1 exists, won't introduce twice"); return; } break; } } // add cursor channel to control points and sort baseCtrl.XCtrl.insert(baseCtrl.XCtrl.begin() + i, x); baseCtrl.YCtrl.insert(baseCtrl.XCtrl.begin() + i, baseCtrl.Baseline[x-1]); baseCtrl.YSlope.insert(baseCtrl.XCtrl.begin() + i, gNaN); // write new baseline to stack PushStack(baseCtrl.XCtrl, baseCtrl.YCtrl, baseCtrl.YSlope); } void BaseInteractive::RemoveCtrlPoint(double x) { if(baseCtrl.XCtrl.empty()) { qDebug() << "No control points to be deleted"; return; } // find nearest control-point int i = 1; if(x < baseCtrl.XCtrl[0]) i = 0; else { for(; i= x) { if(baseCtrl.XCtrl[i] - x > x - baseCtrl.XCtrl[i-1]) --i; break; } } } // select first of (possibly 2) nearest channels if (i == 0 || i >= baseCtrl.XCtrl.size()-1) { qDebug() << "can't remove first/last control point"; return; } // remove this control point and update baseCtrl.XCtrl.erase(baseCtrl.XCtrl.begin() + i); baseCtrl.YCtrl.erase(baseCtrl.YCtrl.begin() + i); baseCtrl.YSlope.erase(baseCtrl.YSlope.begin() + i); // write new baseline to stack PushStack(baseCtrl.XCtrl, baseCtrl.YCtrl, baseCtrl.YSlope); } void BaseInteractive::ModifyCtrlPoint(int x, double y) { // disable all baseline buttons // remember windowbuttondownfcn and cursor // set windowbuttondownfcn to baseModify and cursor to grabbing hand // wait for return // if baseModify changed baseline, push it to stack int i = 0; for(; i= baseCtrl.XCtrl.size()) return; baseCtrl.YCtrl[i] = y; PushStack(baseCtrl.XCtrl, baseCtrl.YCtrl, baseCtrl.YSlope); // revert windowbuttondownfcn and cursor // enable baseline buttons } void BaseInteractive::EditSlope(double x, double dy) { if(baseCtrl.XCtrl.empty()) { qDebug() << "No control points to be edited"; return; } // find nearest control-point int i = 1; int n = baseCtrl.XCtrl.size(); if(x < baseCtrl.XCtrl[0]) i = 0; else { for(; i= x) { if(baseCtrl.XCtrl[i] - x > x - baseCtrl.XCtrl[i-1]) --i; break; } } if(i == n) i = n-1; } // select first of (possibly 2) nearest channels //rowvec tmp; //idx = idx(1); //tmp << baseCtrl.XCtrl[i]; //stdvec eCp = Independ::calValues(Cal_Energy, tmp, p); bool allowNaN; if(i == 0 || i == n-1) { allowNaN = false; } else { allowNaN = true; } if ( allowNaN || qIsFinite(dy) ) { baseCtrl.YSlope[i] = dy; // write new baseline to stack PushStack(baseCtrl.XCtrl, baseCtrl.YCtrl, baseCtrl.YSlope); } else { QMessageBox::warning(0, "Warning", "Input value invalid."); } } void BaseInteractive::PushStack(stdvec cx, stdvec cy, stdvec cdy, bool modified) { BaseCtrlStack stack; stack.cx = cx; stack.cy = cy; stack.cdy = cdy; baseCtrl.BaseStack.push_back(stack); baseCtrl.ReplotNeeded = modified; //UpdateBaseControl(baseCtrl, m_para); }