⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shape.cpp

📁 This is my assignment for my tutor s Class. and many problems exist,so you should comprhend it and i
💻 CPP
字号:
// Shape.cpp : implementation file
//
#include "stdafx.h"
#include "FilmDesign.h"
#include "Shape.h"
#include "math.h"
#include "Parameter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define  PI  3.1415926
/////////////////////////////////////////////////////////////////////////////
// CShape

IMPLEMENT_DYNCREATE(CShape, CView)

CShape::CShape():m_Axis()
{     
	this->m_Shapeofkinds=1;
	this->m_Daona[0]=0.0;
	this->m_Daona[1]=0.0;
	this->m_InAngle=0;
	this->m_WaveLength=450.0;
	this->m_ThickKinds=2;
	this->m_VibrateKinds=1;
	this->m_InN=1.0;
	for(int i=0;i<MAX;i++)
	{   m_Shape[i].SetName("玻璃基片");
		m_Shape[i].SetA(0.0);
		m_Shape[i].SetN(0.0);
		m_Shape[i].SetK(0.0);
		m_Shape[i].SetM(0.0);
		m_Shape[i].SetUse(false);
		
	}
    
    this->m_Title="X-Y Graph";
	this->SetLine(PS_SOLID,2,RGB(0,20,30));

    this->m_fWaveLength.RemoveAll();
	this->m_Reflectance.RemoveAll();
	this->m_Transistance.RemoveAll();
	this->m_Absorption.RemoveAll();

}

CShape::~CShape()
{
}


BEGIN_MESSAGE_MAP(CShape, CView)
	//{{AFX_MSG_MAP(CShape)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShape drawing

void CShape::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here


	


}

/////////////////////////////////////////////////////////////////////////////
// CShape diagnostics

#ifdef _DEBUG
void CShape::AssertValid() const
{
	CView::AssertValid();
}

void CShape::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CShape message handlers

CShape::CShape(CData data[],CAxis axis):m_Axis()
{
	this->m_Shapeofkinds=1;
    this->m_Daona[0]=0.0f;
	this->m_Daona[1]=0.0f;
	this->m_ThickKinds=2;
	this->m_InAngle=0;
	this->m_WaveLength=450.0f;
	this->m_VibrateKinds=3;
	this->m_InN=1.0f;
	for(int i=0;data[i].GetUse();i++)
	{
	   m_Shape[i].SetName(data[i].GetName());
	   m_Shape[i].SetA(data[i].GetA());
	   m_Shape[i].SetN(data[i].GetN());
	   m_Shape[i].SetK(data[i].GetK());
	   m_Shape[i].SetM(data[i].GetM());
	   m_Shape[i].SetUse(data[i].GetUse());
	   
	 }


    m_Axis.SetCenter(axis.GetCenter()) ;
	m_Axis.SetColor(axis.GetColor() );
	m_Axis.SetIntervalx(axis.GetIntervalx());
	m_Axis.SetIntervaly(axis.GetIntervaly());
	m_Axis.SetLablex(axis.GetLablex());
	m_Axis.SetLabley(axis.GetLabley());
	m_Axis.SetLineStye(axis.GetLineStyle());
	m_Axis.SetRange(axis.GetMinx(),axis.GetMaxx(),axis.GetMiny(),axis.GetMaxy()) ;
	m_Axis.SetWidth(axis.GetWidth());
	m_Axis.SetRatio(axis.GetRatio());
    this->m_Title="X-Y Graph";
   	this->SetLine(PS_SOLID,2,RGB(0,20,30));

}

void CShape::Create(CData data[])
{
    int i;
	for( i=0;data[i].GetUse();i++)
	{
	   m_Shape[i].SetName(data[i].GetName());
	   m_Shape[i].SetA(data[i].GetA());
	   m_Shape[i].SetN(data[i].GetN());
	   m_Shape[i].SetK(data[i].GetK());
	   m_Shape[i].SetM(data[i].GetM());
	   m_Shape[i].SetUse(data[i].GetUse());
	   
	 }
	for(;m_Shape[i].GetUse()==true;i++)
		m_Shape[i].SetUse(false);
	 
}

CData* CShape::Getm_Shape()
{  
	return (this->m_Shape) ;

}



CAxis CShape::GetAxis()
{
	return this->m_Axis ;

}

