Verified Commit 57dfb500 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

automatically calculating paths

parent 6441f977
......@@ -227,4 +227,12 @@
</instrument>
</instrument_space>
<configuration>
<path>
<target_2thM>90</target_2thM>
<target_2thS>90</target_2thS>
</path>
</configuration>
</paths>
......@@ -47,7 +47,7 @@ if [ $create_appdir -ne 0 ]; then
mkdir -p ${APPDIRNAME}/DEBIAN
# debian package control file
echo -e "Package: ${APPNAME}\nVersion: 1.3.2" > ${APPDIRNAME}/DEBIAN/control
echo -e "Package: ${APPNAME}\nVersion: 1.3.3" > ${APPDIRNAME}/DEBIAN/control
echo -e "Architecture: $(dpkg --print-architecture)" >> ${APPDIRNAME}/DEBIAN/control
echo -e "Section: base\nPriority: optional" >> ${APPDIRNAME}/DEBIAN/control
echo -e "Description: TAS pathfinding software" >> ${APPDIRNAME}/DEBIAN/control
......
......@@ -15,8 +15,8 @@
<key>CFBundleDisplayName</key> <string>TAS-Paths</string>
<key>CFBundleIdentifier</key> <string>eu.ill.cs.takin.taspaths</string>
<key>CFBundleExecutable</key> <string>taspaths</string>
<key>CFBundleVersion</key> <string>1.3.2</string>
<key>CFBundleShortVersionString</key> <string>1.3.2</string>
<key>CFBundleVersion</key> <string>1.3.3</string>
<key>CFBundleShortVersionString</key> <string>1.3.3</string>
<key>CFBundleIconFile</key> <string>taspaths.icns</string>
<key>NSPrincipalClass</key> <string>NSApplication</string>
......
......@@ -34,7 +34,7 @@
#define TASPATHS_TITLE "TAS-Paths"
// version number of this software
#define TASPATHS_VERSION "1.3.2"
#define TASPATHS_VERSION "1.3.3"
/**
......
......@@ -449,12 +449,16 @@ bool PathsTool::OpenFile(const QString& file)
SetInstrumentStatus(Qrlu, E,
in_angular_limits, colliding);
// if the analyser or monochromator angle changes, the mesh also needs to be updated
if(kf_fixed && !tl2::equals<t_real>(oldA6, anaScAngle, g_eps))
// if the analyser or monochromator angle changes, the mesh also needs to be updated.
// need to use gui epsilon here, because oldA6 and oldA2 come from double spin boxes with that precision
if(kf_fixed && !tl2::equals<t_real>(oldA6, anaScAngle, g_eps_gui))
ValidatePathMesh(false);
if(!kf_fixed && !tl2::equals<t_real>(oldA2, monoScAngle, g_eps))
if(!kf_fixed && !tl2::equals<t_real>(oldA2, monoScAngle, g_eps_gui))
ValidatePathMesh(false);
if(m_autocalcpath)
CalculatePath();
if(this->m_dlgConfigSpace)
{
this->m_dlgConfigSpace->UpdateInstrument(
......@@ -683,6 +687,9 @@ void PathsTool::GotoCoordinates(
angles.anaXtalAngle);
m_tascalc.SetKfix(kf);
//if(m_autocalcpath)
// CalculatePath();
}
}
......@@ -763,6 +770,9 @@ void PathsTool::GotoAngles(std::optional<t_real> a1,
instr.GetAnalyser().SetAxisAngleOut(t_real{2} * *a5);
instr.GetAnalyser().SetAxisAngleInternal(*a5);
}
//if(m_autocalcpath)
// CalculatePath();
}
}
......@@ -1241,6 +1251,11 @@ PathsTool::PathsTool(QWidget* pParent) : QMainWindow{pParent}
{
this->m_dlgConfigSpace->UpdateTarget(a2, a4, sensesCCW);
}
else
{
if(m_autocalcpath)
CalculatePath();
}
});
......@@ -2204,7 +2219,7 @@ void PathsTool::ExternalPathAvailable(const InstrumentPath& path)
/**
* calculate the mesh of possible paths
*/
void PathsTool::CalculatePathMesh()
bool PathsTool::CalculatePathMesh()
{
m_stop_requested = false;
m_pathsbuilder.StartPathMeshWorkflow();
......@@ -2213,7 +2228,7 @@ void PathsTool::CalculatePathMesh()
ValidatePathMesh(false);
// start calculation in a background thread
m_futCalc = std::async(std::launch::async, [this]()
m_futCalc = std::async(std::launch::async, [this]() -> bool
{
// check if a stop has been requested
#define CHECK_STOP \
......@@ -2221,7 +2236,7 @@ void PathsTool::CalculatePathMesh()
{ \
SetTmpStatus("Calculation aborted."); \
m_pathsbuilder.FinishPathMeshWorkflow(false); \
return; \
return false; \
}
const Instrument& instr = m_instrspace.GetInstrument();
......@@ -2251,7 +2266,7 @@ void PathsTool::CalculatePathMesh()
{
m_pathsbuilder.FinishPathMeshWorkflow(false);
SetTmpStatus("Error: Configuration space calculation failed.");
return;
return false;
}
CHECK_STOP
......@@ -2261,7 +2276,7 @@ void PathsTool::CalculatePathMesh()
{
m_pathsbuilder.FinishPathMeshWorkflow(false);
SetTmpStatus("Error: Wall positions index tree calculation failed.");
return;
return false;
}
CHECK_STOP
......@@ -2271,7 +2286,7 @@ void PathsTool::CalculatePathMesh()
{
m_pathsbuilder.FinishPathMeshWorkflow(false);
SetTmpStatus("Error: Obstacle contour lines calculation failed.");
return;
return false;
}
CHECK_STOP
......@@ -2281,7 +2296,7 @@ void PathsTool::CalculatePathMesh()
{
m_pathsbuilder.FinishPathMeshWorkflow(false);
SetTmpStatus("Error: Line segment calculation failed.");
return;
return false;
}
CHECK_STOP
......@@ -2297,7 +2312,7 @@ void PathsTool::CalculatePathMesh()
{
m_pathsbuilder.FinishPathMeshWorkflow(false);
SetTmpStatus("Error: Voronoi regions calculation failed.");
return;
return false;
}
CHECK_STOP
......@@ -2307,21 +2322,32 @@ void PathsTool::CalculatePathMesh()
m_pathsbuilder.FinishPathMeshWorkflow(true);
SetTmpStatus("Path mesh calculated.");
// also directly calculate a path if possible
bool ok = true;
if(m_autocalcpath)
ok = CalculatePath();
return ok;
});
// block till the calculations are finished
//m_futCalc.get();
bool ok = true;
//ok = m_futCalc.get();
return ok;
}
/**
* calculate the path from the current to the target position
*/
void PathsTool::CalculatePath()
bool PathsTool::CalculatePath()
{
m_stop_requested = false;
m_pathvertices.clear();
if(!m_pathmeshvalid)
return false;
// get the scattering angles
const Instrument& instr = m_instrspace.GetInstrument();
t_real curMonoScatteringAngle = instr.GetMonochromator().GetAxisAngleOut();
......@@ -2355,9 +2381,9 @@ void PathsTool::CalculatePath()
if(!path.ok)
{
QMessageBox::critical(this, "Error", "No path could be found.");
//QMessageBox::critical(this, "Error", "No path could be found.");
SetTmpStatus("Error: No path could be found.");
return;
return false;
}
// get the vertices on the path
......@@ -2365,9 +2391,9 @@ void PathsTool::CalculatePath()
m_pathvertices = m_pathsbuilder.GetPathVertices(path, true, false);
if(!m_pathvertices.size())
{
QMessageBox::critical(this, "Error", "No valid path could be found.");
//QMessageBox::critical(this, "Error", "No valid path could be found.");
SetTmpStatus("Error: No valid path could be found.");
return;
return false;
}
emit PathAvailable(m_pathvertices.size());
......@@ -2387,6 +2413,7 @@ void PathsTool::CalculatePath()
ostrMsg << ".";
SetTmpStatus(ostrMsg.str());
return true;
}
......@@ -2396,10 +2423,12 @@ void PathsTool::CalculatePath()
void PathsTool::TrackPath(std::size_t idx)
{
// block path recalculation during tracking
m_autocalcpath = false;
if(m_dlgConfigSpace)
m_dlgConfigSpace->SetBlockCalc(true);
BOOST_SCOPE_EXIT(&m_dlgConfigSpace)
BOOST_SCOPE_EXIT(&m_autocalcpath, &m_dlgConfigSpace)
{
m_autocalcpath = true;
if(m_dlgConfigSpace)
m_dlgConfigSpace->SetBlockCalc(false);
} BOOST_SCOPE_EXIT_END
......
......@@ -88,7 +88,7 @@ private:
QLabel *m_labelCollisionStatus{ nullptr };
bool m_stop_requested{ false };
std::future<void> m_futCalc{};
std::future<bool> m_futCalc{};
QMenu *m_menuOpenRecent{ nullptr };
QMenuBar *m_menubar{ nullptr };
......@@ -130,6 +130,7 @@ private:
InstrumentSpace m_instrspace{};
PathsBuilder m_pathsbuilder{};
bool m_pathmeshvalid{false};
bool m_autocalcpath{true};
// calculated path vertices
std::vector<t_vec2> m_pathvertices{};
......@@ -231,8 +232,8 @@ protected slots:
void ExternalPathAvailable(const InstrumentPath& path);
// calculation of the meshes and paths
void CalculatePathMesh();
void CalculatePath();
bool CalculatePathMesh();
bool CalculatePath();
// called after the plotter has initialised
void AfterGLInitialisation();
......
......@@ -66,25 +66,30 @@ PathPropertiesWidget::PathPropertiesWidget(QWidget *parent)
for(std::size_t i=1; i<m_num_coord_elems; ++i)
QWidget::setTabOrder(m_spinFinish[i-1], m_spinFinish[i]);
// default values
m_spinFinish[0]->setValue(90.);
m_spinFinish[1]->setValue(90.);
QPushButton *btnGotoFinish = new QPushButton("Jump to Target Angles", this);
m_btnCalcMesh = new QPushButton(CALC_MESH_TITLE, this);
m_btnCalcPath = new QPushButton(CALC_PATH_TITLE, this);
btnGotoFinish->setToolTip("Set the current instrument position to the given target angles.");
m_btnCalcMesh->setToolTip("Calculate the mesh of possible paths used for pathfinding.");
m_btnCalcPath->setToolTip("Calculate the actual path from the current to the target instrument position.");
//m_btnCalcMesh->setShortcut(Qt::ALT | Qt::Key_M);
//m_btnCalcPath = new QPushButton(CALC_PATH_TITLE, this);
//m_btnCalcPath->setToolTip("Calculate the actual path from the current to the target instrument position.");
//m_btnCalcPath->setShortcut(Qt::ALT | Qt::Key_P);
QPushButton *btnGotoFinish = new QPushButton("Jump to Target Angles", this);
btnGotoFinish->setToolTip("Set the current instrument position to the given target angles.");
m_sliderPath = new QSlider(Qt::Horizontal, this);
m_sliderPath->setToolTip("Path tracking.");
m_btnGo = new QToolButton(this);
SetGoButtonText(true);
m_btnGo->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
// TODO: change the label "monochromator" to "analyser" for ki=const mode
const char* labels[] = {"Mono./Ana.:", "Sample:"};
......@@ -113,8 +118,8 @@ PathPropertiesWidget::PathPropertiesWidget(QWidget *parent)
layoutPath->setContentsMargins(4,4,4,4);
int y = 0;
layoutPath->addWidget(m_btnCalcMesh, y++, 0, 1, 3);
layoutPath->addWidget(m_btnCalcPath, y, 0, 1, 2);
layoutPath->addWidget(m_btnCalcMesh, y, 0, 1, 2);
//layoutPath->addWidget(m_btnCalcPath, y, 0, 1, 2);
layoutPath->addWidget(m_btnGo, y++, 2, 2, 1);
layoutPath->addWidget(m_sliderPath, y, 0, 1, 2);
}
......@@ -162,10 +167,10 @@ PathPropertiesWidget::PathPropertiesWidget(QWidget *parent)
});
// calculate path
connect(m_btnCalcPath, &QPushButton::clicked, [this]()
/*connect(m_btnCalcPath, &QPushButton::clicked, [this]()
{
emit CalculatePath();
});
});*/
// path tracking slider value has changed
connect(m_sliderPath, &QSlider::valueChanged, [this](int value)
......@@ -216,7 +221,7 @@ void PathPropertiesWidget::SetGoButtonText(bool start)
else
m_btnGo->setText("");
m_btnGo->setToolTip("Start path tracking.");
m_btnGo->setToolTip("Start path tracking from current to target instrument position.");
}
else
{
......@@ -328,14 +333,15 @@ void PathPropertiesWidget::PathAvailable(std::size_t numVertices)
{
m_btnGo->setEnabled(false);
m_sliderPath->setEnabled(false);
return;
}
m_btnGo->setEnabled(true);
m_sliderPath->setEnabled(true);
m_sliderPath->setMinimum(0);
m_sliderPath->setMaximum(numVertices-1);
m_sliderPath->setValue(0);
else
{
m_btnGo->setEnabled(true);
m_sliderPath->setEnabled(true);
m_sliderPath->setMinimum(0);
m_sliderPath->setMaximum(numVertices-1);
m_sliderPath->setValue(0);
}
}
......@@ -344,7 +350,7 @@ void PathPropertiesWidget::PathAvailable(std::size_t numVertices)
*/
void PathPropertiesWidget::PathMeshValid(bool valid)
{
m_btnCalcPath->setEnabled(valid);
//m_btnCalcPath->setEnabled(valid);
if(!valid)
PathAvailable(0);
......
......@@ -65,7 +65,7 @@ private:
QDoubleSpinBox *m_spinFinish[m_num_coord_elems]{nullptr, nullptr};
QSlider *m_sliderPath = nullptr;
QPushButton *m_btnCalcMesh = nullptr;
QPushButton *m_btnCalcPath = nullptr;
//QPushButton *m_btnCalcPath = nullptr;
QToolButton *m_btnGo = nullptr;
QTimer m_pathTrackTimer{};
......
......@@ -211,6 +211,7 @@ int main(int argc, char** argv)
qRegisterMetaType<t_vec>("t_vec");
qRegisterMetaType<t_mat>("t_mat");
qRegisterMetaType<std::string>("std::string");
qRegisterMetaType<std::size_t>("std::size_t");
qRegisterMetaType<CalculationState>("CalculationState");
// create main window
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment