📄 umlentitycontainer.cpp
字号:
void CUMLEntityContainer::SetDefaultLineStyle( CUMLLineSegment* line )
/* ============================================================
Function : CUMLEntityContainer::SetDefaultLineStyle
Description : Sets the default line style of a newly drawn
line.
Access : Public
Return : void
Parameters : CUMLLineSegment* line - Segment in the line to set style for
Usage : Call after a line is drawn to set the line style.
============================================================*/
{
CUMLEntity* start = GetStartNode( line );
CUMLEntity* end = GetEndNode( line );
BOOL dashed = FALSE;
BOOL owned = FALSE;
if( start )
{
if( start->GetType() == _T( "uml_note" ) )
dashed = TRUE;
}
if( end )
{
if( end->GetType() == _T( "uml_note" ) )
dashed = TRUE;
if( end->GetType() == _T( "uml_package" ) && !dashed )
owned = TRUE;
}
if( dashed )
line->AddLineStyle( STYLE_DASHED );
if( owned )
line->SetLineStyle( STYLE_CIRCLECROSS );
}
CPoint CUMLEntityContainer::GetLinkPosition( CUMLEntity* obj, CUMLLineSegment* line ) const
/* ============================================================
Function : CUMLEntityContainer::GetLinkPosition
Description : Gets the link position for the line "line"
on the object "obj".
Access : Public
Return : CPoint - Link position
Parameters : CUMLEntity* obj - Object to check
CUMLLineSegment* line - Line to check
Usage : Call to get the position of the link between
"line" and "obj".
============================================================*/
{
CPoint result( -1, -1 );
CPoint start;
int linkOffset = 0;
int type = LINK_NONE;
if( line->GetLink( LINK_START ) == obj->GetName() )
{
type = line->GetLinkType( LINK_START );
linkOffset = line->GetOffset( LINK_START );
}
else if( line->GetLink( LINK_END ) == obj->GetName() )
{
type = line->GetLinkType( LINK_END );
linkOffset = line->GetOffset( LINK_END );
}
CRect rect = obj->GetRect();
start = obj->GetLinkPosition( type );
switch( type )
{
case LINK_LEFT:
case LINK_RIGHT:
{
result.x = start.x;
result.y = rect.top + linkOffset;
}
break;
case LINK_TOP:
case LINK_BOTTOM:
{
result.y = start.y;
result.x = rect.left + linkOffset;
}
break;
}
return result;
}
void CUMLEntityContainer::Save( CArchive& ar )
/* ============================================================
Function : CUMLEntityContainer::Save
Description : Saves the container data to file.
Access : Public
Return : void
Parameters : CArchive& ar - Archive to save to
Usage : Call to save the container data.
============================================================*/
{
CString package = GetPackage();
SetPackage( _T( "all" ) );
ar.WriteString( GetString() + _T( "\r\n" ) );
int count = 0;
CDiagramEntity* obj;
while( ( obj = GetAt( count++ ) ) )
ar.WriteString( obj->GetString() + _T( "\r\n" ) );
SetPackage( package );
SetModified( FALSE );
}
void CUMLEntityContainer::Save( CString& filename )
/* ============================================================
Function : CUMLEntityContainer::Save
Description : Saves the container data to file.
Access : Public
Return : void
Parameters : CString& filename - Filename to save to.
Usage : Call to save the container data. If
"filename" is empty, a standard Windows
file dialog will be displayed, and the
variable will contain the selected filename
on return.
============================================================*/
{
CString package = GetPackage();
SetPackage( _T( "all" ) );
CTextFile file;
CStringArray stra;
stra.Add( GetString() + _T( "\r\n" ) );
int count = 0;
CDiagramEntity* obj;
while( ( obj = GetAt( count++ ) ) )
stra.Add( obj->GetString() + _T( "\r\n" ) );
if( file.WriteTextFile( filename, stra ) )
{
SetPackage( package );
SetModified( FALSE );
}
else
AfxMessageBox( file.GetErrorMessage() );
}
void CUMLEntityContainer::SetDisplayOptions( int displayOption )
/* ============================================================
Function : CUMLEntityContainer::SetDisplayOptions
Description : Sets the display options for the objects
in the container.
Access : Public
Return : void
Parameters : int displayOption - Display option(s) to set.
Usage : Call to set new display options.
It can be a combination of the following:
"DISPLAY_ALL" Show everything
"DISPLAY_ONLY_PUBLIC" Show only public attributes and operations.
"DISPLAY_NO_MARKERS" Don't show access markers
"DISPLAY_NO_ATTRIBUTES" Don't show attributes
"DISPLAY_NO_OPERATIONS" Don't show operations.
"DISPLAY_NO_OPERATION_ATTRIBUTE_NAMES" Don't show names for operation parameters
============================================================*/
{
m_displayOptions = displayOption;
CUMLEntity* obj;
int count = 0;
while( ( obj = GetObjectAt( count++ ) ) )
obj->SetDisplayOptions( displayOption );
}
int CUMLEntityContainer::GetDisplayOptions() const
/* ============================================================
Function : CUMLEntityContainer::GetDisplayOptions
Description : Gets the current display option(s)
Access : Public
Return : int - Current display option(s)
Parameters : none
Usage : Call to get the current display options.
It can be a combination of the following:
"DISPLAY_ALL" Show everything
"DISPLAY_ONLY_PUBLIC" Show only public attributes and operations.
"DISPLAY_NO_MARKERS" Don't show access markers
"DISPLAY_NO_ATTRIBUTES" Don't show attributes
"DISPLAY_NO_OPERATIONS" Don't show operations.
"DISPLAY_NO_OPERATION_ATTRIBUTE_NAMES" Don't show names for operation parameters
============================================================*/
{
return m_displayOptions;
}
void CUMLEntityContainer::SetColor( COLORREF color )
/* ============================================================
Function : CUMLEntityContainer::SetColor
Description : Sets the color of the container.
Access : Public
Return : void
Parameters : COLORREF color - New color
Usage : The color is used as background color for
the editor and will be saved/loaded with
the rest of the container data.
============================================================*/
{
m_color = color;
}
COLORREF CUMLEntityContainer::GetColor() const
/* ============================================================
Function : CUMLEntityContainer::GetColor
Description : Gets the container color
Access : Public
Return : COLORREF - Container color
Parameters : none
Usage : The color is used as background color for
the editor and will be saved/loaded with
the rest of the container data.
============================================================*/
{
return m_color;
}
BOOL CUMLEntityContainer::PackageExists( const CString& name, CUMLEntity* filter )
/* ============================================================
Function : CUMLEntityContainer::PackageExists
Description : Checks if a package already exists in the
container.
Access : Public
Return : BOOL - "TRUE" if it exists
Parameters : const CString& name - Name to check
CUMLEntity* filter - Object to skip
Usage : Call to see if a name already exist in the
diagram
============================================================*/
{
BOOL result = FALSE;
CString oldpackage = GetPackage();
SetPackage( _T( "all" ) );
CUMLEntity* obj;
int count = 0;
while( ( obj = GetObjectAt( count++ ) ) )
if( obj->GetTitle() == name && obj != filter )
result = TRUE;
SetPackage( oldpackage );
return result;
}
CString CUMLEntityContainer::GetString() const
/* ============================================================
Function : CDiagramEntityContainer::GetString
Description : Returns a string representation of the
virtual paper size and current paper color.
Access : Public
Return : CString - Resulting string
Parameters : none
Usage : Call to get a string representing the paper
size of the container. The format is
"paper:x,y,color;" where "x" and "y" are the
horisontal and vertical sizes, and "color" is
the paper color.
============================================================*/
{
CString str;
str.Format( _T( "paper:%i,%i,%i;" ), GetVirtualSize().cx, GetVirtualSize().cy, static_cast< int >( GetColor() ) );
return str;
}
BOOL CUMLEntityContainer::FromString( const CString& str )
/* ============================================================
Function : CDiagramEntityContainer::FromString
Description : Sets the virtual paper size from a string.
Access : Public
Return : BOOL - "TRUE" if the string
represented a
paper.
Parameters : const CString& str - The string
representation.
Usage : Call to set the paper size of the container
from a string. The format is "paper:x,y,color;"
where "x" and "y" are the horisontal and
vertical sizes, "color" the background color.
============================================================*/
{
BOOL result = FALSE;
CTokenizer main( str, _T( ":" ) );
CString header;
CString data;
if( main.GetSize() == 2 )
{
main.GetAt( 0, header );
main.GetAt( 1, data );
header.TrimLeft();
header.TrimRight();
data.TrimLeft();
data.TrimRight();
if( header == _T( "paper" ) )
{
CTokenizer tok( data.Left( data.GetLength() - 1 ) );
int size = tok.GetSize();
if( size == 3 )
{
int right;
int bottom;
int color;
tok.GetAt(0, right );
tok.GetAt(1, bottom );
tok.GetAt(2, color );
SetVirtualSize( CSize( right, bottom ) );
SetColor( static_cast< COLORREF >( color ) );
result = TRUE;
}
}
}
return result;
}
BOOL CUMLEntityContainer::LineSelected( CUMLLineSegment* line ) const
/* ============================================================
Function : CUMLEntityContainer::LineSelected
Description : Check if all segments in the line where
"line" is a part is selected.
Access : Public
Return : BOOL - "TRUE" if all of the line is selected
Parameters : CUMLLineSegment* line - Segment to check
Usage : Call to see if a complete line is selected.
============================================================*/
{
BOOL result = FALSE;
if( line->IsSelected() )
{
CUMLEntity* obj = GetStartNode( line );
if( obj && obj->IsSelected() )
{
obj = GetEndNode( line );
if( obj && obj->IsSelected() )
{
result = TRUE;
CUMLLineSegment* seg = GetStartSegment( line );
while( seg )
{
if( !seg->IsSelected() )
result = FALSE;
seg = GetNextSegment( seg );
}
}
}
}
return result;
}
void CUMLEntityContainer::Undo()
/* ============================================================
Function : CUMLEntityContainer::Undo
Description : Undos the last operation
Access : Public
Return : void
Parameters : none
Usage : We fix links and restore the paper size,
color and current package as well.
============================================================*/
{
if( GetUndo()->GetSize() )
{
// We remove all current data
RemoveAll();
// We get the last entry from the undo-stack
// and clone it into the container data
CUMLUndoItem* undo = static_cast< CUMLUndoItem* >( GetUndo()->GetAt( GetUndo()->GetUpperBound() ) );
int count = ( undo->arr ).GetSize();
for( int t = 0 ; t < count ; t++ )
{
CDiagramEntity* obj = static_cast< CDiagramEntity* >( ( undo->arr ).GetAt( t ) );
Add( obj->Clone() );
}
FixLinks( GetData() );
// Set the saved virtual size as well
SetVirtualSize( undo->pt );
SetColor( undo->col );
SetPackage( undo->package );
// We remove the entry from the undo-stack
delete undo;
GetUndo()->RemoveAt( GetUndo()->GetUpperBound() );
}
}
void CUMLEntityContainer::Snapshot()
/* ============================================================
Function : CUMLEntityContainer::Snapshot
Description : Takes a snapshot of the current data state.
Access : Public
Return : void
Parameters : none
Usage : We fix links and get the paper size, color
and package as well.
============================================================*/
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -