dlgaddlayer.cpp

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

CPP
635
字号
//////////////////////////////////////////////////////
//
// NRDB Pro - Spatial database and mapping application
//
// Copyright (c) 1989-2004 Richard D. Alexander
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// NRDB Pro is part of the Natural Resources Database Project 
// 
// Homepage: http://www.nrdb.co.uk/
// Users' Forum: http://nrdb.mypalawan.info/
// 

#include "stdafx.h"
#include "nrdb.h"
#include "DlgAddLayer.h"
#include "maplayer.h"
#include "dlgselectfeatures.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

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

COLORREF CDlgAddLayer::m_crSel = DEFAULT_COLOUR;

/////////////////////////////////////////////////////////////////////////////
// CDlgAddLayer dialog


CDlgAddLayer::CDlgAddLayer(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgAddLayer::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgAddLayer)
	//}}AFX_DATA_INIT

   m_pTooltip = NULL;
   m_bMapLines = FALSE;
}

CDlgAddLayer::~CDlgAddLayer()
{
   if (m_pTooltip != NULL) delete m_pTooltip;
};

void CDlgAddLayer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgAddLayer)
	DDX_Control(pDX, IDC_LABEL, m_cbLabel);
	DDX_Control(pDX, IDC_MAPOBJ, m_cbMapObj);
	DDX_Control(pDX, IDC_SELECTALL, m_pbSelectAll);
	DDX_Control(pDX, IDC_COLOR, m_pbColour);		
	DDX_Control(pDX, IDC_FTYPE, m_cbFType);
	DDX_Control(pDX, IDC_FEATURE, m_lbFeature);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgAddLayer, CDialog)
	//{{AFX_MSG_MAP(CDlgAddLayer)
	ON_CBN_SELCHANGE(IDC_FTYPE, OnSelchangeFtype)	
	ON_BN_CLICKED(IDC_SELECTALL, OnSelectall)
	ON_BN_CLICKED(IDC_SELECT, OnSelect)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_DICTIONARY, OnDictionary)
	ON_LBN_SELCHANGE(IDC_FEATURE, OnSelchangeFeature)
	ON_WM_MOUSEMOVE()	
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

void CDlgAddLayer::Reset()
{
   CString s = AfxGetApp()->GetProfileString(BDGetDataSource(), "DefaultColour");

   int r,g,b;
   if (sscanf(s, "%i,%i,%i", &r, &g, &b))
   {
      m_crSel = RGB(r,g,b);      
   }
}

/////////////////////////////////////////////////////////////////////////////
// CDlgAddLayer message handlers

BOOL CDlgAddLayer::OnInitDialog() 
{
	CFeatureType ftype;

	CDialog::OnInitDialog();

   long lFTypeSel = BDFTypeSel();
   m_bInit = TRUE;

  // Load in list of feature types
   
   m_cbFType.Init(lFTypeSel);  

   OnSelchangeFtype();

   OnSelchangeFeature();   

   // Set previous color

   m_pbColour.SetColour(m_crSel);

   // Enable tooltips

   BDHwndDialog() = m_hWnd;

   m_bInit = FALSE;
      
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////
//
// Remove feature types that don't have map attributes
//

void CDlgAddLayer::RemoveNonMapFTypes()
{
   BeginWaitCursor();

   // Produce a list of feature types with map attributes

   for (int i = 0; i < m_cbFType.GetCount(); i++)
   {    
      if (!IsMapFType(m_cbFType.GetItemData(i)))
      {
         m_cbFType.DeleteString(i);
         i--;
      }
   }
   
   // Set selection

   if (m_cbFType.GetCurSel() == CB_ERR) m_cbFType.SetCurSel(0);

   EndWaitCursor();
}

///////////////////////////////////////////////////////////////////////////////
//
// Determines if a ftype or its 1:1 parent has map attributes
//

BOOL CDlgAddLayer::IsMapFType(long lFType)
{
   CAttrArray aAttr;
   CFeatureType ftype;

   BOOL bMapFType = FALSE;

   // Optimization, store list of ftypes which have already been checked

   for (int i = 0; i < m_aFTypeMap.GetSize(); i++)
   {
      if (m_aFTypeMap[i].m_lFType == lFType) return m_aFTypeMap[i].m_bMap;      
   }

   // Determine if ftype inherits polylines or coordinates attr one to one

   if (BDFTypeAttrInit(BDHandle(), lFType, &aAttr))
   {
      for (int i = 0; i < aAttr.GetSize(); i++)
      {
         if (aAttr.GetAt(i)->GetDataType() == BDMAPLINES ||
             aAttr.GetAt(i)->GetDataType() == BDCOORD ||
             aAttr.GetAt(i)->GetDataType() == BDIMAGE)
         {
            bMapFType = TRUE;
            break;
         }
      }
      // Check parent

      if (!bMapFType && BDFTypeI(BDHandle(), lFType, &ftype) &&
          lFType != ftype.m_lId)
      {
         return IsMapFType(ftype.m_lId);
      }
   }

   // Add to optimization list

   CFTypeMap ftypemap;
   ftypemap.m_lFType = lFType;
   ftypemap.m_bMap = bMapFType;
   m_aFTypeMap.Add(ftypemap);

   return bMapFType;
}

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

void CDlgAddLayer::OnSelchangeFtype() 
{   
// Remove feature types that don't have map attributes

   RemoveNonMapFTypes();

 // Update list of features and attributes

	CFeature feature;

   m_lbFeature.ResetContent();

   int index = m_cbFType.GetCurSel();
   if (index != LB_ERR)
   {
      feature.m_lFeatureTypeId = m_cbFType.GetItemData(index);

	// Update list of features

      BOOL bFound = BDFeature(BDHandle(), &feature, BDSELECT2);
      while (bFound)
      {
         index = m_lbFeature.AddString(feature.m_sName);
         m_lbFeature.SetItemData(index, feature.m_lId);

         // Previous selection

         if (m_bInit && BDIsFeatureSel(feature.m_lFeatureTypeId, feature.m_lId)) 
         {
            m_lbFeature.SetSel(index);
         }
         
         bFound = BDGetNext(BDHandle());
      }
      BDEnd(BDHandle());
   };   

   if (m_lbFeature.GetSelCount() == 0)
   {
      OnSelectall();
   }

   OnSelchangeFeature();

   InitAttr();
   if (m_cbMapObj.GetCount() == 0)
   {
      InitParentAttr();
   }
}

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

void CDlgAddLayer::InitAttr()
{
   CAttrArray aAttr;   
   CAttribute* pAttr;      
   CString sFType;
   CFeatureType ftype;
   CString s;

   RemoveAttr();   

   // Retrieve selected feature and type
   
   int iFType = m_cbFType.GetCurSel();
   
   if (iFType != CB_ERR)
   {      
      long lFType = m_cbFType.GetItemData(iFType);

  // Retrieve attribute values for the feature

     BOOL bFound = BDFTypeAttrInit(BDHandle(), lFType, &aAttr);

  // Add the default 'blank' label

     int index = m_cbLabel.AddString(BDString(IDS_NONE));        
     m_cbLabel.SetItemDataPtr(index, NULL);        

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

        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) + "]";        
        }

        if (pAttr->GetDataType() == BDMAPLINES || pAttr->GetDataType() == BDCOORD || 
            pAttr->GetDataType() == BDIMAGE) 

⌨️ 快捷键说明

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