|
#include <rxvar.h>
// Traits fo std::map<CString, T> for case-insensive comparison
class NoCase
{
public:
NoCase() {}
bool operator()(const CString &str1, const CString &str2) const
{
return (str1.CompareNoCase(str2) < 0);
}
};
void VarResbufToString(resbuf &rbValue, CString &csVal)
{
switch (rbValue.restype)
{
case RTREAL:
csVal.Format(L"%lf (RTREAL)", rbValue.resval.rreal);
break;/* Real number */
case RTPOINT:
csVal.Format(L"(%lf, %lf) (RTPOINT)"
, rbValue.resval.rpoint[X]
, rbValue.resval.rpoint[Y]
);
break;/* 2D point X and Y only */
case RT3DPOINT:
csVal.Format(L"(%lf, %lf, %lf) (RT3DPOINT)"
, rbValue.resval.rpoint[X]
, rbValue.resval.rpoint[Y]
, rbValue.resval.rpoint[Z]
);
break;/* 3D point - X, Y, and Z */
case RTSHORT:
csVal.Format(L"%d (RTSHORT)", rbValue.resval.rint);
break;/* Short integer */
case RTSTR:
csVal.Format(L"'%s' (RTSTR)", rbValue.resval.rstring);
acutDelString(rbValue.resval.rstring);
break;/* String */
case RTLONG:
csVal.Format(L"%ld", rbValue.resval.rlong);
break;/* Long integer */
case RTENAME:
csVal = L"unexpected: (RTENAME)";
break;//* Entity name */
case RTPICKS:
csVal = L"unexpected: (RTPICKS)";
break;//* Pick set */
case RTORINT:
csVal = L"unexpected: (RTORINT)";
break;//* Orientation */
default:
csVal.Format(L"unexpected: restype=%d", rbValue.restype);
break;
}
}
void getAllAcadVariablesFromCommandGroup(std::map<CString, CString, NoCase> &varMap)
{
AcEdCommandStack *cmdStack = acedRegCmds;
AcEdCommandIterator *it = cmdStack->iterator();
if (it)
{
const AcEdCommand *command=0;
LPCTSTR group = NULL, globalName = NULL;
CString csGroup, csGlobalName;
CString groupPattern(L"ACAD_SETVAR");
int istat;
for (; !it->done(); it->next())
{
if (command = it->command())
{
globalName = command->globalName();
group = it->commandGroup();
csGlobalName = globalName;
csGroup = group;
if (!csGroup.CompareNoCase(groupPattern))
{
struct resbuf rbValue;
CString csVal;
istat = acedGetVar(csGlobalName, &rbValue);
if (istat == RTNORM)
{
VarResbufToString(rbValue, csVal);
CString &csOldVal = varMap[csGlobalName];
if (!csOldVal.IsEmpty())
{
if (csOldVal.CompareNoCase(csVal))
{
acutPrintf(L"\nVariable '%s': Different values!\n"
L"\nOld = '%s'"
L"\nNew = '%s'"
, (LPCWSTR)csOldVal, (LPCWSTR)csVal
);
}
}
csOldVal = csVal;
}
}
}
}
delete it;
}
}
void cmdListAcadVars()
{
AcRxVariablesDictionary *pVarDic = AcRxVariablesDictionary::get();
if (!pVarDic)
return;
CWnd *pParent = acedGetAcadDwgView();
CFileDialog *dia = new CFileDialog(FALSE, _T("txt"), L"AcadVars.txt", OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, _T("*.txt|"), pParent);
if (!dia)
return;
if (dia->DoModal() != IDOK)
return;
CString csPath = dia->GetPathName();
delete dia;
Acad::ErrorStatus es;
const AcStringArray &allVars = pVarDic->getAllNames();
int i, nCount = allVars.length();
resbuf rbValue;
std::map<CString, CString, NoCase> varMap;
for (i = 0; i < nCount; ++i)
{
AcRxVariable *pVar = pVarDic->getVariable(allVars[i]);
CString csName = pVar->name();
CString csVal;
if (pVar)
{
es = pVar->getValue(rbValue);
if (es == Acad::eOk)
VarResbufToString(rbValue, csVal);
else
csVal = L"** error **";
varMap[csName] = csVal;
}
}
getAllAcadVariablesFromCommandGroup(varMap);
CStdioFile file;
if (file.Open(csPath, CFile::typeText | CFile::modeWrite | CFile::modeCreate))
{
CString csLine;
for each (const std::pair<CString, CString> entry in varMap)
{
file.WriteString(entry.first);
file.WriteString(L" = ");
file.WriteString(entry.second);
file.WriteString(L"\n");
}
file.Close();
}
} |
|