KiCad PCB EDA Suite
Loading...
Searching...
No Matches
automatic_fit.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <math/box2.h>
23#include <math/vector2d.h>
24
25#include <optional>
26
27
28namespace KIGFX
29{
30
39{
40public:
42 void Record( const BOX2I& aBox, std::optional<double> aMarginScale, double aScale, const VECTOR2D& aCenter )
43 {
44 m_valid = true;
45 m_box = aBox;
46 m_marginScale = aMarginScale;
47 m_scale = aScale;
48 m_center = aCenter;
49 }
50
51 void Clear() { m_valid = false; }
52
54 bool Holds( double aScale, const VECTOR2D& aCenter ) const
55 {
56 return m_valid && aScale == m_scale && aCenter == m_center;
57 }
58
59 const BOX2I& GetBox() const { return m_box; }
60
61 std::optional<double> GetMarginScale() const { return m_marginScale; }
62
63private:
64 bool m_valid = false;
66 std::optional<double> m_marginScale;
67 double m_scale = 0.0;
69};
70
71} // namespace KIGFX
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
What the last zoom to fit showed, so a canvas that changes size can fit it again.
bool Holds(double aScale, const VECTOR2D &aCenter) const
True while a view at aScale and aCenter shows exactly what the last fit left.
const BOX2I & GetBox() const
std::optional< double > GetMarginScale() const
std::optional< double > m_marginScale
void Record(const BOX2I &aBox, std::optional< double > aMarginScale, double aScale, const VECTOR2D &aCenter)
Note a fit of aBox that left the view at aScale and aCenter.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
VECTOR2< double > VECTOR2D
Definition vector2d.h:707