BOOL COptionsGrid::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	TransformSnap* pSnap = &(GetDocument()->m_snap);

	Grid = pSnap->GetAccurateGrid();
	SnapGrid = pSnap->GetGridSnap();
	ShowGrid 	= GetDocument()->GetOptions()->ShowGrid();
	Units 		= GetDocument()->GetOptions()->GetUnits();

	CheckDlgButton( GRIDBOX_SHOW, ShowGrid );
	CheckDlgButton( GRIDBOX_SNAP, SnapGrid );

	CheckRadioButton(GRIDBOX_MM,GRIDBOX_INCHES,GRIDBOX_MM+Units);
	if (Grid == NormalGrid)
		CheckRadioButton(GRIDBOX_NORMAL,GRIDBOX_USER,GRIDBOX_NORMAL);
	else if (Grid == FineGrid)
		CheckRadioButton(GRIDBOX_NORMAL,GRIDBOX_USER,GRIDBOX_FINE);
	else
		CheckRadioButton(GRIDBOX_NORMAL,GRIDBOX_USER,GRIDBOX_USER);

	// Set up the display of the grid spacing correctly
	OnChange();	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
BOOL COptionsGrid::OnApply() 
{
	ShowGrid  = IsDlgButtonChecked(GRIDBOX_SHOW);
	SnapGrid  = IsDlgButtonChecked(GRIDBOX_SNAP);

	int hold = GetCheckedRadioButton(GRIDBOX_MM,GRIDBOX_INCHES);
	if (hold == GRIDBOX_MM)
		Units = 0;
	else
		Units = 1;


	hold = GetCheckedRadioButton(GRIDBOX_NORMAL,GRIDBOX_USER);
	switch (hold)
	{
		case GRIDBOX_NORMAL:
			Grid = NormalGrid;
			break;
		case GRIDBOX_FINE:
			Grid = FineGrid;
			break;
		case GRIDBOX_USER:
			{
				CString s;
				GetDlgItemText(GRIDBOX_SPACING,s);
				Grid = _tstof( s );
				if (Units == 0)
					Grid = (Grid * static_cast<double>(PIXELSPERMM));
				else
					Grid = (Grid * 254.0 * PIXELSPERMM) / 1000.0;
				break;
			}
	}

	if (Grid <=0 )
	{
		Grid = FineGrid;
	}

	// Write these settings back
	TransformSnap* pSnap = &(GetDocument()->m_snap);

	pSnap->SetAccurateGrid(Grid);
	pSnap->SetGridSnap( SnapGrid );

	GetDocument()->GetOptions()->SetGridShow( ShowGrid == TRUE );
	GetDocument()->GetOptions()->SetUnits( Units == TRUE );

	// Write the settings to the registry
	CRegistry::Set("ShowGrid",ShowGrid);
	CRegistry::Set("Units",Units);
	CRegistry::Set("Grid",Grid);

	return CPropertyPage::OnApply();
}
void CLibraryView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
	// Count the symbols and determine the page count and splits
	CLibraryDoc * pDoc = GetDocument();
	CLibraryDoc::idCollection::iterator it = pDoc->m_SymbolMap.begin();


	TransformSnap s;
	s.SetGridSnap( FALSE );
	CTinyCadDoc doc;

	const int inter_spacing = 20;
	const int text_spacing = 25;
	double current_y = 0;

	int pages = (pDoc->m_SymbolMap.size() / m_symbols_per_print_page) + 1;

	pInfo->SetMinPage( 1 );
	pInfo->SetMaxPage( pages );
	
	CScrollView::OnBeginPrinting(pDC, pInfo);
}
void CLibraryView::OnDraw(CDC* pDC)
{
	CLibraryDoc * pDoc = GetDocument();

	CLibraryDoc::idCollection::iterator it = pDoc->m_SymbolMap.begin();
	Transform	view_transform;

	if (pDC->IsPrinting())
	{
		view_transform.SetZoomFactor( 5.0 );
	}

	// The font for naming with
	CFont theFont;
	theFont.CreateFont(static_cast<int>(view_transform.doubleScale( 16 )),0,0,0,400,FALSE,FALSE,FALSE,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS | CLIP_LH_ANGLES,
		DEFAULT_QUALITY,DEFAULT_PITCH | FF_MODERN,_T("Courier New"));

	CFont theFont2;
	theFont2.CreateFont(static_cast<int>(view_transform.doubleScale( 14 )),0,0,0,400,FALSE,FALSE,FALSE,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS | CLIP_LH_ANGLES,
		DEFAULT_QUALITY,DEFAULT_PITCH | FF_MODERN,_T("Courier New"));

	CFont theFont3;
	theFont3.CreateFont(static_cast<int>(view_transform.doubleScale( 16 )),0,0,0,400,FALSE,FALSE,FALSE,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS | CLIP_LH_ANGLES,
		DEFAULT_QUALITY,DEFAULT_PITCH |  FF_SWISS, _T("Arial"));

	CFont *oldFont = pDC->SelectObject( &theFont );

	TransformSnap s;
	s.SetGridSnap( FALSE );
	s.SetAccurateGrid(FineGrid);
	CTinyCadDoc doc;
	
	const int inter_spacing = 20;
	const int text_spacing = 25;
	int current_index = 0;
	int current_y = 0;
	int start_y = 0;
	
	double height = view_transform.doubleDeScale( pDC->GetDeviceCaps( VERTRES ) );
	int advance = 0;

	double max_height;
	double max_width;

	if (!pDC->IsPrinting())
	{
		CRect r;
		GetClientRect( r );
		max_width = r.Width();
		max_height = height / m_symbols_per_screen_page;

		// Establish where to start drawing from...
		advance = static_cast<int>(GetScrollPosition().y / max_height);
		current_y = static_cast<int>(advance * max_height);
		start_y = current_y;
	}
	else
	{
		max_width = view_transform.doubleDeScale( pDC->GetDeviceCaps( HORZRES ) );
		max_height = (height - text_spacing*4) / m_symbols_per_print_page;

		CString s = GetDocument()->m_pLibrary->m_name;
		CContext q( pDC, view_transform );
		pDC->SelectObject( &theFont3 );
		q.TextOut( 5, 0, s );
		s.Format(_T("Page %d of %d"), m_printing_page + 1, (GetDocument()->m_SymbolMap.size() / m_symbols_per_print_page) + 1 );
		q.TextOut( 5, height - text_spacing, s );

		// Establish where to start drawing from...
		current_y = text_spacing * 2;
		advance = (m_printing_page * m_symbols_per_print_page);
	}

	while ( advance > 0 && it != pDoc->m_SymbolMap.end() )
	{
		++ it;
		++ current_index;
		-- advance;
	}

	for (;it != pDoc->m_SymbolMap.end(); ++it )
	{
		CContext q( pDC, view_transform );
		
		// Display the name of this symbol
		pDC->SelectObject( &theFont );
			
		// Now access the symbol and draw it next to the name
		CDPoint p;
		CLibraryStoreNameSet &s = GetDocument()->getNameSet(it);
		CDesignFileSymbol *pSymbol = s.GetDesignSymbol( &doc, 0 );

		// Determine the rotation
		int orientation = s.orientation;


		drawingCollection method;
		if (pSymbol)
		{
			pSymbol->GetMethod( 0, false, method );
			p = pSymbol->GetTr( 0, false );
		}
		else
		{
			p = CDPoint(-75,-15);
		}

		if (orientation >= 2)
		{
			CDPoint q = p;
			p.x = q.y;
			p.y = q.x;
		}

		int block_height = 0;
		double zoom = min( (max_width*75) / fabs(p.x), (max_height*75)/fabs(p.y) );
		zoom = min( 100, zoom );
		zoom = max( 2, zoom );
		block_height = static_cast<int>(max_height);

		// Fill in the background rectangle
		q.SetOrigin( CDPoint( 0, -current_y) );
		if (!pDC->IsPrinting())
		{
			if (current_index == pDoc->getSelected())
			{
				q.SelectBrush( cOFFPAGE );
			}
			else
			{
				q.SelectBrush( cWHITE );
			}
			q.SelectPen( cBLACK,0,0);
			q.Rectangle( CDRect(0,0,max_width, block_height ));
		}
		else
		{
			q.SelectPen( cOFFPAGE,0,0 );
			q.MoveTo( CDPoint(0,0) );
			q.LineTo( CDPoint(max_width, 0) );
		}

		// Draw the name
		q.SetTextAlign(TA_LEFT | TA_BOTTOM | TA_NOUPDATECP);
		q.SetBkMode( TRANSPARENT );
		q.SetTextColor( RGB(0,0,0) );

		// Do this for each of the names in the symbol set
		int text_pos_y = 20;
		int text_pos_x = 5;
		int text_col_width = 0;
		for (int i =0; i < s.GetNumRecords(); i++)
		{
			CSymbolRecord &r = s.GetRecord( i );

			pDC->SelectObject( &theFont );
			q.TextOut( text_pos_x, text_pos_y, r.name );

			pDC->SelectObject( &theFont2 );
			q.TextOut( text_pos_x, text_pos_y + 16, r.description );
			text_pos_y += 35;

			text_col_width = max( text_col_width, static_cast<int>(view_transform.DeScale( pDC->GetTextExtent( r.description ).cx )) );
			text_col_width = max( text_col_width, static_cast<int>(view_transform.DeScale( pDC->GetTextExtent( r.name ).cx ) ) );

			if (text_pos_y > max_height - 40)
			{
				// Move across to the other side...
				text_pos_x += text_col_width + 30;
				text_col_width = 0;
				text_pos_y = 20;
			}
		}

		int width_offset = max( 250, text_col_width + text_pos_x + 30 );
		int width_to_fill = static_cast<int>(max_width) - width_offset;

		// Now display the symbol
		CDPoint old;

		q.SetZoomFactor( zoom/100.0 *  q.GetTransform().GetZoomFactor() );
		int centering_height = static_cast<int>((max_height * 100) / zoom);
		int centering_width = static_cast<int>((width_to_fill * 100) / zoom);
		q.SetOrigin( CDPoint( -(width_offset*100)/zoom, ((-current_y)*100)/zoom) );
		switch (orientation)
		{
		case 2:
			old = q.SetTRM( CDPoint((centering_width-p.x)/2, (centering_height - p.y)/2) , CDPoint(0,0), orientation );
			break;
		case 3:
			old = q.SetTRM( CDPoint(centering_width / 2 + p.x/2, (centering_height-p.y)/2) , CDPoint(0,0), orientation );
			break;
		default:
			old = q.SetTRM( CDPoint((centering_width-p.x)/2, (centering_height-p.y)/2) , CDPoint(0,0), orientation );
			break;
		}

		 
		if (pSymbol)
		{
			drawingIterator paint_it = method.begin();
			while (paint_it != method.end())
			{
				(*paint_it)->Paint( q, draw_normal );
				++ paint_it;
			}

			delete pSymbol;
		}

		q.EndTRM( old );

		current_index ++;
		current_y += block_height;

		if (current_y - start_y + block_height > height)
		{
			break;
		}
	}

	pDC->SelectObject( oldFont );

	SetScrollSizes( MM_TEXT, GetDocSize() );
}
Esempio n. 5
0
void CTinyCadView::OnDraw(CDC* pDC)
{
	//CTinyCadDoc* pDoc = GetCurrentDocument();
	CDC BitmapDC;
	CBitmap *old_bitmap = NULL;

	int selected;

	CRect client;
	if (pDC->IsKindOf(RUNTIME_CLASS(CPaintDC)))
	{
		client = static_cast<CPaintDC*> (pDC)->m_ps.rcPaint;
	}
	else
	{
		GetClientRect(&client);
	}

	// Are we going to use off-screen drawing?
	BOOL osb = !pDC->IsPrinting() && m_use_offscreen_drawing && CreateBitmap(*pDC, client.Width(), client.Height());

	if (osb)
	{
		BitmapDC.CreateCompatibleDC(pDC);
		old_bitmap = BitmapDC.SelectObject(&m_bitmap);
	}

	{
		CContext dc(osb ? &BitmapDC : pDC, GetTransform(), this);

		CDPoint origin = GetTransform().GetOrigin();

		if (osb)
		{
			CPoint point = CPoint(-client.left, -client.top);
			dc.SetPixelOffset(point);
		}

		if (pDC->IsPrinting())
		{
			dc.SetBlack(CTinyCadRegistry::GetPrintBandW());
		}

		CDPoint Start, End;
		CRect rect;
		GetClientRect(&rect);
		TransformSnap snap;
		snap.SetGridSnap(FALSE);
		Start = GetTransform().DeScale(snap, CPoint(rect.left, rect.top));
		End = GetTransform().DeScale(snap, CPoint(rect.right, rect.bottom));

		// Is any of this region in the off-page area?
		if (!pDC->IsPrinting())
		{

			// Paint the region white
			if (pDC->IsPrinting())
			{
				dc.SelectBrush(cWHITE);
				dc.SelectPen(PS_SOLID, 1, cWHITE);
			}
			else
			{
				COLORREF col = GetCurrentDocument()->GetOptions()->GetUserColor().Get(CUserColor::BACKGROUND);
				dc.SelectBrush(col, 0);
				dc.SelectPen(PS_SOLID, 1, col);
			}
			dc.Rectangle(CDRect(Start.x - 2, Start.y - 2, End.x + 2, End.y + 2));

			dc.SelectBrush(cOFFPAGE);
			dc.SelectPen(PS_SOLID, 1, cOFFPAGE);

			if (End.x > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x)
			{
				CDPoint a = CDPoint(GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x, 0);
				dc.Rectangle(CDRect(a.x, a.y, End.x, End.y));
			}
			if (End.y > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y)
			{
				CDPoint a = CDPoint(Start.x, GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y);
				dc.Rectangle(CDRect(a.x, a.y, End.x, End.y));
			}
			if (Start.x < 0) dc.Rectangle(CDRect(0, Start.y, Start.x, End.y));
			if (Start.y < 0) dc.Rectangle(CDRect(Start.x, 0, End.x, Start.y));

			// Fill this region with a grid
			double grid = GetCurrentDocument()->m_snap.GetGrid();
			double SGrid = dc.GetTransform().doubleScale(grid);
			if (GetCurrentDocument()->GetOptions()->ShowGrid() && SGrid > 10)
			{
				double x = dc.GetTransform().GetOrigin().x;
				double y = dc.GetTransform().GetOrigin().y;

				TransformSnap s = GetCurrentDocument()->m_snap;
				s.SetGridSnap(TRUE);

				x = s.Snap(x);
				y = s.Snap(y);

				for (double xp = x >= 0 ? x : 0; xp < End.x && xp < GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x; xp += grid)
				{
					for (double yp = y >= 0 ? y : 0; yp < End.y && yp < GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y; yp += grid)
					{
						dc.SetPixel(CDPoint(xp, yp), 0);
					}
				}
			}
		}

		Start -= CDPoint(10, 10);
		End += CDPoint(10, 10);

		GetCurrentDocument()->GetSelectBegin();

		drawingIterator it = GetCurrentDocument()->GetDrawingBegin();
		while (it != GetCurrentDocument()->GetDrawingEnd())
		{
			CDrawingObject *obj = *it;

			selected = !pDC->IsPrinting() && GetCurrentDocument()->IsSelected(obj);
			paint_options options = selected ? draw_selected : draw_normal;

			if (!pDC->IsPrinting() || !obj->IsConstruction())
			{
				if (pDC->IsPrinting() || obj->IsInside(Start.x, End.x, Start.y, End.y))
				{
					obj->Paint(dc, options);
				}
			}

			++it;
		}

		// Now draw the selectable object, so it stands out...
		CDrawingObject *obj = GetCurrentDocument()->GetSelectable();
		if (obj != NULL && !GetCurrentDocument()->IsSelected(obj))
		{
			paint_options options = draw_selectable;
			GetCurrentDocument()->GetSelectable()->Paint(dc, options);
		}

		// If only one item is selected then just draw its handles now
		if (GetCurrentDocument()->IsSingleItemSelected())
		{
			GetCurrentDocument()->GetSingleSelectedItem()->PaintHandles(dc);
		}

		// if necessary turn back on the current object to be edited
		if (GetCurrentDocument()->GetEdit() != NULL) {
			//ATLTRACE2("TinyCadView::GetCurrentDocument->GetEdit->Paint(dc, draw_selected=%d)\n",draw_selected);
			GetCurrentDocument()->GetEdit()->Paint(dc, draw_selected);
		}

		// Draw the design details
		GetCurrentDocument()->Display(dc);
	}

	if (osb)
	{
		pDC->BitBlt(client.left, client.top, client.Width(), client.Height(), &BitmapDC, 0, 0, SRCCOPY);
		BitmapDC.SelectObject(old_bitmap);
	}
}