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

📄 dlgeditattributes.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            {
               pImageFile = new CImageFile;
               if (pImageFile->Initialise(*pAttr->GetLongBinary()))
               {
                  m_Grid.SetColor(iCol, iRow, BD_BLUE,  BD_BLUE);
               } else
               {
                  delete pImageFile;
                  pImageFile = NULL;
               }                             
               m_Grid.SetInteger(iCol, iRow, (LONG)(LPCSTR)pImageFile);            			   
            }

            // For files, store a pointer to the file object

            CFileObj* pFileObj = NULL;
            if (pAttr->GetDataType() == BDFILE)
            {
               pFileObj = new CFileObj;
               if (pFileObj->Initialise(*pAttr->GetLongBinary()))
               {
                  m_Grid.SetColor(iCol, iRow, BD_BLUE,  BD_BLUE);
               } else
               {
                  delete pFileObj;
                  pFileObj = NULL;
               }                             
               m_Grid.SetInteger(iCol, iRow, (LONG)(LPCSTR)pFileObj);            			   

            }


            iCol++;
         };
         iRow++;

         bFound = BDGetNext(BDHandle());
      } 

   } while (bFound);
   BDEnd(BDHandle());

   EndWaitCursor();

   return bOK;
	
}

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

void CDlgEditAttributes::InitMapObject()
{
   CDateTime date;
   CString sDate,sCoord;
   CAttrArray aAttr;
   long lData = 0;

   // Set date

   date.AsSystemDate();
   date.DateAsString(sDate);
   m_Grid.SetValue(COL_DATE, 1, sDate);

   // Set coordinate

   BDFTypeAttrInit(BDHandle(), m_lFType, &aAttr);   
   BDEnd(BDHandle());

   for (int i = 0; i < aAttr.GetSize(); i++)
   {
      CBDAttribute* pAttr = (CBDAttribute*)aAttr.GetAt(i);                                 

      // Initialise coordinates

      long lCol = COL_DATE+i+1;
      long lRow = 1;

      if (m_pMapLayerObj->GetDataType() == BDCOORD)
      {
         if (pAttr->GetDataType() == BDCOORD)
         {
            CCoord* pCoord = (CCoord*)m_pMapLayerObj->GetMapObject();
            pAttr->SetCoord(*pCoord);
            sCoord = pAttr->AsString();
            m_Grid.SetValue(lCol, lRow, pAttr->AsString());                     
         }
      }

      // Initialise polygons / polylines

      else if (m_pMapLayerObj->GetDataType() == BDMAPLINES)
      {         
         if (pAttr->GetDataType() == BDMAPLINES)
         {           
            // Create new map object that may be deleted

            CLongLines* pLongLines = new CLongLines;
            pLongLines->Copy(*(CLongLines*)m_pMapLayerObj->GetMapObject());
            m_Grid.SetInteger(lCol, lRow, (LONG)(LPCSTR)pLongLines);                                    
         }
      }
   }
}

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

