📄 umlentitycontainer.cpp
字号:
if( GetUndoStackSize() > 0 && GetUndo()->GetSize() == GetUndoStackSize() )
{
delete GetUndo()->GetAt( 0 );
GetUndo()->RemoveAt( 0 );
}
CUMLUndoItem* undo = new CUMLUndoItem;
while( !undo && GetUndo()->GetSize() )
{
// We seem - however unlikely -
// to be out of memory.
// Remove first element in
// undo-stack and try again
delete GetUndo()->GetAt( 0 );
GetUndo()->RemoveAt( 0 );
undo = new CUMLUndoItem;
}
if( undo )
{
// Save current virtual size
undo->pt = GetVirtualSize();
undo->col = GetColor();
undo->package = GetPackage();
// Save all objects
int count = GetData()->GetSize();
for( int t = 0 ; t < count ; t++ )
( undo->arr ).Add( GetAt( t )->Clone() );
FixLinks( &( undo->arr ) );
// Add to undo stack
GetUndo()->Add( undo );
}
}
void CUMLEntityContainer::FixLinks( CObArray *arr )
/* ============================================================
Function : CUMLEntityContainer::FixLinks
Description : Fixes links between the objects in "arr"
Access : Public
Return : void
Parameters : CObArray *arr - Container to fix
Usage : Call to maintain integrity for links even
when copied. The links are attached by
name, and objects get a new name when
copied, therefore we must restore links in
the container.
============================================================*/
{
int count = arr->GetSize();
for( int t = 0 ; t < count ; t++ )
{
CUMLEntity* obj = static_cast< CUMLEntity* >( arr->GetAt( t ) );
if( obj->GetOldId().GetLength() )
{
for( int i = 0 ; i < count ; i++ )
{
if( t != i )
{
CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( arr->GetAt( i ) );
if( line )
{
if( line->GetLink( LINK_START ) == obj->GetOldId() )
line->SetLink( LINK_START, obj->GetName() );
if( line->GetLink( LINK_END ) == obj->GetOldId() )
line->SetLink( LINK_END, obj->GetName() );
}
}
}
obj->SetOldId( _T( "" ) );
}
}
}
CSize CUMLEntityContainer::CalcMinimumRestraints( const CString& name )
/* ============================================================
Function : CUMLEntityContainer::CalcMinimumRestraints
Description : Calculates the minimum size for the object
with the name "name" as regards to
attached links.
Access : Public
Return : CSize - Minimum size
Parameters : const CString& name - Name of object to test
Usage : The objects themselves don't know about the
attached links. Therefore, they have to ask
the container for the minimum size of the
object as far as attached links goes.
============================================================*/
{
CSize result( -1, -1 );
BOOL horz = FALSE;
BOOL vert = FALSE;
if( name.GetLength() )
{
int max = GetSize();
for( int t = 0 ; t < max ; t++ )
{
CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
if( line )
{
int offset = -1;
if( line->GetLink( LINK_START ) == name )
offset = line->GetOffset( LINK_START );
if( line->GetLink( LINK_END ) == name )
offset = line->GetOffset( LINK_END );
if( offset != -1 )
{
if( line->IsHorizontal() )
{
if( result.cx == -1 )
result.cx = offset;
else if( offset > result.cx )
result.cx = offset;
horz = TRUE;
}
else
{
if( result.cy == -1 )
result.cy = offset;
else if( offset > result.cy )
result.cy = offset;
vert = TRUE;
}
if( horz && vert )
return result;
}
}
}
}
return result;
}
void CUMLEntityContainer::SetProjectName( const CString& value )
/* ============================================================
Function : CUMLEntityContainer::SetProjectName
Description : Sets the project name
Access : Public
Return : void
Parameters : const CString& value - New name
Usage : Call to set the project name. Used when
exporting.
============================================================*/
{
m_project = value;
}
CString CUMLEntityContainer::GetProjectName() const
/* ============================================================
Function : CUMLEntityContainer::GetProjectName
Description : Gets the project name
Access : Public
Return : CString - Project name
Parameters : none
Usage : Call to get the project name. Used when
exporting.
============================================================*/
{
return m_project;
}
void CUMLEntityContainer::SetProjectLocation( const CString& value )
/* ============================================================
Function : CUMLEntityContainer::SetProjectLocation
Description : Sets the location (directories) of the
project.
Access : Public
Return : void
Parameters : const CString& value - New location
Usage : Call to set the direction of the project.
This is an informational function that is
used when exporting.
============================================================*/
{
m_location = value;
}
CString CUMLEntityContainer::GetProjectLocation() const
/* ============================================================
Function : CUMLEntityContainer::GetProjectLocation
Description : Get the project directory
Access : Public
Return : CString - Result
Parameters : none
Usage : Call to get the project directory.
This is an informational function that is
used when exporting.
============================================================*/
{
return m_location;
}
void CUMLEntityContainer::Export( CStringArray& stra, UINT format ) const
/* ============================================================
Function : CDiagramEntityContainer::Export
Description : Exports all objects to the format "format".
Access : Public
Return : void
Parameters : CStringArray& stra - "CStingArray" that
will be filled with
the exported data on
return.
UINT format - Format to save 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
============================================================*/
{
switch( format )
{
case EXPORT_HTML:
ExportHTML( stra );
break;
case EXPORT_CPP:
ExportCPP();
break;
case EXPORT_H:
ExportH();
break;
}
}
void CUMLEntityContainer::ExportHTML( CStringArray& stra ) const
/* ============================================================
Function : CUMLEntityContainer::ExportHTML
Description : Exports the contents of the data array to
HTML-format into "stra"
Access : Private
Return : void
Parameters : CStringArray& stra - Array to fill with HTML
Usage : Call to fill "stra" with HTML generated from
the current container data.
============================================================*/
{
// Creating headers
CStringArray ext;
CTextFile file;
CString filename;
filename = GetApplicationDirectory() + _T( "html_header.txt" );
if( file.ReadTextFile( filename, ext ) )
{
stra.Append( ext );
}
else
{
CString title;
title.Format( _T( "<title>%s</title>" ), GetProjectName() );
stra.Add( _T( "<html>" ) );
stra.Add( _T( "<head>" ) );
stra.Add( title );
stra.Add( _T( "<meta name=\"generator\" content=\"UMLEditorDemo\">" ) );
stra.Add( _T( "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">" ) );
stra.Add( _T( "</head>" ) );
stra.Add( _T( "<body>" ) );
}
CString div;
div.Format( _T( "<div style='position:relative;height:%i;'>" ), GetTotalHeight() );
stra.Add( div );
// Creating the individual objects.
// Create lines first, as they might
// be to tall vertically (there is a
// minimum height of the divs)
int max = GetSize();
for( int t = 0 ; t < max ; t++ )
{
CUMLLineSegment* obj = dynamic_cast< CUMLLineSegment* >( GetObjectAt( t ) );
if( obj )
if( GetPackage() == obj->GetPackage() )
stra.Add( obj->Export( EXPORT_HTML ) );
}
for( t = 0 ; t < max ; t++ )
{
CUMLEntity* obj = GetObjectAt( t );
CUMLLineSegment* seg = dynamic_cast< CUMLLineSegment* >( GetObjectAt( t ) );
if( !seg )
if( GetPackage() == obj->GetPackage() )
stra.Add( obj->Export( EXPORT_HTML ) );
}
// Adding jogs
// For each line we find in the data, we check against
// every other line onwards. If they cross, we add a
// div with a jog-picture.
CString horzTemplate( _T( "<div style='position:absolute;left:%i;top:%i;width:16;height:8;background-image:url(\"images/lrjog.gif\");background-repeat:no-repeat;);'> </div>" ) );
CString vertTemplate( _T( "<div style='position:absolute;left:%i;top:%i;width:8;height:16;background-image:url(\"images/udjog.gif\");background-repeat:no-repeat;);'> </div>" ) );
CString result;
max = GetSize();
for( int i = 0 ; i < max ; i++ )
{
CUMLLineSegment* obj = dynamic_cast< CUMLLineSegment* >( GetObjectAt( i ) );
if( obj && GetPackage() == obj->GetPackage() )
{
BOOL horz = obj->IsHorizontal();
for( int t = i + 1 ; t < max ; t++ )
{
CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( GetObjectAt( t ) );
if( line )
{
if( horz && !line->IsHorizontal() )
{
if( min( obj->GetLeft(), obj->GetRight() ) < line->GetLeft() &&
max( obj->GetLeft(), obj->GetRight() ) > line->GetLeft() &&
min( line->GetTop(), line->GetBottom() ) < obj->GetTop() &&
max( line->GetTop(), line->GetBottom() ) > obj->GetTop() )
{
CRect rect( round( line->GetLeft() - 7 ), round( obj->GetTop() - 7 ), round( line->GetLeft() + 7 ), round( obj->GetTop() + 4 ) );
result.Format( vertTemplate, rect.left, rect.top );
stra.Add( result );
}
}
else if( !horz && ( line->IsHorizontal() ) )
{
if( min( line->GetLeft(), line->GetRight() ) < obj->GetLeft() &&
max( line->GetLeft(), line->GetRight() ) > obj->GetLeft() &&
min( obj->GetTop(), obj->GetBottom() ) < line->GetTop() &&
max( obj->GetTop(), obj->GetBottom() ) > line->GetTop() )
{
CRect rect( round( obj->GetLeft() - 7 ), round( line->GetTop() - 7 ), round( obj->GetLeft() + 4 ), round( line->GetTop() + 7 ) );
result.Format( horzTemplate, rect.left, rect.top );
stra.Add( result );
}
}
}
}
}
}
stra.Add( _T( "</div>" ) );
// Creating footer
filename = GetApplicationDirectory() + _T( "html_footer.txt" );
if( file.ReadTextFile( filename, ext ) )
{
stra.Append( ext );
}
else
{
stra.Add( _T( "</body>" ) );
stra.Add( _T( "</html>" ) );
}
}
void CUMLEntityContainer::ExportCPP() const
/* ============================================================
Function : CUMLEntityContainer::ExportCPP
Description : Export the contents of the container to
cpp-files.
Access : Private
Return : void
Parameters : none
Usage : Call to generate cpp-files from the data in
the container.
============================================================*/
{
CUMLEntityContainer* const local = const_cast<CUMLEntityContainer* const>(this);
CString current = GetPackage();
local->SetPackage( _T( "all" ) );
CString str;
int max = GetSize();
CString location = GetProjectLocation() + _T( "\\" ) + GetProjectName();
CDiskObject cdo;
local->SetErrorMessage( _T( "" ) );
if( cdo.CreateDirectory( location ) )
{
for( int t = 0 ; t < max ; t++ )
{
CUMLEntityClass* obj = dynamic_cast< CUMLEntityClass* >( GetAt( t ) );
if( obj )
{
CString title = obj->GetTitle();
if( title.GetLength() )
{
CStringArray baseClassArray;
CStringArray baseClassAccessArray;
GetBaseClassArray( obj, baseClassArray, baseClassAccessArray );
CStringArray baseClassFilenameArray;
baseClassFilenameArray.Append( baseClassArray );
if( GetStripLeadingClassCharacter() )
{
title = title.Right( title.GetLength() - 1 );
int size = baseClassFilenameArray.GetSize();
for( int i = 0 ; i < size ; i++ )
{
CString baseClassFilename = baseClassFilenameArray[ i ].Right( baseClassFilenameArray[ i ].GetLength() - 1 );
baseClassFilenameArray[ i ] = baseClassFilename;
}
}
obj->SetBaseClassArray( baseClassArray, baseClassAccessArray );
CString path = GetObjectPath( obj );
path.Replace( _TCHAR( ':' ), _TCHAR( '\\' ) );
if( path.GetLength() )
{
if( path[0] != _TCHAR( '\\' ) )
path = _T( "\\" ) + path;
}
CString filename = location + path + _T( "\\" ) + title;
obj->SetFilename( title );
filename += _T( ".cpp" );
obj->SetBaseClassFilenameArray( baseClassFilenameArray );
str = obj->Export( EXPORT_CPP );
if( str.GetLength() )
{
if( cdo.CreateFile( filename ) )
{
CTextFile file( _T( "" ), _T( "\n" ) );;
if( !file.WriteTextFile( filename, str ) )
local->SetErrorMessage( file.GetErrorMessage() );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -