2020-12-26 14:31:24 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/networktables/NTField2D.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
#include <vector>
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <fmt/format.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <ntcore_cpp.h>
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
#include <wpi/Endian.h>
|
|
|
|
|
#include <wpi/MathExtras.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
#include <wpi/SmallVector.h>
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <wpi/StringExtras.h>
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
using namespace glass;
|
|
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
class NTField2DModel::ObjectModel : public FieldObjectModel {
|
2020-09-12 10:55:46 -07:00
|
|
|
public:
|
2021-06-06 16:13:58 -07:00
|
|
|
ObjectModel(std::string_view name, NT_Entry entry)
|
2020-09-12 10:55:46 -07:00
|
|
|
: m_name{name}, m_entry{entry} {}
|
|
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
const char* GetName() const override { return m_name.c_str(); }
|
2020-09-12 10:55:46 -07:00
|
|
|
NT_Entry GetEntry() const { return m_entry; }
|
|
|
|
|
|
|
|
|
|
void NTUpdate(const nt::Value& value);
|
|
|
|
|
|
|
|
|
|
void Update() override {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (auto value = nt::GetEntryValue(m_entry)) {
|
|
|
|
|
NTUpdate(*value);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
bool Exists() override { return nt::GetEntryType(m_entry) != NT_UNASSIGNED; }
|
|
|
|
|
bool IsReadOnly() override { return false; }
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<const frc::Pose2d> GetPoses() override { return m_poses; }
|
|
|
|
|
void SetPoses(wpi::span<const frc::Pose2d> poses) override;
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void SetPose(size_t i, frc::Pose2d pose) override;
|
|
|
|
|
void SetPosition(size_t i, frc::Translation2d pos) override;
|
|
|
|
|
void SetRotation(size_t i, frc::Rotation2d rot) override;
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
private:
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void UpdateNT();
|
2020-09-12 10:55:46 -07:00
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
std::string m_name;
|
2020-09-12 10:55:46 -07:00
|
|
|
NT_Entry m_entry;
|
|
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
std::vector<frc::Pose2d> m_poses;
|
2020-09-12 10:55:46 -07:00
|
|
|
};
|
|
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void NTField2DModel::ObjectModel::NTUpdate(const nt::Value& value) {
|
|
|
|
|
if (value.IsDoubleArray()) {
|
|
|
|
|
auto arr = value.GetDoubleArray();
|
|
|
|
|
auto size = arr.size();
|
|
|
|
|
if ((size % 3) != 0) {
|
|
|
|
|
return;
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
m_poses.resize(size / 3);
|
|
|
|
|
for (size_t i = 0; i < size / 3; ++i) {
|
|
|
|
|
m_poses[i] = frc::Pose2d{
|
|
|
|
|
units::meter_t{arr[i * 3 + 0]}, units::meter_t{arr[i * 3 + 1]},
|
|
|
|
|
frc::Rotation2d{units::degree_t{arr[i * 3 + 2]}}};
|
|
|
|
|
}
|
|
|
|
|
} else if (value.IsRaw()) {
|
|
|
|
|
// treat it simply as an array of doubles
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view data = value.GetRaw();
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
|
|
|
|
|
// must be triples of doubles
|
|
|
|
|
auto size = data.size();
|
|
|
|
|
if ((size % (3 * 8)) != 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_poses.resize(size / (3 * 8));
|
2021-06-06 16:13:58 -07:00
|
|
|
const char* p = data.data();
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
for (size_t i = 0; i < size / (3 * 8); ++i) {
|
|
|
|
|
double x = wpi::BitsToDouble(
|
|
|
|
|
wpi::support::endian::readNext<uint64_t, wpi::support::big,
|
|
|
|
|
wpi::support::unaligned>(p));
|
|
|
|
|
double y = wpi::BitsToDouble(
|
|
|
|
|
wpi::support::endian::readNext<uint64_t, wpi::support::big,
|
|
|
|
|
wpi::support::unaligned>(p));
|
|
|
|
|
double rot = wpi::BitsToDouble(
|
|
|
|
|
wpi::support::endian::readNext<uint64_t, wpi::support::big,
|
|
|
|
|
wpi::support::unaligned>(p));
|
|
|
|
|
m_poses[i] = frc::Pose2d{units::meter_t{x}, units::meter_t{y},
|
|
|
|
|
frc::Rotation2d{units::degree_t{rot}}};
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void NTField2DModel::ObjectModel::UpdateNT() {
|
|
|
|
|
if (m_poses.size() < (255 / 3)) {
|
|
|
|
|
wpi::SmallVector<double, 9> arr;
|
|
|
|
|
for (auto&& pose : m_poses) {
|
|
|
|
|
auto& translation = pose.Translation();
|
2021-10-25 08:58:12 -07:00
|
|
|
arr.push_back(translation.X().value());
|
|
|
|
|
arr.push_back(translation.Y().value());
|
|
|
|
|
arr.push_back(pose.Rotation().Degrees().value());
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
}
|
|
|
|
|
nt::SetEntryTypeValue(m_entry, nt::Value::MakeDoubleArray(arr));
|
|
|
|
|
} else {
|
|
|
|
|
// send as raw array of doubles if too big for NT array
|
|
|
|
|
std::vector<char> arr;
|
|
|
|
|
arr.resize(m_poses.size() * 3 * 8);
|
|
|
|
|
char* p = arr.data();
|
|
|
|
|
for (auto&& pose : m_poses) {
|
|
|
|
|
auto& translation = pose.Translation();
|
|
|
|
|
wpi::support::endian::write64be(
|
2021-10-25 08:58:12 -07:00
|
|
|
p, wpi::DoubleToBits(translation.X().value()));
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
p += 8;
|
|
|
|
|
wpi::support::endian::write64be(
|
2021-10-25 08:58:12 -07:00
|
|
|
p, wpi::DoubleToBits(translation.Y().value()));
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
p += 8;
|
|
|
|
|
wpi::support::endian::write64be(
|
2021-10-25 08:58:12 -07:00
|
|
|
p, wpi::DoubleToBits(pose.Rotation().Degrees().value()));
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
p += 8;
|
|
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
nt::SetEntryTypeValue(m_entry,
|
|
|
|
|
nt::Value::MakeRaw({arr.data(), arr.size()}));
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
void NTField2DModel::ObjectModel::SetPoses(wpi::span<const frc::Pose2d> poses) {
|
|
|
|
|
m_poses.assign(poses.begin(), poses.end());
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
UpdateNT();
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void NTField2DModel::ObjectModel::SetPose(size_t i, frc::Pose2d pose) {
|
|
|
|
|
if (i < m_poses.size()) {
|
|
|
|
|
m_poses[i] = pose;
|
|
|
|
|
UpdateNT();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void NTField2DModel::ObjectModel::SetPosition(size_t i,
|
|
|
|
|
frc::Translation2d pos) {
|
|
|
|
|
if (i < m_poses.size()) {
|
|
|
|
|
m_poses[i] = frc::Pose2d{pos, m_poses[i].Rotation()};
|
|
|
|
|
UpdateNT();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
void NTField2DModel::ObjectModel::SetRotation(size_t i, frc::Rotation2d rot) {
|
|
|
|
|
if (i < m_poses.size()) {
|
|
|
|
|
m_poses[i] = frc::Pose2d{m_poses[i].Translation(), rot};
|
|
|
|
|
UpdateNT();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
NTField2DModel::NTField2DModel(std::string_view path)
|
2020-09-12 10:55:46 -07:00
|
|
|
: NTField2DModel{nt::GetDefaultInstance(), path} {}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
NTField2DModel::NTField2DModel(NT_Inst inst, std::string_view path)
|
2020-09-12 10:55:46 -07:00
|
|
|
: m_nt{inst},
|
2021-06-06 16:13:58 -07:00
|
|
|
m_path{fmt::format("{}/", path)},
|
|
|
|
|
m_name{m_nt.GetEntry(fmt::format("{}/.name", path))} {
|
2020-09-12 10:55:46 -07:00
|
|
|
m_nt.AddListener(m_path, NT_NOTIFY_LOCAL | NT_NOTIFY_NEW | NT_NOTIFY_DELETE |
|
|
|
|
|
NT_NOTIFY_UPDATE | NT_NOTIFY_IMMEDIATE);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 00:37:33 -08:00
|
|
|
NTField2DModel::~NTField2DModel() = default;
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
void NTField2DModel::Update() {
|
|
|
|
|
for (auto&& event : m_nt.PollListener()) {
|
|
|
|
|
// .name
|
|
|
|
|
if (event.entry == m_name) {
|
|
|
|
|
if (event.value && event.value->IsString()) {
|
|
|
|
|
m_nameValue = event.value->GetString();
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// common case: update of existing entry; search by entry
|
|
|
|
|
if (event.flags & NT_NOTIFY_UPDATE) {
|
|
|
|
|
auto it = std::find_if(
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
m_objects.begin(), m_objects.end(),
|
2020-09-12 10:55:46 -07:00
|
|
|
[&](const auto& e) { return e->GetEntry() == event.entry; });
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
if (it != m_objects.end()) {
|
2020-09-12 10:55:46 -07:00
|
|
|
(*it)->NTUpdate(*event.value);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle create/delete
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view name = event.name;
|
|
|
|
|
if (wpi::starts_with(name, m_path)) {
|
|
|
|
|
name.remove_prefix(m_path.size());
|
2020-12-28 12:58:06 -08:00
|
|
|
if (name.empty() || name[0] == '.') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
auto [it, match] = Find(event.name);
|
2020-09-12 10:55:46 -07:00
|
|
|
if (event.flags & NT_NOTIFY_DELETE) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (match) {
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
m_objects.erase(it);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
continue;
|
|
|
|
|
} else if (event.flags & NT_NOTIFY_NEW) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!match) {
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
it = m_objects.emplace(
|
|
|
|
|
it, std::make_unique<ObjectModel>(event.name, event.entry));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
} else if (!match) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (event.flags & (NT_NOTIFY_NEW | NT_NOTIFY_UPDATE)) {
|
|
|
|
|
(*it)->NTUpdate(*event.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NTField2DModel::Exists() {
|
|
|
|
|
return m_nt.IsConnected() && nt::GetEntryType(m_name) != NT_UNASSIGNED;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
bool NTField2DModel::IsReadOnly() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
FieldObjectModel* NTField2DModel::AddFieldObject(std::string_view name) {
|
|
|
|
|
auto fullName = fmt::format("{}{}", m_path, name);
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
auto [it, match] = Find(fullName);
|
|
|
|
|
if (!match) {
|
|
|
|
|
it = m_objects.emplace(
|
|
|
|
|
it, std::make_unique<ObjectModel>(fullName, m_nt.GetEntry(fullName)));
|
|
|
|
|
}
|
|
|
|
|
return it->get();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
void NTField2DModel::RemoveFieldObject(std::string_view name) {
|
|
|
|
|
auto [it, match] = Find(fmt::format("{}{}", m_path, name));
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
if (match) {
|
|
|
|
|
nt::DeleteEntry((*it)->GetEntry());
|
|
|
|
|
m_objects.erase(it);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NTField2DModel::ForEachFieldObject(
|
2021-06-06 16:13:58 -07:00
|
|
|
wpi::function_ref<void(FieldObjectModel& model, std::string_view name)>
|
2020-09-12 10:55:46 -07:00
|
|
|
func) {
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
for (auto&& obj : m_objects) {
|
|
|
|
|
if (obj->Exists()) {
|
2021-06-06 16:13:58 -07:00
|
|
|
func(*obj, wpi::drop_front(obj->GetName(), m_path.size()));
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
|
|
|
|
|
std::pair<NTField2DModel::Objects::iterator, bool> NTField2DModel::Find(
|
2021-06-06 16:13:58 -07:00
|
|
|
std::string_view fullName) {
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
auto it = std::lower_bound(
|
|
|
|
|
m_objects.begin(), m_objects.end(), fullName,
|
2021-06-06 16:13:58 -07:00
|
|
|
[](const auto& e, std::string_view name) { return e->GetName() < name; });
|
[glass] Field2d enhancements (#3234)
- Add raw support for pose lists > 255/3 in length
- Improve drag selection, especially with closely overlapping objects
- Drag selection of corner also highlights center of object with smaller circle
- Multiple styles (box, line, closed line, track)
- Configurable line and arrow settings (color, weight)
- Add tooltip for object name, index, x, y, rotation
- Context menu for pose edit/add/remove
- View/edit in feet or inches as well as meters
- Configurable object selectability
Implementation: use vector of Pose2d internally, use units
2021-03-27 13:34:44 -07:00
|
|
|
return {it, it != m_objects.end() && (*it)->GetName() == fullName};
|
|
|
|
|
}
|