BOOL CDlgEditAttributes::InitialiseCols()
{
   SS_CELLTYPE celltype; 
   SS_CELLTYPE celltypeedit; 
   CAttrArray aAttr;
   BOOL bOK = TRUE;
   CFeature feature;
   double dHeight;
   LOGFONT lf;
   HFONT hFont;

   // Set the default font for the grid
   
   memset(&lf,0,sizeof(LOGFONT));
   lf.lfHeight = -11;
   lf.lfPitchAndFamily = 12;   
   lf.lfCharSet = NRDB_CHARSET;
   strcpy(lf.lfFaceName, BDString(IDS_DEFAULTFONT));         
   hFont = ::CreateFontIndirect(&lf);   

   m_Grid.SetFont(-1,-1,hFont, TRUE);

   // Set title for first column

   CFeatureType ftype;   
   BDFTypeI(BDHandle(), m_lFType, &ftype);
   BDFeatureType(BDHandle(), &ftype, BDSELECT);
   m_Grid.SetValue(COL_FEATURE, ROW_HEADER, ftype.m_sDesc);
   m_Grid.ShowCol(COL_FEATUREID, FALSE);
   m_Grid.SetLock(COL_FEATURE, -1, TRUE);
   
   // Retrieve the attribute data

   BDFTypeAttrInit(BDHandle(), m_lFType, &aAttr);   
   BDEnd(BDHandle());
      
   // Initialise the column headings

   int iCol = COL_DATE;
   int iRow = ROW_HEADER;
   m_Grid.SetValue(iCol++, iRow, BDString(IDS_DATE));      
      
   m_Grid.SetColWidth(-1, 12);

   // Set row height

   m_Grid.GetRowHeight(0, &dHeight);
   m_Grid.SetRowHeight(0, dHeight*2);
   
   // Initialise array for links

   m_aFTypeLink.SetSize(aAttr.GetSize()+5);

   // For each column set titles and data
      
   for (int i = 0; i < aAttr.GetSize(); i++)
   {
      CAttribute* pAttr = aAttr.GetAt(i);            
      m_Grid.SetValue(iCol, iRow, pAttr->GetDesc());
      m_Grid.SetColUserData(iCol, pAttr->GetDataType());

	  if (pAttr->GetDataType() == BDTEXT || pAttr->GetDataType() == BDHOTLINK ||
         pAttr->GetDataType() == BDLONGTEXT)
     {        
         m_Grid.SetColWidth(iCol, 20);
         m_Grid.SetTypeEdit(&celltypeedit, ES_STATIC, BD_SHORTSTR-1, SS_CHRSET_CHR, 
                             SS_CASE_NOCASE);           
         m_Grid.SetCellType(iCol, -1, &celltypeedit);
     };

     if (pAttr->GetDataType() == BDTEXT || pAttr->GetDataType() == BDHOTLINK)
     {
         m_Grid.SetColWidth(iCol, 20);         
     }

	  // Set the cell type for map lines
	  
      if (pAttr->GetDataType() == BDMAPLINES || pAttr->GetDataType() == BDIMAGE ||
          pAttr->GetDataType() == BDFILE)
	  {
		 m_Grid.SetLock(iCol, -1, TRUE);
		 m_Grid.SetTypeInteger(&celltype, 0, 0xFFFFFFFF);   
		 m_Grid.SetCellType(iCol, -1, &celltype);
		 m_Grid.SetColor(iCol, -1, BD_WHITE, BD_WHITE);
	  }
    
	  // Set cell type for links

	  if (pAttr->GetDataType() == BDLINK)
	  {         		
// Ability to add to list

       CString sFType;

       sFType += BDString(IDS_ADDNEW); 
       m_aFTypeLink[iCol].Add(-1);  

       feature.m_lFeatureTypeId = pAttr->GetFTypeLink();
       BOOL bFound = BDFeature(BDHandle(), &feature, BDSELECT2);
		 while (bFound)
		 {          
			 if (!sFType.IsEmpty()) sFType += "\t";
          feature.m_sName.TrimRight();
			 sFType += feature.m_sName;
			 m_aFTypeLink[iCol].Add(feature.m_lId);			 
			 bFound = BDGetNext(BDHandle());
		 }
		 BDEnd(BDHandle());    
    
       m_Grid.SetTypeComboBox(&celltype, SS_CB_DROPDOWN, sFType);
		 m_Grid.SetCellType(iCol, -1, &celltype);		 
	  }

      iCol++;
   };
   m_Grid.SetMaxCols(iCol-1);

   return bOK;
}

///////////////////////////////////////////////////////////////////////////////
//
// Free any allocated resources
//

void CDlgEditAttributes::OnDestroy() 
{	
   if (IsWindow(m_Grid.GetSafeHwnd()))
   {
      for (int i = 1; i <= m_Grid.GetMaxRows(); i++)
      {
         DeleteRow(i, FALSE);	  
      }   
   };

   CDialog::OnDestroy();
}

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

BOOL CDlgEditAttributes::DeleteRow(int iRow, BOOL bDelete)
{      
   BOOL bDeleted = FALSE;

   for (int iCol = COL_DATE; iCol <= m_Grid.GetMaxCols(); iCol++)
   {
	   DeleteCell(iCol, iRow);            
   };	

   if (bDelete)
   {
      // Only delete the row if it there is still one remaining for the
      // same feature
      
      if (GetFeature(iRow) == GetFeature(iRow-1) || 
          (iRow+1 <= m_Grid.GetMaxRows() && GetFeature(iRow) == GetFeature(iRow+1)))
      {
          m_Grid.DelRow(iRow);
          bDeleted = TRUE;
      }
           
   };

   return bDeleted;
}

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

void CDlgEditAttributes::OnDelete() 
{	   
   SS_CELLCOORD topleft, bottomright;   
   long lRow, lCol;

   BeginWaitCursor();   
   if (!m_Grid.GetSelectBlock(&topleft, &bottomright))
   {
	   m_Grid.GetActiveCell(&lCol, &lRow);   
	   bottomright.Col = topleft.Col = lCol;
	   bottomright.Row = topleft.Row = lRow;
   }
   
  // All rows

   if (topleft.Row == -1)
   {
	   topleft.Row = 1;
	   bottomright.Row = m_Grid.GetMaxRows();
   }

  // All columns

   if (topleft.Col == -1)
   {	 	  
     for (int i = topleft.Row; i <= bottomright.Row; i++)
     {         
        if (DeleteRow(i))
        {
           bottomright.Row--;
           i--;
        };        
     };
  } 

  // Clear cells

  else
  {
     // if cell contains a pointer then delete it

     for (int iCol = max(COL_DATE, topleft.Col); iCol <= bottomright.Col; iCol++)            
     {
        for (int iRow = topleft.Row; iRow <= bottomright.Row; iRow++)
        {
			DeleteCell(iCol, iRow);           
        }
     }
     m_Grid.ClearDataRange(max(COL_DATE, topleft.Col), topleft.Row, 
                           bottomright.Col, bottomright.Row);
   }   

   RedrawWindow();
   
   EndWaitCursor();
}

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