void CShape::ShowData(CDC* pDC)
{    
	CString m_TextN,m_TextK,m_TextM,m_TextUse;

	for(int i=0;this->m_Shape[i].GetUse()==true;i++)
	{
        
    	m_TextN.Format("%8.4f",this->m_Shape[i].GetN());
		m_TextK.Format("%8.4f",this->m_Shape[i].GetK());
		m_TextM.Format("%8.4f",this->m_Shape[i].GetM());
		m_TextUse.Format("%2d",this->m_Shape[i].GetUse());
		
		pDC->TextOut(10,200+i*20,this->m_Shape[i].GetName());
	    pDC->TextOut(100,200+i*20,m_TextN);
		pDC->TextOut(200,200+i*20,m_TextK);
		pDC->TextOut(300,200+i*20,m_TextM);
		pDC->TextOut(400,200+i*20,m_TextUse);
		
	}

}

void CShape::SetAxis(long minx, long maxx, long miny, long maxy, double intervalx, double intervaly)
{    
	m_Axis.SetRange(minx,maxx,miny,maxy);
	m_Axis.SetIntervalx(intervalx);
    m_Axis.SetIntervaly(intervaly);

}

void CShape::SetText( CString lablex, CString labley)

{
	
	m_Axis.SetLablex(lablex);
	m_Axis.SetLabley(labley);

}
void CShape::SetText(CString title)
{
	 this->m_Title=title;
}

void CShape::SetColor(COLORREF colorx,COLORREF colory)
{   
	COLORREF scolor[]={colorx,colory};

	m_Axis.SetColor(scolor);
}

void CShape::SetAxisWidth(int width)
{
    this->m_Axis.SetWidth(width);
}


void CShape::Compute(CDC *pDC,CRect rectClient)
{   

	//draw name of line
    this->DrawTitle(pDC);
    

	//this->SetAxis(200,1000,0,100,50,10);
	//is->SetCenter(100,600);
	
    double ratio[2];
	ratio[0]=(rectClient.right-rectClient.left)/(m_Axis.GetMaxx()-m_Axis.GetMinx());
	ratio[1]=(rectClient.bottom-rectClient.top)/(m_Axis.GetMaxy()-m_Axis.GetMiny());
	m_Axis.SetRatio(&ratio[0]);

    
	double R, R1,R2;
	
    if((this->m_VibrateKinds==1)||(this->m_VibrateKinds==2))
	{
	   
	   this->m_fWaveLength.RemoveAll();
	   this->m_Reflectance.RemoveAll();
	   this->m_Transistance.RemoveAll();
	   this->m_Absorption.RemoveAll();
	   for(double i=this->m_Axis.GetMinx(); i<=this->m_Axis.GetMaxx();i++)
	   {
	       double R=this->CalReflectance(i,m_VibrateKinds);
		   
		   this->m_fWaveLength.Add((float)i);
		   this->m_Reflectance.Add((float)R);
		   this->m_Transistance.Add((float)(100-R));
		   this->m_Absorption.Add(0.0f);
		  
	
	   }
	  }

    if(this->m_VibrateKinds==3)
	{
		
       this->m_fWaveLength.RemoveAll();
	   this->m_Reflectance.RemoveAll();
	   this->m_Transistance.RemoveAll();
	   this->m_Absorption.RemoveAll();
	    for(double i=this->m_Axis.GetMinx(); i<=this->m_Axis.GetMaxx();i+=1)
		{   
	
	      R1=this->CalReflectance(i,1);
		  R2=this->CalReflectance(i,2);
		  R=(R1+R2)/2;
		  	  
		   this->m_fWaveLength.Add((float)i);
		   this->m_Reflectance.Add((float)R);
		   this->m_Transistance.Add((float)(100-R));
		   this->m_Absorption.Add(0.0f);
		  
		  
		}

	
	}

		
		
		
	
		
	

	
}






void CShape::CalAngles()
{   
	int num=this->GetLayerNum();

	double angle=(double)asin(sin(this->m_InAngle)*this->m_InN/m_Shape[num].GetN());
	m_Shape[num].SetA(angle);

	for(;num>=1;num-=1)
	{
		angle=(double)asin(m_Shape[num].GetN()*sin(m_Shape[num].GetA())/m_Shape[num-1].GetN());
		m_Shape[num-1].SetA(angle);
	}
}

