home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / SocketEdit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  4.5 KB  |  176 lines

  1. // SocketEdit.cpp : implementation file
  2. //
  3.  
  4. #include "precompile.h"
  5. #include "stdafx.h"
  6. #include "modeledit.h"
  7. #include "socketedit.h"
  8.  
  9. #include "regmgr.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. // Externs
  18. extern TCHAR szRegKeyCompany[];
  19. extern TCHAR szRegKeyApp[];
  20. extern TCHAR szRegKeyVer[];
  21.  
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CSocketEdit dialog
  25.  
  26.  
  27. CSocketEdit::CSocketEdit(CWnd* pParent /*=NULL*/)
  28.     : CDialog(CSocketEdit::IDD, pParent)
  29. {
  30.     //{{AFX_DATA_INIT(CSocketEdit)
  31.     m_Attachment = _T("");
  32.     m_Name = _T("");
  33.     m_NodeName=_T("");
  34.     m_PosX = 0.0f;
  35.     m_PosY = 0.0f;
  36.     m_PosZ = 0.0f;
  37.     m_RotX = 0.0f;
  38.     m_RotY = 0.0f;
  39.     m_RotZ = 0.0f;
  40.     m_SclX = 100.0f;
  41.     m_SclY = 100.0f;
  42.     m_SclZ = 100.0f;
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46.  
  47. void CSocketEdit::DoDataExchange(CDataExchange* pDX)
  48. {
  49.     CDialog::DoDataExchange(pDX);
  50.     //{{AFX_DATA_MAP(CSocketEdit)
  51.     DDX_Control(pDX, IDC_APPLY, m_cApply);
  52.     DDX_Text(pDX, IDC_SOCKETEDIT_ATTACHMENT, m_Attachment);
  53.     DDX_Text(pDX, IDC_SOCKETEDIT_NAME, m_Name);
  54.     DDX_Text(pDX, IDC_SOCKETEDIT_NODENAME, m_NodeName);
  55.     DDX_Text(pDX, IDC_SOCKETEDIT_POSX, m_PosX);
  56.     DDX_Text(pDX, IDC_SOCKETEDIT_POSY, m_PosY);
  57.     DDX_Text(pDX, IDC_SOCKETEDIT_POSZ, m_PosZ);
  58.     DDX_Text(pDX, IDC_SOCKETEDIT_ROTX, m_RotX);
  59.     DDX_Text(pDX, IDC_SOCKETEDIT_ROTY, m_RotY);
  60.     DDX_Text(pDX, IDC_SOCKETEDIT_ROTZ, m_RotZ);
  61.     DDX_Text(pDX, IDC_SOCKETEDIT_SCLX, m_SclX);
  62.     DDX_Text(pDX, IDC_SOCKETEDIT_SCLY, m_SclY);
  63.     DDX_Text(pDX, IDC_SOCKETEDIT_SCLZ, m_SclZ);
  64.     //}}AFX_DATA_MAP
  65.  
  66.         //this just makes sure that if it is close to 0 that it is
  67.     //cut to zero to prevent a certain side effect of numerical
  68.     //instability that was producing weird values in the edit
  69.     //box of the orientation fields.
  70.     if(fabs(m_RotX) < 0.0001)
  71.         m_RotX = 0;
  72.  
  73.     if(fabs(m_RotY) < 0.0001)
  74.         m_RotY = 0;
  75.  
  76.     if(fabs(m_RotZ) < 0.0001)
  77.         m_RotZ = 0;
  78. }
  79.  
  80.  
  81. BEGIN_MESSAGE_MAP(CSocketEdit, CDialog)
  82.     //{{AFX_MSG_MAP(CSocketEdit)
  83.     ON_BN_CLICKED(IDC_SOCKETEDIT_ATTACHMENT_LOAD, OnAttachmentLoad)
  84.     ON_BN_CLICKED(IDC_APPLY, OnApply)
  85.     //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CSocketEdit message handlers
  90.  
  91. void CSocketEdit::OnAttachmentLoad() 
  92. {
  93.     // Open up a load window for the socket attachment edit
  94.     // Look up the open directory in the registry
  95.     CRegMgr regMgr;
  96.     CString csOpenDir;
  97.     if (regMgr.Init(szRegKeyCompany, szRegKeyApp, szRegKeyVer, "OpenDir", HKEY_CURRENT_USER))
  98.     {
  99.         UINT32 dwSize = 256;
  100.         regMgr.Get("Attachment", csOpenDir.GetBufferSetLength(dwSize), dwSize);
  101.         csOpenDir.ReleaseBuffer(-1);
  102.         // Default to the model directory if the attachment directory hasn't been defined
  103.         if (csOpenDir.IsEmpty())
  104.         {
  105.             dwSize = 256;
  106.             regMgr.Get("Model", csOpenDir.GetBufferSetLength(dwSize), dwSize);
  107.             csOpenDir.ReleaseBuffer(-1);
  108.         }
  109.     }
  110.  
  111.     csOpenDir += "*.lta;*.ltc";
  112.  
  113.     // get the filename
  114.     CString sFilter;
  115.     sFilter.LoadString(IDS_LOADMODELFILTER);
  116.  
  117.     CFileDialog dlg (TRUE, "lta", (csOpenDir.GetLength()) ? (LPCTSTR)csOpenDir : NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, sFilter, this);
  118.     if (dlg.DoModal() != IDOK)
  119.     {
  120.         return;
  121.     }
  122.  
  123.     // Store the open directory in the registry
  124.     csOpenDir = dlg.GetPathName();
  125.     csOpenDir = csOpenDir.Left(csOpenDir.GetLength() - dlg.GetFileName().GetLength());
  126.     regMgr.Set("Attachment", (LPCTSTR)csOpenDir);
  127.  
  128.     // Update the dialog
  129.     m_Attachment = dlg.GetPathName();
  130.     UpdateData(FALSE);
  131. }
  132.  
  133. void CSocketEdit::OnApply() 
  134. {
  135.     if (!UpdateData(TRUE))
  136.     {
  137.                 //this just makes sure that if it is close to 0 that it is
  138.     //cut to zero to prevent a certain side effect of numerical
  139.     //instability that was producing weird values in the edit
  140.     //box of the orientation fields.
  141.     if(fabs(m_RotX) < 0.0001)
  142.         m_RotX = 0;
  143.  
  144.     if(fabs(m_RotY) < 0.0001)
  145.         m_RotY = 0;
  146.  
  147.     if(fabs(m_RotZ) < 0.0001)
  148.         m_RotZ = 0;
  149.  
  150.         return;
  151.     }
  152.  
  153.     EndDialog(IDC_APPLY);    
  154. }
  155.  
  156. BOOL CSocketEdit::OnInitDialog() 
  157. {
  158.     //this just makes sure that if it is close to 0 that it is
  159.     //cut to zero to prevent a certain side effect of numerical
  160.     //instability that was producing weird values in the edit
  161.     //box of the orientation fields.
  162.     if(fabs(m_RotX) < 0.0001)
  163.         m_RotX = 0;
  164.  
  165.     if(fabs(m_RotY) < 0.0001)
  166.         m_RotY = 0;
  167.  
  168.     if(fabs(m_RotZ) < 0.0001)
  169.         m_RotZ = 0;
  170.  
  171.     CDialog::OnInitDialog();
  172.     
  173.     return TRUE;  // return TRUE unless you set the focus to a control
  174.                   // EXCEPTION: OCX Property Pages should return FALSE
  175. }
  176.