void CDlgEditAttributes::DeleteCell(int iCol, int iRow)
{
   long lDataType, lData;

   m_Grid.GetColUserData(iCol, &lDataType);
   if (lDataType == BDMAPLINES)
   {
      m_Grid.GetInteger(iCol, iRow, &lData);
      CLongLines* pMapLines = (CLongLines*)(LONG)lData; 
      if (pMapLines != NULL)
      {
         delete pMapLines;                  
         m_Grid.SetInteger(iCol, iRow, NULL);
         m_Grid.SetColor(iCol, iRow, BD_WHITE, BD_WHITE);
      }            
   }   
   // Delete image file

   if (lDataType == BDIMAGE)
   {
      m_Grid.GetInteger(iCol, iRow, &lData);
      CImageFile* pImageFile = (CImageFile*)(LONG)lData; 
      if (pImageFile != NULL)
      {
         delete pImageFile;                  
         m_Grid.SetColor(iCol, iRow, BD_WHITE, BD_WHITE);
      }            
   }

   // Delete file objects

   if (lDataType == BDFILE)
   {
      m_Grid.GetInteger(iCol, iRow, &lData);
      CFileObj* pFileObj = (CFileObj*)(LONG)lData; 
      if (pFileObj != NULL)
      {
         delete pFileObj;                  
         m_Grid.SetColor(iCol, iRow, BD_WHITE, BD_WHITE);
      }            
   }

   m_Grid.SetValue(iCol, iRow, "");
}

///////////////////////////////////////////////////////////////////////////////
//
// Validates and saves the data
//

void CDlgEditAttributes::OnOK() 
{
   BOOL bOK = TRUE;
   CDateTime datetime;
   CAttrArray aAttr; 
   
   aAttr.m_lFeature = 0;
   long lFeature;

   BDBeginTrans(BDHandle());

   BeginWaitCursor();

  // Switch off edit mode to save last value

   m_Grid.SetEditMode(FALSE);	

  // Firstly delete all existing values

   ASSERT(m_alFeatures.GetSize() == 1);
   aAttr.m_lFeature = m_alFeatures[0];
   aAttr.m_lFType = m_lFType;

   BOOL bFound = BDAttribute(BDHandle(),  &aAttr, BDDELETEALL);
   BDEnd(BDHandle());

  // Validate each row and add to the database

   for (int iRow = 1; bOK && iRow <= m_Grid.GetMaxRows(); iRow++)
   {
      lFeature = GetFeature(iRow);
      if (lFeature != aAttr.m_lFeature)
      {
         aAttr.m_lFeature = lFeature;
         aAttr.m_lFType = m_lFType;

         BOOL bFound = BDAttribute(BDHandle(),  &aAttr, BDDELETEALL);
         BDEnd(BDHandle());
      }

	   if (GetRowDateTime(iRow, datetime))
	   {
		  aAttr.m_lDate = datetime.GetDateLong();		  

		  int iColError = RetrieveRow(iRow, aAttr);
        if (iColError == 0)
		  {
			  bOK = BDAttribute(BDHandle(),  &aAttr, BDADD);
		  } else
		  {
			  DisplayError(iColError, iRow);			  
			  bOK = FALSE;
		  }
      } 
	   
	   // If date and time are invalid, check that fields are empty

	   else if (!m_Grid.GetValue(COL_DATE, iRow).IsEmpty())
	   {
		  DisplayError(COL_DATE, iRow);			  
		  bOK = FALSE;
	   }	   

     // If row does not contain a date check that it contains no data

      else
      {
         for (int i = COL_DATE; i <= m_Grid.GetMaxCols(); i++)
         {
            if (m_Grid.GetValue(i, iRow) != "")
            {
               DisplayError(i, iRow, BDString(IDS_NODATE));
               bOK = FALSE;
            }
         }            
      }
   }
   BDEnd(BDHandle());
   EndWaitCursor();


   // If all okay then commit otherwise rollback
   if (bOK)
   {
      BDCommit(BDHandle());
	  CDialog::OnOK();
   } else
   {
	  BDRollBack(BDHandle());
   }
}

⌨️ 快捷键说明

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