Скачиваний:
8
Добавлен:
01.05.2014
Размер:
22.69 Кб
Скачать
// part32View.cpp : implementation of the CPart32View class
//

#include "stdafx.h"
#include "part32.h"

#include "part32Doc.h"
#include "CntrItem.h"
#include "part32View.h"

#include "SetDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPart32View

IMPLEMENT_DYNCREATE(CPart32View, CScrollView)

BEGIN_MESSAGE_MAP(CPart32View, CScrollView)
	//{{AFX_MSG_MAP(CPart32View)
	ON_WM_DESTROY()
	ON_WM_SETFOCUS()
	ON_WM_SIZE()
	ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
	ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
	ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_CHAR()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_FIGURE_DELETE, OnFigureDelete)
	ON_COMMAND(ID_CONTEINER_SET1VIEW, OnConteinerSet1view)
	ON_COMMAND(ID_SETS_SET1, OnSetsSet1)
	ON_UPDATE_COMMAND_UI(ID_SETS_SET1, OnUpdateSetsSet1)
	ON_COMMAND(ID_SETS_SET2, OnSetsSet2)
	ON_UPDATE_COMMAND_UI(ID_SETS_SET2, OnUpdateSetsSet2)
	ON_COMMAND(ID_CONTEINER_SET2VIEW, OnConteinerSet2view)
	ON_COMMAND(ID_SETS_UNION, OnSetsUnion)
	ON_COMMAND(ID_SETS_CROSS, OnSetsCross)
	ON_COMMAND(ID_SETS_SUBTRACTION, OnSetsSubtraction)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPart32View construction/destruction

CPart32View::CPart32View()
{
	m_pSelection = NULL;
	// TODO: add construction code here
	// TODO: add construction code here
	m_FirstPoint = CPoint(0,0);       
    m_SecondPoint = CPoint(0,0);   
    m_MoveLastPoint = CPoint(0,0);
    m_pTempElement = 0;
	m_pSelected = 0;
	StringData="";
	CaretCreated=false;
	doMove=false;

	m_Scale=1;
	SetScrollSizes(MM_TEXT, CSize(0,0));

	SetNom=1;
}

CPart32View::~CPart32View()
{
}

BOOL CPart32View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPart32View drawing

void CPart32View::OnDraw(CDC* pDC)
{
	CPart32Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	// TODO: also draw all OLE items in the document

	// Draw the selection at an arbitrary position.  This code should be
	//  removed once your real drawing code is implemented.  This position
	//  corresponds exactly to the rectangle returned by CPart32CntrItem,
	//  to give the effect of in-place editing.

	// TODO: remove this code when final draw code is complete.

	if (m_pSelection == NULL)
	{
		POSITION pos = pDoc->GetStartPosition();
		m_pSelection = (CPart32CntrItem*)pDoc->GetNextClientItem(pos);
	}
	if (m_pSelection != NULL)
		m_pSelection->Draw(pDC, m_pSelection->m_Rect);


	CString str;

	if (SetNom==1)
	{
	if (pDoc->set1.count()!=0)				//при перерисовка окна, перерисовываем все фигуры по итератору
	{
		ArSetIterator<Shape*> it(pDoc->set1);
	
		while(!it.end())
		{
			
			if(pDC->RectVisible(it.currentItem()->GetBoundRect()))
			{   
				str.Format("%d",it.currentPos());
				pDC->TextOut(it.currentItem()->getX()-10,it.currentItem()->getY()-10,str);
				it.currentItem()->Draw(pDC,m_pSelected);
			}

			it.next();
		}
	}
	}
	if (SetNom==2)
	{
	if (pDoc->set2.count()!=0)				//при перерисовка окна, перерисовываем все фигуры по итератору
	{
		ArSetIterator<Shape*> it2(pDoc->set2);
	
		while(!it2.end())
		{
			
			if(pDC->RectVisible(it2.currentItem()->GetBoundRect()))
			{   
				str.Format("%d",it2.currentPos());
				pDC->TextOut(it2.currentItem()->getX()-10,it2.currentItem()->getY()-10,str);
				it2.currentItem()->Draw(pDC,m_pSelected);
			}

			it2.next();
		}
	}
	}

	if (SetNom==3)
	{
	if (pDoc->set3.count()!=0)				//при перерисовка окна, перерисовываем все фигуры по итератору
	{
		ArSetIterator<Shape*> it3(pDoc->set3);
	
		while(!it3.end())
		{
			
			if(pDC->RectVisible(it3.currentItem()->GetBoundRect()))
			{   
				str.Format("%d",it3.currentPos());
				pDC->TextOut(it3.currentItem()->getX()-10,it3.currentItem()->getY()-10,str);
				it3.currentItem()->Draw(pDC,m_pSelected);
			}

			it3.next();
		}
	}
	}

}

