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

📄 viewtsgraph.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
       {             
          double dPosX = 0;
          
          if (m_dRange != 0)
          {
             dPosX = (int)(m_dOriginX + ((datetime - m_dtStart)*m_dLenX)/m_dRange);
          };
          
          pDC->MoveTo((int)dPosX, (int)m_dOriginY);
          pDC->LineTo((int)dPosX, (int)(m_dOriginY+m_dTickLength));
                           
          datetime.Advance(1,0);
       };      
   };
 
 // Draw ticks for months
   
   if (bOK && m_bMonths)
   {       
       int nMonth = max(1,m_dtStart.GetMonth());
       int nYear = m_dtStart.GetYear();
       CDateTime datetime;       
       do
       {
         CDateTime date(nYear,nMonth,1,0,0,0);
         datetime = date;
         nMonth++;
         if (nMonth > 12)
         {
            nMonth = 1;
            nYear++;
         }
       } while (datetime < m_dtStart);
  
       while (datetime < m_dtEnd)
       {             
          double dPosX = 0;
          
          if (m_dRange != 0)
          {
              dPosX = m_dOriginX + (((datetime - m_dtStart)*m_dLenX)/m_dRange);
          };             
          
          pDC->MoveTo((int)dPosX, (int)m_dOriginY);
          pDC->LineTo((int)dPosX, (int)(m_dOriginY+m_dTickLength*2));
          
      // Increment the month
      
          int nMonth = datetime.GetMonth();
          int nYear = datetime.GetYear();
          nMonth += 1;
          if (nMonth > 12)
          { 
             nMonth = 1;
             nYear += 1;
          };
          datetime = CDateTime(nYear,nMonth,1,0,0,0);
       }; 
   }
 
 // Draw ticks for years
 
   if (bOK)
   {       
 
 // Determine first visible year
    
       int nYear = m_dtStart.GetYear();
       CDateTime datetime;       
       do
       {
         CDateTime date(nYear,1,1,0,0,0);
         datetime = date;
         nYear++;
       } while(datetime < m_dtStart);   
 
 // Display ticks for years
       
       while (datetime <= m_dtEnd)
       {         
          if (!m_bDecades || m_bYearTicks || datetime.GetYear() % 10 == 0)
          {
             double dPosX = 0;
          
             if (m_dRange != 0)
             {
                dPosX = m_dOriginX + (((datetime - m_dtStart)*m_dLenX)/m_dRange);
             };
          
             int nTick = datetime.GetYear() % 10 == 0 ? 2 : 1;

             pDC->MoveTo((int)dPosX, (int)m_dOriginY);             
             pDC->LineTo((int)dPosX, (int)(m_dOriginY+m_dTickLength*nTick));             
          };
       
       // Increment the year
          
          int nYear = datetime.GetYear();          
          nYear += 1;
          datetime = CDateTime(nYear,1,1,0,0,0);
       }; 
   }  
  
   // Label the axis
   LabelXAxis(pDC);

   // Tidy up

   pDC->SelectObject(pFontOld);
  
};

///////////////////////////////////////////////////////////////////////////////
//                      
// CTSPlotView::LabelXAxis()
//
// Label the X axis for the graph
//

