找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1374|回复: 0

利用ACAD2000 ARX的AcGs类的AcGsView对象,编程实现对图纸空间和模型空间的PAN和ZOOM

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-1-22 12:37:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. PAN & ZOOM USING ACGSVIEW
  2. Product AUTOCAD  Author LEE,HENRY
  3. Date 30-APR-99  Document ID 32452
  4. Expiration date    Attachments 32452.zip
  5. Keywords API_TAHOE_OK

  6. Developer Consulting Group technical solution. Autodesk confidential, for ADN members only. Please read the disclaimer

  7. Question


  8. ObjectARX 2000 has AcGs classes specially the AcGsView object. Can I use
  9. AcGsView to pan and zoom programmatically?


  10. Answer


  11. The key to the pan and zoom capability of AcGsView is to initialize the
  12. object properly. There is a global function acgsGetGsView() which will help
  13. you to do so. However, it is design to retrieve the persistently shaded
  14. AcGsView associated with the specified viewport. This method will return NULL
  15. if there is no such view unless the bCreateIfNone flag is set to true; in
  16. this case, an AcGsView will be created and linked to the specified viewport.

  17. Moreover, it is designed to work in 3D view. But, 2D view is just a special
  18. case of 3D view. We can certainly mimic the 2D view situation.

  19. So, the very first thing is asking AutoCAD to generate an AcGsView object
  20. under all circumstances.


  21. bool getGsViewObj(AcGsView*& pView, int& vportNum)
  22. {
  23.      struct resbuf rb;
  24.      int rt = acedGetVar("CVPORT", &rb);
  25.      if(rt != RTNORM)
  26.      {
  27.          acutPrintf("\nError acquiring sysvar "CVPORT" value.");
  28.          return false;
  29.      }

  30.      vportNum = rb.resval.rint;
  31.      pView = acgsGetGsView(vportNum, true);
  32.      if(!pView)
  33.      {
  34.          acutPrintf("\nError obtaining AcGsView object.");
  35.          return false;
  36.      }
  37.      return true;
  38. }


  39. Secondly, we need to verify if we are dealing with paper space or not. This
  40. is mainly because, paper space is a 2D space.


  41. //
  42. // see solution 1881
  43. //
  44. bool purePaperSpace()
  45. {
  46.      struct resbuf rb;
  47.      int nTileMode, nVport;
  48.      acedGetVar("tilemode", &rb);
  49.      nTileMode = rb.resval.rint;
  50.      acedGetVar("cvport", &rb);
  51.      nVport = rb.resval.rint;
  52.      if(nTileMode == 0 && nVport == 1)
  53.          return true;
  54.      else
  55.          return false;
  56. }


  57. In the case of panning, it is a matter of transforming the view target point
  58. based on the user input.


  59. void myPan()
  60. {
  61.      acedDwgPoint pt1, pt2;
  62.      if(!get2Points(pt1, pt2, false))
  63.          return;
  64.      AcGsView* pView = NULL;
  65.      int vportNum;
  66.      if(!getGsViewObj(pView, vportNum))
  67.          return;

  68.      AcGePoint3d camaraPt = pView->position();
  69.      AcGeVector3d upVector = pView->upVector();

  70.      double fieldWd = pView->fieldWidth();
  71.      double fieldHt = pView->fieldHeight();

  72.      double xShift = pt1[X] - pt2[X];
  73.      double yShift = pt1[Y] - pt2[Y];
  74.      
  75.      AcGePoint3d targetOrinPt = pView->target();
  76.      AcGePoint3d targetPt(targetOrinPt.x + xShift,
  77.          targetOrinPt.y + yShift, targetOrinPt.z);
  78.      AcGsView::Projection projType = pView->isPerspective() ?     
  79.          AcGsView::Projection::kPerspective :
  80. AcGsView::Projection::kParallel;
  81.      pView->setView(camaraPt, targetPt, upVector, fieldWd, fieldHt,
  82. projType);
  83.      pView->update();
  84.      
  85.      if(purePaperSpace())
  86.      {
  87.          tweakToUpdateWindow();
  88.          acgsSetViewParameters(vportNum, pView, false, true);
  89.      }
  90.      else
  91.          acgsSetViewParameters(vportNum, pView, true, true);
  92. }


  93. In the case of zooming, it is a matter of resetting the view target point and
  94. also the view window size based on the use input.


  95. void myZoom()
  96. {
  97.      acedDwgPoint pt1, pt2;
  98.      if(!get2Points(pt1, pt2, true))
  99.          return;
  100.      AcGsView* pView = NULL;
  101.      int vportNum;
  102.      if(!getGsViewObj(pView, vportNum))
  103.          return;

  104.      AcGePoint3d camaraPt = pView->position();
  105.      AcGeVector3d upVector = pView->upVector();
  106.      double xMin = min(pt1[X], pt2[X]);
  107.      double xMax = max(pt1[X], pt2[X]);
  108.      double yMin = min(pt1[Y], pt2[Y]);
  109.      double yMax = max(pt1[Y], pt2[Y]);
  110.      double fieldWd = xMax - xMin;
  111.      double fieldHt = yMax - yMin;
  112.      AcGePoint3d targetPt(xMin+fieldWd/2, yMin+fieldHt/2, 0);
  113.      AcGsView::Projection projType = pView->isPerspective() ?         
  114.   
  115.          AcGsView::Projection::kPerspective :
  116. AcGsView::Projection::kParallel;
  117.      pView->setView(camaraPt, targetPt, upVector, fieldWd, fieldHt,
  118. projType);
  119.      pView->update();
  120.      
  121.      if(purePaperSpace())
  122.      {
  123.          tweakToUpdateWindow();
  124.          acgsSetViewParameters(vportNum, pView, false, true);
  125.      }
  126.      else
  127.          acgsSetViewParameters(vportNum, pView, true, true);
  128. }


  129. You probably wondering at this point, why there is a tweakToUpdateWindow();
  130. function call if it is paper space?

  131. Well, that is where the limitation of AcGsView generated from the
  132. acgsGetGsView() coming in. The view parameters are calculated properly, but
  133. the view is not update by the setView(), update() and
  134. acgsSetViewParameters(). Nor it will be updated by acedUpdateDisplay(). So
  135. the workaround that I can come up with, is to calculated the view window
  136. client area size and move the window just slightly to force AutoCAD to update
  137. the paper space viewport.


  138. void tweakToUpdateWindow()
  139. {
  140.      CView* pActiveView =
  141. acedGetAcadFrame()->GetActiveFrame()->GetActiveView();
  142.      CRect rect;
  143.      pActiveView->GetClientRect(&rect);
  144.      rect.InflateRect(1,0,16,0);
  145.      pActiveView->MoveWindow(rect, TRUE);
  146. }


  147. Please find the attached project for all the related code in its entirety.

  148. See also,
  149. solution 8781 - HOW TO SIMULATE ZOOM WINDOW IN OBJECTARX WITHOUT
  150. ADS_COMMAND()
  151. solution 1881 - HOW DO I KNOW I'M IN PAPERSPACE FOR SURE  
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-5 03:10 , Processed in 0.388839 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表