KiCad PCB EDA Suite
Loading...
Searching...
No Matches
snap_frame.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 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef TOOL_SNAP_FRAME_H
19#define TOOL_SNAP_FRAME_H
20
21#include <map>
22#include <optional>
23#include <utility>
24#include <vector>
25
26#include <snap/snap_resolver.h>
27
28
29template <typename Payload>
31{
33 std::vector<SNAP_CANDIDATE> candidates;
34 std::optional<SNAP_STABLE_ID> retainedId;
35 std::map<SNAP_STABLE_ID, Payload> presentation;
36 std::vector<SNAP_STABLE_ID> stickyIds;
37 double rankingHysteresis = 0.0;
40};
41
42
43template <typename Payload>
49
50
51template <typename Payload>
53{
55 std::optional<SNAP_FRAME_PRESENTATION<Payload>> presentation;
56};
57
58
59template <typename Payload>
61{
63 resolver.SetRankingHysteresis( aInput.rankingHysteresis );
64 resolver.SetFeasibilityCallback( std::move( aInput.feasibility ) );
65 resolver.SetTraceCallback( std::move( aInput.trace ) );
66 resolver.SetStickyCandidates( std::move( aInput.stickyIds ) );
67 resolver.SetRetainedCandidate( aInput.retainedId );
68
69 for( SNAP_CANDIDATE& candidate : aInput.candidates )
70 resolver.AddCandidate( std::move( candidate ) );
71
73 output.result = resolver.Resolve( aInput.context );
74
75 for( const SNAP_STABLE_ID& id : output.result.accepted )
76 {
77 auto payload = aInput.presentation.find( id );
78
79 if( payload != aInput.presentation.end() )
80 {
81 output.presentation = { id, std::move( payload->second ) };
82 break;
83 }
84 }
85
86 return output;
87}
88
89#endif
std::function< SNAP_RESULT(const SNAP_SOURCE_CONTEXT &, const std::vector< SNAP_CANDIDATE > &)> FEASIBILITY_CALLBACK
std::function< void(const std::string &)> TRACE_CALLBACK
static FILENAME_RESOLVER * resolver
SNAP_FRAME_OUTPUT< Payload > ResolveSnapFrame(SNAP_FRAME_INPUT< Payload > aInput)
Definition snap_frame.h:60
std::optional< SNAP_STABLE_ID > retainedId
Definition snap_frame.h:34
SNAP_RESOLVER::TRACE_CALLBACK trace
Definition snap_frame.h:39
SNAP_RESOLVER::FEASIBILITY_CALLBACK feasibility
Definition snap_frame.h:38
std::map< SNAP_STABLE_ID, Payload > presentation
Definition snap_frame.h:35
SNAP_SOURCE_CONTEXT context
Definition snap_frame.h:32
std::vector< SNAP_CANDIDATE > candidates
Definition snap_frame.h:33
double rankingHysteresis
Definition snap_frame.h:37
std::vector< SNAP_STABLE_ID > stickyIds
Definition snap_frame.h:36
std::optional< SNAP_FRAME_PRESENTATION< Payload > > presentation
Definition snap_frame.h:55
SNAP_RESULT result
Definition snap_frame.h:54
SNAP_STABLE_ID id
Definition snap_frame.h:46
std::vector< SNAP_STABLE_ID > accepted