zyx137 发表于 2009-6-19 14:53:00

autocadmap短线检查源码

<p>//-------------------------------------短线检查----------------------------------------------------------<br/>void CleanupShortLine()<br/>{<br/>&nbsp;SetCurLayer(_T("checklayer"),250);<br/>&nbsp;ade_id cleanupVarId = ADE_NULLID;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // variable ID<br/>&nbsp;ade_id cleanupModelId = ADE_NULLID;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // clean ID<br/>&nbsp; &nbsp;ade_id cleanupactionVarId = ADE_NULLID;&nbsp;&nbsp;&nbsp; //variable ID<br/>&nbsp;ads_name ss;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // selection set<br/>&nbsp;long qty = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // quantity数量<br/>&nbsp;long totalqty=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //所有错误的总和<br/>&nbsp;int type = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // clean error group type<br/>&nbsp;int subtype = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // clean error group subtype<br/>&nbsp;int done = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //是否完成清理工作<br/>&nbsp;int resultCode = 0;<br/>&nbsp;CString str;<br/>&nbsp;//给cleanup变量分配内存,变量初始化为它们的缺省值,使用tpm_varalloc.<br/>&nbsp;cleanupVarId = tpm_varalloc();<br/>&nbsp;&nbsp;&nbsp; cleanupactionVarId=tpm_varalloc();<br/>&nbsp;//为cleanup模型分配内存,使用 tpm_cleanalloc. <br/>&nbsp;cleanupModelId = tpm_cleanalloc();</p><p>&nbsp;if( ! cleanupVarId || ! cleanupModelId ||!cleanupactionVarId) <br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf(_T("\n内存分配失败."));<br/>&nbsp;&nbsp;tpm_varfree(cleanupVarId);<br/>&nbsp;&nbsp;tpm_cleanfree(cleanupModelId);<br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;tpm_cleanactionlistins(cleanupVarId,1,1,cleanupactionVarId);//必须在tpm_cleaninit前调用<br/>&nbsp;tpm_cleanactionlistins(cleanupVarId,2,256,cleanupactionVarId);//必须在tpm_cleaninit前调用</p><p>&nbsp;if(acedSSGet(_T("X"),NULL,NULL,NULL,ss)!= RTNORM)//第一个参数为NULL为自由选,“X”为全选<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf(_T("\n获取选择集失败!"));<br/>&nbsp;&nbsp;tpm_varfree(cleanupVarId); <br/>&nbsp;&nbsp;tpm_cleanfree(cleanupModelId); <br/>&nbsp;&nbsp;tpm_varfree(cleanupactionVarId); <br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;// 初始化一个目标选择集命名为 ss进行清理工作<br/>&nbsp;tpm_cleaninit(cleanupModelId, cleanupVarId, ss);//初始化清理模型<br/>&nbsp;resultCode = tpm_cleanstart(cleanupModelId);//开始清理进程</p><p>&nbsp;if( resultCode != RTNORM )<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf(_T("\n清理工作启动失败.")); <br/>&nbsp;&nbsp;tpm_varfree(cleanupVarId); <br/>&nbsp;&nbsp;tpm_varfree(cleanupactionVarId); <br/>&nbsp;&nbsp;tpm_cleanfree(cleanupModelId); <br/>&nbsp;&nbsp;return; <br/>&nbsp;}<br/>&nbsp;// Count errors by group type and subtype<br/>&nbsp;while ( ! done)<br/>&nbsp;{<br/>&nbsp;&nbsp;resultCode = tpm_cleangroupnext(cleanupModelId);<br/>&nbsp;&nbsp;if ( resultCode == RTNORM ) <br/>&nbsp;&nbsp;{ <br/>&nbsp;&nbsp;&nbsp;if (tpm_cleancomplete(cleanupModelId) == TRUE ) <br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;done = 1; <br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;else <br/>&nbsp;&nbsp;&nbsp;{ <br/>&nbsp;&nbsp;&nbsp;&nbsp;type = tpm_cleangrouptype(cleanupModelId); <br/>&nbsp;&nbsp;&nbsp;&nbsp;subtype = tpm_cleangroupsubtype(cleanupModelId); <br/>&nbsp;&nbsp;&nbsp;&nbsp;tpm_cleangroupqty(cleanupModelId, &amp;qty); <br/>&nbsp;&nbsp;&nbsp;&nbsp;tpm_cleangroupmark(cleanupModelId);<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;tpm_cleangroupfix(cleanupModelId);<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(qty&gt;0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acutPrintf(_T("\n组类型:%d,子类型:%d,错误数目:%</p><p>d"),type,subtype,qty); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;totalqty+=qty;<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;} // else <br/>&nbsp;&nbsp;} // if <br/>&nbsp;&nbsp;else<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;acutPrintf(_T("\n没有要清理的对象"));<br/>&nbsp;&nbsp;}<br/>&nbsp;} // while<br/>&nbsp;resultCode = tpm_cleanend(cleanupModelId);//完成清理进程并更新图形,修复被tpm_cleanerrorfix指定的</p><p>要修复的错误<br/>&nbsp;&nbsp;&nbsp; resultCode = acedSSFree(ss);//最后释放选择集<br/>&nbsp;tpm_cleanfree(cleanupModelId);//释放清理模型<br/>&nbsp;tpm_varfree(cleanupVarId);//释放配置变量<br/>&nbsp;tpm_varfree(cleanupactionVarId);//释放配置变量<br/>&nbsp;if(totalqty==0)<br/>&nbsp;&nbsp;str.Format(_T("\n恭喜!未找到任何错误。"));<br/>&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp; str.Format(_T("短线错误%d处"),totalqty);<br/>&nbsp;acedAlert(str);<br/>}<br/></p>
页: [1]
查看完整版本: autocadmap短线检查源码