Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
persp3d.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_PERSP3D_H
3#define SEEN_PERSP3D_H
4
5/*
6 * Implementation of 3D perspectives as SPObjects
7 *
8 * Authors:
9 * Maximilian Albert <Anhalter42@gmx.de>
10 *
11 * Copyright (C) 2007 Authors
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#include <list>
17#include <map>
18#include <vector>
19
20#include "document.h"
21#include "inkscape.h" // for SP_ACTIVE_DOCUMENT
22#include "sp-object.h"
23#include "transf_mat_3x4.h"
24#include "xml/node-observer.h"
25
26class SPBox3D;
27class Persp3D;
28
29namespace Inkscape {
30class ObjectSet;
31}
32
34{
35 friend class Persp3D;
36 ~Persp3DNodeObserver() override = default; // can only exist as a direct base of Persp3D
37
39};
40
42{
43public:
45
47
48 // Also write the list of boxes into the xml repr and vice versa link boxes to their persp3d?
49 std::vector<SPBox3D *> boxes;
51
52 // for debugging only
54};
55
56class Persp3D final
57 : public SPObject
58 , private Persp3DNodeObserver
59{
60public:
61 Persp3D();
62 ~Persp3D() override;
63 int tag() const override { return tag_of<decltype(*this)>; }
64
65 std::unique_ptr<Persp3DImpl> perspective_impl;
66
67protected:
68 void build(SPDocument* doc, Inkscape::XML::Node* repr) override;
69 void release() override;
70
71 void set(SPAttr key, char const* value) override;
72
73 void update(SPCtx* ctx, unsigned int flags) override;
74
75 Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, unsigned int flags) override;
76
77
78public:
79 // FIXME: Make more of these inline!
81 return cast<Persp3D>(SP_ACTIVE_DOCUMENT->getObjectByRepr(repr));
82 }
84 return perspective_impl->tmat.column(axis);
85 }
86 Geom::Point get_PL_dir_from_pt (Geom::Point const &pt, Proj::Axis axis) const; // convenience wrapper around the following two
87 Geom::Point get_finite_dir (Geom::Point const &pt, Proj::Axis axis) const;
89 double get_infinite_angle (Proj::Axis axis) const;
90 static bool VP_is_finite (Persp3DImpl *persp_impl, Proj::Axis axis);
91 void toggle_VP (Proj::Axis axis, bool set_undo = true);
92 static void toggle_VPs (std::list<Persp3D *>, Proj::Axis axis);
93 void set_VP_state (Proj::Axis axis, Proj::VPState state);
94 void rotate_VP (Proj::Axis axis, double angle, bool alt_pressed); // angle is in degrees
95 void apply_affine_transformation (Geom::Affine const &xform);
96
97 void add_box (SPBox3D *box);
98 void remove_box (SPBox3D *box);
99 bool has_box (SPBox3D *box) const;
100
101 void update_box_displays ();
102 void update_box_reprs ();
103 void update_z_orders ();
104 unsigned int num_boxes () const { return perspective_impl->boxes.size(); }
105 std::list<SPBox3D *> list_of_boxes() const;
106
107 bool perspectives_coincide(Persp3D const *rhs) const;
108 void absorb(Persp3D *persp2);
109
112
114
115 void print_debugging_info () const;
116 static void print_debugging_info_all(SPDocument *doc);
117 static void print_all_selected();
118
119private:
120 friend Persp3DNodeObserver; // for static_cast
122};
123
124#endif // SEEN_PERSP3D_H
125
126/*
127 Local Variables:
128 mode:c++
129 c-file-style:"stroustrup"
130 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
131 indent-tabs-mode:nil
132 fill-column:99
133 End:
134*/
135// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
SPAttr
Definition attributes.h:27
constexpr int tag_of
Convenience function to retrieve the tag (class id) of a given type.
Definition cast.h:26
3x3 matrix representing an affine transformation.
Definition affine.h:70
Two-dimensional point that doubles as a vector.
Definition point.h:66
Interface for XML node observers.
Interface for refcounted XML nodes.
Definition node.h:80
std::vector< SPBox3D * > boxes
Definition persp3d.h:49
Proj::TransfMat3x4 tmat
Definition persp3d.h:46
SPDocument * document
Definition persp3d.h:50
int my_counter
Definition persp3d.h:53
~Persp3DNodeObserver() override=default
void notifyAttributeChanged(Inkscape::XML::Node &, GQuark, Inkscape::Util::ptr_shared, Inkscape::Util::ptr_shared) final
Attribute change callback.
Definition persp3d.cpp:36
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Virtual build: set persp3d attributes from its associated XML node.
Definition persp3d.cpp:63
std::list< SPBox3D * > list_of_boxes() const
Definition persp3d.cpp:470
static void toggle_VPs(std::list< Persp3D * >, Proj::Axis axis)
Definition persp3d.cpp:358
double get_infinite_angle(Proj::Axis axis) const
Definition persp3d.cpp:334
void toggle_VP(Proj::Axis axis, bool set_undo=true)
Definition persp3d.cpp:344
bool perspectives_coincide(Persp3D const *rhs) const
Definition persp3d.cpp:481
Persp3DNodeObserver & nodeObserver()
Definition persp3d.h:121
Persp3D()
Definition persp3d.cpp:53
~Persp3D() override
void add_box(SPBox3D *box)
Definition persp3d.cpp:397
unsigned int num_boxes() const
Definition persp3d.h:104
static Persp3D * document_first_persp(SPDocument *document)
Definition persp3d.cpp:248
void update_box_displays()
Definition persp3d.cpp:433
Geom::Point get_infinite_dir(Proj::Axis axis) const
Definition persp3d.cpp:324
static Persp3D * create_xml_element(SPDocument *document)
Definition persp3d.cpp:203
void set_VP_state(Proj::Axis axis, Proj::VPState state)
Definition persp3d.cpp:366
void rotate_VP(Proj::Axis axis, double angle, bool alt_pressed)
Definition persp3d.cpp:373
void update(SPCtx *ctx, unsigned int flags) override
Definition persp3d.cpp:192
void update_box_reprs()
Definition persp3d.cpp:444
bool has_box(SPBox3D *box) const
Definition persp3d.cpp:419
Geom::Point get_PL_dir_from_pt(Geom::Point const &pt, Proj::Axis axis) const
Definition persp3d.cpp:309
void apply_affine_transformation(Geom::Affine const &xform)
Definition persp3d.cpp:390
std::unique_ptr< Persp3DImpl > perspective_impl
Definition persp3d.h:65
static void print_debugging_info_all(SPDocument *doc)
Definition persp3d.cpp:542
void print_debugging_info() const
Definition persp3d.cpp:520
friend Persp3DNodeObserver
Definition persp3d.h:120
bool has_all_boxes_in_selection(Inkscape::ObjectSet *set) const
Definition persp3d.cpp:503
Proj::Pt2 get_VP(Proj::Axis axis) const
Definition persp3d.h:83
void release() override
Virtual release of Persp3D members before destruction.
Definition persp3d.cpp:79
Geom::Point get_finite_dir(Geom::Point const &pt, Proj::Axis axis) const
Definition persp3d.cpp:318
static bool VP_is_finite(Persp3DImpl *persp_impl, Proj::Axis axis)
Definition persp3d.cpp:339
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags) override
Virtual write: write object attributes to repr.
Definition persp3d.cpp:263
static void print_all_selected()
Definition persp3d.cpp:553
static Persp3D * get_from_repr(Inkscape::XML::Node *repr)
Definition persp3d.h:80
int tag() const override
Definition persp3d.h:63
void absorb(Persp3D *persp2)
Definition persp3d.cpp:487
void remove_box(SPBox3D *box)
Definition persp3d.cpp:410
void update_z_orders()
Definition persp3d.cpp:456
Typed SVG document implementation.
Definition document.h:101
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * repr
Definition sp-object.h:193
SPDocument * document
Definition sp-object.h:188
Helper class to stream background task notifications as a series of messages.
Interface for XML node observers.
static cairo_user_data_key_t key
guint32 GQuark
Interface for XML documents.
Definition document.h:43
Unused.
Definition sp-object.h:94