void CPart32View::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();


	// TODO: remove this code when final selection model code is written
	m_pSelection = NULL;    // initialize selection

//	CSize sizeTotal;
	// TODO: calculate the total size of this view
//	sizeTotal.cx = sizeTotal.cy = 100;
	   ResetScrollSizes(); 

//	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CPart32View printing

BOOL CPart32View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CPart32View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CPart32View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CPart32View::OnDestroy()
{
	// Deactivate the item on destruction; this is important
	// when a splitter view is being used.
   CScrollView::OnDestroy();
   COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
   if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
   {
      pActiveItem->Deactivate();
      ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
   }
}


/////////////////////////////////////////////////////////////////////////////
// OLE Client support and commands

BOOL CPart32View::IsSelected(const CObject* pDocItem) const
{
	// The implementation below is adequate if your selection consists of
	//  only CPart32CntrItem objects.  To handle different selection
	//  mechanisms, the implementation here should be replaced.

	// TODO: implement this function that tests for a selected OLE client item

	return pDocItem == m_pSelection;
}

void CPart32View::OnInsertObject()
{
	// Invoke the standard Insert Object dialog box to obtain information
	//  for new CPart32CntrItem object.
	COleInsertDialog dlg;
	if (dlg.DoModal() != IDOK)
		return;

	BeginWaitCursor();

	CPart32CntrItem* pItem = NULL;
	TRY
	{
		// Create new item connected to this document.
		CPart32Doc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		pItem = new CPart32CntrItem(pDoc);
		ASSERT_VALID(pItem);

		// Initialize the item from the dialog data.
		if (!dlg.CreateItem(pItem))
			AfxThrowMemoryException();  // any exception will do
		ASSERT_VALID(pItem);
		
        if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
			pItem->DoVerb(OLEIVERB_SHOW, this);

		ASSERT_VALID(pItem);

		// As an arbitrary user interface design, this sets the selection
		//  to the last item inserted.

		// TODO: reimplement selection as appropriate for your application

		m_pSelection = pItem;   // set selection to last inserted item
		pDoc->UpdateAllViews(NULL);
	}
	CATCH(CException, e)
	{
		if (pItem != NULL)
		{
			ASSERT_VALID(pItem);
			pItem->Delete();
		}
		AfxMessageBox(IDP_FAILED_TO_CREATE);
	}
	END_CATCH

	EndWaitCursor();
}

// The following command handler provides the standard keyboard
//  user interface to cancel an in-place editing session.  Here,
//  the container (not the server) causes the deactivation.
void CPart32View::OnCancelEditCntr()
{
	// Close any in-place active item on this view.
	COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
	if (pActiveItem != NULL)
	{
		pActiveItem->Close();
	}
	ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}

// Special handling of OnSetFocus and OnSize are required for a container
//  when an object is being edited in-place.
void CPart32View::OnSetFocus(CWnd* pOldWnd)
{
	COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
	if (pActiveItem != NULL &&
		pActiveItem->GetItemState() == COleClientItem::activeUIState)
	{
		// need to set focus to this item if it is in the same view
		CWnd* pWnd = pActiveItem->GetInPlaceWindow();
		if (pWnd != NULL)
		{
			pWnd->SetFocus();   // don't call the base class
			return;
		}
	}

	CScrollView::OnSetFocus(pOldWnd);
}

