DlgPgPosition.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgPgPosition.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "DlgPgPosition.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgPgPosition property page
  24. IMPLEMENT_DYNCREATE(CDlgPgPosition, CPropertyPage)
  25. CDlgPgPosition::CDlgPgPosition() : CPropertyPage(CDlgPgPosition::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CDlgPgPosition)
  28. m_fBanking = 0.0f;
  29. m_fHeading = 0.0f;
  30. m_fPitch = 0.0f;
  31. m_fX = 0.0f;
  32. m_fY = 0.0f;
  33. m_fZ = 0.0f;
  34. //}}AFX_DATA_INIT
  35. }
  36. CDlgPgPosition::~CDlgPgPosition()
  37. {
  38. }
  39. void CDlgPgPosition::DoDataExchange(CDataExchange* pDX)
  40. {
  41. if( theApp.m_bDisableDataExchange) return;
  42. CPropertyPage::DoDataExchange(pDX);
  43. SetModified( TRUE);
  44. // obtain document
  45. CWorldEditorDoc* pDoc = theApp.GetDocument();
  46. // if document doesn't exist, return
  47. if( pDoc == NULL) return;
  48. // get active view
  49. CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
  50. // if dialog is recieving data
  51. if( pDX->m_bSaveAndValidate == FALSE)
  52. {
  53. // is CSG on?
  54. if( pDoc->m_pwoSecondLayer != NULL)
  55. {
  56. // yes, pick up coordinates for editting from second layer
  57. m_fHeading = DegAngle( pDoc->m_plSecondLayer.pl_OrientationAngle(1));
  58. m_fPitch = DegAngle( pDoc->m_plSecondLayer.pl_OrientationAngle(2));
  59. m_fBanking = DegAngle( pDoc->m_plSecondLayer.pl_OrientationAngle(3));
  60. m_fX = pDoc->m_plSecondLayer.pl_PositionVector(1);
  61. m_fY = pDoc->m_plSecondLayer.pl_PositionVector(2);
  62. m_fZ = pDoc->m_plSecondLayer.pl_PositionVector(3);
  63. }
  64. // otherwise if we are in entity mode and there is only one entity selected
  65. else if( (pDoc->m_iMode == ENTITY_MODE) && ( pDoc->m_selEntitySelection.Count() == 1) )
  66. {
  67. // lock selection's dynamic container
  68. pDoc->m_selEntitySelection.Lock();
  69. // get first entity
  70. CEntity *penEntityOne = pDoc->m_selEntitySelection.Pointer(0);
  71. // unlock selection's dynamic container
  72. pDoc->m_selEntitySelection.Unlock();
  73. // get placement of first entity
  74. CPlacement3D plEntityOnePlacement = penEntityOne->GetPlacement();
  75. m_fHeading = DegAngle( plEntityOnePlacement.pl_OrientationAngle(1));
  76. m_fPitch = DegAngle( plEntityOnePlacement.pl_OrientationAngle(2));
  77. m_fBanking = DegAngle( plEntityOnePlacement.pl_OrientationAngle(3));
  78. m_fX = plEntityOnePlacement.pl_PositionVector(1);
  79. m_fY = plEntityOnePlacement.pl_PositionVector(2);
  80. m_fZ = plEntityOnePlacement.pl_PositionVector(3);
  81. }
  82. m_udSelection.MarkUpdated();
  83. }
  84. //{{AFX_DATA_MAP(CDlgPgPosition)
  85. DDX_Text(pDX, IDC_EDIT_BANKING, m_fBanking);
  86. DDX_Text(pDX, IDC_EDIT_HEADING, m_fHeading);
  87. DDX_Text(pDX, IDC_EDIT_PITCH, m_fPitch);
  88. DDX_Text(pDX, IDC_EDIT_X, m_fX);
  89. DDX_Text(pDX, IDC_EDIT_Y, m_fY);
  90. DDX_Text(pDX, IDC_EDIT_Z, m_fZ);
  91. //}}AFX_DATA_MAP
  92. // if dialog is giving data
  93. if( pDX->m_bSaveAndValidate != FALSE)
  94. {
  95. // is CSG on?
  96. if( pDoc->m_pwoSecondLayer != NULL)
  97. {
  98. // yes, copy coordinates from editting controls into second layer
  99. pDoc->m_plSecondLayer.pl_OrientationAngle(1) = AngleDeg( m_fHeading);
  100. pDoc->m_plSecondLayer.pl_OrientationAngle(2) = AngleDeg( m_fPitch);
  101. pDoc->m_plSecondLayer.pl_OrientationAngle(3) = AngleDeg( m_fBanking);
  102. pDoc->m_plSecondLayer.pl_PositionVector(1) = m_fX;
  103. pDoc->m_plSecondLayer.pl_PositionVector(2) = m_fY;
  104. pDoc->m_plSecondLayer.pl_PositionVector(3) = m_fZ;
  105. // snap values to grid
  106. pDoc->SnapToGrid( pDoc->m_plSecondLayer, SNAP_FLOAT_12);
  107. theApp.m_vfpCurrent.vfp_plPrimitive = pDoc->m_plSecondLayer;
  108. // update all document's views
  109. pDoc->UpdateAllViews( NULL);
  110. }
  111. // otherwise if we are in entity mode
  112. else if( pDoc->m_iMode == ENTITY_MODE)
  113. {
  114. // there must be only one entity selected
  115. ASSERT( pDoc->m_selEntitySelection.Count() == 1);
  116. // lock selection's dynamic container
  117. pDoc->m_selEntitySelection.Lock();
  118. // get first entity
  119. CEntity *penEntityOne = pDoc->m_selEntitySelection.Pointer(0);
  120. // unlock selection's dynamic container
  121. pDoc->m_selEntitySelection.Unlock();
  122. // get placement of first entity
  123. CPlacement3D plEntityOnePlacement = penEntityOne->GetPlacement();
  124. plEntityOnePlacement.pl_OrientationAngle(1) = AngleDeg( m_fHeading);
  125. plEntityOnePlacement.pl_OrientationAngle(2) = AngleDeg( m_fPitch);
  126. plEntityOnePlacement.pl_OrientationAngle(3) = AngleDeg( m_fBanking);
  127. plEntityOnePlacement.pl_PositionVector(1) = m_fX;
  128. plEntityOnePlacement.pl_PositionVector(2) = m_fY;
  129. plEntityOnePlacement.pl_PositionVector(3) = m_fZ;
  130. // snap entity's placement
  131. pDoc->SnapToGrid( plEntityOnePlacement, SNAP_FLOAT_12);
  132. // set placement back to entity
  133. penEntityOne->SetPlacement( plEntityOnePlacement);
  134. pDoc->SetModifiedFlag( TRUE);
  135. pDoc->UpdateAllViews( NULL);
  136. m_udSelection.MarkUpdated();
  137. // update all document's views
  138. pDoc->UpdateAllViews( NULL);
  139. }
  140. }
  141. }
  142. BEGIN_MESSAGE_MAP(CDlgPgPosition, CPropertyPage)
  143. //{{AFX_MSG_MAP(CDlgPgPosition)
  144. // NOTE: the ClassWizard will add message map macros here
  145. //}}AFX_MSG_MAP
  146. END_MESSAGE_MAP()
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CDlgPgPosition message handlers
  149. BOOL CDlgPgPosition::OnIdle(LONG lCount)
  150. {
  151. // obtain document
  152. CWorldEditorDoc* pDoc = theApp.GetDocument();
  153. if( (pDoc == NULL) || !IsWindow(m_hWnd)) return FALSE;
  154. // if selections have been changed (they are not up to date)
  155. if( !pDoc->m_chSelections.IsUpToDate( m_udSelection))
  156. {
  157. // update dialog data
  158. UpdateData( FALSE);
  159. }
  160. return TRUE;
  161. }
  162. BOOL CDlgPgPosition::PreTranslateMessage(MSG* pMsg)
  163. {
  164. if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
  165. {
  166. // move coordinates from page to entity and snap them
  167. UpdateData( TRUE);
  168. // place snapped coordinates back to dialog
  169. UpdateData( FALSE);
  170. // the message is handled
  171. return TRUE;
  172. }
  173. return CPropertyPage::PreTranslateMessage(pMsg);
  174. }