高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】problem with layout and viewpor
problem with layout and viewport
problem with layout and viewport
hallo,
at the moment we improve our import with layout import.
1. we import all modelspace -- like odread example
2. we iterate over the layoutdictionary und over the viewports in the layouts
- for the first layout we create a paper und draw all paperspace entities on it
- for all others we create drawing that showing the modelspace
the problem is that most dwg/dxf drawing work nice but a few are not zoomed right.
we call zoomextents() on all first viewports. i have found in odmfcapp that you check
the bounding box with the following code. but odgsview is always null.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
static bool getlayoutextents(const oddbobjectid& spaceid, const odgsview* pview, odgeboundblock3d& bbox)
{
oddbblocktablerecordptr pspace = spaceid.safeopenobject();
oddblayoutptr playout = pspace->getlayoutid().safeopenobject();
odgeextents3d ext;
if(playout->getgeomextents(ext)==eok)
{
ext.transformby(pview->viewingmatrix());
bbox.set(ext.minpoint(), ext.maxpoint());
return (ext.minpoint()!=ext.maxpoint());
}
return false;
}
void zoom_extents(odgsview* pview, oddbobject* pvpobj)
{
oddbdatabase* pdb = pvpobj->database();
odabstractviewpeptr pvppe(pview);
odgeboundblock3d bbox;
bool bbboxvalid = pvppe->viewextents(pview, bbox);
// paper space overall view
oddbviewportptr pvp = oddbviewport::cast(pvpobj);
if(pvp.get() && pvp->number() == 1)
{
if(!bbboxvalid || !(bbox.minpoint().x < bbox.maxpoint().x && bbox.minpoint().y < bbox.maxpoint().y))
{
bbboxvalid = ::getlayoutextents(pdb->getpaperspaceid(), pview, bbox);
}
}
else if(!bbboxvalid) // model space viewport
{
bbboxvalid = ::getlayoutextents(pdb->getpaperspaceid(), pview, bbox);
}
if(!bbboxvalid)
{
// set to somewhat reasonable (e.g. paper size)
if(pdb->getmeasurement()==oddb::kmetric)
{
bbox.set(odgepoint3d::korigin, odgepoint3d(297., 210., 0.)); // set to papersize iso a4 (portrait)
}
else
{
bbox.set(odgepoint3d::korigin, odgepoint3d(11., 8.5, 0.)); // ansi a (8.50 x 11.00) (landscape)
}
bbox.transformby(pview->viewingmatrix());
}
pvppe->zoomextents(pview, &bbox);
}
oddbobjectptr pvpobj = pdb->activeviewportid().safeopenobject(oddb::kforwrite );
oddbabstractviewportdataptr pavd(pvpobj);
odgsview* pview = pavd->gsview(pvpobj);
zoom_extents(pview, pvport);
by searching in the forum and example source found and create the following code. but it did not work. odgsview is
always null.
---------------------------------------------------------------------------------------------------------------------------------
odgsdeviceptr pdevice = phostapp->gsbitmapdevice();
// create the vectorization context.
odgicontextfordbdatabaseptr pdwgcontext = odgicontextfordbdatabase::createobject();
// set the database to be vectorized.
pdwgcontext->setdatabase(pdb);
// cast the device to a cdwgvectorizedevice smart pointer.
// prepare the device to render the active layout in this database.
pdevice = oddbgsmanager::setupactivelayoutviews(pdevice, pdwgcontext);
//oddbobjectptr pvpobj = pdb->activeviewportid().safeopenobject(oddb::kforwrite );
oddbabstractviewportdataptr pavd(pvport);
odgsview* pview = pavd->gsview(pvport);
zoom_extents(pview, pvport);
our import code for layouts
---------------------------------------------------------------------------------------------------------------------------
for (; !playoutiter->done(); playoutiter->next())
{
oddbobjectid idcur = playoutiter->objectid();
if (idcur == idmslayout)
{
continue;
}
oddblayoutptr playout = playoutiter->objectid().safeopenobject();
oddbblocktablerecordptr pblock = playout->getblocktablerecordid().safeopenobject();
oddbobjectiteratorptr piter = pblock->newiterator();
for (; !piter->done(); piter->step())
{
oddbentityptr pent = piter->objectid().safeopenobject();
oddblayertablerecordptr player = pent->layerid().safeopenobject();
/*
import all paperspace entities
*/
}
playout->getplotpapersize(paperwidth,paperheight);
switch (playout->plotrotation()) {
case oddbplotsettings::k0degrees :
case oddbplotsettings::k180degrees :
break;
case oddbplotsettings::k90degrees :
case oddbplotsettings::k270degrees :
dreal tmp = paperwidth;
paperwidth = paperheight;
paperheight = tmp;
break;
}
oddbobjectidarray viewportids = playout->getviewportarray();
if (viewportids.length()) {
for (int ii = 0; ii < (int) viewportids.length(); ii++)
{
oddbviewportptr pvport = viewportids[ii].safeopenobject(oddb::kforwrite);
if (ii == 0) {
pvport->zoomextents();
}
if (ii == 0) {
/*
create paper
*/
}
/*
create views to paperspace entities or modelspace entities
*/
}
}
}
my tests
----------------------------------------------------------------------------------------------------------------
i make a difference when i call or not the following functions :
pdb->setcurrentlayout(idcur);
pvport->zoomextents(); // only one first viewport per layout
please help. i test and try for days and i do not know what is right or what is bad.
thanks for any help.
i can send you my dwg/dxf test files but the rar have 36 megabyte.
you may upload the file to our server directly.
see instructions at
vladimir
hallo,,
i have uploaded my example files.
the folowing three files were the problem. when i change my code that the first file is ok than the others file were bad. i have found no way to display a layouts right.
problem is only the position of the viewports in the layout. the layout looks right but is not in the middle of the paper.
i this is not enough i can make screenshots and the source code in sync.
0309agrs00u10001.dwg
5_gud_gr_dw_002_01.dwg
d----910106_gl.1_trog2.0.dwg
in my case zoom extents didn't work in paperspacefff">.
i solved the problem as belowed:
1. check your code when you call zoom_extents function.
you should call this after you load the dwg/dxf file.
2. add pavd->setview(pvpobj, pview);
after zoom_extents(pview, pvpobj);
last edited by hafa; 1st june 2008 at 06:11 pmfff">.
1. this is logic with no file read i can not zoom i have not the objects ...
2. pavd what class ????
oddbobjectptr pvpobj = pdb->activeviewportid().safeopenobject(oddb::kforwrite );
oddbabstractviewportdataptr pavd(pvpobj);
you can find this on editorobject.cpp(odamfcapp example)
void odexzoomcmd::executefff">(odedcommandcontext* pcmdctx)
hallo,
ok i have added this line but to call zoom_extends i need a valid odgsview. i my code this is always null. see the code above. what is wrong that pview is null.
// create the vectorization context.
odgicontextfordbdatabaseptr pdwgcontext = odgicontextfordbdatabase::createobject();
// set the database to be vectorized.
pdwgcontext->setdatabase(pdb);
// cast the device to a cdwgvectorizedevice smart pointer.
// prepare the device to render the active layout in this database.
pdevice = oddbgsmanager::setupactivelayoutviews(pdevice, pdwgcontext);
oddbobjectptr pvpobj = pdb->activeviewportid().safeopenobject(oddb::kforwrite );
oddbabstractviewportdataptr pavd(pvpobj);
odgsview* pview = pavd->gsview(pvpobj);
zoom_extents(pview, pvport);
pavd->setview(pvpobj, pview);
which dd version do you use?
(the bug with null gs view in paperspace was present in 2.5.1 and fixed in 2.5.2)
vladimir
hallo,
i use 2.5.2 linux gcc 4.1. i have downloaded the libs today and the md5sum is the same.
md5sum dd_lnxx86_gs.a
87ccb15e8149c7905d96c4b7536320c3 dd_lnxx86_gs.a
i cannot reproduce that.
what exactly should i insert in some of our samples, to reproduce the bug?
(the code you quoted (very similar at least) is used in odamfcapp sample, and it works. i cannot imagine any difference between windows and linux in that case)
vladimir
hallo,
ok i have changed odreadex. i uploaded my odreadex directory with *.cpp *.h and makefile. i have added a few functions in dbdumper.cpp. it begins with dumplayouts(...).
i have test this with the following line.
./odreadex 0309agrs00u10001.dwg
0309agrs00u10001.dwg is from dwg.rar
and the output (only the finish)
......
planar. . . . . . . . . . . . . true
planarity . . . . . . . . . . . kplanar
origin. . . . . . . . . . . . [-171.3 478.3 0.0]
u-axis. . . . . . . . . . . . [1.0 0.0 -0.0]
v-axis. . . . . . . . . . . . [-0.0 1.0 0.0]
. . . . . . . . . . . . . . . . . . true
model-space-layout. . . . . . . . . true
current sheetname . . . . . . . . 0309agrs00u10001_v
. . . . . . . . . . . . . . . . . . true
model-space-layout. . . . . . . . . true
modelspace sheetname. . . . . . . model
paper-space-layout. . . . . . . . . true
sheetname . . . . . . . . . . . . 0309agrs00u10001_v
layout entities . . . . . . . . . 467
paper width . . . . . . . . . . . 1599.9459
paper height. . . . . . . . . . . 894.969
plot centered . . . . . . . . . . 0
odgsview. . . . . . . . . . . . . false
speicherzugriffsfehler
i this will help to find where is the bug. i hope not in my code.
i looked at your source and it is immediately obvious that there is no gs view attached to the active layout.
actually you picked the wrong sample to start working with gs.
odvectorizeex is the correct one.
first of all odgsinitialize() should be called after odinitialize.
(this requirement will be probably removed, but currently it is effective)
then, setupactivelayoutviews() should be calle, for the created gs device.
vladimir
|