📄 femmviewview.cpp
字号:
if (EditAction==1){
CComplex z;
int i;
CFemmviewDoc *pDoc=GetDocument();
z.Set(mx,my);
i=pDoc->contour.GetSize();
if(i>0){
if (z!=pDoc->contour[i-1])
pDoc->contour.Add(z);
}
else pDoc->contour.Add(z);
DrawUserContour(FALSE);
}
CView::OnRButtonDown(nFlags, point);
}
void CFemmviewView::OnEditCopyAsMetafile()
{
// puts a metafile drawing of the screen on the clipboard
CMetaFileDC Meta;
RECT r;
CRgn R;
Meta.CreateEnhanced(NULL,NULL,NULL,NULL);
GetClientRect(&r);
R.CreateRectRgnIndirect(&r);
Meta.SelectClipRgn(&R);
OnDraw(&Meta);
HENHMETAFILE hMeta=Meta.CloseEnhanced();
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_ENHMETAFILE,hMeta);
CloseClipboard();
}
void CFemmviewView::OnEditCopy()
{
// puts a bitmap of the screen on the clipboard
RECT r;
CDC tempDC;
CBitmap bitmap;
CDC *pDC=GetDC();
GetClientRect(&r);
tempDC.CreateCompatibleDC(pDC);
bitmap.CreateCompatibleBitmap(pDC, r.right, r.bottom);
tempDC.SelectObject(&bitmap);
tempDC.BitBlt(0, 0, r.right, r.bottom, pDC, 0, 0, SRCCOPY);
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP, HBITMAP(bitmap));
CloseClipboard();
}
void CFemmviewView::OnReload()
{
CFemmviewDoc *pDoc=GetDocument();
BeginWaitCursor();
pDoc->OnReload();
EndWaitCursor();
if (d_ResetOnReload==FALSE) pDoc->FirstDraw=FALSE;
RedrawView();
}
void CFemmviewView::OnMenuArea()
{
CFemmviewDoc *pDoc=GetDocument();
if(EditAction==1){
EraseUserContour(TRUE);
pDoc->contour.RemoveAll();
}
EditAction=2;
// update check boxes in the main menu...
CMainFrame *MFrm;
MFrm=(CMainFrame *)GetParentFrame();
CMenu* MMnu=MFrm->GetMenu();
CToolBar *pToolBar;
pToolBar=&MFrm->m_toolBar;
CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
MMnu->CheckMenuItem(ID_MENU_AREA, MF_CHECKED);
MMnu->CheckMenuItem(ID_MENU_CONTOUR, MF_UNCHECKED);
MMnu->CheckMenuItem(ID_MENU_POINT, MF_UNCHECKED);
tc->CheckButton(ID_MENU_AREA, TRUE);
tc->CheckButton(ID_MENU_CONTOUR, FALSE);
tc->CheckButton(ID_MENU_POINT, FALSE);
}
void CFemmviewView::OnMenushowpts()
{
CFrameWnd *MFrm;
MFrm=GetParentFrame();
CMenu* MMnu=MFrm->GetMenu();
if(PtsFlag==FALSE){
PtsFlag=TRUE;
MMnu->CheckMenuItem(ID_MENUSHOWPTS, MF_CHECKED);
}
else{
PtsFlag=FALSE;
MMnu->CheckMenuItem(ID_MENUSHOWPTS, MF_UNCHECKED);
}
RedrawView();
}
void CFemmviewView::OnMenuContour()
{
CFemmviewDoc *pDoc=GetDocument();
if(EditAction==2){
int i;
BOOL flg=FALSE;
pDoc->bHasMask=FALSE;
for(i=0;i<pDoc->blocklist.GetSize();i++){
if (pDoc->blocklist[i].IsSelected==TRUE){
pDoc->blocklist[i].IsSelected=FALSE;
flg=TRUE;
}
}
if(flg==TRUE) RedrawView();
}
EditAction=1;
CMainFrame *MFrm;
MFrm=(CMainFrame *)GetParentFrame();
CMenu* MMnu=MFrm->GetMenu();
CToolBar *pToolBar;
pToolBar=&MFrm->m_toolBar;
CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
MMnu->CheckMenuItem(ID_MENU_AREA, MF_UNCHECKED);
MMnu->CheckMenuItem(ID_MENU_CONTOUR, MF_CHECKED);
MMnu->CheckMenuItem(ID_MENU_POINT, MF_UNCHECKED);
tc->CheckButton(ID_MENU_AREA, FALSE);
tc->CheckButton(ID_MENU_CONTOUR, TRUE);
tc->CheckButton(ID_MENU_POINT, FALSE);
}
void CFemmviewView::OnMenuPoint()
{
CFemmviewDoc *pDoc=GetDocument();
if (EditAction==1){
EraseUserContour(TRUE);
pDoc->contour.RemoveAll();
}
if (EditAction==2){
int i;
BOOL flg=FALSE;
pDoc->bHasMask=FALSE;
for(i=0;i<pDoc->blocklist.GetSize();i++){
if (pDoc->blocklist[i].IsSelected==TRUE){
pDoc->blocklist[i].IsSelected=FALSE;
flg=TRUE;
}
}
if(flg==TRUE) RedrawView();
}
EditAction=0;
// update check boxes in the main menu...
CMainFrame *MFrm;
MFrm=(CMainFrame *)GetParentFrame();
CMenu* MMnu=MFrm->GetMenu();
CToolBar *pToolBar;
pToolBar=&MFrm->m_toolBar;
CToolBarCtrl *tc=&pToolBar->GetToolBarCtrl();
MMnu->CheckMenuItem(ID_MENU_AREA, MF_UNCHECKED);
MMnu->CheckMenuItem(ID_MENU_CONTOUR, MF_UNCHECKED);
MMnu->CheckMenuItem(ID_MENU_POINT, MF_CHECKED);
tc->CheckButton(ID_MENU_AREA, FALSE);
tc->CheckButton(ID_MENU_CONTOUR, FALSE);
tc->CheckButton(ID_MENU_POINT, TRUE);
}
void CFemmviewView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CFemmviewDoc *pDoc=GetDocument();
if (nChar==VK_LEFT) OnPanLeft();
if (nChar==VK_RIGHT) OnPanRight();
if (nChar==VK_UP) OnPanUp();
if (nChar==VK_DOWN) OnPanDown();
if (nChar==VK_PRIOR) OnZoomIn(); // page up
if (nChar==VK_NEXT) OnZoomOut(); // page down
if (nChar==VK_HOME) OnZoomNatural();
if ((nChar==VK_TAB) && (EditAction!=2)) EnterPoint();
if ((nChar==VK_DELETE) && (EditAction==1)){
int k;
k=pDoc->contour.GetSize();
if(k>1){
EraseUserContour(FALSE);
pDoc->contour.RemoveAt(k-1);
DrawUserContour(TRUE);
}
else if(k!=0){
EraseUserContour(TRUE);
pDoc->contour.RemoveAt(0);
}
}
if ((nChar==VK_ESCAPE) && (EditAction==1)){
EraseUserContour(TRUE);
pDoc->contour.RemoveAll();
}
if ((nChar==VK_SHIFT) && (EditAction==1)){
if(pDoc->contour.GetSize()>1)
{
CBendContourDlg dlg;
dlg.DoModal();
if (dlg.m_angle!=0){
EraseUserContour(FALSE);
pDoc->BendContour(dlg.m_angle,dlg.m_anglestep);
DrawUserContour(TRUE);
}
}
}
if ((nChar==VK_ESCAPE) && (EditAction==2)){
BOOL flg=FALSE;
int i;
for(i=0;i<pDoc->blocklist.GetSize();i++)
{
if(pDoc->blocklist[i].IsSelected==TRUE)
{
flg=TRUE;
pDoc->blocklist[i].IsSelected=FALSE;
}
}
if (flg==TRUE) RedrawView();
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CFemmviewView::EnterPoint()
{
CGetPoint pDlg;
double x,y,t;
CFemmviewDoc* pDoc = GetDocument();
// Send present parameter values to the dialog
// pDlg.m_rji=TheDoc->vi[0];
if(pDoc->Coords==FALSE){
pDlg.m_coord1 = mx;
pDlg.m_coord2 = my;
if(pDoc->ProblemType==0){
pDlg.m_label1 = "x-coord";
pDlg.m_label2 = "y-coord";
}
else{
pDlg.m_label1 = "r-coord";
pDlg.m_label2 = "z-coord";
}
}
else{
pDlg.m_coord1=sqrt(mx*mx+my*my);
pDlg.m_coord2=atan2(my,mx)*180/PI;
pDlg.m_label1="radius";
pDlg.m_label2="degrees";
}
// Display dialog and collect data
if(pDlg.DoModal()==IDOK)
{
if(pDoc->Coords==FALSE){
x=pDlg.m_coord1;
y=pDlg.m_coord2;
}
else{
t=pDlg.m_coord2*PI/180;
x=pDlg.m_coord1*cos(t);
y=pDlg.m_coord1*sin(t);
}
if (EditAction==0) DisplayPointProperties(x,y);
if (EditAction==1){
CComplex z;
z.Set(x,y);
pDoc->contour.Add(z);
DrawUserContour(FALSE);
}
}
}
void CFemmviewView::SpecialLine(CDC *pDC, int X0, int Y0, int X1, int Y1, int flag)
{
double l;
int i,j,k,p,x,y,z;
int hi,lo,zj;
BOOL InLine,DrawIt;
COLORREF c;
COLORREF Red;
RECT r;
GetClientRect(&r);
Red=SelColor;
int x0,y0,x1,y1,xb,yb;
x0=X0; y0=Y0;
x1=X1; y1=Y1;
xb=r.right;
yb=r.bottom;
DrawIt=TRUE;
// test to see if any of the endpoints are offscreen.
// if they are, crop them to the screen size
if ((x0<0) || (x0>xb) || (x1<0) || (x1>xb) ||
(y0<0) || (y0>yb) || (y1<0) || (y1>yb))
{
DrawIt=FALSE;
double z,dx0,dx1,dy0,dy1,dxb,dyb;
dx0=(double) x0;
dy0=(double) y0;
dx1=(double) x1;
dy1=(double) y1;
dxb=(double) xb;
dyb=(double) yb;
if ((x1-x0)!=0)
{
// test left side;
z=(-dx0)/(dx1-dx0);
if ((z>=0.) && (z<=1.))
{
DrawIt=TRUE;
if(x0<0)
{
dx0=0;
x0=0;
dy0=dy0+z*(dy1-dy0);
y0=(int) dy0;
}
else{
dx1=0;
x1=0;
dy1=dy0+z*(dy1-dy0);
y1=(int) dy1;
}
}
// test right side;
z=(dxb-dx0)/(dx1-dx0);
if ((z>=0.) && (z<=1.))
{
DrawIt=TRUE;
if(x0>xb)
{
dx0=dxb;
x0=xb;
dy0=dy0+z*(dy1-dy0);
y0=(int) dy0;
}
else{
dx1=dxb;
x1=xb;
dy1=dy0+z*(dy1-dy0);
y1=(int) dy1;
}
}
}
if ((y1-y0)!=0)
{
// test top side;
z=(-dy0)/(dy1-dy0);
if ((z>=0.) && (z<=1.))
{
DrawIt=TRUE;
if(y0<0)
{
dy0=0;
y0=0;
dx0=dx0+z*(dx1-dx0);
x0=(int) dx0;
}
else{
dy1=0;
y1=0;
dx1=dx0+z*(dx1-dx0);
x1=(int) dx1;
}
}
// test bottom side;
z=(dyb-dy0)/(dy1-dy0);
if ((z>=0.) && (z<=1.))
{
DrawIt=TRUE;
if(y0>dyb)
{
dy0=dyb;
y0=yb;
dx0=dx0+z*(dx1-dx0);
x0=(int) dx0;
}
else{
dy1=dyb;
y1=yb;
dx1=dx0+z*(dx1-dx0);
x1=(int) dx1;
}
}
}
}
if(!DrawIt) return;
l=(double)((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
l=sqrt(l);
k=(int) l;
for(i=0;i<=k;i++)
{
if(k!=0){
x=x0+((x1-x0)*i)/k;
y=y0+((y1-y0)*i)/k;
}
else{
x=x0;
y=y0;
}
z=x+y*r.right;
// check if this point is already in the line
// in the case that a red line is supposed to be drawn;
if(flag==FALSE)
{
// bisection search to see if the pixel under
// consideration is already in LinePix
InLine=FALSE;
lo=0;
hi=LinePix.GetSize()-1;
if(hi>=0){
zj=LinePix[0].z;
if(z<=zj){
hi=0;
if(z==zj) InLine=TRUE;
}
zj=LinePix[hi].z;
if(z>=zj){
hi+=1;
lo=hi;
if(z==zj) InLine=TRUE;
}
while((hi-lo)>1){
j=(lo+hi)/2;
zj=LinePix[j].z;
if(zj==z){
InLine=TRUE;
break;
}
else if(zj<z) lo=j;
else hi=j;
}
}
else hi=0;
if(InLine==FALSE){
CPixel NewPixel;
NewPixel.z=z;
NewPixel.c=pDC->GetPixel(x,y);
if (hi==LinePix.GetSize()) LinePix.Add(NewPixel);
else LinePix.InsertAt(hi,NewPixel);
}
}
// if line is to be erased, get entry out of the pixel list
if(flag!=FALSE){
// bisection search to find the pixel
InLine=FALSE;
lo=0;
hi=LinePix.GetSize()-1;
if(hi>=0){
zj=LinePix[0].z;
if(z<=zj){
hi=0;
if(z==zj){
InLine=TRUE;
p=0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -