📄 tabtoolsimulate.cpp
字号:
// TabtoolSimulate.cpp : implementation file
//
#include "stdafx.h"
#include "Simulate.h"
#include "TabtoolSimulate.h"
#include "MainFrm.h"
#include "SimulateDoc.h"
#include "SimulateView.h"
#include "DialogOfSingleMissle.h"
#include "DialogOfAllDirections.h"
#include "NProbability.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabtoolSimulate dialog
CTabtoolSimulate::CTabtoolSimulate(CWnd* pParent /*=NULL*/)
: CDialog(CTabtoolSimulate::IDD, pParent)
{
//{{AFX_DATA_INIT(CTabtoolSimulate)
//}}AFX_DATA_INIT
m_fAlfa1SM = 0.0;
m_fAlfa2SM = 0.0;
m_fCitaSM = 0.0;
m_fVfSM = 0.0;
m_fVmSM = 0.0;
m_fVtSM = 0.0;
m_fMiuSM = 0.0;
m_fSigemaSM = 0.0;
m_nTimesSM = 1;
m_nYScanLinesSM = 200;
m_fAlfa1AD = 0.0;
m_fAlfa2AD = 0.0;
m_fCitaAD = 0.0;
m_fVfAD = 0.0;
m_fVmAD = 0.0;
m_fVtAD = 0.0;
m_nYScanLinesAD = 200;
m_nIntervalsAD = 1;
m_fMinDistanceAD = 0.0;
m_fMaxDistanceAD = 0.0;
}
void CTabtoolSimulate::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTabtoolSimulate)
DDX_Control(pDX, IDC_TABTOOL_SIMULATE_IMPORTANTMESHESLIST, m_ImportantMeshesList);
DDX_Control(pDX, IDC_TABTOOL_SIMULATE_MESHESLIST1, m_MeshesList1);
DDX_Control(pDX, IDC_TABTOOL_SIMULATE_MESHESWANTEDLIST, m_MeshesWantedList);
DDX_Control(pDX, IDC_TABTOOL_SIMULATE_MESHESLIST, m_MeshesList);
DDX_Control(pDX, IDC_PROGRESS1, m_ProgressBar);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTabtoolSimulate, CDialog)
//{{AFX_MSG_MAP(CTabtoolSimulate)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_ADDONE, OnTabtoolSimulateAddone)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_ADDALL, OnTabtoolSimulateAddall)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_REMOVEALL, OnTabtoolSimulateRemoveall)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_REMOVEONE, OnTabtoolSimulateRemoveone)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_SINGLEMISSILE, OnTabtoolSimulateSinglemissile)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_ALLDIRECTIONS, OnTabtoolSimulateAlldirections)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_MULTIMISSILES, OnTabtoolSimulateMultimissiles)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_ADDALL1, OnTabtoolSimulateAddall1)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_ADDONE1, OnTabtoolSimulateAddone1)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_REMOVEALL1, OnTabtoolSimulateRemoveall1)
ON_BN_CLICKED(IDC_TABTOOL_SIMULATE_REMOVEONE1, OnTabtoolSimulateRemoveone1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabtoolSimulate message handlers
BOOL CTabtoolSimulate::Create(CWnd * pParentWnd)
{
return CDialog::Create(CTabtoolSimulate::IDD, pParentWnd);
}
void CTabtoolSimulate::OnOK()
{
return;
}
void CTabtoolSimulate::OnCancel()
{
return;
}
CView * CTabtoolSimulate::GetRenderView()
{
CSimulateApp *pApp = (CSimulateApp *)AfxGetApp();
CMainFrame *pMainFrame = (CMainFrame *)pApp->m_pMainWnd;
CView *pView = (CView *)pMainFrame->m_wndSplitter.GetPane(0,1);
return pView;
}
void CTabtoolSimulate::ResetAll()
{
//Reset the two lists used to caculate the weight center
m_MeshesList.ResetContent();
m_MeshesWantedList.ResetContent();
//Reset the two lists used to select the important meshes
m_MeshesList1.ResetContent();
m_ImportantMeshesList.ResetContent();
UpdateData(FALSE);
}
void CTabtoolSimulate::OnTabtoolSimulateAddone()
{
// TODO: Add your control notification handler code here
CString sMeshName;
int nIndex;
if((nIndex = m_MeshesList.GetCurSel()) != LB_ERR)
{
m_MeshesList.GetText(nIndex, sMeshName);
if(sMeshName.IsEmpty())
return;
else
{
if(m_MeshesList.DeleteString(nIndex) == LB_ERR)
return;
nIndex = m_MeshesWantedList.AddString(sMeshName);
if(nIndex == LB_ERR || nIndex == LB_ERRSPACE)
return;
}
}
}
void CTabtoolSimulate::OnTabtoolSimulateAddall()
{
// TODO: Add your control notification handler code here
CString sMeshName;
int nIndex;
int nItems;
int nReturnItem;
if((nItems = m_MeshesList.GetCount()) != LB_ERR)
{
for(nIndex = 0; nIndex < nItems; nIndex++)
{
m_MeshesList.GetText(nIndex, sMeshName);
if(sMeshName.IsEmpty())
return;
else
{
nReturnItem = m_MeshesWantedList.AddString(sMeshName);
if(nReturnItem == LB_ERR || nReturnItem == LB_ERRSPACE)
return;
}
}
m_MeshesList.ResetContent();
}
}
void CTabtoolSimulate::OnTabtoolSimulateRemoveall()
{
// TODO: Add your control notification handler code here
CString sMeshName;
int nIndex;
int nItems;
int nReturnItem;
if((nItems = m_MeshesWantedList.GetCount()) != LB_ERR)
{
for(nIndex = 0; nIndex < nItems; nIndex++)
{
m_MeshesWantedList.GetText(nIndex, sMeshName);
if(sMeshName.IsEmpty())
return;
else
{
nReturnItem = m_MeshesList.AddString(sMeshName);
if(nReturnItem == LB_ERR || nReturnItem == LB_ERRSPACE)
return;
}
}
m_MeshesWantedList.ResetContent();
}
}
void CTabtoolSimulate::OnTabtoolSimulateRemoveone()
{
// TODO: Add your control notification handler code here
CString sMeshName;
int nIndex;
if((nIndex = m_MeshesWantedList.GetCurSel()) != LB_ERR)
{
m_MeshesWantedList.GetText(nIndex, sMeshName);
if(sMeshName.IsEmpty())
return;
else
{
if(m_MeshesWantedList.DeleteString(nIndex) == LB_ERR)
return;
nIndex = m_MeshesList.AddString(sMeshName);
if(nIndex == LB_ERR || nIndex == LB_ERRSPACE)
return;
}
}
}
void CTabtoolSimulate::OnTabtoolSimulateSinglemissile()
{
// TODO: Add your control notification handler code here
CSimulateDoc* pDoc = ((CSimulateView *)GetRenderView())->GetDocument();
ASSERT_VALID(pDoc);
CString sMsg;
float fPI = 3.1415926535;
int i;
int nMeshesWantedItems;
nMeshesWantedItems = m_MeshesWantedList.GetCount();
if(nMeshesWantedItems == LB_ERR)
{
sMsg.Format("计算形心列表框操作出错!");
AfxMessageBox(sMsg, MB_ICONSTOP | MB_OK);
return;
}
if(nMeshesWantedItems == 0)
{
sMsg.Format("未选择进行形心计算的部件!");
AfxMessageBox(sMsg ,MB_ICONEXCLAMATION | MB_OK);
return;
}
int nImportantMeshesItems = m_ImportantMeshesList.GetCount();
int nUnimportantMeshesItems = m_MeshesList1.GetCount();
if(nImportantMeshesItems == LB_ERR | nUnimportantMeshesItems == LB_ERR)
{
sMsg.Format("重要部件列表框操作出错!");
AfxMessageBox(sMsg, MB_ICONSTOP | MB_OK);
return;
}
if(nImportantMeshesItems == 0)
{
sMsg.Format("未选择用于分析的重要部件!");
AfxMessageBox(sMsg ,MB_ICONEXCLAMATION | MB_OK);
return;
}
CString * pImportantMeshNameArray = new CString [nImportantMeshesItems];
for(i = 0; i < nImportantMeshesItems; i++)
{
m_ImportantMeshesList.GetText(i, pImportantMeshNameArray[i]);
}
//Now it's the big time to show the dialog for input messages!
CDialogOfSingleMissle DialogOfSingleMissle;
DialogOfSingleMissle.m_fAlfa1 = m_fAlfa1SM;
DialogOfSingleMissle.m_fAlfa2 = m_fAlfa2SM;
DialogOfSingleMissle.m_fCita = m_fCitaSM;
DialogOfSingleMissle.m_fVf = m_fVfSM;
DialogOfSingleMissle.m_fVm = m_fVmSM;
DialogOfSingleMissle.m_fVt = m_fVtSM;
DialogOfSingleMissle.m_fMiu = m_fMiuSM;
DialogOfSingleMissle.m_fSigema = m_fSigemaSM;
DialogOfSingleMissle.m_nTimes = m_nTimesSM;
DialogOfSingleMissle.m_nYScanLines = m_nYScanLinesSM;
if(DialogOfSingleMissle.DoModal() == IDOK)
{
//If the input values are checked! let's prepare the data for calculation!
CVertex DetonationVertex;
float fDetonationConeAngle;
float fAlfa1 = DialogOfSingleMissle.m_fAlfa1;
float fAlfa2 = DialogOfSingleMissle.m_fAlfa2;
float fCita = DialogOfSingleMissle.m_fCita;
float fVf = DialogOfSingleMissle.m_fVf;
float fVm = DialogOfSingleMissle.m_fVm;
float fVt = DialogOfSingleMissle.m_fVt;
float fFai1;
float fFai2;
double dX, dY, dZ, dTemp;
m_fAlfa1SM = DialogOfSingleMissle.m_fAlfa1;
m_fAlfa2SM = DialogOfSingleMissle.m_fAlfa2;
m_fCitaSM = DialogOfSingleMissle.m_fCita;
m_fVfSM = DialogOfSingleMissle.m_fVf;
m_fVmSM = DialogOfSingleMissle.m_fVm;
m_fVtSM = DialogOfSingleMissle.m_fVt;
m_fMiuSM = DialogOfSingleMissle.m_fMiu;
m_fSigemaSM = DialogOfSingleMissle.m_fSigema;
m_nTimesSM = DialogOfSingleMissle.m_nTimes;
m_nYScanLinesSM = DialogOfSingleMissle.m_nYScanLines;
CNProbability NProbability(DialogOfSingleMissle.m_fMiu,
DialogOfSingleMissle.m_fSigema);
fFai1 = atan((fVm * sin(fCita*fPI/180.) + fVf * sin(fCita*fPI/180. + fAlfa1*fPI/180.))/
(fVm * cos(fCita*fPI/180.) + fVf * cos(fCita*fPI/180. + fAlfa1*fPI/180.) - fVt)) - fCita*fPI/180.;
fFai2 = atan((fVm * sin(fCita*fPI/180.) + fVf * sin(fCita*fPI/180. + fAlfa2*fPI/180.))/
(fVm * cos(fCita*fPI/180.) + fVf * cos(fCita*fPI/180. + fAlfa2*fPI/180.) - fVt)) - fCita*fPI/180.;
if(fFai1 < 0.)fFai1 = fPI + fFai1;
if(fFai2 < 0.)fFai2 = fPI + fFai2;
fDetonationConeAngle = fFai2 - fFai1;
CEllipseSphere EllipseSphere;
(EllipseSphere.m_VertexCenter).m_fX = (pDoc->m_fGlobalXMin +
pDoc->m_fGlobalXMax)/2.0;
(EllipseSphere.m_VertexCenter).m_fY = (pDoc->m_fGlobalYMin +
pDoc->m_fGlobalYMax)/2.0;
(EllipseSphere.m_VertexCenter).m_fZ = (pDoc->m_fGlobalZMin +
pDoc->m_fGlobalZMax)/2.0;
EllipseSphere.m_fA = (pDoc->m_fGlobalXMax -
pDoc->m_fGlobalXMin)/2.0;
EllipseSphere.m_fB = (pDoc->m_fGlobalYMax -
pDoc->m_fGlobalYMin)/2.0;
EllipseSphere.m_fC = (pDoc->m_fGlobalZMax -
pDoc->m_fGlobalZMin)/2.0;
//now let's calculate the Weight Center of the selected TriMeshes
float fTotalArea, fSumOfWeightX, fSumOfWeightY, fSumOfWeightZ;
CVertex TriMeshesWeightCenterVertex;
int Index, nIndex;
CString sMeshName;
fTotalArea = 0.0;
fSumOfWeightX = 0.0;
fSumOfWeightY = 0.0;
fSumOfWeightZ = 0.0;
for(nIndex = 0; nIndex < nMeshesWantedItems; nIndex++)
{
m_MeshesWantedList.GetText(nIndex, sMeshName);
Index = pDoc->GetNumTriMeshes();
while(Index--)
{
if((pDoc->GetTriMesh(Index))->m_sName == sMeshName)
{
//We have found the mesh
//So just get the m_fArea and the m_WeightCenter
fTotalArea = fTotalArea + (pDoc->GetTriMesh(Index))->m_fArea;
fSumOfWeightX = fSumOfWeightX + (pDoc->GetTriMesh(Index))->m_fArea * ((pDoc->GetTriMesh(Index))->m_WeightCenter).m_fX;
fSumOfWeightY = fSumOfWeightY + (pDoc->GetTriMesh(Index))->m_fArea * ((pDoc->GetTriMesh(Index))->m_WeightCenter).m_fY;
fSumOfWeightZ = fSumOfWeightZ + (pDoc->GetTriMesh(Index))->m_fArea * ((pDoc->GetTriMesh(Index))->m_WeightCenter).m_fZ;
break;
}
}
}
TriMeshesWeightCenterVertex.m_fX = fSumOfWeightX/fTotalArea;
TriMeshesWeightCenterVertex.m_fY = fSumOfWeightY/fTotalArea;
TriMeshesWeightCenterVertex.m_fZ = fSumOfWeightZ/fTotalArea;
float fLengthOfDPToWC; //The length of the detonation point to the weight center
float fLengthOfDetonation; //The half length of the detonation boundary
CString * pUnimportantMeshNameArray;
if(nUnimportantMeshesItems == 0)
{
//There do not exist any unimportant mesh
//so let's process this situation
pUnimportantMeshNameArray = NULL;
}
else
{
//There must exist some unimportant meshes
//so we should store them to an array
pUnimportantMeshNameArray = new CString [nUnimportantMeshesItems];
for(i = 0; i < nUnimportantMeshesItems; i++)
{
m_MeshesList1.GetText(i, pUnimportantMeshNameArray[i]);
}
}
CSimulateView *pSimulateView;
pSimulateView = (CSimulateView *)GetRenderView();
TCHAR szCurDir[260];
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
DWORD dwExitCode;
BOOL fSuccess;
FILE * ExeFile;
HANDLE hProcess;
//Get the current directory
GetCurrentDirectory(sizeof(szCurDir)/sizeof(TCHAR), szCurDir);
//Change the current directory to the start directory
SetCurrentDirectory((pSimulateView->GetDocument())->m_szStartDirectory);
//Create the directory for single missile simulation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -