Slnkdwf 4.21: coördinaten markers in fac_verify, dwglimits opleveren , fac_verify owner controle van bestanden/folders

svn path=/Slnkdwf/trunk/; revision=46855
This commit is contained in:
Jos Groot Lipman
2020-05-19 10:52:05 +00:00
parent 09bc294ff7
commit 93830c0ef6
14 changed files with 243 additions and 24 deletions

View File

@@ -7,6 +7,10 @@
#define SECURITY_WIN32
#include "Security.h"
#include "accctrl.h"
#include "aclapi.h"
#include "sddl.h"
// CAbout
extern HINSTANCE g_hInstance;
@@ -120,3 +124,118 @@ STDMETHODIMP CAbout::Sleep(LONG pVal)
return S_OK;
}
STDMETHODIMP CAbout::fileOwner(BSTR fname, BSTR* pVal)
{
CString filename(fname);
CString result = "<unknown>";
DWORD dwRtnCode = 0;
PSID pSidOwner = NULL;
BOOL bRtnBool = TRUE;
LPTSTR AcctName = NULL;
LPTSTR DomainName = NULL;
DWORD dwAcctName = 1, dwDomainName = 1;
SID_NAME_USE eUse = SidTypeUnknown;
HANDLE hFile;
PSECURITY_DESCRIPTOR pSD = NULL;
// Get the handle of the file object.
hFile = CreateFile(
filename,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS,
NULL);
// Check GetLastError for CreateFile error code.
if (hFile == INVALID_HANDLE_VALUE) {
return myAtlReportError(GetObjectCLSID(), "\nCAbout::fileOwner('%ls')", (LPCSTR)fname);
}
// Get the owner SID of the file.
dwRtnCode = GetSecurityInfo(
hFile,
SE_FILE_OBJECT,
OWNER_SECURITY_INFORMATION,
&pSidOwner,
NULL,
NULL,
NULL,
&pSD);
CloseHandle(hFile);
// Check GetLastError for GetSecurityInfo error condition.
if (dwRtnCode != ERROR_SUCCESS) {
return myAtlReportError(GetObjectCLSID(), "\nCAbout::fileOwner('%ls') GetSecurityInfo", (LPCSTR)fname);
}
// First call to LookupAccountSid to get the buffer sizes.
bRtnBool = LookupAccountSid(
NULL, // local computer
pSidOwner,
AcctName,
(LPDWORD)&dwAcctName,
DomainName,
(LPDWORD)&dwDomainName,
&eUse);
// Reallocate memory for the buffers.
AcctName = (LPTSTR)GlobalAlloc(GMEM_FIXED, dwAcctName);
// Check GetLastError for GlobalAlloc error condition.
if (AcctName == NULL) {
return myAtlReportError(GetObjectCLSID(), "\nCAbout::fileOwner('%ls') GlobalAlloc", (LPCSTR)fname);
}
DomainName = (LPTSTR)GlobalAlloc(GMEM_FIXED, dwDomainName);
// Check GetLastError for GlobalAlloc error condition.
if (DomainName == NULL) {
return myAtlReportError(GetObjectCLSID(), "\nCAbout::fileOwner('%ls') GlobalAlloc", (LPCSTR)fname);
}
// Second call to LookupAccountSid to get the account name.
bRtnBool = LookupAccountSid(
NULL, // name of local or remote computer
pSidOwner, // security identifier
AcctName, // account name buffer
(LPDWORD)&dwAcctName, // size of account name buffer
DomainName, // domain name
(LPDWORD)&dwDomainName, // size of domain name buffer
&eUse); // SID type
// Check GetLastError for LookupAccountSid error condition.
if (bRtnBool == FALSE) {
DWORD dwErrorCode = 0;
dwErrorCode = GetLastError();
if (dwErrorCode == ERROR_NONE_MAPPED)
{
LPTSTR psz;
ConvertSidToStringSid(pSidOwner, &psz);
result = CString(DomainName) + "\\" + psz;
LocalFree(psz);
}
else
{
return myAtlReportError(GetObjectCLSID(), "\nCAbout::fileOwner('%ls') LookupAccountSid", (LPCSTR)fname);
}
}
else if (bRtnBool == TRUE)
{
// Print the account name.
result = CString(DomainName) + "\\" + AcctName;
}
GlobalFree(DomainName);
GlobalFree(AcctName);
(*pVal) = result.AllocSysString();
return S_OK;
}

