-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathController.h
More file actions
123 lines (94 loc) · 3.36 KB
/
Controller.h
File metadata and controls
123 lines (94 loc) · 3.36 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
/*
Copyright (C) 2010-2011 Igor Izyumin
This file is part of xpcb.
xpcb 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.
xpcb 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 xpcb. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <QObject>
#include "global.h"
#include <QPointer>
#include <QPainter>
#include <QMouseEvent>
#include <QUndoCommand>
#include "PCBView.h"
#include "PCBObject.h"
#include "Editor.h"
class Document;
class PCBDoc;
class FPDoc;
class LayerWidget;
class SelFilterWidget;
class ActionBar;
class Layer;
class Controller;
class CtrlAction;
/// The controller mediates all interaction between the model and view. It
/// also manages selection. Other control tasks are handled by delegates.
class Controller : public QObject
{
Q_OBJECT
public:
enum SelectionMaskT { SM_PARTS, SM_REFDES, SM_VALUE, SM_PINS, SM_TRACES,
SM_VERTICES, SM_AREAS, SM_TEXT, SM_CUTOUTS, SM_OUTLINE, SM_DRC };
explicit Controller(QObject *parent = 0);
void registerView(PCBView* view);
void registerActionBar(ActionBar* bar);
void registerLayerWidget(LayerWidget* widget);
void registerDoc(Document* doc);
void draw(QPainter* painter, QRect &rect, const Layer &layer);
bool docIsOpen() {return doc() != NULL;}
void selectObj(QSharedPointer<PCBObject> obj);
void hideObj(QSharedPointer<PCBObject> obj);
void unhideObj(QSharedPointer<PCBObject> obj);
Document* doc() {return mDoc; }
PCBView* view() {return mView; }
QPoint snapToPlaceGrid(const QPoint &p) const;
QPoint snapToRouteGrid(const QPoint &p) const;
// returns the object hit radius in pcb units
int hitRadius() const {return 10*mView->transform().inverted().m11(); }
bool isLayerVisible(const Layer& l) const;
const Layer& activeLayer() const;
void registerAction(const CtrlAction* action) { mActions.append(action); updateActions(); }
void installEditor(QSharedPointer<AbstractEditor> editor);
void clearSelection() { mSelectedObjs.clear(); updateEditor(); }
static void drawCrosshair45(QPainter* painter, QPoint pos);
public slots:
void onPlaceGridChanged(int grid) { mPlaceGrid = grid; }
void onRouteGridChanged(int grid) { mRouteGrid = grid; }
protected slots:
void onEditorOverlayChanged();
void onEditorFinished();
void onEditorActionsChanged();
void onDocumentChanged();
protected:
virtual bool eventFilter(QObject *watched, QEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void updateEditor();
void updateActions();
PCBView* mView;
Document* mDoc;
QSharedPointer<AbstractEditor> mEditor;
LayerWidget* mLayerWidget;
ActionBar* mActionBar;
/// Selected objects
QList<QSharedPointer<PCBObject> > mSelectedObjs;
/// Hidden objects
QList<QSharedPointer<PCBObject> > mHiddenObjs;
/// List of registered actions
QList<const CtrlAction* > mActions;
int mPlaceGrid;
int mRouteGrid;
};
#endif // CONTROLLER_H