void CPart32View::OnSize(UINT nType, int cx, int cy)
{
	CScrollView::OnSize(nType, cx, cy);
	COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
	if (pActiveItem != NULL)
		pActiveItem->SetItemRects();
}

/////////////////////////////////////////////////////////////////////////////
// OLE Server support

// The following command handler provides the standard keyboard
//  user interface to cancel an in-place editing session.  Here,
//  the server (not the container) causes the deactivation.
void CPart32View::OnCancelEditSrvr()
{
	GetDocument()->OnDeactivateUI(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// CPart32View diagnostics

#ifdef _DEBUG
void CPart32View::AssertValid() const
{
	CScrollView::AssertValid();
}

void CPart32View::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CPart32Doc* CPart32View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPart32Doc)));
	return (CPart32Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPart32View message handlers
CPart32CntrItem* CPart32View::OleClickTest(CPoint point)
{
	CPart32CntrItem* myOle;
	myOle=m_pSelection;
	if (myOle!=NULL)
	{
		if (!myOle->m_Rect.PtInRect(point)) myOle=NULL;
	}
	return myOle;
}


void CPart32View::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CPart32CntrItem* myOle;
	myOle=OleClickTest(point);

	if (myOle!=NULL) myOle->DoVerb(OLEIVERB_PRIMARY,this);		//инициализация объекта ole

	CScrollView::OnLButtonDblClk(nFlags, point);
}

Shape* CPart32View::CreateElement()			//создаем фигуру выбранного типа
{  	
	CPart32Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);                 

	switch(pDoc->GetElementType())
	{
		case TRIANGLE:
			return new CTriangleEntity(m_SecondPoint.x-m_FirstPoint.x,m_SecondPoint.y-m_FirstPoint.y,m_FirstPoint.x,m_FirstPoint.y);
     
		case TRAPEZ:
			return new CTrapeziumEntity(10,m_SecondPoint.x-m_FirstPoint.x,m_SecondPoint.y-m_FirstPoint.y,m_FirstPoint.x,m_FirstPoint.y);

		case TEXT:
			return new CTextEntity(StringData,m_FirstPoint.x,m_FirstPoint.y);

		case TRAPEZTEXT:
			return new CTextTrapeziumEntity(StringData,10,m_SecondPoint.x-m_FirstPoint.x,m_SecondPoint.y-m_FirstPoint.y,m_FirstPoint.x,m_FirstPoint.y);

		default:
			AfxMessageBox("Bad Element code", MB_OK);
			AfxAbort();
			return 0;
	}
}

Shape* CPart32View::SelectElement(CPoint aPoint)
{
	CPart32Doc* pDoc = GetDocument();				//выделенный элемент
	ASSERT_VALID(pDoc);

	CClientDC aDC(this);
	OnPrepareDC(&aDC);
	aDC.DPtoLP(&aPoint);

	Shape* element=0;
	CRect aRect(0,0,0,0);

	if (SetNom==1)
	{
	if (pDoc->set1.count()!=0)
	{

		ArSetIterator<Shape*> it(pDoc->set1);
	
		while(!it.end())
		{
			element=it.currentItem();

			aRect=it.currentItem()->GetBoundRect();
	
			if(aRect.PtInRect(aPoint))
			return element;

			it.next();
		}
	}
	}
	if (SetNom==2)
	{
	if (pDoc->set2.count()!=0)
	{

		ArSetIterator<Shape*> it2(pDoc->set2);
	
		while(!it2.end())
		{
			element=it2.currentItem();

			aRect=it2.currentItem()->GetBoundRect();
	
			if(aRect.PtInRect(aPoint))
			return element;

			it2.next();
		}
	}
	}
	return 0;
}


