1 /*******************************************************************
2
3 Part of the Fritzing project - http://fritzing.org
4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de
5
6 Fritzing is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Fritzing is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
18
19 ********************************************************************
20
21 $Revision: 6112 $:
22 $Author: cohen@irascible.com $:
23 $Date: 2012-06-28 00:18:10 +0200 (Do, 28. Jun 2012) $
24
25 ********************************************************************/
26
27 #include "viewgeometry.h"
28 #include "utils/graphicsutils.h"
29
ViewGeometry()30 ViewGeometry::ViewGeometry( )
31 {
32 m_z = -1;
33 m_loc.setX(-1);
34 m_loc.setY(-1);
35 m_line.setLine(-1,-1,-1,-1);
36 m_wireFlags = NoFlag;
37 }
38
ViewGeometry(const ViewGeometry & that)39 ViewGeometry::ViewGeometry(const ViewGeometry & that )
40 {
41 set(that);
42 }
43
ViewGeometry(QDomElement & geometry)44 ViewGeometry::ViewGeometry(QDomElement & geometry) {
45 m_wireFlags = (WireFlags) geometry.attribute("wireFlags").toInt();
46 m_z = geometry.attribute("z").toDouble();
47 m_loc.setX(geometry.attribute("x").toDouble());
48 m_loc.setY(geometry.attribute("y").toDouble());
49 QString x1 = geometry.attribute("x1");
50 if (!x1.isEmpty()) {
51 m_line.setLine( geometry.attribute("x1").toDouble(),
52 geometry.attribute("y1").toDouble(),
53 geometry.attribute("x2").toDouble(),
54 geometry.attribute("y2").toDouble() );
55 }
56 QString w = geometry.attribute("width");
57 if (!w.isEmpty()) {
58 m_rect.setX(geometry.attribute("x").toDouble());
59 m_rect.setY(geometry.attribute("y").toDouble());
60 m_rect.setWidth(geometry.attribute("width").toDouble());
61 m_rect.setHeight(geometry.attribute("height").toDouble());
62 }
63
64 GraphicsUtils::loadTransform(geometry.firstChildElement("transform"), m_transform);
65 }
66
setZ(double z)67 void ViewGeometry::setZ(double z) {
68 m_z = z;
69 }
70
z() const71 double ViewGeometry::z() const {
72 return m_z ;
73 }
74
setLoc(QPointF loc)75 void ViewGeometry::setLoc(QPointF loc) {
76 m_loc = loc;
77 }
78
loc() const79 QPointF ViewGeometry::loc() const {
80 return m_loc ;
81 }
82
setLine(QLineF loc)83 void ViewGeometry::setLine(QLineF loc) {
84 m_line = loc;
85 }
86
line() const87 QLineF ViewGeometry::line() const {
88 return m_line;
89 }
90
offset(double x,double y)91 void ViewGeometry::offset(double x, double y) {
92 m_loc.setX(x + m_loc.x());
93 m_loc.setY(y + m_loc.y());
94 }
95
selected()96 bool ViewGeometry::selected() {
97 return m_selected;
98 }
99
setSelected(bool selected)100 void ViewGeometry::setSelected(bool selected) {
101 m_selected = selected;
102 }
103
rect() const104 QRectF ViewGeometry::rect() const {
105 return m_rect;
106 }
107
setRect(double x,double y,double width,double height)108 void ViewGeometry::setRect(double x, double y, double width, double height)
109 {
110 m_rect.setRect(x, y, width, height);
111 }
112
setRect(const QRectF & r)113 void ViewGeometry::setRect(const QRectF & r)
114 {
115 setRect(r.x(), r.y(), r.width(), r.height());
116 }
117
setTransform(QTransform transform)118 void ViewGeometry::setTransform(QTransform transform) {
119 m_transform = transform;
120 }
121
transform() const122 QTransform ViewGeometry::transform() const {
123 return m_transform;
124 }
125
set(const ViewGeometry & that)126 void ViewGeometry::set(const ViewGeometry & that) {
127 m_z = that.m_z;
128 m_line = that.m_line;
129 m_loc = that.m_loc;
130 m_transform = that.m_transform;
131 m_wireFlags = that.m_wireFlags;
132 m_rect = that.m_rect;
133 }
134
setRouted(bool routed)135 void ViewGeometry::setRouted(bool routed) {
136 setWireFlag(routed, RoutedFlag);
137 }
138
setPCBTrace(bool trace)139 void ViewGeometry::setPCBTrace(bool trace) {
140 setWireFlag(trace, PCBTraceFlag);
141 }
142
setSchematicTrace(bool trace)143 void ViewGeometry::setSchematicTrace(bool trace) {
144 setWireFlag(trace, SchematicTraceFlag);
145 }
146
setRatsnest(bool ratsnest)147 void ViewGeometry::setRatsnest(bool ratsnest) {
148 setWireFlag(ratsnest, RatsnestFlag);
149 }
150
setNormal(bool normal)151 void ViewGeometry::setNormal(bool normal) {
152 setWireFlag(normal, NormalFlag);
153 }
154
setAutoroutable(bool autoroutable)155 void ViewGeometry::setAutoroutable(bool autoroutable) {
156 setWireFlag(autoroutable, AutoroutableFlag);
157 }
158
getRouted() const159 bool ViewGeometry::getRouted() const {
160
161 return m_wireFlags.testFlag(RoutedFlag);
162 }
163
getNormal() const164 bool ViewGeometry::getNormal() const {
165
166 return m_wireFlags.testFlag(NormalFlag);
167 }
168
getPCBTrace() const169 bool ViewGeometry::getPCBTrace() const {
170 return m_wireFlags.testFlag(PCBTraceFlag);
171 }
172
getAnyTrace() const173 bool ViewGeometry::getAnyTrace() const {
174 return getPCBTrace() || getSchematicTrace();
175 }
176
getSchematicTrace() const177 bool ViewGeometry::getSchematicTrace() const {
178 return m_wireFlags.testFlag(SchematicTraceFlag);
179 }
180
getRatsnest() const181 bool ViewGeometry::getRatsnest() const {
182 return m_wireFlags.testFlag(RatsnestFlag);
183 }
184
getAutoroutable() const185 bool ViewGeometry::getAutoroutable() const {
186 return m_wireFlags.testFlag(AutoroutableFlag);
187 }
188
setWireFlag(bool setting,WireFlag flag)189 void ViewGeometry::setWireFlag(bool setting, WireFlag flag) {
190 if (setting) {
191 m_wireFlags |= flag;
192 }
193 else {
194 m_wireFlags &= ~flag;
195 }
196 }
197
flagsAsInt() const198 int ViewGeometry::flagsAsInt() const {
199 return (int) m_wireFlags;
200 }
201
setWireFlags(WireFlags wireFlags)202 void ViewGeometry::setWireFlags(WireFlags wireFlags) {
203 m_wireFlags = wireFlags;
204 }
205
hasFlag(ViewGeometry::WireFlag flag)206 bool ViewGeometry::hasFlag(ViewGeometry::WireFlag flag) {
207 return (m_wireFlags & flag) ? true : false;
208 }
209
hasAnyFlag(ViewGeometry::WireFlags flags)210 bool ViewGeometry::hasAnyFlag(ViewGeometry::WireFlags flags) {
211 return (m_wireFlags & flags) ? true : false;
212 }
213
214
wireFlags() const215 ViewGeometry::WireFlags ViewGeometry::wireFlags() const {
216 return m_wireFlags;
217 }
218