umleditor.cpp
来自「uml编辑器很牛」· C++ 代码 · 共 1,677 行 · 第 1/4 页
CPP
1,677 行
============================================================*/
{
int result = 0;
CUMLEntityContainer* objs = GetUMLEntityContainer();
if( objs )
result = objs->GetDisplayOptions();
return result;
}
void CUMLEditor::SetColor( COLORREF col )
/* ============================================================
Function : CUMLEditor::SetColor
Description : Sets the background color of the editor.
Also sets the color of the container - as
it is saved with the container data.
Access : Public
Return : void
Parameters : COLORREF col - Color to set
Usage : Call to set the editor color.
============================================================*/
{
GetUMLEntityContainer()->Snapshot();
SetBackgroundColor( col );
GetUMLEntityContainer()->SetColor( col );
}
CUMLEntityContainer * CUMLEditor::GetUMLEntityContainer() const
/* ============================================================
Function : CUMLEditor::GetUMLEntityContainer
Description : Get the container as a "CUMLEntityContainer".
Access : Private
Return : CUMLEntityContainer * - The container
Parameters : none
Usage : Convenience function.
============================================================*/
{
return static_cast< CUMLEntityContainer * >( GetDiagramEntityContainer() );
}
CString CUMLEditor::BrowseForFolder()
/* ============================================================
Function : CUMLEditor::BrowseForFolder
Description : Displays the Windows folder browsing dialog.
Access : Private
Return : CString - Selected folder.
Parameters : none
Usage : Call to let the user enter a folder (to save
c++-code to).
============================================================*/
{
LPITEMIDLIST pidl;
BROWSEINFO bi;
ZeroMemory( &bi, sizeof( BROWSEINFO ) );
CString str;
CString title;
title.LoadString( IDS_UML_SELECT_FOLDER );
_TCHAR initialPath[ _MAX_PATH ];
lstrcpy( initialPath, m_exportPath );
_TCHAR buffer[ _MAX_PATH ];
ZeroMemory( buffer, _MAX_PATH );
bi.hwndOwner = AfxGetMainWnd()->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = NULL;
bi.lpszTitle = title;
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lpfn = BFFCallbackProc;
bi.lParam = (LPARAM) initialPath;
if( ( pidl = ::SHBrowseForFolder( &bi ) ) != NULL )
{
if( SUCCEEDED( ::SHGetPathFromIDList( pidl, buffer ) ) )
{
m_exportPath = buffer;
str = buffer;
}
LPMALLOC smalloc;
if( SUCCEEDED( SHGetMalloc( &smalloc ) ) )
{
smalloc->Free( pidl );
smalloc->Release();
}
}
return str;
}
void CUMLEditor::ExportEMF()
/* ============================================================
Function : CUMLEditor::ExportEMF
Description : Exports the current diagram to an EMF-file.
Access :
Return : void
Parameters : none
Usage : Call to export the diagram to an EMF file
for - for example - inclusion into a
word-processing document.
============================================================*/
{
CFileDialog dlg( FALSE, _T( "emf") );
if( dlg.DoModal() == IDOK )
{
CClientDC dc( this );
CMetaFileDC metaDC;
CRect rect( 0,0,
GetVirtualSize().cx,
GetVirtualSize().cy );
// Himetric rect
CRect r( 0, 0, 8 * 2540, 11 * 2540 );
metaDC.CreateEnhanced( &dc, dlg.GetPathName(), &r, _T( "UMLEditor Drawing" ) );
metaDC.SetAttribDC( dc.m_hDC );
SetRedraw( FALSE );
COLORREF col = GetBackgroundColor();
SetBackgroundColor( RGB( 255, 255, 255 ) );
Print( &metaDC, rect, 1 );
SetBackgroundColor( col );
SetRedraw( TRUE );
RedrawWindow();
::DeleteEnhMetaFile ( metaDC.CloseEnhanced() );
}
}
void CUMLEditor::ExportCPP( const CString& project, BOOL bHeaderOnly )
/* ============================================================
Function : CUMLEditor::ExportCPP
Description : Exports the current diagram to c++-code.
Access : Private
Return : void
Parameters : const CString& project - Project name
Usage : Call to export the diagram to c++-code.
============================================================*/
{
CUMLEntityContainer* container = GetUMLEntityContainer();
if( container )
{
CString location = BrowseForFolder();
if( location.GetLength() )
{
BOOL modified0 = container->BaseClassClasses();
BOOL modified1 = container->AddInterfacesToClasses();
BOOL modified2 = container->VirtualizeClasses();
CStringArray stra;
container->SetStripLeadingClassCharacter( GetStripLeadingClassCharacter() );
container->SetProjectName( project );
container->SetProjectLocation( location );
if( !bHeaderOnly )
container->Export( stra, EXPORT_CPP );
container->Export( stra, EXPORT_H );
CString err = container->GetErrorMessage();
if( err.GetLength() )
AfxMessageBox( err );
else
{
if( modified0 || modified1 || modified2 )
{
ModifyLinkedPositions();
SetModified( TRUE );
RedrawWindow();
}
AfxMessageBox( IDS_UML_EXPORT_FINISHED );
}
}
}
}
void CUMLEditor::ExportHTML()
/* ============================================================
Function : CUMLEditor::ExportHTML
Description : Export the current diagram to HTML-format.
Access : Private
Return : void
Parameters : const CString& project - Project name
Usage : Call to export the current diagram to HTML.
============================================================*/
{
CUMLEntityContainer* container = GetUMLEntityContainer();
if( container )
{
CStringArray stra;
CString filename;
container->Export( stra, EXPORT_HTML );
CString err = container->GetErrorMessage();
if( err.IsEmpty() )
{
CTextFile file( _T( "html" ), _T( "\n" ) );
if( !file.WriteTextFile( filename, stra ) )
{
if( file.GetErrorMessage().GetLength() )
AfxMessageBox( file.GetErrorMessage() );
}
else
{
CString imagedir( filename );
int find = imagedir.ReverseFind( _TCHAR( '\\' ) );
if( find != -1 )
imagedir = imagedir.Left( find );
imagedir += _T( "\\images" );
CString source( GetApplicationDirectory() + _T( "images" ) );
CDiskObject cdo;
if( !cdo.CopyDirectory( source, imagedir ) )
AfxMessageBox( cdo.GetErrorMessage() );
else
AfxMessageBox( IDS_UML_EXPORT_FINISHED );
}
}
else
AfxMessageBox( err );
}
}
void CUMLEditor::SetStripLeadingClassCharacter( BOOL stripLeadingClassLetter )
/* ============================================================
Function : CUMLEditor::SetStripLeadingClassCharacter
Description : Sets the flag for if the leading character
of a class should be stripped away for the
filename when exporting to cpp.
Access : Public
Return : void
Parameters : BOOL stripLeadingClassLetter - "TRUE" if char
should be stripped
Usage : Call with "TRUE" to generate cpp-filenames
without the first letter.
============================================================*/
{
m_stripLeadingClassLetter = stripLeadingClassLetter;
}
BOOL CUMLEditor::GetStripLeadingClassCharacter() const
/* ============================================================
Function : CUMLEditor::GetStripLeadingClassCharacter
Description : Gets if the leading character should be
removed when generating cpp-filenames.
Access : Public
Return : BOOL - If "TRUE", leading char will be
removed.
Parameters : none
Usage : Call to check if the leading char should be
removed from class filnames when exporting
to c++.
============================================================*/
{
return m_stripLeadingClassLetter;
}
BOOL CUMLEditor::IsLinkSelected() const
/* ============================================================
Function : CUMLEditor::IsLinkSelected
Description : Check if a link is selected.
Access : Public
Return : BOOL - "TRUE" if a link is selected
Parameters : none
Usage : Check to see if a link is selected. Returns
TRUE if only segments of a single link is
selected.
============================================================*/
{
BOOL result = FALSE;
if( GetUMLEntityContainer() )
result = GetUMLEntityContainer()->IsLinkSelected();
return result;
}
void CUMLEditor::FlipLink()
/* ============================================================
Function : CUMLEditor::FlipLink
Description : Flips the direction of the currently
selected link.
Access : Public
Return : void
Parameters : none
Usage : Call to flip the currently selected link.
============================================================*/
{
if( IsLinkSelected() )
GetUMLEntityContainer()->FlipLink();
}
void CUMLEditor::Import()
/* ============================================================
Function : CUMLEditor::Import
Description : Imports data into the selected class object
from a h-file.
Access : Public
Return : void
Parameters : none
Usage : Call to import data from a h-file to a
selected "CUMLEntityClass".
============================================================*/
{
if( GetUMLEntityContainer() )
GetUMLEntityContainer()->Import();
}
void CUMLEditor::Save( CString& filename )
/* ============================================================
Function : CUMLEditor::Save
Description : Saves the data to the file "filename"
Access :
Return : void
Parameters : CString& filename - File to save to
Usage : Call to save data. If "filename" is empty,
a standard Windows file dialog will be
displayed, and the variable will contain
the selected filename on return.
============================================================*/
{
if( GetUMLEntityContainer() )
GetUMLEntityContainer()->Save( filename );
}
void CUMLEditor::Load( CString& filename )
/* ============================================================
Function : CUMLEditor::Load
Description : Loads data from the file "filename"
Access :
Return : void
Parameters : CString& filename - File to load from
Usage : Call to load data. If "filename" is empty,
a standard Windows file dialog will be
displayed, and the variable will contain
the selected filename on return.
============================================================*/
{
if( GetUMLEntityContainer() )
GetUMLEntityContainer()->Load( filename );
}
#pragma warning( default : 4706 )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?