Altium C++ SDK 3.0
Loading...
Searching...
No Matches
DXP.Util.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef DXP_UTIL_H_INCLUDED
4#define DXP_UTIL_H_INCLUDED
5
6#include <sstream>
7#include <string>
8#include <vector>
9
10#include "DXP.Types.h"
11#include "DXP.Interfaces.h"
12
13using namespace std;
14using namespace DXP;
15
16/*..................................................................................................*/
18/*..................................................................................................*/
19
20/*..................................................................................................*/
21bool ProcessKeyByClient(WORD keyID);
22/*..................................................................................................*/
23
24/*..................................................................................................*/
26{
27 std::wstring ComputerName;
28 std::wstring UserName;
29 std::wstring ProcessID;
30};
31/*..................................................................................................*/
32
33/*..................................................................................................*/
34bool FileOwnership_IsOwnedByOther (const std::wstring & ADataFileName, std::wstring * AComputerName, std::wstring * AUserName);
35bool FileOwnership_Details (const std::wstring & ADataFileName, TFileOwnershipDetails * ADetails);
36
37void FileOwnership_WarnOwnedByOther (const std::wstring & AFullFileName, const std::wstring & AComputerName, const std::wstring & AUserName, TFileOwnershipWarningLevel AFileOwnershipWarningLevel);
38void FileOwnership_WarnOwnedByOther_Message (const std::wstring & AFullFileName, const std::wstring & AComputerName, const std::wstring & AUserName);
39void FileOwnership_WarnOwnedByOther_Dialog (const std::wstring & AFullFileName, const std::wstring & AComputerName, const std::wstring & AUserName);
40void FileOwnership_ReportAcquisition_Message(const std::wstring & AFullFileName, const std::wstring & AComputerName, const std::wstring & AUserName);
41
42bool OwnershipFileIsDangling(const std::wstring & ALockFileName);
43void FileOwnership_CleanDanglingOwnershipFile(const std::wstring & ADataFileName);
44
45HANDLE FileOwnership_RegisterAcquisition (const std::wstring & ADataFileName);
46HANDLE FileOwnership_UnRegisterAcquisition(const std::wstring & ADataFileName, HANDLE ALockFileHandleInteger);
47std::wstring GetOwnershipFileName(const std::wstring & ADataFileName);
48/*..................................................................................................*/
49
50/*..................................................................................................*/
51std::wstring GetLocalComputerName();
52std::wstring GetLocalUserName();
54std::wstring GetCurrentProductName();
55/*..................................................................................................*/
56
57/*..................................................................................................*/
58std::wstring ExtractFilePath(const std::wstring & FileName);
59std::wstring ExtractFileDir (const std::wstring & FileName);
60std::wstring ExtractFileName(const std::wstring & FileName);
61std::wstring ExtractFileExt (const std::wstring &FileName);
62std::wstring ChangeFileExt(const std::wstring & FileName, const std::wstring & Extension);
63/*..................................................................................................*/
64
65/*..................................................................................................*/
66std::wstring AddSlash(const std::wstring & Str, const WCHAR ASlash = L'\\');
67/*..................................................................................................*/
68
69/*..................................................................................................*/
70void ShowWarning (const std::wstring & Text, const std::wstring & Caption = L"");
71void ShowInfo (const std::wstring & Text, const std::wstring & Caption = L"");
72void ShowError (const std::wstring & Text, const std::wstring & Caption = L"");
73void ShowMessage (const std::wstring & Text);
74bool ConfirmOKCancel (const std::wstring & Text);
75bool ConfirmNoYes (const std::wstring & Text);
76int ConfirmNoYesCancel (const std::wstring & Text);
77bool ConfirmNoYesWithCaption(const std::wstring & Caption, const std::wstring & Text);
78/*..................................................................................................*/
79
80/*..................................................................................................*/
81bool FileExists(const std::wstring & FileName);
82HANDLE FileOpen (const std::wstring & FileName, unsigned int Mode);
83void FileClose (HANDLE handle);
84/*..................................................................................................*/
85
86/*..................................................................................................*/
87IOptionsReader* ServerOptionsReader(const std::wstring & serverName);
88IOptionsWriter* ServerOptionsWriter(const std::wstring & serverName);
89/*..................................................................................................*/
90
91/*..................................................................................................*/
92wstring GetTime();
93double Now();
94double EncodeDate(WORD Year, WORD Month, WORD Day);
95double EncodeTime(WORD Hour, WORD Min, WORD Sec, WORD MSec);
96/*..................................................................................................*/
97
98/*..................................................................................................*/
99class WStringVector : public std::vector<std::wstring>
100{
101public:
103
104 bool LoadFromFile(const std::wstring & FileName);
105 bool SaveToFile (const std::wstring & FileName);
106 void Sort();
107
108 WStringVector(bool ACaseSensitive = true) : CaseSensitive(ACaseSensitive) {}
109};
110/*..................................................................................................*/
111
112/*..................................................................................................*/
114{
115public:
116 bool operator() (const wstring& a, const wstring& b) const
117 {
118 return wcscmp(a.c_str(), b.c_str()) < 0;
119 }
120};
121/*..................................................................................................*/
122
123/*..................................................................................................*/
125{
126public:
127 bool operator() (const wstring& a, const wstring& b) const
128 {
129 return _wcsicmp(a.c_str(), b.c_str()) < 0;
130 }
131};
132/*..................................................................................................*/
133
134/*..................................................................................................*/
137/*..................................................................................................*/
138
139/*..................................................................................................*/
141/*..................................................................................................*/
142
143/*..................................................................................................*/
144void RunCommand (const std::wstring & IdString, std::wstring SpecialParameter);
145void RunCommand (const std::wstring & IdString, std::wstring SpecialParameter, IServerDocumentView * const DocumentView);
146/*..................................................................................................*/
147
148/*..................................................................................................*/
149void MessageRouter_SendCommandToModule(const wstring & AProcess, wstring * AParameters, IServerDocumentView * const DocumentView);
150/*..................................................................................................*/
151
152/*..................................................................................................*/
153std::wstring & LTrim(std::wstring & s); // trim from start
154std::wstring & RTrim(std::wstring & s); // trim from end
155std::wstring & Trim(std::wstring & s); // trim from both ends
156
157std::wstring & UpperCase(std::wstring & s);
158
159std::wstring StringReplace(const std::wstring & S, const std::wstring & OldPattern, const std::wstring & NewPattern, bool ReplaceAll = true, bool IgnoreCase = false);
160
161vector<wstring> &Split(const wstring &s, wchar_t delim, vector<wstring> &elems);
162vector<wstring> Split(const wstring &s, wchar_t delim);
163/*..................................................................................................*/
164
165/*..................................................................................................*/
166std::wstring ToWString(float val);
167std::wstring ToWString(double val);
168
169template <typename T> std::wstring ToWString(T val)
170{
171 std::wstringstream ss;
172 ss<<val;
173 return std::wstring(ss.str());
174}
175/*..................................................................................................*/
176
177/*..................................................................................................*/
178std::wstring GetTemporaryFileName();
179std::wstring GetTemporaryFileName(const std::wstring & BaseFolder);
180/*..................................................................................................*/
181
182/*..................................................................................................*/
183bool GetString_PrefixAndIndex(const std::wstring & Str, const std::wstring & Prefix, int * Index);
184/*..................................................................................................*/
185
186/*..................................................................................................*/
187bool StringStartsWithButNotEqual(const std::wstring & AString, const std::wstring & SubString);
188/*..................................................................................................*/
189
190/*..................................................................................................*/
191void StatusBar_SetState(int Index, const std::wstring & S);
192std::wstring StatusBar_GetState(int Index);
196/*..................................................................................................*/
197
198/*..................................................................................................*/
199//normal progress in status bar, normal progress in Win7 taskbar button
200void Percent_Init(const std::wstring & InitialString, int TotalCount);
202void Percent_UpdateByNumber(int AmountToIncrement);
204
205//marquee progress in status bar, marquee progress in Win7 taskbar button
206void Percent_BeginUndeterminedOperation(const std::wstring & InitialString);
208
209//status bar - N/A, marquee progress in Win7 taskbar button
210void Percent_BeginComplexOperation(const std::wstring & InitialString);
212/*..................................................................................................*/
213
214/*..................................................................................................*/
215IServerDocument * CreateNewDocumentFromDocumentKind(const std::wstring & DocumentKind);
216/*..................................................................................................*/
217
218/*..................................................................................................*/
219double round(double num);
220/*..................................................................................................*/
221
222/*..................................................................................................*/
223double CoordToMils(int C);
224double CoordToMMs (int C);
225
226int MilsToCoord (double M);
227double MilsToRealCoord(double M);
228int MMsToCoord (double M);
229double MMsToRealCoord (double M);
230/*..................................................................................................*/
231
232/*..................................................................................................*/
233double DegreesToRadians(double Angle);
234double RadiansToDegrees(double R);
235/*..................................................................................................*/
236
237#endif // DXP_UTIL_H_INCLUDED
void RunCommand(const std::wstring &IdString, std::wstring SpecialParameter)
std::wstring GetLocalComputerName()
std::wstring & UpperCase(std::wstring &s)
bool OwnershipFileIsDangling(const std::wstring &ALockFileName)
int ConfirmNoYesCancel(const std::wstring &Text)
bool ProcessKeyByClient(WORD keyID)
void FileOwnership_CleanDanglingOwnershipFile(const std::wstring &ADataFileName)
IOptionsReader * ServerOptionsReader(const std::wstring &serverName)
void FileOwnership_ReportAcquisition_Message(const std::wstring &AFullFileName, const std::wstring &AComputerName, const std::wstring &AUserName)
bool FileExists(const std::wstring &FileName)
void FileOwnership_WarnOwnedByOther_Dialog(const std::wstring &AFullFileName, const std::wstring &AComputerName, const std::wstring &AUserName)
double DegreesToRadians(double Angle)
HANDLE FileOwnership_RegisterAcquisition(const std::wstring &ADataFileName)
void ShowWarning(const std::wstring &Text, const std::wstring &Caption=L"")
IClientAPI_Interface * ClientAPI()
double MMsToRealCoord(double M)
bool GetString_PrefixAndIndex(const std::wstring &Str, const std::wstring &Prefix, int *Index)
std::wstring ToWString(float val)
void FileOwnership_WarnOwnedByOther_Message(const std::wstring &AFullFileName, const std::wstring &AComputerName, const std::wstring &AUserName)
void Percent_Update()
double CoordToMMs(int C)
std::wstring & LTrim(std::wstring &s)
HANDLE FileOpen(const std::wstring &FileName, unsigned int Mode)
double EncodeDate(WORD Year, WORD Month, WORD Day)
bool FileOwnership_IsOwnedByOther(const std::wstring &ADataFileName, std::wstring *AComputerName, std::wstring *AUserName)
double EncodeTime(WORD Hour, WORD Min, WORD Sec, WORD MSec)
void Percent_EndUndeterminedOperation()
wstring GetTime()
void ShowMessage(const std::wstring &Text)
void ShowInfo(const std::wstring &Text, const std::wstring &Caption=L"")
std::wstring StatusBar_GetState(int Index)
void StatusBar_SetStateDefault()
IOptionsWriter * ServerOptionsWriter(const std::wstring &serverName)
std::wstring GetOwnershipFileName(const std::wstring &ADataFileName)
void Percent_Init(const std::wstring &InitialString, int TotalCount)
HANDLE FileOwnership_UnRegisterAcquisition(const std::wstring &ADataFileName, HANDLE ALockFileHandleInteger)
IClient * GetClientInterface()
std::wstring ExtractFileDir(const std::wstring &FileName)
double MilsToRealCoord(double M)
std::wstring ExtractFilePath(const std::wstring &FileName)
std::wstring ExtractFileExt(const std::wstring &FileName)
std::wstring & RTrim(std::wstring &s)
std::wstring ChangeFileExt(const std::wstring &FileName, const std::wstring &Extension)
double RadiansToDegrees(double R)
void StatusBar_PushStatus()
void ShowError(const std::wstring &Text, const std::wstring &Caption=L"")
double round(double num)
std::wstring ExtractFileName(const std::wstring &FileName)
bool IsAltiumViewer()
std::wstring GetTemporaryFileName()
bool FileOwnership_Details(const std::wstring &ADataFileName, TFileOwnershipDetails *ADetails)
void Percent_UpdateByNumber(int AmountToIncrement)
void MessageRouter_SendCommandToModule(const wstring &AProcess, wstring *AParameters, IServerDocumentView *const DocumentView)
int MilsToCoord(double M)
void Percent_EndComplexOperation()
void Percent_BeginUndeterminedOperation(const std::wstring &InitialString)
void StatusBar_SetState(int Index, const std::wstring &S)
void FileOwnership_WarnOwnedByOther(const std::wstring &AFullFileName, const std::wstring &AComputerName, const std::wstring &AUserName, TFileOwnershipWarningLevel AFileOwnershipWarningLevel)
void Percent_Finish()
double Now()
int MMsToCoord(double M)
std::wstring StringReplace(const std::wstring &S, const std::wstring &OldPattern, const std::wstring &NewPattern, bool ReplaceAll=true, bool IgnoreCase=false)
void Percent_BeginComplexOperation(const std::wstring &InitialString)
std::wstring GetCurrentProcessIdString()
void FileClose(HANDLE handle)
void StatusBar_PopStatus()
std::wstring AddSlash(const std::wstring &Str, const WCHAR ASlash=L'\\')
std::wstring GetCurrentProductName()
vector< wstring > & Split(const wstring &s, wchar_t delim, vector< wstring > &elems)
std::wstring GetLocalUserName()
bool ConfirmOKCancel(const std::wstring &Text)
bool ConfirmNoYes(const std::wstring &Text)
double CoordToMils(int C)
bool StringStartsWithButNotEqual(const std::wstring &AString, const std::wstring &SubString)
std::wstring & Trim(std::wstring &s)
IServerDocument * CreateNewDocumentFromDocumentKind(const std::wstring &DocumentKind)
bool ConfirmNoYesWithCaption(const std::wstring &Caption, const std::wstring &Text)
std::wstring SpecialFolder_MyDesigns()
Definition DXP.Util.h:125
bool operator()(const wstring &a, const wstring &b) const
Definition DXP.Util.h:127
Definition DXP.Util.h:114
bool operator()(const wstring &a, const wstring &b) const
Definition DXP.Util.h:116
WStringVector(bool ACaseSensitive=true)
Definition DXP.Util.h:108
bool CaseSensitive
Definition DXP.Util.h:102
bool SaveToFile(const std::wstring &FileName)
bool LoadFromFile(const std::wstring &FileName)
Definition DXP.AbstractClasses.h:16
TFileOwnershipWarningLevel
Definition DXP.Types.h:80
Definition DXP.Interfaces.h:2004
Definition DXP.Interfaces.h:1467
Definition DXP.Interfaces.h:1058
Definition DXP.Interfaces.h:1073
Definition DXP.Interfaces.h:715
Definition DXP.Interfaces.h:764
Definition DXP.Util.h:26
std::wstring UserName
Definition DXP.Util.h:28
std::wstring ProcessID
Definition DXP.Util.h:29
std::wstring ComputerName
Definition DXP.Util.h:27