KiCad PCB EDA Suite
Loading...
Searching...
No Matches
diff_scene.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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 this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 */
20
21#ifndef KICAD_DIFF_SCENE_H
22#define KICAD_DIFF_SCENE_H
23
24#include <kicommon.h>
25
28
29#include <base_units.h>
30#include <gal/color4d.h>
31#include <lset.h>
32#include <math/box2.h>
33
34#include <wx/string.h>
35
36#include <array>
37#include <map>
38#include <optional>
39
40class SHAPE_POLY_SET;
41
42
43namespace KICAD_DIFF
44{
45
58
59
67inline constexpr std::array<CATEGORY, 4> PAINT_ORDER{
68 CATEGORY::MODIFIED,
69 CATEGORY::ADDED,
70 CATEGORY::REMOVED,
71 CATEGORY::CONFLICT,
72};
73
74
75inline constexpr std::size_t CATEGORY_COUNT = PAINT_ORDER.size();
76
90{
93 wxString label; // shown by interactive renderer as a hover tooltip
94
100
101 using PolygonList = std::vector<std::vector<std::vector<VECTOR2I>>>;
103};
104
105
124
125
133{
134 std::vector<VECTOR2I> outline;
135 bool filled = false;
136 int lineWidth = 0;
139};
140
141
154
155
163{
164 std::vector<DOCUMENT_SEGMENT> segments;
165 std::vector<DOCUMENT_POLYGON> polygons;
166 std::vector<DOCUMENT_CIRCLE> circles;
167
168 bool Empty() const { return segments.empty() && polygons.empty() && circles.empty(); }
169};
170
171
184{
185 virtual ~GEOMETRY_SINK() = default;
186
187 virtual void FillPolygon( const DOCUMENT_POLYGON& aPoly ) = 0;
188 virtual void StrokePolygon( const DOCUMENT_POLYGON& aPoly ) = 0;
189 virtual void DrawSegment( const DOCUMENT_SEGMENT& aSegment ) = 0;
190 virtual void DrawCircle( const DOCUMENT_CIRCLE& aCircle ) = 0;
191};
192
193
200inline void IterateDocumentGeometry( const DOCUMENT_GEOMETRY& aGeometry, GEOMETRY_SINK& aSink )
201{
202 if( aGeometry.Empty() )
203 return;
204
205 for( const DOCUMENT_POLYGON& poly : aGeometry.polygons )
206 aSink.FillPolygon( poly );
207
208 for( const DOCUMENT_POLYGON& poly : aGeometry.polygons )
209 aSink.StrokePolygon( poly );
210
211 for( const DOCUMENT_SEGMENT& segment : aGeometry.segments )
212 aSink.DrawSegment( segment );
213
214 for( const DOCUMENT_CIRCLE& circle : aGeometry.circles )
215 aSink.DrawCircle( circle );
216}
217
218
220{
228
229 BOX2I documentBBox; // union of all change bboxes
230 std::vector<SCENE_SHAPE> addedShapes;
231 std::vector<SCENE_SHAPE> removedShapes;
232 std::vector<SCENE_SHAPE> modifiedShapes;
233 std::vector<SCENE_SHAPE> conflictShapes;
234
241};
242
243
254{
255 switch( aKind )
256 {
257 case DOC_KIND::SCH:
259 return schIUScale;
260
261 case DOC_KIND::PCB:
262 case DOC_KIND::FP_LIB:
265 default:
266 return pcbIUScale;
267 }
268}
269
270
276{
277 KIGFX::COLOR4D added = KIGFX::COLOR4D( 0.20, 0.65, 0.20, 1.0 ); // green
278 KIGFX::COLOR4D removed = KIGFX::COLOR4D( 0.80, 0.20, 0.20, 1.0 ); // red
279 KIGFX::COLOR4D modified = KIGFX::COLOR4D( 0.85, 0.65, 0.10, 1.0 ); // amber
280 KIGFX::COLOR4D conflict = KIGFX::COLOR4D( 0.65, 0.20, 0.70, 1.0 ); // magenta
281 KIGFX::COLOR4D background = KIGFX::COLOR4D( 0.97, 0.97, 0.97, 1.0 ); // near-white
282 KIGFX::COLOR4D foreground = KIGFX::COLOR4D( 0.10, 0.10, 0.10, 1.0 ); // near-black
283
287 KIGFX::COLOR4D reference = KIGFX::COLOR4D( 0.38, 0.38, 0.38, 0.55 );
288 KIGFX::COLOR4D comparison = KIGFX::COLOR4D( 0.38, 0.38, 0.38, 0.55 );
289};
290
291
304
305
311
312
320
321
333KICOMMON_API std::optional<BOX2I> BBoxFromGeometry( const DOCUMENT_GEOMETRY& aGeometry );
334
335
342
343
350 const LSET& aVisibleLayers );
351
352
361
362
368KICOMMON_API bool IsRoutingNetChange( const ITEM_CHANGE& aChange );
369
370
375KICOMMON_API wxString ChangeDisplayLabel( const ITEM_CHANGE& aChange );
376
377
391
392
399KICOMMON_API DOCUMENT_POLYGON MakeBBoxOutline( const BOX2I& aBBox, const KIGFX::COLOR4D& aColor, int aLineWidth = 0 );
400
401
410
411
419KICOMMON_API void CollectChangeBBoxes( const DOCUMENT_DIFF& aDiff, std::map<KIID_PATH, BOX2I>& aOut );
420
421
425KICOMMON_API const std::vector<SCENE_SHAPE>& ShapesFor( const DIFF_SCENE& aScene, CATEGORY aCategory );
426
427
433KICOMMON_API std::optional<BOX2I> HighlightedBBox( const DIFF_SCENE& aScene, const KIID_PATH& aChangeId,
434 const std::array<bool, CATEGORY_COUNT>& aCategoryVisible );
435
436} // namespace KICAD_DIFF
437
438#endif // KICAD_DIFF_SCENE_H
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Represent a set of closed polygons.
#define KICOMMON_API
Definition kicommon.h:27
CHANGE_KIND
Coarse classification of a single item-level change between two documents.
constexpr std::size_t CATEGORY_COUNT
Definition diff_scene.h:75
wxString ChangeDisplayLabel(const ITEM_CHANGE &aChange)
User-facing item label used consistently by scene tooltips and change tree entries.
DIFF_SCENE BuildScene(const DOCUMENT_DIFF &aDiff, const DIFF_COLOR_THEME &aTheme)
Build a DIFF_SCENE from a DOCUMENT_DIFF, populating the shape lists and computing the union bbox.
DOCUMENT_POLYGON MakeBBoxOutline(const BOX2I &aBBox, const KIGFX::COLOR4D &aColor, int aLineWidth)
Build a DOCUMENT_POLYGON outlining a bounding box.
LSET GeometryLayerSet(const DOCUMENT_GEOMETRY &aGeometry)
Return the union of every non-empty layer set carried by the geometry.
void CollectChangeBBoxes(const DOCUMENT_DIFF &aDiff, std::map< KIID_PATH, BOX2I > &aOut)
Walk a DOCUMENT_DIFF and populate a (KIID_PATH → BOX2I) map with each changed item's bbox,...
const EDA_IU_SCALE & IuScaleForDocKind(DOC_KIND aKind)
Internal-unit scale a document kind's coordinates are expressed in.
Definition diff_scene.h:253
KIGFX::COLOR4D ThemeColorFor(const DIFF_COLOR_THEME &aTheme, CATEGORY aCategory)
Map a CATEGORY to its color in a DIFF_COLOR_THEME.
std::optional< BOX2I > HighlightedBBox(const DIFF_SCENE &aScene, const KIID_PATH &aChangeId, const std::array< bool, CATEGORY_COUNT > &aCategoryVisible)
Union bbox of every visible SCENE_SHAPE whose changeId matches aChangeId.
void IterateDocumentGeometry(const DOCUMENT_GEOMETRY &aGeometry, GEOMETRY_SINK &aSink)
Walk a DOCUMENT_GEOMETRY in the canonical render order shared by the GAL and plotter renderers: every...
Definition diff_scene.h:200
void AppendGeometry(DOCUMENT_GEOMETRY &aDst, DOCUMENT_GEOMETRY &&aSrc)
Move all primitives from aSrc into aDst.
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
void ExpandBBoxToGeometry(DIFF_SCENE &aScene)
Grow the scene's documentBBox to also include the extent of any background geometry.
bool IsRoutingNetChange(const ITEM_CHANGE &aChange)
Presentation predicate for PCB routing changes that should be displayed as one net-level entry/shape.
CATEGORY
Visual category each ITEM_CHANGE belongs to in the scene.
Definition diff_scene.h:52
const std::vector< SCENE_SHAPE > & ShapesFor(const DIFF_SCENE &aScene, CATEGORY aCategory)
Read-only access to a DIFF_SCENE's shape list for a given category.
constexpr std::array< CATEGORY, 4 > PAINT_ORDER
Paint order.
Definition diff_scene.h:67
SHAPE_POLY_SET PolySetFromPolygonList(const SCENE_SHAPE::PolygonList &aPolygons)
Build a SHAPE_POLY_SET from a SCENE_SHAPE::PolygonList.
std::optional< BOX2I > BBoxFromGeometry(const DOCUMENT_GEOMETRY &aGeometry)
Compute the tight bounding box of a DOCUMENT_GEOMETRY, inflating each primitive by half its stroke so...
CATEGORY CategoryFor(CHANGE_KIND aKind)
Map a CHANGE_KIND to the visual category it belongs to.
DOCUMENT_GEOMETRY FilterGeometryByVisibleLayers(const DOCUMENT_GEOMETRY &aGeometry, const LSET &aVisibleLayers)
Copy geometry primitives whose layer set intersects aVisibleLayers.
KIGFX::COLOR4D reference
Default color for source-document context geometry.
Definition diff_scene.h:287
std::vector< SCENE_SHAPE > modifiedShapes
Definition diff_scene.h:232
DOCUMENT_GEOMETRY referenceGeometry
Background geometry from the two source documents.
Definition diff_scene.h:239
std::vector< SCENE_SHAPE > conflictShapes
Definition diff_scene.h:233
std::vector< SCENE_SHAPE > addedShapes
Definition diff_scene.h:230
DOCUMENT_GEOMETRY comparisonGeometry
Definition diff_scene.h:240
DOC_KIND docKind
Source document type.
Definition diff_scene.h:227
std::vector< SCENE_SHAPE > removedShapes
Definition diff_scene.h:231
Filled or stroked circle.
Definition diff_scene.h:146
The full set of changes between two parsed documents of one type.
Aggregate of background geometry extracted from one source document.
Definition diff_scene.h:163
std::vector< DOCUMENT_SEGMENT > segments
Definition diff_scene.h:164
std::vector< DOCUMENT_POLYGON > polygons
Definition diff_scene.h:165
std::vector< DOCUMENT_CIRCLE > circles
Definition diff_scene.h:166
Closed polygon outline from a source document.
Definition diff_scene.h:133
std::vector< VECTOR2I > outline
Definition diff_scene.h:134
Stroked line segment from one of the source documents.
Definition diff_scene.h:117
Sink for the shared DOCUMENT_GEOMETRY walk.
Definition diff_scene.h:184
virtual void StrokePolygon(const DOCUMENT_POLYGON &aPoly)=0
virtual void DrawCircle(const DOCUMENT_CIRCLE &aCircle)=0
virtual void DrawSegment(const DOCUMENT_SEGMENT &aSegment)=0
virtual void FillPolygon(const DOCUMENT_POLYGON &aPoly)=0
virtual ~GEOMETRY_SINK()=default
One change record on a single item.
Shared rendering model consumed by both the GAL renderer (interactive widget) and the plotter rendere...
Definition diff_scene.h:90
std::vector< std::vector< std::vector< VECTOR2I > > > PolygonList
Definition diff_scene.h:101
KIGFX::COLOR4D color
Definition diff_scene.h:92
KIID_PATH changeId
Stable identifier of the ITEM_CHANGE that produced this shape.
Definition diff_scene.h:99
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683