void CPart32View::ShowCursor(CDC* pDC)
{	if (!CaretCreated)
	{
		TEXTMETRIC textmetric;
		pDC->GetTextMetrics(&textmetric);

		CreateSolidCaret(textmetric.tmAveCharWidth/8,textmetric.tmHeight);

		SetCaretPos(m_FirstPoint);
		ShowCaret();
		CaretCreated=true;
	}
}

void CPart32View::ResetScrollSizes()
{
   CClientDC aDC(this);
   OnPrepareDC(&aDC);
   
   CPart32Doc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);  

   CSize DocSize = pDoc->GetDocSize();       
   aDC.LPtoDP(&DocSize);                        
   SetScrollSizes(MM_TEXT, DocSize);            
}


void CPart32View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
		m_FirstPoint = point;  
	StringData.Empty();

    SetCapture();
	HideCaret();
	CaretCreated=false;
	
	CScrollView::OnLButtonDown(nFlags, point);
}


void CPart32View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CPart32Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc); 

	CClientDC aDC(this);
	
	if (pDoc->is_TextEnter)
	{	
		if (!doMove)
		{
			m_SecondPoint = point;
			ShowCursor(&aDC);
		}
		else
		{
			if(this == GetCapture())
			ReleaseCapture(); 
		}
	}
	else
	{
		if (m_pTempElement)
		{
			if (SetNom==1)
			{
				pDoc->set1.insertEl(pDoc->index1,m_pTempElement);
				pDoc->index1++;	
				Invalidate();
			}//добавление в контейнер
			else
			{
				pDoc->set2.insertEl(pDoc->index2,m_pTempElement);
				pDoc->index2++;	
				pDoc->index2++;
				Invalidate();
			}
		}

		if(this == GetCapture())
		ReleaseCapture();       
		
	}

	if (doMove==true){doMove=false;}

	if(m_pTempElement)
	{  	
		m_pTempElement = 0;      
	}
	
	CScrollView::OnLButtonUp(nFlags, point);
}

void CPart32View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC aDC(this);
	OnPrepareDC(&aDC);


	if((nFlags & MK_LBUTTON) && (this == GetCapture()))
	{
		if (!doMove)
		{
			aDC.DPtoLP(&point);
			m_SecondPoint = point; 
	
			if(m_pTempElement)
			{
				aDC.SetROP2(R2_NOTXORPEN);			//перерисовка фигуры

				m_pTempElement->Draw(&aDC);
		 		delete m_pTempElement;      
				m_pTempElement = 0;          
			}

			m_pTempElement = CreateElement();
			m_pTempElement->Draw(&aDC);
		}
		else
		{
			aDC.SetROP2(R2_NOTXORPEN);				//перемещение фигуры
			m_pSelected->Draw(&aDC,m_pSelected); 
			m_pSelected->move(point.x-m_MoveLastPoint.x,point.y-m_MoveLastPoint.y);
			m_pSelected->Draw(&aDC,m_pSelected);

			Invalidate();
		}
	}
	else
	{
		CRect aRect;
		Shape* pCurrentSelection = SelectElement(point);			//выделение фигуры
	
		if ((pCurrentSelection==m_pSelected)&&(m_pSelected)){doMove=true;}

		if(pCurrentSelection!=m_pSelected)
		{	doMove=false;
			if(m_pSelected)
			{
				aRect = m_pSelected->GetBoundRect();
				aDC.LPtoDP(aRect);
				aRect.NormalizeRect();
				InvalidateRect(aRect, FALSE);
			}
			m_pSelected = pCurrentSelection;
			if(m_pSelected) 
			{	
				aRect = m_pSelected->GetBoundRect();
				aDC.LPtoDP(aRect);
				aRect.NormalizeRect();
				InvalidateRect(aRect, FALSE);
			}
		}


	}

	m_MoveLastPoint=point;
		
	CScrollView::OnMouseMove(nFlags, point);
}

