bool ColoredPolygon::RemoveDots()
{
    if (_selectedDots.size() > 0)
    {
        RemoveDot(_selectedDots);
        _selectedDots.clear();
        _dotUnderCursor.clear();
        GenerateTriangles();
        return true;
    }
    return false;
}
Esempio n. 2
0
CString CPathUtilEx::GetRelativePath(const CString& strMainPathOrFile2, const CString& strRelativePathOrFile2)
{	
	//去除点号
	CString strMainPathOrFile = strMainPathOrFile2;
	CString strRelativePathOrFile = strRelativePathOrFile2;
	if (strMainPathOrFile.IsEmpty() || strRelativePathOrFile.IsEmpty())
	{
		return _T("");
	}
	if (!RemoveDot(strMainPathOrFile))
	{
		return _T("");
	}

	if (!RemoveDot(strRelativePathOrFile))
	{
		return _T("");
	}

	if (strMainPathOrFile.Find(strRelativePathOrFile) == 0) //就是子串
	{
		return strRelativePathOrFile;
	}

	//按照斜杠解析出每个文件夹名称
	CStringArray strTempMainArray;
	int nStart = 0;
	for (int i=0; i<strMainPathOrFile.GetLength(); ++i)
	{
		if (strMainPathOrFile[i] == _T('\\'))  //找到斜杠
		{
			CString strTemp = strMainPathOrFile.Mid(nStart, i-nStart);
			if (!strTemp.IsEmpty())
			{
				strTempMainArray.Add(strTemp);
			}
			nStart = i+1;
		}
	}
	if (strMainPathOrFile[strMainPathOrFile.GetLength()-1] != _T('\\'))
	{
		strTempMainArray.Add(strMainPathOrFile.Mid(nStart));
	}

	CStringArray strTempRelativeArray;
	nStart = 0;
	for (int i=0; i<strRelativePathOrFile.GetLength(); ++i)
	{
		if (strRelativePathOrFile[i] == _T('\\'))  //找到斜杠
		{
			CString strTemp = strRelativePathOrFile.Mid(nStart, i-nStart);
			if (!strTemp.IsEmpty())
			{
				strTempRelativeArray.Add(strTemp);
			}
			nStart = i+1;
		}
	}
	if (strRelativePathOrFile[strRelativePathOrFile.GetLength()-1] != _T('\\'))
	{
		strTempRelativeArray.Add(strRelativePathOrFile.Mid(nStart));
	}

	//计算相对路径
	if (strTempMainArray.GetSize() == 0 || strTempRelativeArray.GetSize() == 0)
	{
		return strRelativePathOrFile;
	}

	if (strTempMainArray[0].CompareNoCase(strTempRelativeArray[0]) != 0)  //根盘符不一样,直接返回绝对路径
	{
		return strRelativePathOrFile;
	}

	int nNotSameIndex=0;
	for (; nNotSameIndex<strTempMainArray.GetSize() && nNotSameIndex<strTempRelativeArray.GetSize(); ++nNotSameIndex)
	{
		if (strTempMainArray[nNotSameIndex].CompareNoCase(strTempRelativeArray[nNotSameIndex]) != 0)
		{
			break;
		}
	}

	int nFolderCount = (int)strTempMainArray.GetSize()-nNotSameIndex-1;
	CString strPath;
	for (int i=0; i<nFolderCount; i++)
	{
		strPath +=_T("..\\");
	}

	for (int i=nNotSameIndex; i<strTempRelativeArray.GetSize(); i++)
	{
		strPath += strTempRelativeArray[i];
		if (i < strTempRelativeArray.GetSize()-1)  //不是最后一个
		{
			strPath += _T('\\');
		}
	}

	return strPath;
}