mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-19 19:54:07 +00:00
1a17ba9e6d
Last round of straight-swap Qt value types in ViewportWindow + its
overlay co-pilot.
setBackgroundColor(const QColor&) → (float r, float g, float b, float a)
QColor background_color_ → Eigen::Vector4f (linear, 0..1)
QPoint {nav_,box_select_,fps_, } → Eigen::Vector2i
{section_drag_start_mouse_}
QSet<int> fps_keys_held_ → std::unordered_set<int>
QElapsedTimer fps_last_tick_, → Stopwatch (new header in
fly_render_clock_, IfcViewerCore — std::chrono-
render_thread_local_ backed, exposes the existing
timers in render() QElapsedTimer .start/.restart/
.elapsed/.nsecsElapsed surface)
Also propagates the QPoint → Eigen::Vector2i change through
OverlayRenderer::encodeMarquee since the marquee corner coords flow
through that interface.
API-level helpers:
toV2i(QPoint) — small inline in ViewportWindow.cpp, isolates
the QMouseEvent→Vector2i conversion at the
five mouse-event handlers
Stopwatch.h — new file, IfcViewerCore. Same call shape as
QElapsedTimer; backed by std::chrono::steady_clock.
QSet method swaps:
.isEmpty() → .empty()
.contains(k) → .count(k) (C++17, no std contains() until C++20)
.remove(k) → .erase(k)
Eigen::Vector2i doesn't have .manhattanLength(); the box-select drag
threshold uses std::abs(diff.x()) + std::abs(diff.y()) inline.
Bonsai side: View.cpp's setBackgroundColor wrapper now decomposes the
QColor into floats at the call site (kept locally so the bonsai UI
keeps its QColor-driven theming).
Closes #81 + the QElapsedTimer half of #83. QTimer
(pivot_indicator_hide_timer_) still uses Qt — it needs the host's
scheduleOnce mechanism that lands with #85.
Builds: desktop / bonsai / web all green. Tests 100/100.
63 lines
2.8 KiB
C++
63 lines
2.8 KiB
C++
/********************************************************************************
|
|
* *
|
|
* This file is part of IfcOpenShell. *
|
|
* *
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* IfcOpenShell 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 *
|
|
* Lesser GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
* *
|
|
********************************************************************************/
|
|
|
|
#ifndef IFCVIEWER_STOPWATCH_H
|
|
#define IFCVIEWER_STOPWATCH_H
|
|
|
|
// Qt-free QElapsedTimer replacement: a thin wrapper over
|
|
// std::chrono::steady_clock that exposes the handful of methods our code
|
|
// actually uses (start, restart, elapsed-as-ms, nsecsElapsed, isValid).
|
|
// Same call-site API as QElapsedTimer so the existing diagnostics keep
|
|
// reading the same way after the type swap.
|
|
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
|
|
class Stopwatch {
|
|
public:
|
|
using Clock = std::chrono::steady_clock;
|
|
using TimePoint = Clock::time_point;
|
|
|
|
Stopwatch() = default;
|
|
|
|
bool isValid() const { return started_; }
|
|
void start() { t0_ = Clock::now(); started_ = true; }
|
|
void restart() { start(); }
|
|
void invalidate() { started_ = false; }
|
|
|
|
// Elapsed milliseconds since start(); matches QElapsedTimer::elapsed().
|
|
int64_t elapsed() const {
|
|
if (!started_) return 0;
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
Clock::now() - t0_).count();
|
|
}
|
|
// Nanoseconds since start; matches QElapsedTimer::nsecsElapsed().
|
|
int64_t nsecsElapsed() const {
|
|
if (!started_) return 0;
|
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
Clock::now() - t0_).count();
|
|
}
|
|
|
|
private:
|
|
TimePoint t0_{};
|
|
bool started_ = false;
|
|
};
|
|
|
|
#endif // IFCVIEWER_STOPWATCH_H
|