void CPart32View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	HideCaret();
	CClientDC aDC(this);

	
	CPart32Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc); 


	if (nChar==VK_SPACE)
	{
		if(m_pTempElement)
			{
				m_pTempElement->Draw(&aDC);
		 		
				if (SetNom==1)
				{
					pDoc->set1.insertEl(pDoc->index1,m_pTempElement);		//добавление эт-та в контейнер
					pDoc->index1++;
					Invalidate();
				}
				else
				{
					pDoc->set2.insertEl(pDoc->index2,m_pTempElement);		//добавление эт-та в контейнер
					pDoc->index2++;
					pDoc->index2++;
					Invalidate();
				}

				m_pTempElement = 0;          
			}

		if(this == GetCapture())
		{	ReleaseCapture(); }
		
		HideCaret();CaretCreated=false;
		StringData.Empty();
	}
	else
	{
		if(this == GetCapture())					//перерисовка элемента
		{
			StringData+=nChar; 
	
			if(m_pTempElement)
			{
				m_pTempElement->Draw(&aDC);
		 		delete m_pTempElement;      
				m_pTempElement = 0;          
			}

			m_pTempElement = CreateElement();
			m_pTempElement->Draw(&aDC);
			
			CSize size=aDC.GetTextExtent(StringData);

			CPoint point(m_FirstPoint.x+size.cx,m_FirstPoint.y);
			SetCaretPos(point);

			ShowCaret();
		}
	}
	
	CScrollView::OnChar(nChar, nRepCnt, nFlags);
}