double CShape::CalReflectance(double wavelength,int VibrateKinds)
{   
	
	this->CalAngles();
	this->CalDaona(wavelength,VibrateKinds);
	double N;
	if(VibrateKinds==1)  N=m_InN*cos(this->m_InAngle);
	if(VibrateKinds==2)  N=m_InN/cos(this->m_InAngle);
	
	double R=((this->m_InN-this->m_Daona[0])*(this->m_InN-this->m_Daona[0])+(this->m_Daona[1])*(this->m_Daona[1]))/
	        ((this->m_InN+this->m_Daona[0])*(this->m_InN+this->m_Daona[0])+(this->m_Daona[1])*(this->m_Daona[1]));
	return 100*R;
    

}


void CShape::CalDaona(double wavelength,int VibrateKinds)
{    double y0,y1,y00,y11;
     y0=this->m_Shape[0].GetN();
	 y1=this->m_Shape[0].GetK();
     y00=y0;
	 y11=y1;
	 double Nk;
	if(this->m_ThickKinds==1)//physical thickness
	{   
		y00=y00*cos(this->m_InAngle);
		for(int i=1;this->m_Shape[i].GetUse()==true;i++)
		{
			
			y0=y00;
	        y1=y11;
			
			if(VibrateKinds ==1)//judge s?
			{
				  Nk=m_Shape[i].GetN()*cos(m_Shape[i].GetA());// infractance of layer i
			}
			if(VibrateKinds==2)//judge P?
			{
				 Nk=m_Shape[i].GetN()/cos(m_Shape[i].GetA());// infractance of layer i
			}
			double angle=2*PI*m_Shape[i].GetN()*m_Shape[i].GetM()*cos(m_Shape[i].GetA())/wavelength;//calculate phase 
			y00=Nk*Nk*y0/
				((Nk*cos(angle)-y1*sin(angle))*(Nk*cos(angle)-y1*sin(angle))+y0*y0*sin(angle)*sin(angle));
			y11=(Nk*(Nk*Nk-y0*y0-y1*y1)*sin(angle)*cos(angle)+Nk*Nk*y1*cos(2*angle))/
				((Nk*cos(angle)-y1*sin(angle))*(Nk*cos(angle)-y1*sin(angle))+y0*y0*sin(angle)*sin(angle));

		}
	
	}
	else //optical thickness
	{
	   	y00=y00/cos(this->m_InAngle);
		for(int i=1;this->m_Shape[i].GetUse()==true;i++)
		{
			
			y0=y00;
	        y1=y11;
			double Nk;
			if(VibrateKinds ==1)//judge s?
			{
				  Nk=m_Shape[i].GetN()*cos(m_Shape[i].GetA());// infractance of layer i
			}
			if(VibrateKinds==2)//judge P?
			{
				 Nk=m_Shape[i].GetN()/cos(m_Shape[i].GetA());// infractance of layer i
			}
			double angle=2*PI*m_Shape[i].GetM()*m_WaveLength*cos(m_Shape[i].GetA())/wavelength;//calculate phase 
			
	        
			y00=Nk*Nk*y0/
				((Nk*cos(angle)-y1*sin(angle))*(Nk*cos(angle)-y1*sin(angle))+y0*y0*sin(angle)*sin(angle));
			y11=(Nk*(Nk*Nk-y0*y0-y1*y1)*sin(angle)*cos(angle)+Nk*Nk*y1*cos(2*angle))/
				((Nk*cos(angle)-y1*sin(angle))*(Nk*cos(angle)-y1*sin(angle))+y0*y0*sin(angle)*sin(angle));




			
		}
	}

	this->m_Daona[0]=y00;
	this->m_Daona[1]=y11;
		

}
int CShape::GetLayerNum()
{  
	int num=0;
	for(int i=1;m_Shape[i].GetUse()==true;i++)
          num=i;
	return num;

}

void CShape::SetShapeofkind(int kind)
{   
	m_Shapeofkinds=kind;

}

int CShape::GetShapeofkind()
{
	return this->m_Shapeofkinds;

}


void CShape::SetThickKind(int kind)
{

	this->m_ThickKinds=kind;
}

int CShape::GetThickKind()
{

	return this->m_ThickKinds;
}


double* CShape::GetDaona()
{
	return this->m_Daona;
}


void CShape::SetAngle(double angle)
{

	this->m_InAngle=angle;
}

double CShape::GetAngle()
{

	return this->m_InAngle*180/PI;
}

void CShape::SetWaveLength(double wavelength)
{
	this->m_WaveLength=wavelength;

}

