示例#1
0
文件: EditList.cpp 项目: pdrezet/brix
// This function stores a copy of the selected icons when a copy or cut is performed
void EditList::BufferSelectedIcons(INXRect selectRect, Project* pProject, DEP* pDEP)
{
	ConData *icondata;
	ConData *otherIcon;
	INXPOSITION pos, otherPos;
	bool isConnected = FALSE;
	INXObjList* temp;
	CFileOperation fo;
	CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	BlockOperations bo;
	UINT i;
	INXString csProjectDir;
	
	pProject->pProjMData->getProjectDir(csProjectDir);
	copySelList->RemoveAll();
	// the following algorithm is used because there isn't a copy constructor
	// copy the condata list to the flattened list
	// copy the selected icons from the flattened list to the copySelList
	temp = LoadTemp();
	bo.AssignIconLineEndPoints(temp);
	
	// if the icon is in the selection box add it to copySelList
	pos = temp->GetHeadPosition();
	while (pos) {
		icondata = (ConData *) (temp->GetNext(pos));
		//if (selectRect.PtInRect(icondata->GetIconCentre())) {
		if (icondata->selected) {
			// Copy user defined blocks to the temp directory
			if (icondata->m_iUserDefined) {
				fo.SetOverwriteMode(true); // set OverwriteMode flag
				fo.Copy(csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(pDEP->hItem) + pDEP->depFilename 
					+ "\\" + icondata->description + ".prg", workDir + TEMPDIR);
				fo.Copy(csProjectDir + DEPDIR + pFrame->m_wndProjectBar.m_cProjTree.GetDEPPath(pDEP->hItem) + pDEP->depFilename 
					+ "\\" + icondata->description, workDir + TEMPDIR);
				//CopyInstance(icondata, pProject, pDEP);
			}
			copySelList->AddTail(icondata);
		}
		// if icon isn't in selection box then delete
		else {
			//delete icondata;
		}
	}
	
	//delete temp;

	// if an input on an icon in copySelList is not connected to another
	// icon in the list then disconnect it
	// remove all tags from ports in the copy list. Don't want same tags as this is confusing.
	pos = copySelList->GetHeadPosition();
	while (pos) {
		icondata = (ConData *) (copySelList->GetNext(pos));
		for (i=0; i<icondata->inputport_num; i++) {
			icondata->inputport[i]->tag = "";
			otherPos = copySelList->GetHeadPosition();
			isConnected = FALSE;
			while (otherPos) {
				otherIcon = (ConData *)(copySelList->GetNext(otherPos));
				if (icondata->inputport[i]->line.exist && icondata->inputport[i]->line.othericonid == otherIcon->identnum) {
					isConnected = TRUE;
				}
			}
			if (!isConnected) {
				icondata->inputport[i]->line.exist = 0;
			}
		}
		for (i=0; i<icondata->startport_num; i++) {
			icondata->startport[i]->tag = "";
			otherPos = copySelList->GetHeadPosition();
			isConnected = FALSE;
			while (otherPos) {
				otherIcon = (ConData *)(copySelList->GetNext(otherPos));
				if (icondata->startport[i]->line.exist && icondata->startport[i]->line.othericonid == otherIcon->identnum) {
					isConnected = TRUE;
				}
			}
			if (!isConnected) {
				icondata->startport[i]->line.exist = 0;
			}
		}
		for (i=0; i<icondata->outputport_num; i++) {
			icondata->outputport[i]->tag = "";
		}
		for (i=0; i<icondata->finishport_num; i++) {
			icondata->finishport[i]->tag = "";
		}
	}

	// save copySelList. This is used for test purposes
	SaveCopy((INXString)workDir + "\\tmpcopy.prg");
	//pView->pasteFlag = TRUE;
	// delete the temp list now the selected blocks have been saved
	bo.DeleteBlock(temp);
}