DlgSnapVertex.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. // DlgSnapVertex.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "WorldEditor.h"
  16. #include "DlgSnapVertex.h"
  17. #ifdef _DEBUG
  18. #undef new
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CDlgSnapVertex dialog
  25. CDlgSnapVertex::CDlgSnapVertex(CWnd* pParent /*=NULL*/)
  26. : CDialog(CDlgSnapVertex::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CDlgSnapVertex)
  29. m_fX = 0.0f;
  30. m_fY = 0.0f;
  31. m_fZ = 0.0f;
  32. //}}AFX_DATA_INIT
  33. }
  34. void CDlgSnapVertex::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  37. CDialog::DoDataExchange(pDX);
  38. if( pDX->m_bSaveAndValidate == FALSE)
  39. {
  40. CBrushVertex *pvtx=pDoc->m_selVertexSelection.GetFirstInSelection();
  41. FLOAT3D vFirst=pvtx->bvx_vAbsolute;
  42. m_fX=vFirst(1);
  43. m_fY=vFirst(2);
  44. m_fZ=vFirst(3);
  45. }
  46. //{{AFX_DATA_MAP(CDlgSnapVertex)
  47. DDX_SkyFloat(pDX, IDC_VTX_SNAP_X, m_fX);
  48. DDX_SkyFloat(pDX, IDC_VTX_SNAP_Y, m_fY);
  49. DDX_SkyFloat(pDX, IDC_VTX_SNAP_Z, m_fZ);
  50. //}}AFX_DATA_MAP
  51. // if dialog is recieving data
  52. if( pDX->m_bSaveAndValidate == FALSE)
  53. {
  54. CBrushVertex *pvtx=pDoc->m_selVertexSelection.GetFirstInSelection();
  55. FLOAT3D vFirst=pvtx->bvx_vAbsolute;
  56. BOOL bValidX, bValidY, bValidZ;
  57. bValidX=bValidY=bValidZ=TRUE;
  58. // for each of the dynamic container
  59. {FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx)
  60. {
  61. if( itvtx->bvx_vAbsolute(1)!=vFirst(1)) bValidX=FALSE;
  62. if( itvtx->bvx_vAbsolute(2)!=vFirst(2)) bValidY=FALSE;
  63. if( itvtx->bvx_vAbsolute(3)!=vFirst(3)) bValidZ=FALSE;
  64. }}
  65. if( !bValidX) GetDlgItem(IDC_VTX_SNAP_X)->SetWindowText(L"");
  66. if( !bValidY) GetDlgItem(IDC_VTX_SNAP_Y)->SetWindowText(L"");
  67. if( !bValidZ) GetDlgItem(IDC_VTX_SNAP_Z)->SetWindowText(L"");
  68. }
  69. // if dialog is giving data
  70. if( pDX->m_bSaveAndValidate != FALSE)
  71. {
  72. CString strX, strY, strZ;
  73. BOOL bApplyX, bApplyY, bApplyZ;
  74. bApplyX=bApplyY=bApplyZ=FALSE;
  75. GetDlgItem(IDC_VTX_SNAP_X)->GetWindowText(strX);
  76. GetDlgItem(IDC_VTX_SNAP_Y)->GetWindowText(strY);
  77. GetDlgItem(IDC_VTX_SNAP_Z)->GetWindowText(strZ);
  78. if( strX!="") bApplyX=TRUE;
  79. if( strY!="") bApplyY=TRUE;
  80. if( strZ!="") bApplyZ=TRUE;
  81. if( bApplyX|bApplyY|bApplyZ)
  82. {
  83. pDoc->RememberUndo();
  84. pDoc->m_woWorld.TriangularizeForVertices( pDoc->m_selVertexSelection);
  85. // for each of the dynamic container
  86. {FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx)
  87. {
  88. DOUBLE3D vNew=FLOATtoDOUBLE(itvtx->bvx_vAbsolute);
  89. if( bApplyX) vNew(1)=m_fX;
  90. if( bApplyY) vNew(2)=m_fY;
  91. if( bApplyZ) vNew(3)=m_fZ;
  92. itvtx->SetAbsolutePosition(vNew);
  93. }}
  94. pDoc->m_woWorld.UpdateSectorsDuringVertexChange( pDoc->m_selVertexSelection);
  95. pDoc->m_woWorld.UpdateSectorsAfterVertexChange( pDoc->m_selVertexSelection);
  96. pDoc->UpdateAllViews( NULL);
  97. pDoc->SetModifiedFlag();
  98. }
  99. }
  100. }
  101. BEGIN_MESSAGE_MAP(CDlgSnapVertex, CDialog)
  102. //{{AFX_MSG_MAP(CDlgSnapVertex)
  103. // NOTE: the ClassWizard will add message map macros here
  104. //}}AFX_MSG_MAP
  105. END_MESSAGE_MAP()
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CDlgSnapVertex message handlers
  108. BOOL CDlgSnapVertex::PreTranslateMessage(MSG* pMsg)
  109. {
  110. if(pMsg->message==WM_KEYDOWN)
  111. {
  112. if( pMsg->wParam==VK_ESCAPE)
  113. {
  114. EndDialog( IDCANCEL);
  115. return TRUE;
  116. }
  117. }
  118. return CDialog::PreTranslateMessage(pMsg);
  119. }