#include "stdafx.h" #include "OTSSampleClr.h" #include namespace OTSCLRINTERFACE { //using namespace Newtonsoft::Json ::Linq; COTSSampleClr::COTSSampleClr() { theSample = new COTSSamplePtr(new COTSSample()); } COTSSampleClr::COTSSampleClr(COTSSamplePtr pSample) // copy constructor { ASSERT(pSample); //theSample= new COTSSamplePtr(new COTSSample(pSample.get())); theSample = new COTSSamplePtr(pSample); //*theSample = pSample; } COTSSampleClr::~COTSSampleClr() { if (theSample != nullptr) { delete theSample; theSample = nullptr; } } COTSSampleClr::!COTSSampleClr() { if (theSample != nullptr) { delete theSample; theSample = nullptr; } } //JObject^ COTSSampleClr:: GetJSONProperty() //{ // // JObject^ SMeasureInfo= gcnew JObject(); // //the propItem list will change according to the value which is selected in the property grid. // //So we have to call setpropItemGrps function every time when we want to update the property grid display. // theSample->get()->SetPropItemGrps(); // //获得 样品属性值 // auto PropItemGrpsList = theSample->get()->GetPropItemGrps(); // // // int iItemGrpCount = PropItemGrpsList.size(); // if (0 == iItemGrpCount) // { // return SMeasureInfo; // } // SMeasureInfo->Add("bSwitch", theSample->get()->GetSwitch()); // SMeasureInfo->Add("ParamLock", theSample->get()->GetParamLock()); // JObject^ SMeasurePara = gcnew JObject(); // //获取样品的测量区域信息 // //获取样品名称 // // CString sSName = theSample->get()->GetName(); // SMeasurePara->Add("sNewSampleName", gcnew String(theSample->get()->GetName())); // // 获取测量区域形状 // auto area = theSample->get()->GetMsrArea(); // SMeasurePara->Add("iShape", (int)area->GetShape()); // //获取样品孔名称 // SMeasurePara->Add("sHoleName" ,gcnew String(theSample->get()->GetSampleHoleName())); // //样品测量区域 // JObject^ rectangleObject = gcnew JObject(); // auto rec = area->GetDomainRect(); // rectangleObject->Add("x", rec.left); // rectangleObject->Add("y", rec.top ); // rectangleObject->Add("width", rec.Width()); // rectangleObject->Add("height", rec.Height()); // SMeasurePara->Add("MeasureRect", rectangleObject); // SMeasureInfo->Add("SMeasurePara", SMeasurePara); // JObject^ TSampleParam = gcnew JObject(); // TSampleParam->Add("sWorkSampleName", gcnew String(theSample->get()->GetName())); // TSampleParam->Add("bSwitch", theSample->get()->GetSwitch()); // SMeasureInfo->Add("TSampleParam", TSampleParam); // JArray^ groupArray = gcnew JArray(); // for (int i = 0; i < iItemGrpCount; i++) // { // JObject^ groupObject = gcnew JObject(); // //获取GROUP ID和Grid的显示组的标题名 // groupObject->Add ("GroupId" ,(int)PropItemGrpsList[i]->GetGroupId()); // groupObject->Add ("Title", gcnew String( PropItemGrpsList[i]->GetName())); // //获取样品属性ID和值 // std::vector PropItemList = PropItemGrpsList[i]->GetItemsList(); // // int iItemCount = PropItemList.size(); // JArray^ itemArray = gcnew JArray(); // for (int k = 0; k < iItemCount; k++) // { // JObject^ SData = gcnew JObject(); // SData->Add("SampleId" ,(int)PropItemList[k]->GetSmplItemId()); // SData->Add("CaptionName", gcnew String( PropItemList[k]->GetName())); // SData->Add("IsReadOnly" , PropItemList[k]->IsReadOnly()); // SData->Add("SampleValType", (int)PropItemList[k]->GetTypeId()); // SData->Add("DescriptionInfo",gcnew String(PropItemList[k]->GetDescription())); // // String^ val = gcnew String(theSample->get()->GetItemValueStr(PropItemList[k]->GetSmplItemId())); // SData->Add("valStr", val); // std::vector comboDownList; // if (PropItemList[k]->GetTypeId() == OTS_ITEM_TYPES::COMBO) // { // comboDownList = theSample->get()->GetItemComboDownList(PropItemList[k]->GetSmplItemId()); // } // // JArray^ jarr = gcnew JArray(); // if (comboDownList.size() > 0) // { // for (int i=0; i < (int)comboDownList.size(); i++) // { // jarr->Add(gcnew String(comboDownList[i])); // } // } // SData->Add("comboDownList", jarr); // itemArray->Add(SData); // } // groupObject->Add("SData", itemArray); // groupArray->Add(groupObject); // // } // SMeasureInfo->Add("ItemGrp", groupArray); // return SMeasureInfo; //} COTSSamplePtr COTSSampleClr::GetSamplePtr() { return *theSample; } // has measure results test bool COTSSampleClr::HasMeasureResult() { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("HasMeasureResult: invalide pointer.")); return false; } return pSample->HasMeasureResult(); } // property item groups list /*bool COTSSampleClr::SetPropItemGrps() { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropItemGrps: invalide pointer.")); return FALSE; } pSample->SetPropItemGrps(); return TRUE; }*/ /*CPropItemGrpClr^ COTSSampleClr::GetPropItemGrpByIndex(int a_nIndex) { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropItemGrps: invalide pointer.")); return nullptr; } CPropItemGrpPtr pPropItemGrp = pSample->GetPropItemGrpByIndex(a_nIndex); if (pPropItemGrp == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropItemGrps: invalide pointer.")); return nullptr; } CPropItemGrpClr^ pPropItemGrpClr = gcnew CPropItemGrpClr(pPropItemGrp); return pPropItemGrpClr; }*/ /*CPropItemGrpClr^ COTSSampleClr::GetPropItemGrpById(int a_nId) { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropItemGrpById: invalide pointer.")); return nullptr; } CPropItemGrpPtr pPropItemGrp = pSample->GetPropItemGrpById((OTS_SAMPLE_PROP_GRID_ITEM_GROUPS)a_nId); if (pPropItemGrp == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropItemGrpById: invalide pointer.")); return nullptr; } CPropItemGrpClr^ pPropItemGrpClr = gcnew CPropItemGrpClr(pPropItemGrp); return pPropItemGrpClr; }*/ /*CPropItemGrpClr^ COTSSampleClr::UpdatePropItemGrp(int a_nId) { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("UpdatePropItemGrp: invalide pointer.")); return nullptr; } CPropItemGrpPtr pPropItemGrp = pSample->UpdatePropItemGrp((OTS_SAMPLE_PROP_GRID_ITEM_GROUPS)a_nId); if (pPropItemGrp == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("UpdatePropItemGrp: invalide pointer.")); return nullptr; } CPropItemGrpClr^ pPropItemGrpClr = gcnew CPropItemGrpClr(pPropItemGrp); return pPropItemGrpClr; }*/ /*CPropItemClr^ COTSSampleClr::GetPropItemById(int a_nId) { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropItemById: invalide pointer.")); return nullptr; } CPropItemPtr pPropItem = pSample->GetPropItemById((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId); if (pPropItem == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropItemById: invalide pointer.")); return nullptr; } CPropItemClr^ pPropItemClr = gcnew CPropItemClr(pPropItem); return pPropItemClr; }*/ // BOOL data (1) /*bool COTSSampleClr::GetPropBOOLData(int a_nId, bool% a_bValue) { bool bRet; BOOL bResult; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropBOOLData: invalide pointer.")); return false; } bRet = pSample->GetPropBOOLData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); a_bValue = bResult; return bRet; }*/ /*bool COTSSampleClr::SetPropBOOLData(int a_nId, bool a_bValue) { bool bResult = FALSE; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropBOOLData: invalide pointer.")); return false; } BOOL bValue = a_bValue; bResult = pSample->SetPropBOOLData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bValue); return bResult; }*/ // int data (16) /*bool COTSSampleClr::GetPropIntData(int a_nId, int% a_nValue) { bool bRet; int bResult; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropIntData: invalide pointer.")); return false; } bRet = pSample->GetPropIntData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); a_nValue = bResult; return bRet; }*/ /*bool COTSSampleClr::SetPropIntData(int a_nId, int a_nValue) { bool bRet = FALSE; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropIntData: invalide pointer.")); return false; } bRet = pSample->SetPropIntData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, a_nValue); return bRet; }*/ // double data (4) /*bool COTSSampleClr::GetPropDoubleData(int a_nId, double% a_dValue) { bool bRet; double bResult; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropDoubleData: invalide pointer.")); return false; } bRet = pSample->GetPropDoubleData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); a_dValue = bResult; return bRet; }*/ /*bool COTSSampleClr::SetPropDoubleData(int a_nId, double a_dValue) { bool bRet = FALSE; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropDoubleData: invalide pointer.")); return false; } bRet = pSample->SetPropDoubleData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, a_dValue); return bRet; }*/ // string data (7) /*bool COTSSampleClr::GetPropStringData(int a_nId, String^% a_strValue) { bool bRet; CString bResult; COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetPropStringData: invalide pointer.")); return false; } bRet = pSample->GetPropStringData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); a_strValue = gcnew String(bResult); return bRet; }*/ /*bool COTSSampleClr::SetPropStringData(int a_nId, String^ a_strValue) { bool bRet = false; if (a_strValue == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropStringData: invalide pointer.")); return false; } COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("SetPropStringData: invalide pointer.")); return false; } CString str = a_strValue; bRet = pSample->SetPropStringData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, str); return bRet; }*/ // combo data (7) //bool COTSSampleClr::GetPropComboData(int a_nId, int% a_nValue) //{ // bool bRet; // int bResult; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetPropComboData: invalide pointer.")); // return false; // } // bRet = pSample->GetPropComboData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // a_nValue = bResult; // return bRet; //} //bool COTSSampleClr::SetPropComboData(int a_nId, int a_nValue) //{ // bool bRet = false; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropComboData: invalide pointer.")); // return false; // } // bRet = pSample->SetPropComboData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, a_nValue); // return bRet; //} //bool COTSSampleClr::GetPropComboStrings(int a_nId, CStringListClr^% a_listComboStrings) //{ // bool bRet; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetPropComboStrings: invalide pointer.")); // return false; // } // std::vector bResult; // bRet = pSample->GetPropComboStrings((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // for (auto pString : bResult) // { // String^ str = gcnew String(pString); // a_listComboStrings->Add(str); // } // return bRet; //} //// time data (2) //bool COTSSampleClr::GetPropTimeData(int a_nId, DateTime^% a_oValue) //{ // bool bRet; // COleDateTime bResult; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetPropTimeData: invalide pointer.")); // return false; // } // bRet = pSample->GetPropTimeData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // a_oValue = gcnew DateTime(bResult.GetYear(), bResult.GetMonth(), bResult.GetDay(), bResult.GetHour(), bResult.GetMinute(), bResult.GetSecond()); // return bRet; //} //bool COTSSampleClr::SetPropTimeData(int a_nId, DateTime^ a_oValue) //{ // bool bRet; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropTimeData: invalide pointer.")); // return false; // } // ASSERT(a_oValue); // if (!a_oValue) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropTimeData: invalide pointer.")); // return false; // } // COleDateTime oVaule(a_oValue->Year, a_oValue->Month, a_oValue->Day, a_oValue->Hour, a_oValue->Minute, a_oValue->Second); // // bRet = pSample->SetPropTimeData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, oVaule); // return bRet; //} //// time span data (1) //bool COTSSampleClr::GetPropTimeSpanData(int a_nId, TimeSpan^% a_oValue) //{ // bool bRet; // COleDateTimeSpan bResult; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetPropTimeSpanData: invalide pointer.")); // return false; // } // bRet = pSample->GetPropTimeSpanData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // #pragma warning(disable : 4244) // a_oValue = gcnew TimeSpan(bResult.GetTotalDays(), bResult.GetTotalHours(), bResult.GetTotalMinutes(), bResult.GetTotalSeconds()); // #pragma warning(default : 4244) // return bRet; //} //bool COTSSampleClr::SetPropTimeSpanData(int a_nId, TimeSpan^ a_oValue) //{ // bool bRet = false; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropTimeSpanData: invalide pointer.")); // return false; // } // ASSERT(a_oValue); // if(!a_oValue) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropTimeSpanData: invalide pointer.")); // return false; // } // COleDateTimeSpan oVaule(a_oValue->Days, a_oValue->Hours, a_oValue->Minutes, a_oValue->Seconds); // // bRet = pSample->SetPropTimeSpanData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, oVaule); // return bRet; //} //// file list data (2) //bool COTSSampleClr::GetPropFileListData(int a_nId, String^% a_strFileName) //{ // bool bRet; // CString bResult; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetPropTimeSpanData: invalide pointer.")); // return false; // } // bRet = pSample->GetPropFileListData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // a_strFileName = gcnew String(bResult); // return bRet; //} //bool COTSSampleClr::SetPropFileListData(int a_nId, String^ a_strFileName) //{ // bool bRet = false; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropTimeSpanData: invalide pointer.")); // return false; // } // ASSERT(a_strFileName); // if(!a_strFileName) // { // LogErrorTrace(__FILE__, __LINE__, _T("SetPropTimeSpanData: invalide pointer.")); // return false; // } // CString str = a_strFileName; // bRet = pSample->SetPropFileListData((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, str); // return bRet; //} //// get related property item //bool COTSSampleClr::GetRelatedPropItem(int a_nId, int% a_nRelatedPropId) //{ // bool bRet; // OTS_SAMPLE_PROP_GRID_ITEMS bResult; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetRelatedPropItem: invalide pointer.")); // return false; // } // bRet = pSample->GetRelatedPropItem((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // a_nRelatedPropId = (int)bResult; // return bRet; //} //// get related property item group //bool COTSSampleClr::GetRelatedPropItemGrp(int a_nId, int% a_nRelatedPropGrpId) //{ // bool bRet; // OTS_SAMPLE_PROP_GRID_ITEM_GROUPS bResult; // COTSSamplePtr pSample = GetSamplePtr(); // if (pSample == nullptr) // { // LogErrorTrace(__FILE__, __LINE__, _T("GetRelatedPropItem: invalide pointer.")); // return false; // } // bRet = pSample->GetRelatedPropItemGrp((OTS_SAMPLE_PROP_GRID_ITEMS)a_nId, bResult); // a_nRelatedPropGrpId = (int)bResult; // // return bRet; //} bool COTSSampleClr::GetBSESize(int% a_nWidth, int% a_nHeight) { COTSSamplePtr pSample = GetSamplePtr(); if (pSample == nullptr) { LogErrorTrace(__FILE__, __LINE__, _T("GetBSESize: invalide pointer.")); return false; } int nWidth = 0; int nHeight = 0; bool bRet = pSample->GetBSESize(nWidth, nHeight); a_nWidth = nWidth; a_nHeight = nHeight; return bRet; } }