void FieldInfoDlg::fillVarList() { m_varList.ResetContent(); // 清空列表 AcStringArray names; switch( m_lt ) { case LT_STRING: StringListHelper::GetAllNames( names ); break; case LT_INT: IntStrListHelper::GetAllNames( names ); break; case LT_OBJECT: DataObjectListHelper::GetAllNames( names ); break; } if( names.isEmpty() ) return; int index = names.find( m_varName ); if( index < 0 ) m_varName = _T( "" ); // 清空 int len = names.length(); for( int i = 0; i < len; i++ ) { m_varList.AddString( names[i].kACharPtr() ); } m_varList.SetCurSel( index ); }
/* * 方法: * 1) 得到原始的字段链表L1和字段列表框中的字段链表L2 * 2) 遍历链表L2,判断字段是否存在于L1中 * a) 如果存在,则该字段保持不变,并从L1中移除该字段; * b) 如果不存在,则转第(3)步 * 3) 该字段是新添加的字段,则执行"增加字段"操作Add * 4) 完成遍历L2,最后剩下的L1的元素就是需要删除的字段 * 5) 执行"删除字段"操作Remove */ void FieldManagerDlg::OnBnClickedApplyBtn() { if( m_fieldListBox.GetCount() > 0 ) { // 切换之前更新上次选择的字段信息 // 并检查字段信息的有效性 if( !updateFieldInfo() ) return; } // 选择的图元类型 CString selType = getSelType(); if( selType.GetLength() == 0 ) return; AcStringArray fields; FieldHelper::GetAllFields( selType, fields ); if( fields.isEmpty() && m_fieldListBox.GetCount() == 0 ) { MessageBox( _T( "没有字段可更新" ) ); return; } // "剩余"字段 // 与m_infoes应该是一一对应的 AcStringArray leftFields; for( int i = 0; i < m_fieldListBox.GetCount(); i++ ) { CString text; m_fieldListBox.GetText( i, text ); leftFields.append( text ); } int len = leftFields.length(); for( int i = 0; i < len; i++ ) { CString field = leftFields[i].kACharPtr(); int index = fields.find( field ); if( index >= 0 ) // 已存在,不变 { fields.removeAt( index ); } else { // 增加字段 FieldHelper::AddField( selType, field ); } // 默认属性设置不需要添加到词典中 if( m_infoes[i]->isDefault() ) { FieldInfoHelper::RemoveFieldInfo( selType, field ); } else { // 新增的字段 if( index < 0 || !FieldInfoHelper::FindFieldInfo( selType, field ) ) { FieldInfoHelper::AddFieldInfo( selType, field, *m_infoes[i] ); } else { // 更新已有的字段信息 FieldInfoHelper::WriteFieldInfo( selType, field, *m_infoes[i] ); } } } // 删除字段 len = fields.length(); for( int i = 0; i < len; i++ ) { FieldHelper::RemoveField( selType, fields[i].kACharPtr() ); } MessageBox( _T( "字段信息更新成功!" ) ); }
static void BlockToEntity( const AcDbObjectId& blkId, const AcGeMatrix3d& blkXform, const AcStringArray& names, const AcStringArray& attValues, AcGeVoidPointerArray& ents ) { // 将块定义分解成独立的图元 // 将属性替换成多行文字 AcTransaction* pTrans = actrTransactionManager->startTransaction(); AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, blkId, AcDb::kForRead ) ) { actrTransactionManager->abortTransaction(); return; } AcDbBlockTableRecord* pBTR = AcDbBlockTableRecord::cast( pObj ); // BUG:不能调用hasAttributeDefinitions()方法 // 调用之后,如果没有在块编辑器中对块进行修改, // 那么进行移动、夹点编辑等操作,没有动态显示效果 //if(!pBTR->hasAttributeDefinitions()) //{ // // 没有属性定义 // acutPrintf(_T("\n没有属性定义")); // actrTransactionManager->abortTransaction(); // return; //} AcDbBlockTableRecordIterator* pIterator; if( Acad::eOk != pBTR->newIterator( pIterator ) ) { actrTransactionManager->abortTransaction(); return; } // 遍历块中的图元,查找AcDbAttributeDefinition for( pIterator->start( true ); !pIterator->done(); pIterator->step( true ) ) { AcDbObjectId objId; if( Acad::eOk != pIterator->getEntityId( objId ) ) continue; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) continue; AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( !pEnt->isKindOf( AcDbAttributeDefinition::desc() ) ) { AcDbEntity* pClone = AcDbEntity::cast( pEnt->clone() ); pClone->transformBy( blkXform ); // 添加到实体集合 ents.append( pClone ); } else { AcDbAttributeDefinition* pAttDef = AcDbAttributeDefinition::cast( pEnt ); pAttDef->convertIntoMTextAttributeDefinition( Adesk::kTrue ); // 获取标签名称 ACHAR* pTag = pAttDef->tag(); int pos = names.find( pTag ); if( pos != -1 ) { // 获取多行文本对象 AcDbMText* pMText = pAttDef->getMTextAttributeDefinition(); pMText->transformBy( blkXform ); pMText->setContents( attValues[pos].kACharPtr() ); // 添加到实体集合 ents.append( pMText ); } acutDelString( pTag ); } } delete pIterator; actrTransactionManager->endTransaction(); }