Horizon
searcher.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/uuid_path.hpp"
4 #include <set>
5 #include <list>
6 
7 namespace horizon {
8 class Searcher {
9 public:
10  enum class Type {
11  SYMBOL_PIN,
12  TEXT,
13  SYMBOL_REFDES,
14  SYMBOL_MPN,
15  NET_LABEL,
16  POWER_SYMBOL,
17  BUS_RIPPER,
18  PAD,
19  PACKAGE_REFDES,
20  PACKAGE_MPN
21  };
22 
23  class TypeInfo {
24  public:
25  TypeInfo(ObjectType ot);
26 
27  TypeInfo(const std::string &n, ObjectType ot = ObjectType::INVALID)
28  : name(n), name_pl(name + "s"), object_type(ot)
29  {
30  }
31  TypeInfo(const std::string &n, const std::string &n_pl, ObjectType ot = ObjectType::INVALID)
32  : name(n), name_pl(n_pl), object_type(ot)
33  {
34  }
35  const std::string name;
36  const std::string name_pl;
37  const ObjectType object_type;
38  };
39 
40  static const std::map<Type, TypeInfo> &get_type_info();
41  static const TypeInfo &get_type_info(Type type);
42 
43  class SearchQuery {
44  public:
45  void set_query(const std::string &q);
46  bool is_valid() const;
47  const std::string &get_query() const;
48  bool matches(const std::string &haystack) const;
49  std::set<Type> types;
50  std::pair<Coordf, Coordf> area_visible;
51  bool exact = false;
52 
53  private:
54  std::string query;
55  };
56 
57  class SearchResult {
58  public:
59  SearchResult(Type ty, const UUID &uu) : type(ty), path(uu)
60  {
61  }
62  SearchResult(Type ty, const UUID &uu, const UUID &uu2) : type(ty), path(uu, uu2)
63  {
64  }
65  Type type;
66  UUIDPath<2> path;
67  Coordi location;
68  UUID sheet;
69  bool selectable = false;
70  };
71 
72  virtual std::list<SearchResult> search(const SearchQuery &q) = 0;
73  virtual std::set<Type> get_types() const = 0;
74  virtual std::string get_display_name(const SearchResult &r) = 0;
75 
76  virtual ~Searcher()
77  {
78  }
79 
80 protected:
81  void sort_search_results(std::list<SearchResult> &results, const SearchQuery &q);
82 };
83 } // namespace horizon
Definition: searcher.hpp:43
Definition: searcher.hpp:57
Definition: searcher.hpp:23
Definition: searcher.hpp:8
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16