bool PropertyDataUpdater::ReadDataFromGE( CMFCPropertyGridCtrl* pPropDataList, const AcDbObjectId& objId ) { if( pPropDataList == NULL ) return false; if( objId.isNull() ) return false; //PrintPropList(pPropDataList); // 填充内容 AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return false; AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForRead ) ) { actrTransactionManager->abortTransaction(); return false; } DataObject* pDO = DataObject::cast( pObj ); if( pDO == 0 ) { actrTransactionManager->abortTransaction(); return false; } //acutPrintf(_T("\n读取数据...")); DataHelperImpl dh( pDO ); int nCount = pPropDataList->GetPropertyCount(); for ( int i = 0; i < nCount; i++ ) { CMFCPropertyGridProperty* pProp = pPropDataList->GetProperty( i ); CString value; dh.getPropertyData( pProp->GetName(), value ); // 更新属性数据 FieldInfo info; // 默认设置(DT_STRING, m_enable=true, m_descr =_T("")) FieldInfoHelper::ReadFieldInfo( pDO->getType(), pProp->GetName(), info ); SetPropValue( pProp, info, value ); // 设置属性值 //DATA_TYPE dt = info.m_dt; //LIST_TYPE lt = info.m_lt; //if (dt == DT_LIST && lt == LT_INT) //{ // //} } actrTransactionManager->endTransaction(); //PrintPropList(pPropDataList); return true; }
LRESULT xRenderSettingPane::OnPropertyChanged(WPARAM wParam, LPARAM lParam) { CMFCPropertyGridProperty * prop = (CMFCPropertyGridProperty *)lParam; IPropertyObj * obj = xRenderSetting::Instance(); const char * name = prop->GetName(); const Property * p = obj->GetProperty(name); if (p) { char cdata[128]; const COleVariant & strValue = prop->GetValue(); CString val = (CString)strValue; Strcpy(cdata, 128, (const char *)val); if (p->type == PT_Bool) { bool bdata = (strValue.boolVal == -1); obj->SetPropertyData(p, &bdata); } else if (p->type == PT_Int && p->enumObj) { const cEnum * e = p->enumObj->GetEnum(cdata); obj->SetPropertyData(p, &e->val); } } return S_OK; }
void DotsPlotWndProperty::UpdatePropertyValue(const wchar_t * propertyName) { CMFCPropertyGridProperty * property = NULL; for (int i = 0; i < this->GetPropertyCount(); i++) { CMFCPropertyGridProperty * aProperty = this->GetProperty(i); if (wcscmp(aProperty->GetName(), propertyName) == 0) { property = aProperty; break; } } if (property == NULL) return; _variant_t value = property->GetValue(); PlotWndPropDots * objProp = (PlotWndPropDots *)this->target; if (wcscmp(propertyName, L"Max Value") == 0) { _variant_t value = property->GetValue(); value.intVal = (int)objProp->GetMaxValue(); property->SetValue(value); } //else if (wcscmp(propertyName, L"Frame Count") == 0) //{ // _variant_t value = property->GetValue(); // value.intVal = (int)objProp->frameCount; // property->SetValue(value); //} }
static void PrintPropList( CMFCPropertyGridCtrl* pPropDataList ) { int count = pPropDataList->GetPropertyCount(); acutPrintf( _T( "\n属性数据控件包含的数据个数:%d" ), count ); for( int i = 0; i < count; i++ ) { CMFCPropertyGridProperty* pProp = pPropDataList->GetProperty( i ); acutPrintf( _T( "\name=%s\tvalue=%s" ), pProp->GetName(), pProp->GetValue() ); } acutPrintf( _T( "\n" ) ); }
LRESULT CSpriteSet::OnPropertyChanged (WPARAM,LPARAM lParam) { CMFCPropertyGridProperty* pProp = (CMFCPropertyGridProperty*) lParam; const COleVariant& strValue=pProp->GetValue();//获得子项值 CString strTmp = CString(strValue.bstrVal); strTmp = pProp->GetName(); return 0; }
BOOL CPropertiesWnd::IsSelectComboItem() { if (IsComboType()) { CMFCPropertyGridProperty *pProp = m_wndPropList.GetCurSel(); if (pProp && pProp->IsGroup()) { CString strName(pProp->GetName()); return (strName.CompareNoCase(_T("ITEM")) == 0); } } return FALSE; }
void CPropertiesWnd::ChangeSelection(CMFCPropertyGridProperty* pNewSel, CMFCPropertyGridProperty* /*pOldSel*/) { if (pNewSel == NULL) { ((CMainFrame*)AfxGetMainWnd())->GetClassView()->SetPreviewProp(NULL); return; } CString strPreview; if (IsComboType()) { if (pNewSel->IsGroup()) { CString strName(pNewSel->GetName()); if (strName.CompareNoCase(_T("ITEM")) == 0) { CMFCPropertyGridProperty* pPreviewProp = pNewSel->GetSubItem(pNewSel->GetSubItemsCount() - 1); ((CMainFrame*)AfxGetMainWnd())->GetClassView()->SetPreviewProp(pPreviewProp); return; } } else { CMFCPropertyGridProperty* pGroupProp = pNewSel->GetParent(); CString strName(pGroupProp->GetName()); if (strName.CompareNoCase(_T("ITEM")) == 0) { CMFCPropertyGridProperty* pPreviewProp = pGroupProp->GetSubItem(pGroupProp->GetSubItemsCount() - 1); ((CMainFrame*)AfxGetMainWnd())->GetClassView()->SetPreviewProp(pPreviewProp); return; } } ((CMainFrame*)AfxGetMainWnd())->GetClassView()->SetPreviewProp(NULL); } else { // the last is preview CMFCPropertyGridProperty* pGroupProp = pNewSel; if (!pNewSel->IsGroup()) { pGroupProp = pNewSel->GetParent(); } if (pGroupProp->GetSubItemsCount() > 2) { CMFCPropertyGridProperty* pPreviewProp = pGroupProp->GetSubItem(pGroupProp->GetSubItemsCount() - 1); ((CMainFrame*)AfxGetMainWnd())->GetClassView()->SetPreviewProp(pPreviewProp); } } }
void CPropertiesWnd::OnPropDownitem() { if (!IsComboType()) { return; } CMFCPropertyGridProperty *pProp = m_wndPropList.GetCurSel(); if (pProp && pProp->IsGroup()) { CString strName(pProp->GetName()); if (strName.CompareNoCase(_T("ITEM")) == 0) { CMFCPropertyGridProperty *pParentProp = pProp->GetParent(); if (pProp == pParentProp->GetSubItem(pParentProp->GetSubItemsCount() - 1)) { return; } int nEnd = 0; CList<CMFCPropertyGridProperty*, CMFCPropertyGridProperty*> lstSubItems; for (int i = pParentProp->GetSubItemsCount() - 1; i >= nEnd; i--) { CMFCPropertyGridProperty *pChildProp = pParentProp->GetSubItem(i); if (pChildProp) { if (pChildProp == pProp) { nEnd = i; lstSubItems.InsertAfter(lstSubItems.GetHeadPosition(), pChildProp); } else { lstSubItems.AddHead(pChildProp); } pParentProp->RemoveSubItem(pChildProp, FALSE); } } for (POSITION pos = lstSubItems.GetHeadPosition(); pos != NULL;) { CMFCPropertyGridProperty* pProp = lstSubItems.GetNext(pos); ASSERT_VALID(pProp); pParentProp->AddSubItem(pProp); } m_wndPropList.AdjustLayout(); } } }
CMFCPropertyGridProperty * BaseProperty::FindProperty(const wchar_t * name) const { CMFCPropertyGridProperty * property = NULL; for (int i = 0; i < this->GetPropertyCount(); i++) { CMFCPropertyGridProperty * aProperty = this->GetProperty(i); if (wcscmp(aProperty->GetName(), name) == 0) { property = aProperty; break; } } return property; }
void CPropertiesWnd::OnPropDelitem() { if (!IsComboType()) { return; } CMFCPropertyGridProperty *pProp = m_wndPropList.GetCurSel(); if (pProp && pProp->IsGroup()) { CString strName(pProp->GetName()); if (strName.CompareNoCase(_T("ITEM")) == 0 && AfxMessageBox(_T("Sure to delete it?"), MB_YESNO) == IDYES) { pProp->GetParent()->RemoveSubItem(pProp); m_wndPropList.RedrawWindow(); } } }
bool PropertyDataUpdater::WriteDataToGE( CMFCPropertyGridCtrl* pPropDataList, const AcDbObjectId& objId ) { if( pPropDataList == NULL ) return false; if( objId.isNull() ) return false; // 没有属性数据可更新 if( pPropDataList->GetPropertyCount() == 0 ) return false; AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return false; AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) { actrTransactionManager->abortTransaction(); return false; } DataObject* pDO = DataObject::cast( pObj ); if( pDO == 0 ) { actrTransactionManager->abortTransaction(); return false; } //acutPrintf(_T("\n写入数据...")); DataHelperImpl dh( pDO ); int nCount = pPropDataList->GetPropertyCount(); for ( int i = 0; i < nCount; i++ ) { CMFCPropertyGridProperty* pProp = pPropDataList->GetProperty( i ); // 扩展数据中默认采用"字符串"类型保存数据 // COleVariant会自动转换成CString CString value = pProp->GetValue(); dh.setPropertyData( pProp->GetName(), value ); // 更新属性数据 } actrTransactionManager->endTransaction(); return true; }
LRESULT xKeyFrameTab::OnPropertyChanged(WPARAM wParam, LPARAM lParam) { int i = GetActiveTab(); IPropertyObj * obj = NULL; switch (i) { case 0: obj = Environment::Instance()->GetKeyFrame(0); break; case 1: obj = Environment::Instance()->GetKeyFrame(1); break; case 2: obj = Environment::Instance()->GetKeyFrame(2); break; case 3: obj = Environment::Instance()->GetKeyFrame(3); break; case 4: obj = Environment::Instance()->GetGlobalParam(); break; } if (!obj) return S_OK; CMFCPropertyGridProperty * prop = (CMFCPropertyGridProperty *)lParam; const char * name = prop->GetName(); const Property * p = obj->GetProperty(name); if (p) { if (p->type == PT_TString && p->size == 128) { const COleVariant & strValue = prop->GetValue(); CString val = (CString)strValue; TString128 data = (LPCTSTR)val; obj->SetPropertyData(p, &data); } else if (p->type == PT_Float) { const COleVariant & strValue = prop->GetValue(); CString val = (CString)strValue; float data = (float)atof((LPCTSTR)val); obj->SetPropertyData(p, &data); } else if (p->type == PT_Color) { xPropertyGridColorPick * colorPick = (xPropertyGridColorPick *)prop; COLORREF color = colorPick->GetColor(); int r = GetRValue(color); int g = GetGValue(color); int b = GetBValue(color); Color4 data = Color4(r / 255.0f, g / 255.0f, b / 255.0f); obj->SetPropertyData(p, &data); } } return S_OK; }