dlgaddlayer.cpp

来自「一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和c」· C++ 代码 · 共 635 行 · 第 1/2 页

CPP
635
字号
        {
           int index = m_cbMapObj.AddString(s);        
           m_cbMapObj.SetItemDataPtr(index, new CFTypeAttr(*(CFTypeAttr*)pAttr));    

           if (m_bInit && BDIsAttrSel(pAttr->GetFTypeId(), pAttr->GetAttrId()))
           {
              m_cbMapObj.SetCurSel(index);
           }
        } else
        {
           int index = m_cbLabel.AddString(s);        
           m_cbLabel.SetItemDataPtr(index, new CFTypeAttr(*(CFTypeAttr*)pAttr));    
           if (m_bInit && BDIsAttrSel(pAttr->GetFTypeId(), pAttr->GetAttrId()))
           {
              m_cbLabel.SetCurSel(index);
           }
        }
     }
     if (m_cbMapObj.GetCurSel() == CB_ERR) m_cbMapObj.SetCurSel(0);     
     
     // Add the parent feature name
     
      if (BDFTypeI(BDHandle(), lFType, &ftype))
      {
         int index = m_cbLabel.AddString(ftype.m_sDesc + " ["+BDString(IDS_NAME)+"]");
         CFTypeAttr ftypeattr;
         ftypeattr.m_lAttrId = BDFEATURE;
         ftypeattr.m_lFType = ftype.m_lId;
         m_cbLabel.SetItemDataPtr(index, new CFTypeAttr(ftypeattr));             
         if (m_bInit && BDIsAttrSel(ftypeattr.m_lFType, ftypeattr.m_lAttrId))
         {
            m_cbLabel.SetCurSel(index);
         }

         if (m_cbLabel.GetCurSel() == LB_ERR)
         {
            m_cbLabel.SetCurSel(index);
         }

      }
   };	
   BDEnd(BDHandle());
   
}

/////////////////////////////////////////////////////////////////////////////
//
// Removes attributes and the corresponding allocated memory
//

void CDlgAddLayer::RemoveAttr()
{
   for (int i = 0; i < m_cbMapObj.GetCount(); i++)
   {
      CFTypeAttr *pAttr = (CFTypeAttr*)m_cbMapObj.GetItemDataPtr(i);
      if (pAttr != NULL)
      {
         delete pAttr;
      };
   }   
   m_cbMapObj.ResetContent();

	for (i = 0; i < m_cbLabel.GetCount(); i++)
   {
      CFTypeAttr *pAttr = (CFTypeAttr*)m_cbLabel.GetItemDataPtr(i);
      if (pAttr != NULL)
      {
         delete pAttr;
      };
   }   
   m_cbLabel.ResetContent();

}

/////////////////////////////////////////////////////////////////////////////
//
// Add map attributes for 1:1 parent features

void CDlgAddLayer::InitParentAttr()
{
   CFeatureType ftypeP;
   CAttrArray aAttr;   
   CAttribute* pAttr;      
   CString s;

   int iFType = m_cbFType.GetCurSel();
   
   if (m_lbFeature.GetCount() > 0 && iFType != CB_ERR)
   {      
      long lFType = m_cbFType.GetItemData(iFType);

      BDFTypeI(BDHandle(), lFType, &ftypeP);
      if (ftypeP.m_lId != lFType)
      {
     // Retrieve attribute values for the feature

        BOOL bFound = BDFTypeAttrInit(BDHandle(), ftypeP.m_lId, &aAttr);

      // Create a list of attributes with spatial data
                  
        for (int i = 0; i < aAttr.GetSize(); i++)
        {
           pAttr = aAttr[i];                    

           // Create string

           s = pAttr->GetDesc();
           if (pAttr->GetDataType() == BDMAPLINES) 
           {
              s += " [" + BDString(IDS_POLYLINESTYPE) + "]";
             
           };
           if (pAttr->GetDataType() == BDCOORD) 
           {           
              s += " [" + BDString(IDS_COORDTYPE) + "]";                     
           };

           if (pAttr->GetDataType() == BDIMAGE) 
           {           
              s += " [" + BDString(IDS_IMAGETYPE) + "]";                     
           };

           // Add string

           if (pAttr->GetDataType() == BDMAPLINES || pAttr->GetDataType() == BDCOORD ||
               pAttr->GetDataType() == BDIMAGE) 
           {
              int index = m_cbMapObj.AddString(s);        
              m_cbMapObj.SetItemDataPtr(index, new CFTypeAttr(*(CFTypeAttr*)pAttr));    

              if (m_bInit && BDIsAttrSel(ftypeP.m_lId, pAttr->GetAttrId()))
              {
                 m_cbMapObj.SetCurSel(index);
              }
           };
        };
      };
   }
   if (m_cbMapObj.GetCurSel() == CB_ERR) m_cbMapObj.SetCurSel(0);     
}

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

