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

📄 umlentitylabel.cpp

📁 uml编辑器很牛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ==========================================================================
	Class :			CUMLEntityLabel

	Author :		Johan Rosengren, Abstrakt Mekanik AB

	Date :			2004-06-21

	Purpose :		"CUMLEntityLabel" is derived from "CUMLEntity" and 
					represents an UML label.

	Description :	The "CUMLEntity"-derived objects are the drawing objects 
					of the UML-editor. The label is a transparent text label 
					that can't be linked to, with setable font name, font 
					size and font attributes.

	Usage :			When loading, create with "CUMLControlFactory::CreateFromString". 
					Otherwise, create instances in the application view or 
					dialog and add them to the editor with "StartDrawingObject". 
					The editor takes responsibility for the object.

   ========================================================================*/
#include "stdafx.h"
#include "UMLEntityLabel.h"
#include "DiagramEditor/Tokenizer.h"
#include "UMLEntityContainer.h"
#include "StringHelpers.h"

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


CUMLEntityLabel::CUMLEntityLabel()
/* ============================================================
	Function :		CUMLEntityLabel::CUMLEntityLabel
	Description :	Constructor
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Create either through "CUMLControlFactory" or
					by calling "new" and adding the pointer to the
					editor via "StartDrawingObject"

   ============================================================*/
{

	SetDefaultSize( CSize( 48, 14 ) );

	CString title;
	title.LoadString( IDS_UML_LABEL );
	SetTitle( title );

	SetType( _T( "uml_label" ) );
	SetConstraints( GetDefaultSize(), CSize( -1, -1 ) );

	SetBkColor( RGB( 0,0,0 ) );

	SetPropertyDialog( &m_dlg, CUMLLabelPropertyDialog::IDD );

	SetPointsize( 12 );
	SetBold( FALSE );
	SetItalic( FALSE );
	SetUnderline( FALSE );

}

CUMLEntityLabel::~CUMLEntityLabel()
/* ============================================================

	Function :		CUMLEntityLabel::~CUMLEntityLabel
	Description :	Destructor
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Note that objects will normally be deleted by
					the container.

   ============================================================*/
{

	if( m_dlg.m_hWnd )
		m_dlg.DestroyWindow();

}

CDiagramEntity* CUMLEntityLabel::Clone()
/* ============================================================
	Function :		CUMLEntityLabel::Clone
	Description :	Creates a new object of this type, copies 
					the data from this object, and returns the 
					new one.
	Access :		Public

	Return :		CDiagramEntity*	-	New object
	Parameters :	none

	Usage :			Call to clone this object

   ============================================================*/
{

	CUMLEntityLabel* obj = new CUMLEntityLabel;
	obj->Copy( this );
	return obj;

}

BOOL CUMLEntityLabel::FromString( const CString& str )
/* ============================================================
	Function :		CUMLEntityLabel::FromString
	Description :	Sets the data for this object from "str"
	Access :		Public

	Return :		BOOL				-	"TRUE" if "str" was a 
											valid representation of 
											this type.
	Parameters :	const CString& str	-	String representation
					
	Usage :			Use when loading from file.

   ============================================================*/
{

	BOOL result = FALSE;
	CString data( str );

	if( LoadFromString( data ) )
	{

		CTokenizer tok( data );
		CString fontName;
		int		bkColor;

		CString package;
		int		pointsize;
		BOOL	bold;
		BOOL	italic;
		BOOL	underline;

		int count = 0;

		tok.GetAt( count++, package );
		tok.GetAt( count++, fontName );
		tok.GetAt( count++, bkColor );
		tok.GetAt( count++, pointsize );
		tok.GetAt( count++, bold );
		tok.GetAt( count++, italic );
		tok.GetAt( count++, underline );

		UnmakeSaveString( package );

		SetPackage( package );
		SetFont( fontName );
		SetBkColor( static_cast< COLORREF >( bkColor ) );
		SetPointsize( pointsize );
		SetBold( bold );
		SetItalic( italic );
		SetUnderline( underline );

		CalcRestraints();
		result = TRUE;
	}

	return result;

}

