AGXDynamics  2.31.1.0
ScriptIDEAutocomplete.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 
18 #pragma once
19 #ifndef AGXPYTHON_SCRIPTIDEAUTOCOMPLETE_H
20 #define AGXPYTHON_SCRIPTIDEAUTOCOMPLETE_H 1
21 
22 #include <agx/config/AGX_USE_PYTHON.h>
23 
24 #if AGX_USE_PYTHON()
25 
26 #include <agxPython/export.h>
27 
28 #include <agx/Referenced.h>
29 
31 
32 #include <thread>
33 #include <mutex>
34 #include <vector>
35 #include <agx/HashTable.h>
36 
37 namespace agxPython
38 {
39 
40  class ScriptIDE;
41  AGX_DECLARE_POINTER_TYPES(ScriptIDEAutocompleteCollection);
42  class AGXPYTHON_EXPORT ScriptIDEAutocompleteCollection : public agxPython::ScriptIDEDataCollection
43  {
44  public:
45 
46  friend class ScriptIDEAutocomplete;
47 
48  enum ItemAttribute
49  {
50  Category = 0,
51  Type,
52  Name,
53  FullName,
54  ModuleName,
55  IsEnabled,
56  Docstring,
57  Completion,
58  NumberOfAttributes,
59  };
60 
61  class AGXPYTHON_EXPORT Item : public agxPython::ScriptIDEData
62  {
63 
64  public:
65 
66  Item();
67 
68  // Copy constructor
69  Item(const Item& copy);
70 
71  Item(void* jediObject, ScriptIDEAutocompleteCollection *collection);
72 
73  virtual agx::String str() const override;
74 
75  virtual agx::String type() const override {
76  return "AutocompleteItem";
77  }
78 
79  virtual bool isGood() const override;
80 
81  protected:
82 
83  virtual ~Item();
84 
85  private:
86 
87  bool m_isGood;
88 
89  };
90  typedef agx::ref_ptr<Item> ItemRef;
91  typedef agx::Vector< ItemRef > ItemRefVector;
92 
93  ScriptIDEAutocompleteCollection();
94 
95  bool add(ScriptIDEDataRef item) override;
96 
97  ItemRefVector getItems();
98 
99  protected:
100 
101  void addToDocstringHash(const agx::String& key, const agx::String& value);
102  agx::String getFromDocstringHash(const agx::String& key) const;
103 
104 
105  virtual ~ScriptIDEAutocompleteCollection();
106 
107  typedef agx::HashTable<agx::String, agx::String> StringHashTable;
108  StringHashTable m_cached_docstring;
109 
110 
111 
112  private:
113 
114  std::mutex m_lock;
115 
116  };
117 
118  AGX_DECLARE_POINTER_TYPES(ScriptIDEAutocomplete);
119  class AGXPYTHON_EXPORT ScriptIDEAutocomplete : public agx::Referenced
120  {
121 
122  public:
123 
124  friend class ScriptIDE;
125  class JediThread;
126 
127  ScriptIDEAutocomplete();
128 
129  virtual bool onUpdate(const agx::String& sourceCode) = 0;
130 
131  ScriptIDE* getIDE();
132 
133  ScriptIDEAutocompleteCollection* getCollection();
134 
135  static void preloadMomentumModules();
136 
137  protected:
138 
139  virtual ~ScriptIDEAutocomplete();
140 
141  private:
142 
143  void refresh(bool readOnly, bool scopeChange);
144 
145  JediThread* m_worker;
146 
147  ScriptIDE* m_ide;
148 
149  ScriptIDEAutocompleteCollectionRef m_suggested;
150  };
151 
152 }
153 
154 #endif
155 
156 #endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Base class providing referencing counted objects.
Definition: Referenced.h:113
Templated vector class.
Definition: Vector.h:52
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
Inheritance with partial specialization due to bug with ref_ptr containers.
#define AGXPYTHON_EXPORT
GLenum type
Definition: gl.h:5539