void CDlgAddLayer::OnOK() 
{
   CString sDateTime, sDate, sTime;   
   CFeature feature;
   CFeatureType ftype;

	int iFType = m_cbFType.GetCurSel();   
   int iMapObj = m_cbMapObj.GetCurSel();
   int iLabel = m_cbLabel.GetCurSel();
   int nMapLines = 0, nCoord = 0;
   
   // Retrieve data

   if (iFType != CB_ERR)
   {      
      if (m_lbFeature.GetSelCount() > 0 ||
          AfxMessageBox(IDS_NOFEATURECONT, MB_YESNO) == IDYES)          
      {
         if (iMapObj == CB_ERR)
         {
            AfxMessageBox(BDString(IDS_SELMAPOBJ));
            return;
         }

         m_lFType = m_cbFType.GetItemData(iFType);            

         BDFTypeSel(m_lFType);
         BDFeatureSel().RemoveAll();

         // Retrieve features

         BDFTypeI(BDHandle(), m_lFType, &ftype);
         for (int i = 0; i < m_lbFeature.GetCount(); i++)
         {
            if (m_lbFeature.GetSel(i))
            {               
               m_alFeatures.Add(m_lbFeature.GetItemData(i));         
               
               feature.m_lFeatureTypeId = ftype.m_lId;
               feature.m_lId = m_lbFeature.GetItemData(i);
               BDFeatureSel().Add(feature);
            };
         }      

         // Add map object attribute

         BDAttrSel().RemoveAll();

         CFTypeAttr* pAttr = (CFTypeAttr*)m_cbMapObj.GetItemDataPtr(iMapObj);     
         
         m_aAttr.Add(*pAttr);
         if (pAttr->GetDataType() == BDMAPLINES) m_bMapLines = TRUE;
                  
         BDAttrSel().Add(*pAttr); 

         // Retrieve attributes
         
         if (iLabel != CB_ERR)
         {
            CFTypeAttr* pAttr = (CFTypeAttr*)m_cbLabel.GetItemDataPtr(iLabel);
            if (pAttr != NULL)
            {
               m_aAttr.Add(*pAttr);    
               BDAttrSel().Add(*pAttr);
            };            
         }      

         // Retrieve the color

         m_color = m_pbColour.GetColour();
         m_crSel = m_color;
      
         CDialog::OnOK();
      }
      
   } else
   {
      AfxMessageBox(BDString(IDS_NOFTYPESEL));
   }
}

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

void CDlgAddLayer::OnSelectall() 
{
   m_lbFeature.SelectAll();
   m_pbSelectAll.Update(m_lbFeature);
}

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

void CDlgAddLayer::OnSelchangeFeature() 
{
   m_pbSelectAll.Update(m_lbFeature);
}

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

void CDlgAddLayer::OnSelect() 
{   
   long lFType = 0; 

   // Determine the parent feature type of that selected

   int index = m_cbFType.GetCurSel();
   if (index != LB_ERR)
   {      
      lFType = m_cbFType.GetItemData(index);
     
   // Create a dialog allowing a sub-set of the features to be selected
   
      CDlgSelectFeatures dlg(lFType);      
      if (dlg.DoModal() == IDOK)
      {
         dlg.Initialise(m_lbFeature);         
      }
   };	
}

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

void CDlgAddLayer::OnClose() 
{	
	CDialog::OnClose();
}

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

BOOL CDlgAddLayer::DestroyWindow() 
{
   // Tidy up

   RemoveAttr();
   	
	return CDialog::DestroyWindow();   
}

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

void CDlgAddLayer::OnDictionary() 
{
   m_cbFType.OnClickDictionary();   
}

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

int CDlgAddLayer::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const
{
   CWnd::OnToolHitTest(point, pTI);
   CString s = BDString(IDS_SELMAPOBJ);
   pTI->lpszText = (LPSTR)malloc(s.GetLength()+1);
   strcpy(pTI->lpszText, s);

   return 1;
}

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

void CDlgAddLayer::OnMouseMove(UINT nFlags, CPoint point) 
{
   CDialog::OnMouseMove(nFlags, point);     	
}

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

void CDlgAddLayer::PostNcDestroy() 
{
   BDHwndDialog() = NULL;
   BDToolTip() = NULL;
	
	CDialog::PostNcDestroy();
}

⌨️ 快捷键说明

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