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

📄 entityrenderer.cpp

📁 mtext,编辑器,支持潜入对象
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* G:\ICADDEV\PRJ\ICAD\ENTITYRENDERER.CPP
 * Copyright (C) 1997-1998 Visio Corporation. All rights reserved.
 * 
 * Abstract
 * 
 * <TODO : Add Abstract here>
 * 
 */ 
#undef	ASSERT
#undef	VERIFY

#include <afxwin.h>         // MFC core and standard components
#include "icad.h"/*DNT*/
#include "EntityRenderer.h"/*DNT*/
#include "db.h"/*DNT*/
#include "gr.h"/*DNT*/
#include "viewport.h"/*DNT*/
#include "IcadView.h"/*DNT*/

#if defined(USE_SMARTHEAP)
	#include "smrtheap.h"/*DNT*/
#endif

// globals that formerly were in icaddraw.cpp
bool           SDS_DontDrawVPGuts;
bool           SDS_DrawVPGutsOnly;

POINT CEntityRenderer::s_PointsBuffer[ePointsBufferSize];

#ifdef _USE_DISP_OBJ_PTS_3D_
/*------------------------------------------------------------------------*//**
@author Denis Petrov
Rewritten for use with 3D display objects.
*//*-------------------------------------------------------------------------*/
void CEntityRenderer::DrawEntity(db_handitem* elp,
								 CDrawDevice* pDrawDevice, 
								 db_drawing* flp, 
								 struct gr_view* gView, 
								 POINT BltArea[2], 
								 int* FstPt, 
								 int xor, 
								 int hl, 
								 int undraw, 
								 int undrawcol, 
								 int fillmode, 
								 int norecurs, 
								 db_viewport* pViewportForVpLayerSettings, 
								 bool bRedraw, 
								 int width)
{
	db_handitem *telp;
	
	// get the target DC in case we have any TrueType text
	CDC*		pDC = pDrawDevice->getCDC();
	CIcadView*	pIcadView = SDS_CMainWindow->GetIcadView();

	gr_displayobject* pOriginal = (struct gr_displayobject *)elp->ret_disp();
	gr_displayobject* pEnd = NULL;
	if(pOriginal == NULL)
	{
		telp = elp;
		// As an optimization, only use the VpLayerSettings if they really are going to matter
		//
		db_viewport *pViewport = NULL;
		if ( ( pViewportForVpLayerSettings != NULL ) &&
			( pViewportForVpLayerSettings->GetVpLayerFrozenLayerCount( ) > 0 ) )
		{
			pViewport = pViewportForVpLayerSettings;
		}
		
		// get the display objects
		int result = gr_getdispobjs(flp,
			NULL,
			&telp,
			&pOriginal,
			&pEnd,
			NULL,
			flp,
			gView,
			0,
			pDC,
			pViewport);

		if(pOriginal == NULL)
			return;

		elp->set_disp(pOriginal);
	}

	int i, j;
	gr_displayobject* pCurDO;
	int rop;
	bool bUsingGDIPath = false;
	bool bNeedToDelete;
	sds_point projectedPoint;
	
	POINT* pPolyPts; 
	int	iFillColor;
	
    //<alm>
    int hl_store = hl;
    //</alm>

	for(pCurDO = pOriginal; pCurDO; pCurDO = pCurDO->next) 
	{
		if(pCurDO->npts < 2 || !pCurDO->chain)
			continue;
		ASSERT(pCurDO->type & DISP_OBJ_PTS_3D);

		if((pCurDO->color == -1 || xor) && !undraw) 
		{
			rop = R2_XORPEN;
			pDrawDevice->SetDrawMode(RasterConstants::MODE_XOR);
		}
		else
		{
			rop = R2_COPYPEN;
			pDrawDevice->SetDrawMode(RasterConstants::MODE_COPY);
		}

		if(pDrawDevice->is3D())
		{
	        if((pCurDO->type & DISP_OBJ_PTS_GDI_FILLPATH ||
				pCurDO->type & DISP_OBJ_PTS_GDI_TRUETYPE) && !bUsingGDIPath)
			{
				SetDcFillColorMem(undraw ? undrawcol : pCurDO->color, hl, rop, pDrawDevice);
				SetDcColorMem(undraw ? undrawcol : pCurDO->color, width, hl, rop, pDrawDevice);
				pDrawDevice->Polygon(NULL, 0, false);
				bUsingGDIPath = true;
			}

			if(bUsingGDIPath)
			{
				pDrawDevice->Polygon((POINT*)pCurDO->chain, -pCurDO->npts, false);
			}
			else
			{
				SetDcFillColorMem(undraw ? undrawcol : pCurDO->color, hl, rop, pDrawDevice);
				SetDcColorMem(undraw ? undrawcol : pCurDO->color, width, hl, rop, pDrawDevice);
				if(pCurDO->type & DISP_OBJ_PTS_CLOSED)
					pDrawDevice->Polygon((POINT*)pCurDO->chain, pCurDO->npts, true);
				else
					pDrawDevice->Polyline((POINT*)pCurDO->chain, pCurDO->npts);
			}

			if(bUsingGDIPath && (!pCurDO->next || pCurDO->GetSourceEntity() != pCurDO->next->GetSourceEntity() ||
				(!(pCurDO->next->type & DISP_OBJ_PTS_GDI_FILLPATH) &&
				!(pCurDO->next->type & DISP_OBJ_PTS_GDI_TRUETYPE))))
			{
				pDrawDevice->Polygon(NULL, 0, false);
				bUsingGDIPath = false;
			}
			continue;
		}
		
		if(pCurDO->type & DISP_OBJ_SPECIAL)
		{
			// DP: currently only IMAGEs special display objects can be drawn
			ASSERT(pCurDO->GetSourceEntity()->ret_type() == DB_IMAGE);

			// DP: don't draw during real time operations (probably for performance reason)
			if(pIcadView->GetRealTime() != NULL)
				continue;

			if(!drawEntitySpecial(pCurDO, pDrawDevice, flp, gView, hl, xor, undraw))
				ASSERT(FALSE); 
			continue;
		}

        //<alm>
        if (pCurDO->type & DISP_OBJ_HIGHLIGHTED)
            hl = 1;
        else
            hl = hl_store;
        //</alm>
	
        if((pCurDO->type & DISP_OBJ_PTS_GDI_FILLPATH ||
			pCurDO->type & DISP_OBJ_PTS_GDI_TRUETYPE) && !bUsingGDIPath)
		{
			// Prepare a GDI path for filling.
			pDC->SetPolyFillMode(ALTERNATE);
			pDC->BeginPath();
			iFillColor = pCurDO->color;
			bUsingGDIPath = true;
		}
		
		if(pCurDO->npts + 2 > ePointsBufferSize)
		{
			pPolyPts = new POINT[pCurDO->npts + 2];
			bNeedToDelete = true;
		}
		else
		{
			pPolyPts = s_PointsBuffer;
			bNeedToDelete = false;
		}
		SetDcFillColorMem(undraw ? undrawcol : pCurDO->color, hl, rop, pDrawDevice);
		SetDcColorMem(undraw ? undrawcol : pCurDO->color, width, hl, rop, pDrawDevice);
		
		// Now draw it!
		if(((pCurDO->type & DISP_OBJ_PTS_FILLABLE) || (pCurDO->type & DISP_OBJ_PTS_GDI_FILLPATH)) && fillmode)
        {
			for(i = 0, j = 0; i < pCurDO->npts; ++i, j += 3)
			{
				gr_ucs2rp(&(pCurDO->chain[j]), projectedPoint, gView);
				gr_rp2pix(gView, projectedPoint[0], projectedPoint[1], (int*)&pPolyPts[i].x, (int*)&pPolyPts[i].y);
				if(BltArea)
				{
					if(*FstPt) 
					{
						BltArea[0].x = pPolyPts[i].x;  
						BltArea[0].y = pPolyPts[i].y;
						BltArea[1].x = pPolyPts[i].x;  
						BltArea[1].y = pPolyPts[i].y;
						*FstPt=0;
					} 
					else 
					{
						if(BltArea[0].x > pPolyPts[i].x)
							BltArea[0].x = pPolyPts[i].x;
						else
							if(BltArea[1].x < pPolyPts[i].x)
								BltArea[1].x = pPolyPts[i].x;
						if(BltArea[0].y > pPolyPts[i].y)
							BltArea[0].y = pPolyPts[i].y;
						else
							if(BltArea[1].y < pPolyPts[i].y)
								BltArea[1].y = pPolyPts[i].y;
					}
				}
			}
			if(pCurDO->type & DISP_OBJ_PTS_CLOSED)
			{
				gr_ucs2rp(&(pCurDO->chain[0]), projectedPoint, gView);
				gr_rp2pix(gView, projectedPoint[0], projectedPoint[1], (int*)&pPolyPts[pCurDO->npts].x, (int*)&pPolyPts[pCurDO->npts].y);
				if(BltArea)
				{
					if(BltArea[0].x > pPolyPts[i].x)
						BltArea[0].x = pPolyPts[i].x;
					else
						if(BltArea[1].x < pPolyPts[i].x)
							BltArea[1].x = pPolyPts[i].x;
					if(BltArea[0].y > pPolyPts[i].y)
						BltArea[0].y = pPolyPts[i].y;
					else
						if(BltArea[1].y < pPolyPts[i].y)
							BltArea[1].y = pPolyPts[i].y;
				}
			}
			
			// Solid Fill or a path for a Solid hatch or for a TTF text contour
			if(pCurDO->type & DISP_OBJ_PTS_CLOSED)
				pDrawDevice->Polygon(pPolyPts, pCurDO->npts + 1, !(pCurDO->type & DISP_OBJ_PTS_GDI_FILLPATH));
			else
				pDrawDevice->Polygon(pPolyPts, pCurDO->npts, !(pCurDO->type & DISP_OBJ_PTS_GDI_FILLPATH));
        }
		else
		{
			if(pCurDO->type & DISP_OBJ_PTS_GDI_TRUETYPE)
			{
				for(i = 0, j = 0; i < pCurDO->npts; ++i, j += 3)
				{
					gr_ucs2rp(&(pCurDO->chain[j]), projectedPoint, gView);
					gr_rp2pix(gView, projectedPoint[0], projectedPoint[1], (int*)&pPolyPts[i].x, (int*)&pPolyPts[i].y);
					if(BltArea)
					{
						if(*FstPt) 
						{
							BltArea[0].x = pPolyPts[i].x;  
							BltArea[0].y = pPolyPts[i].y;
							BltArea[1].x = pPolyPts[i].x;  
							BltArea[1].y = pPolyPts[i].y;
							*FstPt=0;
						} 
						else 
						{
							if(BltArea[0].x > pPolyPts[i].x)
								BltArea[0].x = pPolyPts[i].x;
							else
								if(BltArea[1].x < pPolyPts[i].x)
									BltArea[1].x = pPolyPts[i].x;
							if(BltArea[0].y > pPolyPts[i].y)
								BltArea[0].y = pPolyPts[i].y;
							else
								if(BltArea[1].y < pPolyPts[i].y)
									BltArea[1].y = pPolyPts[i].y;
						}
					}
				}
				if(pCurDO->type & DISP_OBJ_PTS_CLOSED)
				{
					gr_ucs2rp(&(pCurDO->chain[0]), projectedPoint, gView);
					gr_rp2pix(gView, projectedPoint[0], projectedPoint[1], (int*)&pPolyPts[pCurDO->npts].x, (int*)&pPolyPts[pCurDO->npts].y);
					if(BltArea)
					{
						if(BltArea[0].x > pPolyPts[i].x)
							BltArea[0].x = pPolyPts[i].x;
						else
							if(BltArea[1].x < pPolyPts[i].x)
								BltArea[1].x = pPolyPts[i].x;
						if(BltArea[0].y > pPolyPts[i].y)
							BltArea[0].y = pPolyPts[i].y;
						else
							if(BltArea[1].y < pPolyPts[i].y)
								BltArea[1].y = pPolyPts[i].y;
					}
				}
				
				if(pCurDO->type & DISP_OBJ_PTS_CLOSED)
					pDrawDevice->PolyBezier(pPolyPts, pCurDO->npts + 1);
				else
					pDrawDevice->PolyBezier(pPolyPts, pCurDO->npts);
			}
			else
			{
				int k = 0;
				int clipResult;
				sds_point projectedPoint2;
				// Convert the points into the poly list.
				gr_ucs2rp(&(pCurDO->chain[0]), projectedPoint, gView);
				for (i = 1, j = 3; i < pCurDO->npts; ++i, j += 3) 
				{
					gr_ucs2rp(&(pCurDO->chain[j]), projectedPoint2, gView);
					clipResult = gr_vect_rp2pix(projectedPoint, projectedPoint2,
						(int*)&pPolyPts[k].x,  /* Filling 4 ints. */
						gView);
					memcpy(projectedPoint, projectedPoint2, sizeof(sds_point));
					
					if(BltArea && (clipResult==0 || clipResult==2))
					{
						if(k == 0)
						{
							if(*FstPt) 
							{
								BltArea[0].x = pPolyPts[0].x;  
								BltArea[0].y = pPolyPts[0].y;
								BltArea[1].x = pPolyPts[0].x;  
								BltArea[1].y = pPolyPts[0].y;
								*FstPt = 0;
							} 
							else 
							{
								if(BltArea[0].x > pPolyPts[0].x)
									BltArea[0].x = pPolyPts[0].x;
								else
									if(BltArea[1].x < pPolyPts[0].x)
										BltArea[1].x = pPolyPts[0].x;
								if(BltArea[0].y > pPolyPts[0].y)
									BltArea[0].y = pPolyPts[0].y;
								else
									if(BltArea[1].y < pPolyPts[0].y)
										BltArea[1].y = pPolyPts[0].y;
							}
						}
						if(BltArea[0].x > pPolyPts[k + 1].x)
							BltArea[0].x = pPolyPts[k + 1].x;
						else
							if(BltArea[1].x < pPolyPts[k + 1].x)
								BltArea[1].x = pPolyPts[k + 1].x;
						if(BltArea[0].y > pPolyPts[k + 1].y)
							BltArea[0].y = pPolyPts[k + 1].y;
						else
							if(BltArea[1].y < pPolyPts[k + 1].y)
								BltArea[1].y = pPolyPts[k + 1].y;
					} // end of if(BltArea && ...
					
					++k;	
					// each of the cases clipresult==1 and clipresult==2 sets chainidx to 0, which keeps the next code block
					// from executing, so commenting out the continues is valid
					//
					if(clipResult == 1) 
					{
						if(k > 1) // Off the screen.
							pDrawDevice->Polyline(pPolyPts, k);
						// Reset the beg poly point counter.
						k = 0;
					}
					else 
						if(clipResult==2) 
						{  // Chopped it
							pDrawDevice->Polyline(pPolyPts, k + 1);
							// Reset the beg poly point counter.
							k = 0;
						}
						
				} // end of loop over points in poly list
				
				if(pCurDO->type & DISP_OBJ_PTS_CLOSED)
				{
					gr_ucs2rp(&(pCurDO->chain[0]), projectedPoint2, gView);
					clipResult = gr_vect_rp2pix(projectedPoint, projectedPoint2,
						(int*)&pPolyPts[k].x,  /* Filling 4 ints. */
						gView);
					
					if(BltArea && (clipResult==0 || clipResult==2))
					{
						if(BltArea[0].x > pPolyPts[k + 1].x)
							BltArea[0].x = pPolyPts[k + 1].x;
						else
							if(BltArea[1].x < pPolyPts[k + 1].x)
								BltArea[1].x = pPolyPts[k + 1].x;
						if(BltArea[0].y > pPolyPts[k + 1].y)
							BltArea[0].y = pPolyPts[k + 1].y;
						else
							if(BltArea[1].y < pPolyPts[k + 1].y)
								BltArea[1].y = pPolyPts[k + 1].y;
					} // end of if(BltArea && ...
					
					++k;
					// each of the cases clipresult==1 and clipresult==2 sets chainidx to 0, which keeps the next code block
					// from executing, so commenting out the continues is valid
					//
					if(clipResult == 1) 
					{
						if(k > 1) // Off the screen.
							pDrawDevice->Polyline(pPolyPts, k);
						// Reset the beg poly point counter.
						k = 0;
					}
					else 
						if(clipResult==2) 
						{  // Chopped it
							pDrawDevice->Polyline(pPolyPts, k + 1);
							// Reset the beg poly point counter.
							k = 0;
						}
						
				} // end of loop over points in poly list
				
				if(k) 
					pDrawDevice->Polyline(pPolyPts, k + 1);
				
			}
		}
		
	/*
		if(bUsingGDIPath && (!pCurDO->next || pCurDO->GetSourceEntity() != pCurDO->next->GetSourceEntity() ||
				(!(pCurDO->next->type & DISP_OBJ_PTS_GDI_FILLPATH) &&
				!(pCurDO->next->type & DISP_OBJ_PTS_GDI_TRUETYPE))))*/
		//gaowen NO2003-11-17-11:01[	
			if(bUsingGDIPath && (!pCurDO->next || pCurDO->GetSourceEntity() != pCurDO->next->GetSourceEntity() ||
				(!(pCurDO->next->type & DISP_OBJ_PTS_GDI_FILLPATH) &&
				!(pCurDO->next->type & DISP_OBJ_PTS_GDI_TRUETYPE)))||
				(pCurDO->next&&pCurDO->color!=pCurDO->next->color)
				)
		//gaowen NO2003-11-17-11:01]
		{
			// Now let's fill the GDI path.
			pDC->EndPath();
			
			if(IsPrinting())
				SetDcFillColorMem(undraw ? undrawcol : iFillColor, hl, rop, pDrawDevice);
			else
			{
				HBRUSH hBrush;
				if(hl)
				{
					resbuf	rb;
					sds_getvar("BKGCOLOR", &rb);
					int		BGColor = SDS_RGBFromACADColor(rb.resval.rint);
					hBrush = ::CreateHatchBrush(HS_DIAGCROSS, BGColor);
				}
				else
					hBrush = ::CreateSolidBrush(::SDS_BrushColorFromACADColor(undraw ? undrawcol : iFillColor));
				
				::DeleteObject(::SelectObject(pDC->m_hDC, hBrush));
			}
			
			if(hl)
			{
				int	oldBackMode = pDC->SetBkMode(TRANSPARENT);
				pDC->StrokeAndFillPath();
				pDC->SetBkMode(oldBackMode);
			}
			else
				pDC->StrokeAndFillPath();
			
			bUsingGDIPath = false;
		}

		if(bNeedToDelete)
			delete[] pPolyPts;
	} // end of loop over items (DispObjs) to draw
}
#endif

