📄 umllinesegment.cpp
字号:
Access : Public
Return : void
Parameters : int type - "LINK_START" or "LINK_END"
int targetType - The type of the link on
the object this line
segment will be attached
to.
Usage : Call to set a new link type for the line
segment start or end. The possible link
types for "targetType" are:
"LINK_TOP" Link at the top
"LINK_BOTTOM" Link at the bottom
"LINK_LEFT" Link at the left
"LINK_RIGHT" Link at the right
============================================================*/
{
switch( type )
{
case LINK_START:
m_startType = targetType;
break;
case LINK_END:
m_endType = targetType;
break;
}
}
int CUMLLineSegment::GetLinkType( int type ) const
/* ============================================================
Function : CUMLLineSegment::GetLinkType
Description : Returns the type of link the start or end
point is attached to.
Access : Public
Return : int - Any of the "LINK_"-constants
Parameters : int type - "LINK_START" or "LINK_END" for
the start or end point
respectively.
Usage : Call to get the type of link the start or
end of the line is attached to.The possible
link types are:
"LINK_TOP" Link at the top
"LINK_BOTTOM" Link at the bottom
"LINK_LEFT" Link at the left
"LINK_RIGHT" Link at the right
"LINK_START" Link at the start point of a line
"LINK_END" Link at the end point of a line.
============================================================*/
{
int result = LINK_NONE;
switch( type )
{
case LINK_START:
result = m_startType;
break;
case LINK_END:
result = m_endType;
break;
}
return result;
}
int CUMLLineSegment::GetOffset( int type) const
/* ============================================================
Function : CUMLLineSegment::GetOffset
Description : Returns the offset for a line end point.
Access : Public
Return : int - Offset to the top or left.
Parameters : int type - Type of point - "LINK_START"
or "LINK_END" for the start
and end respectively.
Usage : As lines can be attached anywhere on an
object side, the offset from the top or left
side is saved for the two end points.
============================================================*/
{
int result;
if( type == LINK_START )
result = m_startOffset;
else
result = m_endOffset;
return result;
}
void CUMLLineSegment::SetOffset( int type, int linkOffset )
/* ============================================================
Function : CUMLLineSegment::SetOffset
Description : Sets the offset to the x- or y-position on
the object this line is linked to.
Access : Public
Return : void
Parameters : int type - "LINK_START" or "LINK_END"
for the appropriate end
point of the line.
int linkOffset - Offset on the side (from
the top or left).
Usage : As lines can be attached anywhere on an
object side, the offset from the top or left
side is saved for the two end points.
============================================================*/
{
if( type == LINK_START )
m_startOffset = linkOffset;
else
m_endOffset = linkOffset;
}
int CUMLLineSegment::GetLinkCode( CPoint point ) const
/* ============================================================
Function : CUMLLineSegment::GetLinkCode
Description : Get the link code for point.
Access : Public
Return : int - Link code
Parameters : CPoint point - The point to check
Usage : Call to hit-test the object. The function
returns "LINK_START" for the start of the
line, "LINK_END" for the end.
============================================================*/
{
int result = LINK_NONE;
CRect rectTest;
rectTest = GetLinkMarkerRect( LINK_START );
if( rectTest.PtInRect( point ) )
result = LINK_START;
rectTest = GetLinkMarkerRect( LINK_END );
if( rectTest.PtInRect( point ) )
result = LINK_END;
return result;
}
CString CUMLLineSegment::Export( UINT format ) const
/* ============================================================
Function : CUMLLineSegment::Export
Description : Exports this object to the desired format.
Access : Public
Return : CString - Result
Parameters : UINT format - Format to export to
Usage : Called from the editor/container to export
objects. "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;
switch( format )
{
case EXPORT_HTML:
result = ExportHTML();
break;
case EXPORT_CPP:
break;
case EXPORT_H:
break;
}
return result;
}
void CUMLLineSegment::Flip()
/* ============================================================
Function : CUMLLineSegment::Flip
Description : Flip the direction of the link
Access : Public
Return : void
Parameters : none
Usage : Called from flip-commands in the editor/
container.
============================================================*/
{
CString tempString;
int tempInt;
tempString = GetLink( LINK_END );
SetLink( LINK_END, GetLink( LINK_START ) );
SetLink( LINK_START, tempString );
tempInt = GetLinkType( LINK_END );
SetLinkType( LINK_END, GetLinkType( LINK_START ) );
SetLinkType( LINK_START, tempInt );
tempInt = GetOffset( LINK_END );
SetOffset( LINK_END, GetOffset( LINK_START ) );
SetOffset( LINK_START, tempInt );
CRect rect = GetRect();
tempInt = rect.right;
rect.right = rect.left;
rect.left = tempInt;
tempInt = rect.bottom;
rect.bottom = rect.top;
rect.top = tempInt;
SetRect( rect );
}
BOOL CUMLLineSegment::IsSingleLineSegment() const
/* ============================================================
Function : CUMLLineSegment::IsSingleLineSegment
Description : Check if the line is a single-segment line
Access : Public
Return : BOOL - "TRUE" if single-segment
Parameters : none
Usage : Call to see if this line consists of more
segments.
============================================================*/
{
BOOL result = FALSE;
if( ( GetLinkType( LINK_START ) & LINK_ALL ) &&
( GetLinkType( LINK_END ) & LINK_ALL ) )
result = TRUE;
return result;
}
void CUMLLineSegment::DrawDirectionArrow( CDC* dc )
/* ============================================================
Function : CUMLLineSegment::DrawDirectionArrow
Description : Draws the single direction arrow to the
screen.
Access : Private
Return : void
Parameters : CDC* dc - "CDC" to draw to
Usage : Called from the "Draw" function
============================================================*/
{
int hgt = GetMarkerSize().cy / 2;
double x2 = GetLeft();
double x1 = GetRight();
double y2 = GetTop();
double y1 = GetBottom();
if( !( GetLinkType( LINK_START ) & LINK_ALL ) &&
( GetLinkType( LINK_END ) & LINK_ALL ) )
{
x2 = GetRight();
x1 = GetLeft();
y2 = GetBottom();
y1 = GetTop();
}
POINT pts[ 3 ];
if( IsHorizontal() )
{
if( x1 < x2 )
{
pts[ 0 ].x = round( ( x2 - hgt * 4 ) * GetZoom() );
pts[ 0 ].y = round( ( y1 - hgt ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y1 * GetZoom() );
pts[ 2 ].x = pts[ 0 ].x;
pts[ 2 ].y = round( ( y1 + hgt ) * GetZoom() );
}
else
{
pts[ 0 ].x = round( ( x2 + hgt * 4 ) * GetZoom() );
pts[ 0 ].y = round( ( y1 - hgt ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y1 * GetZoom() );
pts[ 2 ].x = pts[ 0 ].x;
pts[ 2 ].y = round( ( y1 + hgt ) * GetZoom() );
}
}
else
{
if( y1 < y2 )
{
pts[ 0 ].x = round( ( x2 - hgt ) * GetZoom() );
pts[ 0 ].y = round( ( y2 - hgt * 4 ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y2 * GetZoom() );
pts[ 2 ].x = round( ( x2 + hgt ) * GetZoom() );
pts[ 2 ].y = pts[ 0 ].y;
}
else
{
pts[ 0 ].x = round( ( x2 - hgt ) * GetZoom() );
pts[ 0 ].y = round( ( y2 + hgt * 4 ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y2 * GetZoom() );
pts[ 2 ].x = round( ( x2 + hgt ) * GetZoom() );
pts[ 2 ].y = pts[ 0 ].y;
}
}
dc->SelectStockObject( BLACK_PEN );
dc->SelectStockObject( BLACK_BRUSH );
dc->Polygon( pts, 3 );
}
void CUMLLineSegment::DrawInheritanceArrow( CDC* dc )
/* ============================================================
Function : CUMLLineSegment::DrawInheritanceArrow
Description : Draws the inheritance arrow to the screen
Access : Private
Return : void
Parameters : CDC* dc - "CDC" to draw to
Usage : Called from the "Draw" function.
============================================================*/
{
int hgt = GetMarkerSize().cy / 2;
double x1 = GetLeft();
double x2 = GetRight();
double y1 = GetTop();
double y2 = GetBottom();
if( ( GetLinkType( LINK_START ) & LINK_ALL ) &&
!( GetLinkType( LINK_END ) & LINK_ALL ) )
{
x1 = GetRight();
x2 = GetLeft();
y1 = GetBottom();
y2 = GetTop();
}
POINT pts[ 3 ];
if( IsHorizontal() )
{
if( x1 < x2 )
{
pts[ 0 ].x = round( ( x2 - hgt * 4 ) * GetZoom() );
pts[ 0 ].y = round( ( y1 - hgt ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y1 * GetZoom() );
pts[ 2 ].x = pts[ 0 ].x;
pts[ 2 ].y = round( ( y1 + hgt ) * GetZoom() );
}
else
{
pts[ 0 ].x = round( ( x2 + hgt * 4 ) * GetZoom() );
pts[ 0 ].y = round( ( y1 - hgt ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y1 * GetZoom() );
pts[ 2 ].x = pts[ 0 ].x;
pts[ 2 ].y = round( ( y1 + hgt ) * GetZoom() );
}
}
else
{
if( y1 < y2 )
{
pts[ 0 ].x = round( ( x2 - hgt ) * GetZoom() );
pts[ 0 ].y = round( ( y2 - hgt * 4 ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y2 * GetZoom() );
pts[ 2 ].x = round( ( x2 + hgt ) * GetZoom() );
pts[ 2 ].y = pts[ 0 ].y;
}
else
{
pts[ 0 ].x = round( ( x2 - hgt ) * GetZoom() );
pts[ 0 ].y = round( ( y2 + hgt * 4 ) * GetZoom() );
pts[ 1 ].x = round( x2 * GetZoom() );
pts[ 1 ].y = round( y2 * GetZoom() );
pts[ 2 ].x = round( ( x2 + hgt ) * GetZoom() );
pts[ 2 ].y = pts[ 0 ].y;
}
}
dc->SelectStockObject( BLACK_PEN );
dc->SelectStockObject( WHITE_BRUSH );
dc->Polygon( pts, 3 );
}
CString CUMLLineSegment::ExportHTML() const
/* ============================================================
Function : CUMLLineSegment::ExportHTML
Description : Exports this object to HTML
Access : Private
Return : CString - The HTML result
Parameters : none
Usage : Called from the export-mechanism
============================================================*/
{
CString result;
if( !( GetStyle() & STYLE_INVISIBLE ) )
{
CRect rect = GetRect();
int style = GetStyle();
rect.NormalizeRect();
int width = max( 1, rect.Width() );
int height = max( 1, rect.Height() );
CString linetype ( _T( "solid" ) );
if( style & STYLE_DASHED )
linetype = _T( "dashed" );
CString orientation( _T( "left" ) );
if( IsHorizontal() )
orientation = _T( "top" );
CString line;
line.Format( _T( "border-%s:1px %s black" ), orientation, linetype );
result.Format( _T( "<div style='position:absolute;left:%i;top:%i;width:%i;height:%i;%s;'> </div>" ),
rect.left,rect.top,width,height,line);
if( GetStyle() & STYLE_ARROWHEAD )
result += GetArrowHeadHTML();
if( GetStyle() & STYLE_CIRCLECROSS )
result += GetCircleCrossHTML();
if( GetStyle() & STYLE_FILLED_ARROWHEAD )
result += GetFilledArrowHeadHTML();
if( GetStyle() & STYLE_FILLED_DIAMOND )
result += GetFilledDiamondHTML();
// Label
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -