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