void CEntityRenderer::outputPolygon(int ndims, 
									int face, 
									struct gr_displayobject *tdo1, 
									CDrawDevice *pDrawDevice,
									struct gr_view *gView, 
									POINT BltArea[2], 
									int *FstPt,
									int undraw,
									int undrawcol,
									int rop,
									int hl,
									int width, 
									bool onlyFill)
{
	int fi1,fi2,fi4;
	
	fi2=(tdo1->npts+face)*ndims;
	
	const int BufferSize = 100;
	bool NeedToDelete;
	
	POINT * pPolyPts; 
	POINT PointBuffer[BufferSize];
	
	if (fi2/ndims > BufferSize)
	{
		pPolyPts = new POINT[fi2/ndims];
		NeedToDelete = true;
	}
	else
	{
		pPolyPts = PointBuffer;
		NeedToDelete = false;
	}
	
	for (fi1=0; fi1<fi2; fi1+=ndims) 
	{
		if (face && fi1>=fi2-ndims) 
		{
			gr_rp2pix(gView,tdo1->chain[0],tdo1->chain[1],(int *)&pPolyPts[fi1/ndims].x,(int *)&pPolyPts[fi1/ndims].y);
		} 
		else 
		{
			gr_rp2pix(gView,tdo1->chain[fi1],tdo1->chain[fi1+1],(int *)&pPolyPts[fi1/ndims].x,(int *)&pPolyPts[fi1/ndims].y);
		}
	} // end of for(fi1=0...
	
	// Expand the Bitblt area if needed.
	if(BltArea) 
	{		
		for (fi1=0; fi1<fi2; fi1+=ndims) 
		{
			fi4=fi1/ndims;
			if(*FstPt) 
			{
				BltArea[0].x=pPolyPts[fi4].x;  
				BltArea[0].y=pPolyPts[fi4].y;
				BltArea[1].x=pPolyPts[fi4].x;  
				BltArea[1].y=pPolyPts[fi4].y;
				*FstPt=0;
			} 
			else 
			{
				if(BltArea[0].x>pPolyPts[fi4].x)
					BltArea[0].x=pPolyPts[fi4].x;
				if(BltArea[0].y>pPolyPts[fi4].y)
					BltArea[0].y=pPolyPts[fi4].y;
				if(BltArea[1].x<pPolyPts[fi4].x)
					BltArea[1].x=pPolyPts[fi4].x;
				if(BltArea[1].y<pPolyPts[fi4].y)
					BltArea[1].y=pPolyPts[fi4].y;
			}
		}
	} // end of if (BltArea)
	SetDcFillColorMem(undraw ? undrawcol : tdo1->color,hl,rop,pDrawDevice);
	SetDcColorMem(undraw ? undrawcol : tdo1->color,width,hl,rop,pDrawDevice);
	pDrawDevice->Polygon(pPolyPts,tdo1->npts+face, onlyFill);
	
	if (NeedToDelete)
	{
		delete [] pPolyPts;
	}
} 

⌨️ 快捷键说明

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