View File

@@ -49,6 +49,7 @@ public:
STDMETHOD(get_VersionString)(BSTR* pVal);
STDMETHOD(get_usTimer)(DOUBLE* pVal);
STDMETHOD(Sleep)(LONG pVal);
STDMETHOD(fileOwner)(BSTR fname, BSTR* pVal);
};
OBJECT_ENTRY_AUTO(__uuidof(About), CAbout)

View File

@@ -67,6 +67,7 @@ interface IWhipFile : IDispatch{
[propput, id(24), helpstring("property minContSize")] HRESULT minContSize([in] DOUBLE newVal);
[propget, id(25), helpstring("property AddContour")] HRESULT AddContour([out, retval] ISLNKContour** pVal);
[propget, id(27), helpstring("property vectorDpi")] HRESULT vectorDpi([out, retval] LONG* pVal);
[propget, id(28), helpstring("property DwgLimits")] HRESULT DwgLimits([out, retval] IBoundingBox** pVal);
};
[
object,
@@ -106,6 +107,8 @@ interface IWhip2PNG : IDispatch{
[propget, id(22), helpstring("property LayerCount")] HRESULT LayerCount([out, retval] LONG* pVal);
[propget, id(23), helpstring("property LayerItem")] HRESULT LayerItem([in] ULONG i, [out, retval] BSTR* pVal);
[id(24), helpstring("method SetAntialias")] HRESULT SetAntialias([in] LONG lFactor, [in, defaultvalue(0)] LONG lMethod);
[propget, id(25), helpstring("property markers")] HRESULT markers([out, retval] LONG* pVal);
[propput, id(25), helpstring("property markers")] HRESULT markers([in] LONG newVal);
};
[
object,
@@ -125,6 +128,7 @@ interface IAbout : IDispatch{
[propget, id(7), helpstring("property VersionString")] HRESULT VersionString([out, retval] BSTR* pVal);
[propget, id(8), helpstring("property usTimer")] HRESULT usTimer([out, retval] DOUBLE* pVal);
[id(9), helpstring("method Sleep")] HRESULT Sleep([in] LONG millisec);
[id(10), helpstring("method fileOwner")] HRESULT fileOwner([in] BSTR fname, [out, retval] BSTR* pVal);
};
[
object,

View File

@@ -1,6 +1,6 @@
// Zorg dat versies alfabetisch altijd op elkaar volgen!
#define SLNK_MAJOR_VERSION 4
#define SLNK_MINOR_VERSION 20
#define SLNK_MINOR_VERSION 21
#define SLNK_BUILD_VERSION 0
// Define resource strings

View File

@@ -157,7 +157,9 @@ WT_Result CSLNKSymbolImpl::serialize (WT_File & file, WT_Units & units,
//(((double)m_x * trans.m_x_scale) + trans.m_translate.m_x)
// Het insertionpoint was misschien wel goed maar test ook de eerste
// x-coordinaat van de bounding countour. Die gaf ook wel eens overflow
if (dx * m_SLNKContour.points()[1].m_x + lshift.m_x > INT_MAX)
// Met rotation rekening houden maakt de expressie complexer
// if (m_Rotation == 0 && dx * m_SLNKContour.points()[1].m_x + lshift.m_x > INT_MAX)
if (dx * m_SLNKContour.points()[1].m_x + lshift.m_x > INT_MAX)
{
throw myCString("\nSLNKDWF symbol (%s, key: %s, label: %s) coordinate overflow. Possible solutions:"
"\nDecrease drawing dwf resolution (%.6f)"

View File

@@ -17,14 +17,15 @@ CWhip2PNG::CWhip2PNG()
m_offsetY = 0;
m_dScale = 1.0;
m_lRotation = 0;
m_AAFactor = 1;
m_AAFactor = 1;
m_AAMethod = 0; // ximatran.cpp resample function
// 0 for slow (bilinear) method
// 1 for fast (nearest pixel) method, or
// 1 for fast (nearest pixel) method, or
// 2 for accurate (bicubic spline interpolation) method.
m_RegExp = ".*";
m_forcePaper = FALSE;
m_forceBW = FALSE;
m_markers = 0;
m_forceGray = FALSE;
m_Maximize = FALSE;
m_dwgScale = 0.0;
@@ -73,7 +74,7 @@ STDMETHODIMP CWhip2PNG::SaveAsWMF(BSTR WMFPath)
if (m_forcePaper)
HRESULT res = m_iWhip2DC.set_paperColor(m_paperColor);
res = m-iWhip2DC->Paint(m_forceBW);
res = m-iWhip2DC->Paint(m_forceBW, m_markers);
HENHMETAFILE hMF = CloseEnhMetaFile(myDC);
DeleteEnhMetaFile(hMF);
DeleteDC(myDC);
@@ -87,7 +88,7 @@ STDMETHODIMP CWhip2PNG::SaveAsWMF(BSTR WMFPath)
HRESULT res;
if (m_forcePaper)
res = m_iWhip2DC.put_paperColor(m_paperColor);
res = m_iWhip2DC.Paint(m_forceBW);
res = m_iWhip2DC.Paint(m_forceBW, m_markers);
HMETAFILE hMF = CloseMetaFile(myDC);
CMetafile::WriteMetaFileAsPlaceable(hMF, CSize(m_sizeX, m_sizeY),m_sizeX/4,CString(WMFPath));
@@ -152,7 +153,7 @@ bool CWhip2PNG::CreateCxImage(CxImage *img)
if (m_forcePaper)
m_iWhip2DC.put_paperColor(m_paperColor);
res = res && SUCCEEDED(m_iWhip2DC.Paint(m_forceBW));
res = res && SUCCEEDED(m_iWhip2DC.Paint(m_forceBW, m_markers));
if (!res)myDoTRACE("Paint faalt??");
if (!img->CreateFromHBITMAP(TmpBmp))
@@ -647,6 +648,20 @@ STDMETHODIMP CWhip2PNG::put_forceBW(VARIANT_BOOL newVal)
return S_OK;
}
STDMETHODIMP CWhip2PNG::get_markers(LONG* pVal)
{
(*pVal) = m_markers;
return S_OK;
}
STDMETHODIMP CWhip2PNG::put_markers(LONG newVal)
{
m_markers = newVal;
return S_OK;
}
STDMETHODIMP CWhip2PNG::get_forceGray(VARIANT_BOOL* pVal)
{
(*pVal) = m_forceGray;

View File

@@ -82,16 +82,16 @@ private:
CComQIPtr<ISLNKEvent> m_SLNKEvent; // For when the user has clicked on the drawing
// Will also hold minmax drawing XY?
//CComQIPtr<IWhip2DC> m_iWhip2DC;
CWhip2DCImpl m_iWhip2DC;
// Een van de volgende twee zal gezet zijn
CComQIPtr<IEPlotSection> m_iEPlotSection;
CString m_WhipPath;
void putDWGInfo();
LONG m_sizeX, m_sizeY;
LONG m_offsetX, m_offsetY;
LONG m_AAFactor, m_AAMethod;
@@ -99,6 +99,7 @@ private:
LONG m_lRotation;
COLORREF m_paperColor; BOOL m_forcePaper;
BOOL m_forceBW;
LONG m_markers;
BOOL m_forceGray;
BOOL m_Maximize;
double m_dwgScale;
@@ -115,6 +116,8 @@ public:
STDMETHOD(put_dwgScale)(DOUBLE newVal);
STDMETHOD(get_forceBW)(VARIANT_BOOL* pVal);
STDMETHOD(put_forceBW)(VARIANT_BOOL newVal);
STDMETHOD(get_markers)(LONG* pVal);
STDMETHOD(put_markers)(LONG newVal);
STDMETHOD(get_forceGray)(VARIANT_BOOL* pVal);
STDMETHOD(put_forceGray)(VARIANT_BOOL newVal);
STDMETHOD(get_LayerCount)(LONG* pVal);

View File

@@ -192,6 +192,20 @@ HRESULT CWhipFile::ProcessContouren()
processLabels(); // En verwerk ze daarna
myDoTRACE("\nFound %d polylines, %d contours and %d labels.", xxxx, m_SLNKContouren.GetCount(), m_SLNKLabels.GetCount());
WT_Point3D dwgPt1 = m_contunits.transform(WT_Logical_Point(INT_MIN, INT_MIN));
WT_Point3D dwgPt2 = m_contunits.transform(WT_Logical_Point(INT_MAX, INT_MAX));
CComQIPtr<IDWGPoint> pt;
m_dwgLimits->get_min(&pt);
pt->put_DwgX(dwgPt1.m_x);
pt->put_DwgY(dwgPt1.m_y);
pt.Release();
CComQIPtr<IDWGPoint> pt2;
m_dwgLimits->get_max(&pt2);
pt2->put_DwgX(dwgPt2.m_x);
pt2->put_DwgY(dwgPt2.m_y);
pt2.Release();
m_W2DFile.close(); // closing Input file.
if (m_iEPlotSection) // is er niet bij empty.w2d
@@ -1374,3 +1388,8 @@ STDMETHODIMP CWhipFile::get_vectorDpi(LONG* pVal)
return S_OK;
}
STDMETHODIMP CWhipFile::get_DwgLimits(IBoundingBox** pVal)
{
return m_dwgLimits->QueryInterface(IID_IBoundingBox, (void**)pVal);
}

View File

@@ -39,6 +39,18 @@ END_COM_MAP()
HRESULT FinalConstruct()
{
//
// Maak object m_dwgLimits
//
CComObject<CBoundingBox> *pBoundingBox;
HRESULT hr = CComObject<CBoundingBox>::CreateInstance(&pBoundingBox);
if (FAILED(hr)) return hr;
pBoundingBox->AddRef();
hr = pBoundingBox->QueryInterface(IID_IBoundingBox, (void **)&m_dwgLimits);
pBoundingBox->Release();
if (FAILED(hr)) return hr;
return S_OK;
}
@@ -71,6 +83,7 @@ private:
double m_FontHeight, m_FontHeightSymbols;
CComQIPtr<IEPlotSection> m_iEPlotSection; // Om scope levend te houden
CComQIPtr<IBoundingBox> m_dwgLimits;
myWT_File m_W2DFile;
long m_vdpi;
WT_View m_view; // Initial view
@@ -102,6 +115,7 @@ public:
STDMETHOD(get_minContSize)(DOUBLE* pVal);
STDMETHOD(put_minContSize)(DOUBLE newVal);
STDMETHOD(get_vectorDpi)(LONG* pVal);
STDMETHOD(get_DwgLimits)(IBoundingBox** pVal);
// Voorheen WhipFileState
public:

View File

@@ -167,7 +167,7 @@ CSize &CWhip2DCImpl::get_Size()
return m_State.m_Size;
}
int CWhip2DCImpl::Paint(VARIANT_BOOL forceBW, VARIANT_BOOL markers /* = VARIANT_FALSE */)
int CWhip2DCImpl::Paint(VARIANT_BOOL forceBW, LONG markers /* = 0 */)
{
#ifdef _DEBUG
/// CneutralGDI neutralGDI("CWhip2DCImpl::Paint");
@@ -314,10 +314,6 @@ int CWhip2DCImpl::Paint(VARIANT_BOOL forceBW, VARIANT_BOOL markers /* = VARIANT_
}
#endif
#ifdef _DEBUG
markers = VARIANT_TRUE;
#endif
if (markers)
{
// Toon bij sterk inzoomen een raster van DWF-punten ter referentie
@@ -328,10 +324,32 @@ int CWhip2DCImpl::Paint(VARIANT_BOOL forceBW, VARIANT_BOOL markers /* = VARIANT_
HFONT fnt = CreateFontIndirect(&lf);
HGDIOBJ oldfont = SelectObject(m_State.myDC, fnt);
if (m_State.m_mul > 10.0)
// Het lijkt aantrekkelijk te tonen waar overflow optreedt
// de tussen-DWF is echter al richting origin verplaatst, daarna speelt overflow niet meer
if (markers > 1) // dan altijd tonen
{
CRect clip;
GetClipBox(m_State.myDC,&clip); // Zichtbaar deel op scherm
GetClipBox(m_State.myDC, &clip); // Zichtbaar deel op scherm
for (int x = clip.TopLeft().x; x <= clip.BottomRight().x; x+= markers)
for (int y = clip.TopLeft().y; y <= clip.BottomRight().y; y+= markers)
{
CPoint pt(x, y);
WT_Logical_Point ptl(m_State.LPToDWF(pt));
SetPixel(m_State.myDC, pt.x, pt.y, RGB(128, 128, 128));
// Altijd DWF-coordinaten
CString txt;
txt.Format("%d", ptl.m_x);
TextOut(m_State.myDC, pt.x + 5, pt.y, txt, txt.GetLength());
txt.Format("%d", ptl.m_y);
TextOut(m_State.myDC, pt.x + 5, pt.y + 10, txt, txt.GetLength());
}
}
else if (m_State.m_mul > 10.0)
{
CRect clip;
GetClipBox(m_State.myDC, &clip); // Zichtbaar deel op scherm
WT_Logical_Point topleft(m_State.LPToDWF(clip.TopLeft()));
WT_Logical_Point botright(m_State.LPToDWF(clip.BottomRight()));
@@ -339,18 +357,18 @@ int CWhip2DCImpl::Paint(VARIANT_BOOL forceBW, VARIANT_BOOL markers /* = VARIANT_
for (int y = topleft.m_y; y >= botright.m_y; y--)
{
CPoint pt = m_State.DWFToLP(WT_Logical_Point(x, y));
SetPixel(m_State.myDC, pt.x, pt.y, RGB(128,128,128));
SetPixel(m_State.myDC, pt.x, pt.y, RGB(128, 128, 128));
// Bij nog sterker inzoomen tonen we DWF-coordinaten
if (m_State.m_mul > 80.0)
{
CString txt;
txt.Format("%d", x);
TextOut(m_State.myDC, pt.x+5, pt.y, txt, txt.GetLength());
TextOut(m_State.myDC, pt.x + 5, pt.y, txt, txt.GetLength());
txt.Format("%d", y);
TextOut(m_State.myDC, pt.x+5, pt.y+10, txt, txt.GetLength());
TextOut(m_State.myDC, pt.x + 5, pt.y + 10, txt, txt.GetLength());
}
}
}
}
SelectObject(m_State.myDC, oldfont);
DeleteObject(fnt);

View File

@@ -126,7 +126,7 @@ public:
const CString &RegExp, long sizeX, long sizeY,
VARIANT_BOOL centerImage, VARIANT_BOOL maximize=FALSE,
double dwgScale=0.0);
int Paint(VARIANT_BOOL forceBW, VARIANT_BOOL markers = VARIANT_FALSE);
int Paint(VARIANT_BOOL forceBW, LONG markers = 0);
int Find(LONG findX, LONG findY, BYTE AsMap,
CString &pContourKey, CString &pContourLayer,
CString &pTextLabel, CString &pTextLayer,

View File

@@ -30,8 +30,24 @@ public:
// CW2D2PNG
long myRound(double x) const // Dikke kans dattie zo inline wordt
{
ATLASSERT(x >= LONG_MIN-0.5);
ATLASSERT(x >= LONG_MIN-0.5); // Anno 2020 lijkt de debugger hier niet op te breaken. Het wordt wel gelogd in het immedate window
ATLASSERT(x <= LONG_MAX+0.5);
#ifdef _DEBUG
/*
if (x - 0.5 <= LONG_MIN)
{
return LONG_MIN;
}
if (x + 0.5 >= LONG_MAX)
{
return LONG_MAX;
}
if (!(x >= LONG_MIN - 0.5 && x <= LONG_MAX + 0.5))
{
int x = 1;
}
*/
#endif
if (x >= 0)
return (long) (x+0.5);
return (long) (x-0.5);

View File

@@ -92,7 +92,7 @@ void PaintToDC(HDC dc, CString dwfPath, int nPage,
if (forPrint)
iWhip2DC.put_paperColor(0xFFFFFF); // Altijd wit papier
iWhip2DC.Paint(VARIANT_FALSE,VARIANT_TRUE); // geen bw, met markers
iWhip2DC.Paint(VARIANT_FALSE, 1); // geen bw, auto markers
//SetMapMode(dc, mm);
}
catch (CString &ee)

View File

@@ -1,3 +1,11 @@
V4.21 19-05-2020
- Coordinaat markers kunnen aansturen
- Whipfile ook property DwgLlimits laten opleveren
- About ook fileOwner kunnen opvragen
V4.19 20-08-2019
- fixje labelpositie
V4.19 12-08-2019
- Geen null-pointer exception bij bepalen vectordpi empty.w2d (die
geen plotsection heeft)