BOOL CViewTSGraph::LabelXAxis(CDC* pDC)
{  
      BOOL bSuccess = TRUE;
   
 // Determine what will be displayed on the axis
                                          
  // Draw the day numbers onto the graph
  
   if (bSuccess && m_bDays)
   {   
   
  // Determine if there is sufficent room to display all the text and
  // have a space either side
          
       long lAdvance = 1;             
       while (m_dLenX < m_dTextWidth * m_dRange *2 / lAdvance && 
              lAdvance < MAX_STEP)
       {
         lAdvance *= 2;
       }
          
  // Output the days
           
       CDateTime datetime = m_dtStart + 0.5;
       while (datetime < m_dtEnd + 1)
       {  
                   
          double dPosX = 0;
          
          if (m_dRange != 0)
          {   
             double dDisp = datetime - m_dtStart;
             dPosX = m_dOriginX + (dDisp * m_dLenX)/m_dRange;
          }                             
                                                                               
          strstream strDay;
          int nDay = datetime.GetDay();
          if (nDay > 0)
          {
             strDay << nDay << ends;
             DrawTextC(pDC, strDay.str(), (int)dPosX,(int)m_dDayY);
             strDay.rdbuf()->freeze(0);
          }
          datetime.Advance(lAdvance,0);   
       }; 
   }
  
  // Draw months onto the graph.  If the starting month falls outside
  // the range of dates then set it to the middle of the date range   
   
   if (bSuccess && m_bMonths)
   {   
       long lAdvance = 1;       
       while (m_dLenX < m_dTextWidth * m_dRange / MAX_DAYS_MONTH / lAdvance && 
              lAdvance < MAX_STEP)
       {
         lAdvance *= 2;
       }


       double dMonthY = m_dMonthY;
       if (m_bDays == FALSE)
       {
          dMonthY = m_dDayY;
       }
  
  // Determine start month that is visible on the graph
   
       int nMonth = max(1,m_dtStart.GetMonth());
       int nYear = m_dtStart.GetYear();
       CDateTime datetime;
       
       do
       {
         CDateTime date(nYear,nMonth,15,0,0,0);
         datetime = date;
         nMonth+=1;
         if (nMonth > 12)
         {
            nMonth = 1;
            nYear++;
         }
       } while (datetime < m_dtStart); 
  
 // If the date selected falls outside the range then set it to the middle of 
 // the date range
 
      if (datetime > m_dtEnd + 1)
      { 
         datetime = m_dtStart+(m_dtEnd-m_dtStart+1)/2;
      };           
       
  // Draw visible labels on the graph
       
       while (datetime <= m_dtEnd+1)
       {             
          int dPosX = 0;
          
          if (m_dRange != 0)
          {
            dPosX = (int)(m_dOriginX + ((datetime - m_dtStart)*m_dLenX)/m_dRange);
          };
                                                                                         
          int nMonth = datetime.GetMonth();
          
          CString strMonthLabels;
          CString strMonth;          
          
          if (m_bMonthsFull)
          {                         
            // If displaying days then append the year to the months name

             if (m_bDays)
             {
                strMonth.Format("%s %i", GetMonthName(nMonth), datetime.GetYear());
             } else
             {
                strMonth.Format("%s", GetMonthName(nMonth));
             }
          } else
          {             
             strMonthLabels.Format("%s", GetMonthName(nMonth));
             strMonth = strMonthLabels[0];
          };          
          DrawTextC(pDC, strMonth.GetBuffer(0), (int)dPosX,(int)dMonthY);
          datetime = datetime + AVERAGE_MONTH * lAdvance;
       }; 
   }
  
  // Draw the years onto the graph, if the decades flag is set then only
  // draw these
  
   if (bSuccess && !m_bDays)
   {                            
  
  // Determine the advance step

       long lAdvance = 1;       
       if (!m_bDecades)
       {                 
          while (m_dLenX < m_dTextWidth * m_dRange *4 / MAX_DAYS_YEAR / lAdvance && 
              lAdvance < MAX_STEP)
          {
            lAdvance *= 2;
          }
       } else
       {
          while (m_dLenX < m_dTextWidth * m_dRange *4 / MAX_DAYS_YEAR / 9 / lAdvance && 
                 lAdvance < MAX_STEP)
          {
            lAdvance *= 2;
          }
       }

  // Determine y position of text
  
       double dYearY = m_dYearY;
       if (m_bMonths == FALSE && m_bMonthsFull == FALSE)
       {        
          dYearY = m_dMonthY;
       }
       else if (m_bDays == FALSE)       
       {
          dYearY = m_dMonthY;
       }
     
  // Determine first visible year label
  
       int nYear = m_dtStart.GetYear();    
       CDateTime datetime;               
       do
       {
         CDateTime date(nYear,7,1,0,0,0);         
         datetime = date;
         nYear++;         
       } while (datetime < m_dtStart);   
       
  // If the year label falls outside the date range then set it to be the
  // middle of the date range
 
      if (datetime > m_dtEnd + 1)
      { 
         datetime = m_dtStart + (m_dtEnd - m_dtStart + 1)/2;
      };         
  
  // Output years
       
       int nDecade = 0;
       while (datetime.GetYear() <= m_dtEnd.GetYear())
       {             
          int dPosX = 0;
          
          if (m_dRange != 0)
          {                     
             dPosX = (int)(m_dOriginX + ((datetime - m_dtStart)*m_dLenX)/m_dRange);           
          };

          if (dPosX > m_dOriginX + m_dLenX) break;
		                                                                                           
          int nYear = datetime.GetYear();
          
          CString strMonthLabels;
          CString strMonth;          
          
          if (m_bDecades == FALSE || nYear%10 == FALSE)
          { 
             if (!m_bDecades || (nDecade++)%lAdvance== 0)
             {
                strstream strDay;
                strDay << datetime.GetYear() << ends;
                DrawTextC(pDC,  strDay.str(), (int)dPosX,(int)dYearY);
                strDay.rdbuf()->freeze(0);
             };
          };          

          if (m_bDecades)
          {
             datetime = datetime + 365.25;
          } else
          {
             datetime = datetime + 365.25 * lAdvance;
          }
       }; 
   }  
   
   return bSuccess;
};

///////////////////////////////////////////////////////////////////////////////

CString CViewTSGraph::GetMonthName(int nMonth)
{
   return CString(CDateTime::GetMonthName(nMonth)).Left(3);
}

///////////////////////////////////////////////////////////////////////////////

void CViewTSGraph::DrawTextC(CDC* pDC, LPCSTR s, int x, int y)
{
    CSize sz = pDC->GetTextExtent(s);

    CRect rect;
    rect.left = x - sz.cx/2;
    rect.right = x + sz.cx/2;
    rect.top = y;
    rect.bottom = y + sz.cy;

    pDC->DrawText(s, &rect, DT_SINGLELINE|DT_TOP|DT_CENTER);
}

///////////////////////////////////////////////////////////////////////////////   

void CViewTSGraph::OnMouseMove(UINT nFlags, CPoint point) 
{	
	CViewGraph::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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