几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-05-06, 11:50 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】problems with copying raster images

problems with copying raster images
problems with copying raster images
hi,
here is a sample code which is running in odamfxapp, dwgdirect 1.14.02.
code:
oddbobjectid iddim,iddim2,iddim3,iddim4,iddim5,idline,idline2,idline3,idline4,idline5,idref,idref2;
oddbobjectid idblock;;
oddbdatabase* pdb = getdocument()->m_pdb;
// place your bitmap here
odstring sfile = "d:\\aspire2.bmp";
/* load the raster image */
odgirasterimageptr rast;
oddbobjectid imagedefid;
{
typedef odsmartptr<odrxrasterservices> odrxrasterservicesptr;
odrxrasterservicesptr prassvcs = odrxdynamiclinker()->loadapp(rx_raster_services_appname);
if ( !prassvcs.isnull() )
rast = prassvcs->loadrasterimage(sfile);
}
oddbblocktablerecordptr bbtr = pdb->getactivelayoutbtrid().safeopenobject(oddb::kforwrite);
/* set the origin point */
odgepoint3d point = odgepoint3d(50.0,50.0,0.0);
double h = 100.0;
double w = 100.0;

point.y -= h;

{
/* open the image dictionary */
oddbobjectid imagedictid = oddbrasterimagedef::createimagedictionary(pdb);
oddbdictionaryptr pimagedict = imagedictid.safeopenobject(oddb::kforwrite);
/* create an imagedef object */
oddbrasterimagedefptr pimagedef = oddbrasterimagedef::createobject();
// check raster variables
oddbrastervariablesptr prvars = oddbrastervariables:penrastervariables(pdb, oddb::kforwrite);
if (odgirasterimage::knone == prvars->userscale())
{
prvars->setuserscale(odgirasterimage::kmeter);
prvars->setimageframe(oddbrastervariables::kimageframeabove);
prvars->setimagequality(oddbrastervariables::kimagequalityhigh);
}
imagedefid = pimagedict->setat("aspire2", pimagedef);
/* set some parameters */
pimagedef->setsourcefilename(sfile);
pimagedef->setimage(rast);
}

oddbrasterimageptr pimage;
{
/* create an image object */
pimage = oddbrasterimage::createobject();
bbtr->appendoddbentity(pimage);

/* set some parameters */
pimage->setimagedefid(imagedefid);
pimage->setorientation(point, odgevector3d(w, 0, 0), odgevector3d(0.0, h, 0));
pimage->setdisplayopt(oddbrasterimage::kshow, true);
pimage->setdisplayopt(oddbrasterimage::kshowunaligned, true);
//pimage->setbrightness(3);
pimage->setdisplayopt(oddbrasterimage::kshow,true);
pimage->setdisplayopt(oddbrasterimage::kshowunaligned ,true);
pimage->setdisplayopt(oddbrasterimage::kclip ,true);
}

// write the raster image to file
pdb->writefile("d:\\test.dwg", oddb::kdwg, oddb::kdhl_1800, theapp.getsavepreview());

pdb = theapp->createdatabase();
{
//copy the raster image from the temp file to the database;
oddbdatabaseptr psenddb = theapp.readfile("d:\\test.dwg", true, false, oda::ksharedenyno );
oddbblocktablerecordptr psendmodelspace = psenddb->getactivelayoutbtrid().safeopenobject();
oddbobjectidarray ids;
oddbrasterimageptr praster;
oddbobjectiteratorptr psendit = psendmodelspace->newiterator();
for (; !psendit->done(); psendit->step()) {
praster = oddbrasterimage::cast(psendit->objectid().safeopenobject());
if(!praster.isnull())
ids.push_back(praster->objectid());
} //for
{
oddbidmappingptr pmapping = oddbidmapping::createobject();
oddbobjectid owner = pdb->getmodelspaceid();
pmapping->setdestdb(pdb);
psenddb->wblockcloneobjects(ids,owner,*pmapping,(oddb::duplicaterecordcloning)/*oddb::kdrcmanglename*/oddb::kdrcmanglename,false);
//move the copied raster image(to be able to see the second opject)
oddbidpair pp(praster->objectid());
if (pmapping->compute(pp)) {
oddbrasterimageptr primage= pp.value().safeopenobject(oddb::kforwrite);
odgematrix3d m;
m.settoidentity();
m.settranslation(odgepoint3d(0.0,0.0,0.0)-odgepoint3d(150.0,150.0,0.0));
primage->transformby(m);
} //if
}
//copy the raster image agan(make a second copy)
{
oddbidmappingptr pmapping1 = oddbidmapping::createobject();
oddbobjectid owner = pdb->getmodelspaceid();
pmapping1->setdestdb(pdb);
psenddb->wblockcloneobjects(ids,owner,*pmapping1,(oddb::duplicaterecordcloning)oddb::kdrcmanglename,false);
}
pdb->writefile("d:\\outputfile.dwg", oddb::kdwg, oddb::kdhl_1800, theapp.getsavepreview());
//now open the output drawing and see the diference. one of the raster image copies is transparent.
}
the problem is that after copying the raster images to another drawing, one of the remains blank - the raster image def is set to null.
is it a bug of dwgdirect?
thanks in advance for any help.
best regards
chudomir
at the moment dd does not map image dictionary by default. it will be fixed in the next maintenance release.
as workaround you can set odrxeventreactor which makes such mapping:
code:
class odwblockrasterimagereactor : public odstaticrxobject<odrxeventreactor>
{
public:
virtual void beginwblockobjects(oddbdatabase* psrc, oddbidmapping& idmap)
{
oddbdatabase* pdst = idmap.destdb();
oda_assert(psrc && pdst);
if (psrc == pdst)
return;
oddbobjectid srcdicid = oddbrasterimagedef::imagedictionary(psrc);
oddbobjectid dstdicid = oddbrasterimagedef::imagedictionary(pdst);
if (!srcdicid.isnull() && !dstdicid.isnull())
{
idmap.assign(oddbidpair(srcdicid, dstdicid, true));
}
}
};
odwblockrasterimagereactor wblockreactor;
odrxevent()->addreactor(&wblockreactor);
//
// ... using wblockcloneobjects()
//
regards,
sergey vishnevetsky
thanks! i'll try.
best regards
chudomir
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】problem with exporting raster image to pdf yang686526 DirectDWG 0 2009-05-06 11:17 PM
【转帖】how to render custom raster yang686526 DirectDWG 0 2009-05-06 03:08 PM
【转帖】exporting dwg with images to dwf yang686526 DirectDWG 0 2009-05-05 10:31 AM
【转帖】dwf exportimport raster images yang686526 DirectDWG 0 2009-05-04 08:21 PM
【转帖】clipping path in rasterimageproc yang686526 DirectDWG 0 2009-05-04 05:49 PM


所有的时间均为北京时间。 现在的时间是 03:17 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多