WSF
Project.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef PROJECT_HPP
13#define PROJECT_HPP
14
15#include <memory>
16#include <string>
17#include <vector>
18
19#include <QMetaType>
20#include <QObject>
21#include <QString>
22
23#include "ScriptDebugger.hpp"
24#include "TerrainMonitor.hpp"
25#include "UtCalendar.hpp"
26#include "UtCallback.hpp"
27#include "UtCallbackHolder.hpp"
28#include "UtPath.hpp"
29#include "UtReferenceTracked.hpp"
30#include "UtWallClock.hpp"
31#include "ViExport.hpp"
32
33class UtQtXmlWriter;
34class UtQtXmlReader;
35
36class QAction;
37class QMenu;
38class UtTextDocument;
39class UtTextDocumentRange;
40class ViFileItem;
41class WsfPProxy;
42class WsfPProxyNode;
43class WsfPProxyPath;
44
45namespace wizard
46{
47class AttributeSet;
49class Editor;
50class ParseResults;
52class ParseWorker;
56class ProxyChange;
57class ProxyHash;
58class RevisionStore;
59class TextSource;
60class TextSourceCache;
61class WsfExe;
62class XML_Context;
63
65class VI_EXPORT Project : public QObject, public UtReferenceTracked
66{
67 Q_OBJECT
68
69public:
70 friend class ParseWorker;
71 friend class ProjectWorkspace;
72
73 typedef UtCallbackN<void()> ParseCompleteCallback;
74
75 explicit Project(ProjectWorkspace* aWorkspacePtr);
76 Project(const Project&) = delete;
77 Project(Project&&) = default;
78 Project& operator=(const Project&) = delete;
79 Project& operator=(Project&&) = default;
80 ~Project() override;
81
82 static Project* Instance();
83
84 QString Name() const;
85
87
88 void AddComponent(const std::string& aName, std::unique_ptr<ProjectComponent> aComponent);
89
90 ProjectComponent* FindComponent(const std::string& aName);
91
94 const UtPath& ProjectDirectory() const { return mProjectDirectory; }
95 bool SetProjectLocation(const UtPath& aProjDirPath, const UtPath& aProjFilePath);
96 bool SetProjectDirectory(const UtPath& aPath);
97 bool SetProjectFilePath(const UtPath& aPath);
98 long long GetMinimumSequenceNumber();
99
100 AttributeSet* FindOptions(const WsfPProxyNode& aNode);
101 AttributeSet* FindOptions(const WsfPProxyPath& aPath);
102 AttributeSet* GetOptions(const WsfPProxyNode& aNode);
103
105 std::vector<UtPath> MapSearchPath() const;
106
108
110 UtCallbackListN<void(bool)> ParseUpdated;
111
114 UtCallbackListN<void(bool)> ParseUpdatedDeferred;
115
116 UtCallbackListN<void()> MainFileListChange;
117 static UtCallbackListN<void(Project*)> ProjectClosing;
118 static UtCallbackListN<void(Project*)> RegisterComponents;
119
120 void GotoRange(const UtTextDocumentRange& aRange);
121 Editor* GotoFile(UtTextDocument* aSourcePtr, bool aRecordLocation = false);
122 Editor* GotoFile(const std::string& aFilePath, bool aRecordLocation = true);
123
124 void WaitForParsing();
125 void SaveAll(bool aSkipProject = true);
126 void TriggerReparse();
127 void InvalidateScenario(bool aInvalidateProxy = false);
128 void FindIncludes(TextSource* aSourcePtr);
129
130 bool SourceReloaded(TextSource* aSourcePtr);
131
132 ProjectWorkspace* GetWorkspace() const { return mWorkspacePtr; }
133
134 const std::string& GetMapItemsXML() const { return mMapItemsXML; }
135 void SetMapItemsXML(const std::string& aXml) { mMapItemsXML = aXml; }
136
137 const std::vector<UtPath>& GetStartupFiles();
138 void SetStartupFiles(const std::vector<UtPath>& aMainFiles);
139 const std::vector<UtPath>& GetProjectDirectories() const { return mProjectDirectories; }
140
141
142 bool AddProjectDirectory(const UtPath& aPath);
143 void RemoveProjectDirectory(const UtPath& aPath);
144 bool IsDirectoryInProject(const UtPath& aPath) const;
145 void ShowSettings();
146 void SetWorkingDirectory(const UtPath& aPath);
147 WsfExe* GetExe() const;
148 void SetExe(WsfExe* aExePtr, bool aEmit);
149 void SetCommandLineArgs(const QString& aArgs);
150 static QString GetDefaultCommandLineArgs();
151 void ExeUpdated(WsfExe* aExePtr);
152 void WaitForAllParsing();
153 ParseResults* TakeParseResults();
154 bool IncludesFile(TextSource* aSourcePtr);
155 bool IncludesStartupFile(TextSource* aSourcePtr);
156 void GiveParseResults();
157 void ProxyReady(std::unique_ptr<WsfPProxy> aProxy, std::unique_ptr<ProxyHash> aProxyHashPtr);
158 void ExportProjectAction();
159 ParseWorker* GetParseWorker() { return mParseWorker; }
160 void InitParseResults();
161 ParseCompleteCallback* ExecuteWhenParseComplete(ParseCompleteCallback* aCallbackPtr);
162 const UtPath& WorkingDirectory() const;
163 bool ParseIsUpToDate() const { return mParseResultsPtr != nullptr; }
166 double GetLastGrammarParseTime() const noexcept { return mLastGrammarParseTime; }
169 double GetLastInputParseTime() const noexcept { return mLastInputParseTime; }
172 double GetLastProxyDeserializeTime() const noexcept { return mLastProxyDeserializeTime; }
175 double GetLastProxyMergeGUI_Time() const noexcept { return mLastProxyMergeGUI_Time; }
176 QString GetCommandLineArgs() const { return mCmdLineArgs; }
177 ParseResults* GetParseResults() { return mParseResultsPtr; }
178 ParseResultsTiny* TinyParseResults() { return mCurrentTinyResultsPtr; }
179 ParseResults* WaitForParseResults() const;
180 void ToXML(XML_Context& aContext) const;
181 bool FromXML(XML_Context& aContext);
182 bool FromXML_StartupFile(XML_Context& aContext);
183 bool SaveAs();
184 bool SaveProject();
185 bool ProjectFilePath(UtPath& aFilePath) const;
186 bool CloseProject(bool aForce = false);
187 CacheSourceProvider* SourceProvider() const { return mSourceProviderPtr; }
188 WsfPProxy* Proxy() const;
189 void HandleProxyNodeMoved(const WsfPProxyNode&, const WsfPProxyNode&);
190 void AddProjectDirectoryBrowse();
191 void ShowRevisionManager();
192 bool OpenFile(const std::string& aFilePath);
193 bool OpenFileInTextEditor(const std::string& aFilePath);
194 QString GetCmdLineArgs() const { return mCmdLineArgs; }
195 void OpenAction();
196
197 void BuildUpContextMenu(QMenu& aMenu);
198
199 void UpdateProxyEpoch(const wizard::ProxyChange& aProxyChange);
200 void UpdateProxyEpoch();
201 UtCalendar GetStartDateTime() const { return mEpoch; }
202
203signals:
206 void Closed();
207
208public slots:
210
211private:
212 std::string GetXmlText() const;
213 void UndoCommand();
214 void RedoCommand();
215 void WriteStartDocument(UtQtXmlWriter& aWriter) const;
216 void WriteEndDocument(UtQtXmlWriter& aWriter) const;
218 void P_CompleteGrammarParsing() noexcept;
220 void P_GrammarParsingStarted() noexcept;
222 void P_CompleteInputParsing() noexcept;
224 void P_InputParsingStarted() noexcept;
226 void P_CompleteProxyDeserialize() noexcept;
228 void P_NotifyParseUpdated() noexcept;
230 void P_ProxyDeserializeStarted() noexcept;
232 void P_CompleteProxyMergeGUI() noexcept;
234 void P_ProxyMergeGUI_Started() noexcept;
239 void P_ParsingAborted() noexcept;
244 void P_CompleteAllParsing() noexcept;
245 bool RequestClose(bool aForce = false);
246 QAction* GoToLocationAction(const UtTextDocumentRange& aRange);
247 void DeferUpdate(bool aFullyReparsed);
248 void FullUpdate();
249 void CleanUpFileList();
250 void Reparse();
251 QString ConstructTitle();
252
253 friend class ProjectParseThread;
254
256 UtPath mProjectDirectory;
257 std::vector<UtPath> mProjectDirectories;
258 std::vector<UtPath> mStartupFiles;
259
261 CacheSourceProvider* mSourceProviderPtr;
262 ProjectWorkspace* mWorkspacePtr;
263 UtCallbackHolder mUtCallbacks;
264
266 bool mQuitting;
267
268 UtPath mProjectFilePath;
269 std::string mLoadedXML;
270 // This holds the XML configuration of the map related items
271 // This is updated when the map window is closed because those
272 // visual items are destroyed at that time. Opening the map window
273 // requires re-parsing this XML data
274 std::string mMapItemsXML;
275
276 UtCallbackListN<void()> OneTimeParseComplete;
277 UtPath mWorkingDirectory;
278 std::string mExePath;
279 QString mCmdLineArgs;
280 std::unique_ptr<AttributeSet> mProxyAttributesRoot;
281 RevisionStore* mRevisionStore;
282
283 using ComponentMap = std::map<std::string, std::unique_ptr<ProjectComponent>>;
284 ComponentMap mComponents;
285
287 // Parse results management --
288 // Because the parsing is done in another thread, and in multiple phases,
289 // managing the parse results isn't as simple as copying the results.
290 //
291 // When parsing begins, a limited set of data is available for access,
292 // called the Tiny parse results. When the parse phase is complete,
293 // the full parse results structure is available.
294 // The proxy data is computed in a subsequent parse phase, and
295 // added to the parse results when that phase is complete.
297
299 ParseResults* mParseResultsPtr;
300
302 ParseResults* mParseResultsPrivatePtr;
303
305 ParseResultsTiny* mParseResultsTinyPtr;
306
307 // Points to the latest 'tiny' parse results
308 ParseResultsTiny* mCurrentTinyResultsPtr;
309
310 ParseWorker* mParseWorker;
323 volatile bool mParsingAllComplete;
324
325 std::unique_ptr<TerrainMonitor> mTerrainMonitor{nullptr};
326
327 bool mEpochListenerSetup{false};
328 UtCalendar mEpoch;
329
333 double mLastGrammarParseTime{0.0};
335 bool mGrammarParsingComplete{false};
337 double mLastInputParseTime{0.0};
339 bool mInputParsingComplete{false};
341 bool mProxyDeserializeComplete{false};
343 double mLastProxyDeserializeTime{0.0};
345 bool mProxyMergeGUI_Complete{false};
347 double mLastProxyMergeGUI_Time{0.0};
349 UtWallClock mParseTimer;
350};
351} // namespace wizard
352
354
355#endif
Q_DECLARE_METATYPE(wizard::ProjectWorkspace *)
#define VI_EXPORT
Definition ViExport.hpp:38
Definition WsfPProxyNode.hpp:60
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
Definition WsfPProxy.hpp:32
Definition AttributeSet.hpp:32
Provides sources to the WsfParser from the TextSourceCache instead of the files directly.
Definition TextSourceCache.hpp:57
Definition Editor.hpp:57
Defines a subset of parse results which stay valid while computing the new parse results.
Definition ParseResults.hpp:118
Provides access to the results of parsing the WSF inputs.
Definition ParseResults.hpp:147
Definition ParseWorker.hpp:50
Definition ProjectComponent.hpp:21
Thread for parsing the WSF source in the background.
Definition ProjectParseThread.hpp:23
Definition ProjectWorkspace.hpp:48
A WSF 'project'. Manages WSF sources files in a WSF project.
Definition Project.hpp:66
UtCallbackListN< void()> MainFileListChange
Definition Project.hpp:116
static UtCallbackListN< void(Project *)> ProjectClosing
Definition Project.hpp:117
Project(const Project &)=delete
RevisionStore & GetRevisionStore()
Definition Project.cpp:1510
const std::string & GetMapItemsXML() const
Definition Project.hpp:134
UtCalendar GetStartDateTime() const
Definition Project.hpp:201
QString GetCmdLineArgs() const
Definition Project.hpp:194
void EventPipeRunConfigurationChanged()
void AddComponent(const std::string &aName, std::unique_ptr< ProjectComponent > aComponent)
Definition Project.cpp:1634
double GetLastInputParseTime() const noexcept
Definition Project.hpp:169
Editor * GotoFile(UtTextDocument *aSourcePtr, bool aRecordLocation=false)
Definition Project.cpp:182
QString Name() const
Definition Project.cpp:116
static Project * Instance()
Definition Project.cpp:111
Project(Project &&)=default
friend class ProjectParseThread
Definition Project.hpp:253
UtCallbackListN< void(bool)> ParseUpdatedDeferred
Definition Project.hpp:114
void GotoRange(const UtTextDocumentRange &aRange)
Definition Project.cpp:162
void ShowStartupFileDialog()
Definition Project.cpp:1265
bool SourceReloaded(TextSource *aSourcePtr)
Definition Project.cpp:145
void TriggerReparse()
Definition Project.cpp:329
const UtPath & ProjectDirectory() const
Definition Project.hpp:94
const std::vector< UtPath > & GetProjectDirectories() const
Definition Project.hpp:139
static UtCallbackListN< void(Project *)> RegisterComponents
Definition Project.hpp:118
ParseResultsTiny * TinyParseResults()
Definition Project.hpp:178
QString GetCommandLineArgs() const
Definition Project.hpp:176
friend class ProjectWorkspace
Definition Project.hpp:71
void ParseUpdatedFull()
ProjectComponent * FindComponent(const std::string &aName)
Definition Project.cpp:1624
ProjectWorkspace * GetWorkspace() const
Definition Project.hpp:132
ParseResults * GetParseResults()
Definition Project.hpp:177
UtCallbackN< void()> ParseCompleteCallback
Definition Project.hpp:73
friend class ParseWorker
Definition Project.hpp:70
std::vector< UtPath > MapSearchPath() const
Paths to be searched for map data relating to this project.
TextSourceCache & GetSourceCache()
Definition Project.cpp:1362
double GetLastProxyMergeGUI_Time() const noexcept
Definition Project.hpp:175
void WaitForParsing()
Waits until the parsing thread is complete. This should only be called from the main thread.
Definition Project.cpp:157
void InvalidateScenario(bool aInvalidateProxy=false)
Definition Project.cpp:334
Project & operator=(Project &&)=default
double GetLastProxyDeserializeTime() const noexcept
Definition Project.hpp:172
Project(ProjectWorkspace *aWorkspacePtr)
Definition Project.cpp:81
UtCallbackListN< void(bool)> ParseUpdated
Called whenever a parse is complete, as many as once per source modification.
Definition Project.hpp:110
CacheSourceProvider * SourceProvider() const
Definition Project.hpp:187
void SetMapItemsXML(const std::string &aXml)
Definition Project.hpp:135
void SaveAll(bool aSkipProject=true)
Definition Project.cpp:300
Project & operator=(const Project &)=delete
bool ParseIsUpToDate() const
Definition Project.hpp:163
ParseWorker * GetParseWorker()
Definition Project.hpp:159
void FindIncludes(TextSource *aSourcePtr)
Definition Project.cpp:412
double GetLastGrammarParseTime() const noexcept
Definition Project.hpp:166
Records a change to proxy data.
Definition ProxyChange.hpp:21
Definition ProxyMerge.hpp:56
A high-level interface into the Change History database.
Definition RevisionStore.hpp:38
Definition TerrainMonitor.hpp:25
Definition TextSourceCache.hpp:35
Definition TextSource.hpp:48
Definition WsfExe.hpp:46
Definition XML_Context.hpp:58
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
Definition Runner.hpp:22
Copyrights Multiple, All Rights Reserved