-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqconstraints.h
More file actions
240 lines (183 loc) · 8.59 KB
/
qconstraints.h
File metadata and controls
240 lines (183 loc) · 8.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef QCONSTRAINTS_H
#define QCONSTRAINTS_H
#include <QDebug>
#include <QGraphicsItem>
#include <QPen>
#include <memory>
namespace Uncertain {
class uStraightLineSegment;
}
//! Graphics: Constraints
namespace QConstraint {
using Uncertain::uStraightLineSegment;
//! Graphics: Base class for markers depicting constraints
class QConstraintBase : public QGraphicsItem
{
protected:
QConstraintBase();
//! Copy constructor
QConstraintBase( const QConstraintBase & other);
//! Copy assignment operator
QConstraintBase & operator= ( const QConstraintBase &) = delete ;
//! Move assignment operator
QConstraintBase & operator= ( QConstraintBase &&) = delete;
public:
// virtual std::shared_ptr<QConstraintBase> clone() const = 0; //!< Clone this constraint
//! Clone this constraint via nonvirtual interface pattern
std::shared_ptr<QConstraintBase> clone() const;
// T qgraphicsitem_cast(QGraphicsItem *item)
// To make this function work correctly with custom items, reimplement the type() function for each custom QGraphicsItem subclass.
enum {Type = UserType +364};
//! Get graphics type (id)
int type() const override { return Type; }
void serialize( QDataStream &out ); //!< serialization
bool deserialize( QDataStream &); //!< deserialization
void setColor( const QColor & col); //!< Set color
void setLineWidth( const int w); //!< Set line width
void setLineStyle( const int s); //!< Set line style
void setAltColor( const QColor &col ); //!< Set color for automatic colorization
void setStatus( bool isrequired,
bool isenforced); //!< Set status
//! Get status enforcment (success/failure)
bool enforced() const { return m_is_enforced; }
virtual void setMarkerSize ( qreal s) = 0; //!< Set marker size
virtual void setGeometry( const uStraightLineSegment &s,
const uStraightLineSegment &t) = 0; //!< Set geometry
static QPen defaultPenReq() { return s_defaultPenReq; } //!< Get default pen for required constraints
static QPen defaultPenRed() { return s_defaultPenRed; } //!< Get default pen for redundant constraints
static void setDefaultPenReq( const QPen &p) { s_defaultPenReq = p; } //!< Set default pen for required constraints
static void setDefaultPenRed( const QPen &p) { s_defaultPenRed = p; } //!< Set default pen for redundant constraints
static void setPenSelected( const QPen &p) { s_penSelected = p;} //!< Set pen for selection
static void setDefaultMarkerSize( int s) { s_defaultMarkerSize = s; } //!< Set default marker size
static void toggleShow() { s_show = !s_show; } //!< Toggle visibility
static void toggleShowColor() { s_showColor =! s_showColor; } //!< Toggle colorization (on/off)
static bool show() {return s_show;} //!< Get status visibility
protected:
~QConstraintBase() override = default;
virtual qreal markerSize() const = 0; //!< Set marker size
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override; //!< Plot marker
void mousePressEvent(QGraphicsSceneMouseEvent *) override; //!< Handle mouse press event
static bool showColor() { return s_showColor; } //!< Get status automatic colorization (on/off)
static int s_defaultMarkerSize; //!< Default marker size
static QPen s_defaultPenReq; //!< Default pen for required constraints
static QPen s_defaultPenRed; //!< Default pen for redundant constraints
static QPen s_penSelected; //!< Pen for selection
const double m_sc = 1000; //!< Scale factor coordinates screen // TODO(meijoc)
QColor m_altColor; //!< Color for automatic colorization (subtasks)
QPen m_pen_req; //!< Pen for required constraint
QPen m_pen_red; //!< Pen for redundant constraint
bool m_is_required = true; //!< Constraint is required? (for painting)
bool m_is_enforced = false; //!< Constraint is enforced? (for painting)
private:
virtual std::shared_ptr<QConstraintBase> doClone() const = 0;
static bool s_showColor;
static bool s_show;
};
//! Graphics: Three copunctual straight lines (circle)
class QCopunctual : public QConstraintBase,
public QGraphicsEllipseItem
{
public:
static std::shared_ptr<QConstraintBase> create(); //!< Create copunctual constraint
void setGeometry( const uStraightLineSegment &s,
const uStraightLineSegment &t) override;
void setMarkerSize ( qreal s) override;
qreal markerSize() const override;
protected:
QCopunctual();
QCopunctual( const QCopunctual & other); //!< Copy constructor
QRectF boundingRect() const override; //!< Get axis-aligned bounding box
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override; //!< Plot the circle
private:
// std::shared_ptr<QConstraintBase> clone() const override;
std::shared_ptr<QConstraintBase> doClone() const override;
};
//! Graphics: Two orthogonal straight lines (square)
class QOrthogonal : public QConstraintBase,
public QGraphicsRectItem
{
public:
static std::shared_ptr<QConstraintBase> create(); //!< Create orthogonallity constraint
void setGeometry( const uStraightLineSegment &s,
const uStraightLineSegment &t) override;
void setMarkerSize ( qreal s) override;
qreal markerSize() const override;
protected:
QOrthogonal();
QOrthogonal( const QOrthogonal & other); //!< Copy constructor
QRectF boundingRect() const override; //!< Get axis-aligned bounding box
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override; //!< Plot square
private:
// std::shared_ptr<QConstraintBase> clone() const override;
std::shared_ptr<QConstraintBase> doClone() const override;
};
//! Graphics: Marker for indentity
class QIdentical : public QConstraintBase,
public QGraphicsPolygonItem
{
public:
static std::shared_ptr<QConstraintBase> create(); //!< Create identity constraint
void setMarkerSize ( qreal s) override;
qreal markerSize() const override;
void setGeometry( const uStraightLineSegment &s,
const uStraightLineSegment &t) override;
protected:
QIdentical();
QIdentical( const QIdentical & other); //!< Copy constructor
QRectF boundingRect() const override; //!< Get axis-aligned bounding box
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override; //!< Plot marker
private:
// std::shared_ptr<QConstraintBase> clone() const override;
std::shared_ptr<QConstraintBase> doClone() const override;
};
//! Graphics: Marker for parallelism
class QParallel : public QConstraintBase
{
public:
static std::shared_ptr<QConstraintBase> create(); //!< Create parallelism constraint
void setGeometry( const uStraightLineSegment &s,
const uStraightLineSegment &t) override;
void setMarkerSize ( qreal s) override;
qreal markerSize() const override;
protected:
QParallel();
QParallel( const QParallel & other); //!< Copy constructor
QRectF boundingRect() const override; //!< Get axis-aligned bounding box
void paint( QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override; //!< Plot marker
private:
// std::shared_ptr<QConstraintBase> clone() const override;
std::shared_ptr<QConstraintBase> doClone() const override;
QGraphicsLineItem a;
QGraphicsLineItem b;
static constexpr double s_sc = 0.2;
static constexpr double s_shear = 0.1;
};
} // namespace QConstraint
#endif // QCONSTRAINTS_H