double CShape::GetWaveLength()
{
	return this->m_WaveLength;

}

void CShape::InPutData()
{
    CFilmDesignApp * app=(CFilmDesignApp*)AfxGetApp();
	this->Create(app->m_Data);
	
}

void CShape::SetVibrateKind(int vibrate)
{  
	this->m_VibrateKinds=vibrate;

}

int CShape::GetVibrateKind()
{
	return this->m_VibrateKinds;

}

void CShape::SetInN(double inN)
{
	this->m_InN=inN;

}

double CShape::GetInN()
{
	return this->m_InN;

}

void CShape::SetLine(int style, int width, COLORREF color)
{
	this->m_Line.style=style;
	this->m_Line.width=width;
	this->m_Line.color=color;

}

CLineSet* CShape::GetLine()
{
	return   &(this->m_Line);
}


void CShape::DrawTitle(CDC *pDC)
{
	pDC->TextOut(400,10,this->GetTitle());

	
}

void CShape::DrawPicture(CDC *pDC, int Kinds)
{  
	CPen *pOldPen,pen(this->m_Line.style,this->m_Line.width,this->m_Line .color);
	pOldPen=pDC->SelectObject(&pen);
    

	
	if(this->m_fWaveLength.GetSize()==0) return;
	switch(this->m_Shapeofkinds)
	{
	    case 1:{
			    double j=this->m_fWaveLength.GetAt(0);
             	double k=this->m_Reflectance.GetAt(0);
				long   x=long(m_Axis.GetCenter().x+(j-this->m_fWaveLength.GetAt(0))*m_Axis.GetRatio()[0]);
				long  y=long(m_Axis.GetCenter().y-k* m_Axis.GetRatio()[1]);
				pDC->MoveTo(x,y);
				for(int i=1;i<this->m_fWaveLength.GetSize();i++)
				{     j=this->m_fWaveLength.GetAt(i);
					  k=this->m_Reflectance.GetAt(i); 
					  x=long(m_Axis.GetCenter().x+(j-this->m_fWaveLength.GetAt(0))*m_Axis.GetRatio()[0]);
					 
					  y=long(m_Axis.GetCenter().y-k* m_Axis.GetRatio()[1]);
					  pDC->LineTo(x,y);
				}
				break;
			}
	    case 2:{
			    double j=this->m_fWaveLength.GetAt(0);
             	double k=this->m_Transistance.GetAt(0);
				long   x=long(m_Axis.GetCenter().x+(j-this->m_fWaveLength.GetAt(0))*m_Axis.GetRatio()[0]);
				long  y=long(m_Axis.GetCenter().y-k*m_Axis.GetRatio()[1]);
				pDC->MoveTo(x,y);
				for(int i=1;i<this->m_fWaveLength.GetSize();i++)
				{     j=this->m_fWaveLength.GetAt(i);
					  k=this->m_Transistance.GetAt(i); 
					  x=long(m_Axis.GetCenter().x+(j-this->m_fWaveLength.GetAt(0))*m_Axis.GetRatio()[0]);
					  y=long(m_Axis.GetCenter().y-k*m_Axis.GetRatio()[1]);
					  pDC->LineTo(x,y);
				}
				break;
			}
			case 3:{
			    double j=this->m_fWaveLength.GetAt(0);
             	double k=this->m_Absorption.GetAt(0);
				long   x=long(m_Axis.GetCenter().x+(j-this->m_fWaveLength.GetAt(0))*m_Axis.GetRatio()[0]);
				long  y=long(m_Axis.GetCenter().y-k*m_Axis.GetRatio()[1]);
				       pDC->MoveTo(x,y);
				for(int i=1;i<this->m_fWaveLength.GetSize();i++)
				{     j=this->m_fWaveLength.GetAt(i);
					  k=this->m_Absorption.GetAt(i); 
					  x=long(m_Axis.GetCenter().x+(j-this->m_fWaveLength.GetAt(0))*m_Axis.GetRatio()[0]);
					  y=long(m_Axis.GetCenter().y-k*m_Axis.GetRatio()[1]);
					  pDC->LineTo(x,y);
				}
				break;
			 }
	    default: break;
		  
    }
	

	pDC->SelectObject(pOldPen);
 
}

void CShape::SetCenter(int x, int y)
{   
	CPoint point;
	point.x=x;
	point.y=y;

	this->m_Axis.SetCenter(point);
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -