📄 umlentityclasstemplate.cpp
字号:
/* ==========================================================================
Class : CUMLEntityClassTemplate
Author : Johan Rosengren, Abstrakt Mekanik AB
Date : 2004-07-12
Purpose : "CUMLEntityClassTemplate" is a specialization of
"CUMLEntityClass" and represents a template class.
Description : The class derives from "CUMLEntityClass" and adds
functionality to handle the template parameter as
well as specialized export-functionality.
Usage : Use as a "CUMLEntityClass".
========================================================================*/
#include "stdafx.h"
#include "UMLEntityClassTemplate.h"
#include "UMLEntityContainer.h"
#include "TextFile/TextFile.h"
CUMLEntityClassTemplate::CUMLEntityClassTemplate()
/* ============================================================
Function : CUMLEntityClassTemplate::CUMLEntityClassTemplate
Description : Constructor
Access : Public
Return : void
Parameters : none
Usage :
============================================================*/
{
SetType( _T( "uml_template" ) );
CString title;
title.LoadString( IDS_UML_TEMPLATE );
SetTitle( title );
SetPropertyDialog( &m_dlg, CUMLTemplatePropertyDialog::IDD );
}
CUMLEntityClassTemplate::~CUMLEntityClassTemplate()
/* ============================================================
Function : CUMLEntityClassTemplate::~CUMLEntityClassTemplate
Description : Destructor
Access : Public
Return : void
Parameters : none
Usage :
============================================================*/
{
if( m_dlg.m_hWnd )
m_dlg.DestroyWindow();
ClearAttributes();
ClearOperations();
ClearProperties();
}
CDiagramEntity* CUMLEntityClassTemplate::Clone()
/* ============================================================
Function : CUMLEntityClassTemplate::Clone
Description : Clone this object to a new object.
Access : Public
Return : CDiagramEntity* - The new object.
Parameters : none
Usage : Call to create a clone of the object. The
caller will have to delete the object.
============================================================*/
{
CUMLEntityClassTemplate* obj = new CUMLEntityClassTemplate;
obj->Copy( this );
return obj;
}
BOOL CUMLEntityClassTemplate::FromString( const CString& str )
/* ============================================================
Function : CUMLEntityClassTemplate::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.
============================================================*/
{
ClearAttributes();
ClearOperations();
BOOL result = FALSE;
CString data( str );
if( LoadFromString( data ) )
{
CTokenizer tok( data );
CString package;
CString fontName;
int bkColor;
CString stereotype;
CString propertylist;
int displayOptions;
CString parameterType;
int attributes;
int operations;
int count = 0;
tok.GetAt( count++, package );
tok.GetAt( count++, fontName );
tok.GetAt( count++, bkColor );
tok.GetAt( count++, stereotype );
tok.GetAt( count++, propertylist );
tok.GetAt( count++, displayOptions );
tok.GetAt( count++, parameterType );
tok.GetAt( count++, attributes);
tok.GetAt( count++, operations);
UnmakeSaveString( package );
UnmakeSaveString( stereotype );
UnmakeSaveString( propertylist );
UnmakeSaveString( parameterType );
SetPackage( package );
SetStereotype( stereotype );
SetFont( fontName );
SetBkColor( static_cast< COLORREF >( bkColor ) );
SetDisplayOptions( displayOptions );
SetParameterType( parameterType );
GetProperties()->FromString( propertylist );
for( int t = 0 ; t < attributes ; t++ )
{
CString str;
tok.GetAt( count + t, str );
CAttribute* at = CAttribute::FromString( str );
if( at )
AddAttribute( at );
}
count = count + t;
for( t = 0 ; t < operations; t++ )
{
CString str;
tok.GetAt( count + t, str );
COperation* op = COperation::FromString( str );
if( op )
AddOperation( op );
}
CalcRestraints();
result = TRUE;
}
return result;
}
CDiagramEntity* CUMLEntityClassTemplate::CreateFromString( const CString& str )
/* ============================================================
Function : CUMLEntityClassTemplate::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.
============================================================*/
{
CUMLEntityClassTemplate* obj = new CUMLEntityClassTemplate;
if(!obj->FromString( str ) )
{
delete obj;
obj = NULL;
}
return obj;
}
CString CUMLEntityClassTemplate::GetString() const
/* ============================================================
Function : CUMLEntityClassTemplate::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();
CString stereotype = GetStereotype();
CString propertylist = ( const_cast< CUMLEntityClassTemplate* >( this )->GetProperties() )->GetString();
CString param = GetParameterType();
MakeSaveString( package );
MakeSaveString( stereotype );
MakeSaveString( propertylist );
MakeSaveString( param );
int attributes = GetAttributes();
int operations = GetOperations();
str.Format( _T( ",%s,%s,%i,%s,%s,%i,%s,%i,%i" ),
package,
GetFont(),
static_cast< int >( GetBkColor() ),
stereotype,
propertylist,
GetDisplayOptions(),
param,
attributes,
operations
);
str += ( const_cast< CUMLEntityClassTemplate* >( this )->GetAttributesContainer() )->GetString();
str += ( const_cast< CUMLEntityClassTemplate* >( this )->GetOperationsContainer() )->GetString();
str += _T( ";" );
str = GetDefaultGetString() + str;
return str;
}
void CUMLEntityClassTemplate::Draw( CDC* dc, CRect rect )
/* ============================================================
Function : CUMLEntityClassTemplate::Draw
Description : Draws the template.
Access :
Return : void
Parameters : CDC* dc - "CDC" to draw to
CRect rect - Rectangle to draw to.
Usage : Called by the editor. Draws the underlying
class object and adds the template parameter
type box if the parameter type is not empty.
============================================================*/
{
CUMLEntityClass::Draw( dc, rect );
CString param = GetParameterType();
if( param.GetLength() )
{
dc->SelectStockObject( WHITE_BRUSH );
CPen pen;
pen.CreatePen( PS_DOT, 0, RGB( 0, 0, 0 ) );
dc->SelectObject( &pen );
int cut = round( GetZoom() * static_cast< double >( GetMarkerSize().cx ) );
CFont font;
int height = round( 10.0 * GetZoom() );
font.CreateFont( -height, 0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0, GetFont() );
CFont* oldfont = NULL;
oldfont = dc->SelectObject( &font );
int width = max( rect.Width() / 2, dc->GetTextExtent( param ).cx );
CRect tpl( rect );
tpl.right += cut;
tpl.left = tpl.right - ( width + cut * 2 );
tpl.bottom = rect.top + cut / 2;
tpl.top = tpl.bottom - ( round( GetZoom() * 12 ) + cut );
dc->Rectangle( tpl );
tpl.InflateRect( -1, -1 );
int mode = dc->SetBkMode( TRANSPARENT );
dc->DrawText( param, tpl, DT_NOPREFIX | DT_SINGLELINE | DT_CENTER | DT_VCENTER );
dc->SelectObject( oldfont );
dc->SetBkMode( mode );
dc->SelectStockObject( WHITE_BRUSH );
dc->SelectStockObject( BLACK_PEN );
}
}
void CUMLEntityClassTemplate::Copy( CDiagramEntity* obj )
/* ============================================================
Function : CUMLEntityClassTemplate::Copy
Description : Copies the information in "obj" to this
object.
Access :
Return : void
Parameters : CDiagramEntity* obj - Object to copy from.
Usage : Call to copy the information from "obj" to
this object.
============================================================*/
{
CUMLEntityClass::Copy( obj );
CUMLEntityClassTemplate* uml = dynamic_cast< CUMLEntityClassTemplate* >( obj );
SetParameterType( uml->GetParameterType() );
}
void CUMLEntityClassTemplate::SetParameterType( const CString& parameterType )
/* ============================================================
Function : CUMLEntityClassTemplate::SetParameterType
Description : Sets the template class parameter type.
Access :
Return : void
Parameters : const CString& parameterType - New parameter
type
Usage : Call to set the parameter type of the
template.
============================================================*/
{
m_parameterType = parameterType;
}
CString CUMLEntityClassTemplate::GetParameterType() const
/* ============================================================
Function : CUMLEntityClassTemplate::GetParameterType
Description : Gets the template class parameter type.
Access :
Return : CString - Parameter type, empty if none.
Parameters : none
Usage : Call to get the parameter type of the
template.
============================================================*/
{
return m_parameterType;
}
CString CUMLEntityClassTemplate::Export( UINT format ) const
/* ============================================================
Function : CUMLEntityClassTemplate::Export
Description : Exports this object to the desired format.
Access : Public
Return : CString - Result
Parameters : UINT format - Format to export to
Usage : "format" can be one of the following:
"EXPORT_CPP" Export to cpp-files
"EXPORT_H" Export to header files
"EXPORT_HTML" Export to HTML-files
============================================================*/
{
CString result;
if( format == EXPORT_H )
result = ExportH();
if( format == EXPORT_HTML )
result = ExportHTML();
return result;
}
CString CUMLEntityClassTemplate::ExportHTML() const
/* ============================================================
Function : CUMLEntityClassTemplate::ExportHTML
Description : Exports the class to DHTML
Access : Private
Return : CString - Generated HTML
Parameters : none
Usage : Called by the export-mechanism
============================================================*/
{
CString result;
result = CUMLEntityClass::ExportHTML();
int left;
int top;
int width;
int height;
CString param = GetParameterType();
CRect rect = GetRect();
CClientDC dc( AfxGetMainWnd() );
CFont font;
font.CreateFont( -10, 0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0, GetFont() );
CFont* oldfont = NULL;
oldfont = dc.SelectObject( &font );
width = max( rect.Width() / 2, dc.GetTextExtent( param ).cx );
dc.SelectObject( oldfont );
int cut = GetMarkerSize().cx;
CRect tpl( rect );
tpl.right += cut;
tpl.left = tpl.right - ( width + cut * 2 );
tpl.bottom = rect.top + cut / 2;
tpl.top = tpl.bottom - ( 12 + cut );
left = tpl.left;
top = tpl.top;
width = tpl.Width();
height = tpl.Height();
CString prefix;
prefix.Format( _T( "<div style='position:absolute;overflow:hidden;left:%i;top:%i;width:%i;height:%i;border:1px dashed black;background-color:#ffffff;font-size:10;font-family:Arial;text-align:center;'>%s</div>\n" ),
left,
top,
width,
height,
param );
result += prefix;
return result;
}
CString CUMLEntityClassTemplate::ExportH() const
/* ============================================================
Function : CUMLEntityClassTemplate::ExportH
Description : Exports the class to a c++-header file.
Access : Private
Return : CString - Generated contents of header
file.
Parameters : none
Usage : Called by the export-mechanism
============================================================*/
{
CString result;
result = CUMLEntityClass::ExportH();
result.Replace( _T( "[%parametertype%]" ), GetParameterType() );
return result;
}
CString CUMLEntityClassTemplate::GetHeaderTemplateFilename() const
/* ============================================================
Function : CUMLEntityClassTemplate::GetHeaderTemplateFilename
Description : Returns the name of the prefered header
file template.
Access :
Return : CString - Name of header file template
Parameters : none
Usage : Call to get the name of the prefered header
file template during generation to c++.
============================================================*/
{
return _T( "h_template_template.txt" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -