|
楼主 |
发表于 2018-11-20 09:07
|
显示全部楼层
void ColorSelect::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
ProError status;
int n_sel;
ProMdl model;
ProMdlType type,type1;
ProSelection *sel;
ProModelitem modelitem;
COLORREF color=RGB(255,0,0);
CColorDialog colorDlg(color);
CArray<ProFeature,ProFeature> feat_list;
status=ProMdlCurrentGet(&model);//获得当前模型
ProSurfaceAppearanceProps proprop;
ProSurfaceAppearanceProps proprop1;
ProName name;
int i;
int j=0;
double rands;
char str[60],str1[60],str2[60],str3[60];
double Color[30];
//产生随机数(0-1)一共产生24个
srand(time(0));
for (int i = 0; i < 24; i++)
{
rands=(rand() % 10) * 0.1;
Color[i]=rands;
}
//int a[30]={1,0,0,1,1,0,1,1,1,1,0,1,0,1,0,0,0,1,0,1,1,0,1,1};
UpdateData(TRUE);//更新编辑框和单选按钮值
if(m_danxuan==8&&m_danxuan1==0)
{
if (IDOK==colorDlg.DoModal());//调用系统颜色选择框
{
color=colorDlg.GetColor();
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
ProMdlNameGet(modelitem.owner,name);
ProWstringToString (str, name);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
/* ProWstringToString(str,proprop1.name);
ProWstringToString(str1,proprop1.label);
ProWstringToString(str2,proprop1.description);
ProWstringToString(str3,proprop1.keywords);*/
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{GetRValue(color)/255.0,GetGValue(color)/255.0,GetBValue(color)/255.0},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
}
else
if(m_danxuan==0&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{0,0,0},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==1&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{1,0,0},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==2&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{1,1,0},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==3&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{1,0,1},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==4&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{1,1,1},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==5&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{0,1,0},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==6&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{0,1,1},{0,1,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
else
if(m_danxuan==7&&m_danxuan1==0)
{
status = ProSelect("part", -1, NULL,NULL, NULL, NULL, &sel, &n_sel);//选择零部件
if(n_sel==0)
return ;
for(i=0;i<n_sel;i++)
{
status = ProSelectionModelitemGet(sel[i],&modelitem);
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.5,0.5,0.5,0.5,0.0,{0,0,1},{0,0,1},0.5,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
//遍历着色(同零件相同色,不同零件不同色,8种颜色循环
else
if(m_danxuan1==1)
{
status= ProMdlTypeGet(model, &type);
if(type==PRO_MDL_ASSEMBLY)
{
status=ProSolidFeatVisit((ProSolid)model,(ProFeatureVisitAction)FeatureAsmVisitAcFn1,FeatFilterAction11,(CArray<ProFeature,ProFeature>*)&feat_list);
int num=(int)feat_list.GetCount();//一级遍历下总元件数
for (int i=0;i<num;i++)
{
ProSolid mdl;
status=ProAsmcompMdlGet((ProAsmcomp *)(&feat_list[i]),(ProMdl *)&mdl);
status = ProMdlToModelitem(mdl,&modelitem);
status=ProMdlTypeGet(mdl,&type1);//一级零部件特征类型
status= ProSurfaceAppearancepropsGet(&modelitem,&proprop1);//获得零件表面属性
ProSurfaceAppearanceProps proprop={0.8,0.8,0.7,0.6,0.0,{Color[j],Color[j+1],Color[j+2]},{0,0,1},proprop1.reflection,*proprop1.name,*proprop1.label,*proprop1.description,*proprop1.keywords};
if(i>0&&i%7==0)//七种颜色循环遍历使用
j=0;
else
{
j=j+3;
}
status= ProSurfaceAppearancepropsSet(&modelitem,&proprop);//设置零部件表,面属性
}
}
}
//模型重生
UpdateData(FALSE);
status=ProWindowRepaint(-1);
status = ProTreetoolRefresh(&model);
ProSolidRegenerate((ProSolid)model,PRO_REGEN_NO_FLAGS);
UsrActivateCurrentWindow();
} |
|