CDiagramEntity* CUMLEntityLabel::CreateFromString( const CString& str )
/* ============================================================
	Function :		CUMLEntityLabel::CreateFromString
	Description :	Static factory function that creates and 
					returns an instance of this class if "str" 
					is a valid representation.
	Access :		Public

	Return :		CDiagramEntity*		-	The object, or "NULL" 
											if "str" is not a 
											representation of 
											this type.
	Parameters :	const CString& str	-	The string to create 
											from.
					
	Usage :			Can be used as a factory for text file loads. 

   ============================================================*/
{

	CUMLEntityLabel* obj = new CUMLEntityLabel;
	if(!obj->FromString( str ) )
	{
		delete obj;
		obj = NULL;
	}

	return obj;

}

void CUMLEntityLabel::Draw( CDC* dc, CRect rect )
/* ============================================================
	Function :		CUMLEntityLabel::Draw
	Description :	Draws this object.
	Access :		Public

	Return :		void
	Parameters :	CDC* dc		-	"CDC" to draw to
					CRect rect	-	Rectangle to draw to
					
	Usage :			Call to draw the object.

   ============================================================*/
{

	if( GetTitle().GetLength() )
	{
	
		CFont font;
		int weight = FW_NORMAL;
		if( GetBold() )
			weight = FW_BOLD;

		font.CreateFont( -round( static_cast< double >( GetPointsize() ) * GetZoom() ), 
			0,0,0,
			weight,
			( BYTE ) GetItalic(),
			( BYTE ) GetUnderline(),0,0,0,0,0,0, 
			GetFont() );

		CFont* oldfont = dc->SelectObject( &font );
		dc->SetBkMode( TRANSPARENT );
		dc->DrawText( GetTitle(), rect, DT_WORDBREAK | DT_NOPREFIX);
		dc->SelectObject( oldfont );

	}

}

void CUMLEntityLabel::SetTitle( CString title )
/* ============================================================
	Function :		CUMLEntityLabel::SetTitle
	Description :	Sets the title of the object. This is the 
					visible label contents.
	Access :		Public

	Return :		void
	Parameters :	CString title	-	New title
					
	Usage :			This function is overridden to recalculate 
					the object rectangle restraints.

   ============================================================*/
{

	CUMLEntity::SetTitle( title );
	CalcRestraints();

}

CString CUMLEntityLabel::GetString() const
/* ============================================================
	Function :		CUMLEntityLabel::GetString
	Description :	Gets a string representation of this object.
	Access :		Public

	Return :		CString	-	Resulting string
	Parameters :	none

	Usage :			Call to get a string representation for
					saving.

   ============================================================*/
{

	CString str;
	CString package = GetPackage();
	MakeSaveString( package );

	str.Format( _T( ",%s,%s,%i,%i,%i,%i,%i;" ), 
			package,
			GetFont(),
			static_cast< int >( GetBkColor() ),
			GetPointsize(),
			GetBold(),
			GetItalic(),
			GetUnderline()
		);

	str = GetDefaultGetString() + str;
	return str;

}

void CUMLEntityLabel::SetRect( CRect rect )
/* ============================================================
	Function :		CUMLEntityLabel::SetRect
	Description :	Sets the object rectangle
	Access :		Public

	Return :		void
	Parameters :	CRect rect	-	New rectangle
					
	Usage :			This function is overridden to recalculate 
					rectangle restraints.

   ============================================================*/
{

	CDiagramEntity::SetRect( rect );
	CalcRestraints();

}

void CUMLEntityLabel::SetRect( double left, double top, double right, double bottom )
/* ============================================================
	Function :		CUMLEntityLabel::SetRect

⌨️ 快捷键说明

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