![]() |
【转帖】problem setting layout and extensions of the layou
problem setting layout and extensions of the layout
problem setting layout and extensions of the layout with some dwg files i have a serious problem when i try to set some of the layouts and their extensions. i use the following class to save all the informations of the dwg: class cinstancedata { public: oddbdatabaseptr pdb; odgicontextfordbdatabaseptr pdwgcontext; // vectorization context. odgsdeviceptr pdevice; // rendering device and set the output stream for the device. oddblayertableptr players; // layer table oddbsymboltableiteratorptr playeriterator; odarray<odstring> layouts; uint ncurrlayout; uint nlayoutpos; colorref nbackgroundcolor; double minx; double miny; double maxx; double maxy; bool bdrawenabled; }; every time the user chooses the layout to set, i call the following methods (handle is a reference to the class cinstancedata illustrated above, and szlayout is the name of the layout). with this method i can set and see all the layouts correctly but with the layout named "model" i cannot see the drawing, while with odamfcapp application i can see the layout "model" correctly. can anyone tell me how to solve the problem or where is the mistake in my code? void winapi setactivelayout(long handle, lpctstr szlayout) { afx_manage_state(afxgetstaticmodulestate()); assert(handle); if (!handle) return; cinstancedata *pdata = (cinstancedata *)handle; // create device using gdi graphic engine pdata->pdevice = null; pdata->pdevice = theapp.m_pgswingdi->createdevice(); // search for layout for (uint i = 0; i < pdata->layouts.size(); i++) { if (pdata->layouts[i].icompare(szlayout) == 0) break; } // if non found, load first layout if (i == pdata->layouts.size()) pdata->ncurrlayout = 0; else pdata->ncurrlayout = i; pdata->pdb->setcurrentlayout(pdata->layouts[pdata->ncurrlayout]); pdata->pdevice = oddbgsmanager::setupactivelayoutviews(pdata->pdevice, pdata->pdwgcontext); odgsview *pview = pdata->pdevice->viewat(0); odabstractviewpeptr pviewabs(pview); odgeboundblock3d boxext; odgepoint3d gmin; odgepoint3d gmax; bool bbboxvalid; try { bbboxvalid = pviewabs->viewextents(pview,boxext); } catch (...) { bbboxvalid = false; } odgspaperlayouthelperptr ppaperlayouthelper = odgspaperlayouthelper::cast(pdata->pdevice); if(ppaperlayouthelper.get() && ppaperlayouthelper->overallview().get() == pview) { if(!bbboxvalid || !(boxext.minpoint().x < boxext.maxpoint().x && boxext.minpoint().y < boxext.maxpoint().y)) { bbboxvalid = ::getlayoutextents(ppaperlayouthelper->layoutid(), pview, boxext); } } else if(!bbboxvalid) // model space viewport { odgslayouthelperptr playouthelper = odgslayouthelper::cast(pdata->pdevice); if(playouthelper.get()) { bbboxvalid = ::getlayoutextents(playouthelper->layoutid(), pview, boxext); } } if(!bbboxvalid) { // set to somewhat reasonable (e.g. paper size) if(pdata->pdb->getmeasurement()==oddb::kmetric) { boxext.set(odgepoint3d::korigin, odgepoint3d(297., 210., 0.)); // set to papersize iso a4 (portrait) } else { boxext.set(odgepoint3d::korigin, odgepoint3d(11., 8.5, 0.)); // ansi a (8.50 x 11.00) (landscape) } boxext.transformby(pview->viewingmatrix()); } odgematrix3d word2eye= pview->viewingmatrix().inverse(); boxext.transformby(word2eye); boxext.getminmaxpoints(gmin, gmax); pdata->minx = gmin.x; pdata->miny = gmin.y; pdata->maxx = gmax.x; pdata->maxy = gmax.y; pview->setviewportbordervisibility(false); pview->orbit(3.1415926535897932384626433, 0.0); setbackgroundcolor(handle, pdata->nbackgroundcolor); setupextents(handle); return; } void setupextents(long handle) { if (((cinstancedata *)handle)->minx == ((cinstancedata *)handle)->maxx) return; if (((cinstancedata *)handle)->miny == ((cinstancedata *)handle)->maxy) return; odgepoint3d min(((cinstancedata *)handle)->minx, ((cinstancedata *)handle)->miny, 0.0); odgepoint3d max(((cinstancedata *)handle)->maxx, ((cinstancedata *)handle)->maxy, 0.0); odgeextents3d ext(min, max); if (ext.isvalidextents() == false) return; odgsview* pview = ((cinstancedata *)handle)->pdevice->viewat(0); odgepoint3d targ = pview->target(); odgevector3d dirfromtarg = pview->position() - targ; // set target to center of the scene, keep view direction: targ = ext.minpoint() + (ext.maxpoint() - ext.minpoint()) / 2.0; if(pview->isfrontclipped() || pview->isbackclipped()) { // keep distance from target to front & back planes targ = targ.orthoproject(odgeplane(pview->target(), dirfromtarg)); } // world extents to view cs: ext.transformby(pview->viewingmatrix()); double fw = ext.maxpoint().x - ext.minpoint().x; double fh = ext.maxpoint().y - ext.minpoint().y; pview->setview(targ + dirfromtarg, targ, pview->upvector(), fw, fh); } thank you attached files |
所有的时间均为北京时间。 现在的时间是 10:23 PM. |