void CPart32View::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CMenu aMenu;
	aMenu.LoadMenu(IDR_CONTEXT_MENU);				//контекстное меню
	ClientToScreen(&point);

	if(m_pSelected)
	 {
      aMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
                                                  point.x, point.y, this);
	 }
	else
	{
      WORD ElementType = GetDocument()->GetElementType();
      aMenu.CheckMenuItem(ID_ELEMENTS_TRIANGLE,
                (TRIANGLE==ElementType?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
      aMenu.CheckMenuItem(ID_ELEMENTS_TRAPEZIUM,
           (TRAPEZ==ElementType?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
      aMenu.CheckMenuItem(ID_ELEMENTS_TEXT,
           (TEXT==ElementType?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
	  aMenu.CheckMenuItem(ID_ELEMENTS_TRAPEZIUMWITHTEXT,
           (TRAPEZTEXT==ElementType?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);


      aMenu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
	}	
}


void CPart32View::OnFigureDelete() 
{
	// TODO: Add your command handler code here
	CPart32Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);					//удаление фигуры из контейнера
	
	bool deleted;

if (SetNom==1)
{
		
	ArSetIterator<Shape*> it(pDoc->set1);
	deleted=false;

		while((!it.end())&&(!deleted))
		{
			if (it.currentItem()==m_pSelected)
			{pDoc->set1.deleteEl(it.currentPos());
			 deleted=true;
			}

			it.next();
		}
}
if (SetNom==2)
{
	ArSetIterator<Shape*> it2(pDoc->set2);
	deleted=false;

		while((!it2.end())&&(!deleted))
		{
			if (it2.currentItem()==m_pSelected)
			{pDoc->set2.deleteEl(it2.currentPos());
			 deleted=true;
			}

			it2.next();
		}
}
    Invalidate();	
}


void CPart32View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
   if(pHint)																//при перерисовке раб области (ползунки)
   {
      CClientDC aDC(this);            
      OnPrepareDC(&aDC);              
     
      CRect aRect=((Shape*)pHint)->GetBoundRect();
      aDC.LPtoDP(aRect);
      aRect.NormalizeRect();
      InvalidateRect(aRect);          
   }
   else
      InvalidateRect(0);	
	
}


void CPart32View::OnConteinerSet1view() 
{
	// TODO: Add your command handler code here
	CPart32Doc* pDoc = GetDocument();		//вызов диалогового окна просмотра контейнера
    ASSERT_VALID(pDoc);	

	SetDlg dlg;

	if (pDoc->set1.count()!=0)
	{
	dlg.set=pDoc->set1;
	ArSetIterator<Shape*> it(pDoc->set1);

	dlg.m_x=it.currentItem()->getX();
	dlg.m_y=it.currentItem()->getY();

	dlg.m_name=it.currentItem()->getName();
	dlg.m_cnt=pDoc->set1.count();
	dlg.m_pos=it.currentPos();
	dlg.m_num=1;
	}

	if (dlg.DoModal()==IDOK)
	{
		InvalidateRect(0);
	}	
}

void CPart32View::OnSetsSet1() 
{
	// TODO: Add your command handler code here
	SetNom=1;
	Invalidate();	
}

void CPart32View::OnUpdateSetsSet1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(SetNom==1);	
}

void CPart32View::OnSetsSet2() 
{
	// TODO: Add your command handler code here
	SetNom=2;
	Invalidate();
}

void CPart32View::OnUpdateSetsSet2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(SetNom==2);	
}

void CPart32View::OnConteinerSet2view() 
{
	// TODO: Add your command handler code here
	CPart32Doc* pDoc = GetDocument();		//вызов диалогового окна просмотра контейнера
    ASSERT_VALID(pDoc);	

	SetDlg dlg;

	if (pDoc->set2.count()!=0)
	{
	dlg.set=pDoc->set2;
	ArSetIterator<Shape*> it(pDoc->set2);

	dlg.m_x=it.currentItem()->getX();
	dlg.m_y=it.currentItem()->getY();

	dlg.m_name=it.currentItem()->getName();
	dlg.m_cnt=pDoc->set2.count();
	dlg.m_pos=it.currentPos();
	dlg.m_num=1;
	}

	if (dlg.DoModal()==IDOK)
	{
		InvalidateRect(0);
	}		
}

void CPart32View::OnSetsUnion() 
{
	// TODO: Add your command handler code here
	CPart32Doc* pDoc = GetDocument();		//вызов диалогового окна просмотра контейнера
    ASSERT_VALID(pDoc);	
	pDoc->set3.clean();

	ArSetIterator<Shape*> it1(pDoc->set1);
	ArSetIterator<Shape*> it2(pDoc->set2);

	while (!it1.end())
	{
		pDoc->set3.insertEl(it1.currentPos(),it1.currentItem());

		it1.next();
	}
	while (!it2.end())
	{
		if (!pDoc->set3.checkPos(it2.currentPos()))
		{
			pDoc->set3.insertEl(it2.currentPos(),it2.currentItem());
		}

		it2.next();
	}

	SetNom=3;
	Invalidate();
	
}

void CPart32View::OnSetsCross() 
{
	// TODO: Add your command handler code here
	CPart32Doc* pDoc = GetDocument();		//вызов диалогового окна просмотра контейнера
    ASSERT_VALID(pDoc);	
	pDoc->set3.clean();

	ArSetIterator<Shape*> it1(pDoc->set1);
	

	while (!it1.end())
	{
	ArSetIterator<Shape*> it2(pDoc->set2);
	while (!it2.end())
	{
		if (it2.currentPos()==it1.currentPos())
		{
			pDoc->set3.insertEl(it1.currentPos(),it1.currentItem());
		}

	it2.next();
	}

	it1.next();
	}

	SetNom=3;
	Invalidate();		
}

void CPart32View::OnSetsSubtraction() 
{
	// TODO: Add your command handler code here
	CPart32Doc* pDoc = GetDocument();		//вызов диалогового окна просмотра контейнера
    ASSERT_VALID(pDoc);	
	pDoc->set3.clean();

	ArSetIterator<Shape*> it1(pDoc->set1);
	bool pres;

	while (!it1.end())
	{
		pres=false;
		ArSetIterator<Shape*> it2(pDoc->set2);
		while (!it2.end())
		{
			if (it2.currentPos()==it1.currentPos())
			{
				pres=true;
			}

			it2.next();
		}

		if (!pres)
		{
			pDoc->set3.insertEl(it1.currentPos(),it1.currentItem());
		}

		it1.next();
	}

	SetNom=3;
	Invalidate();			
}
Соседние файлы в папке part32