⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umllinesegment.cpp

📁 uml编辑器很牛
💻 CPP
📖 第 1 页 / 共 5 页
字号:

		int count = 0;

		tok.GetAt( count++, package );
		tok.GetAt( count++, stereotype );
		tok.GetAt( count++, startLink );
		tok.GetAt( count++, endLink );
		tok.GetAt( count++, startLinkType );
		tok.GetAt( count++, endLinkType );
		tok.GetAt( count++, style );
		tok.GetAt( count++, fontName );
		tok.GetAt( count++, bkColor );
		tok.GetAt( count++, startLabel );
		tok.GetAt( count++, endLabel );
		tok.GetAt( count++, startOffset );
		tok.GetAt( count++, endOffset );
		tok.GetAt( count++, secondaryStartLabel );
		tok.GetAt( count++, secondaryEndLabel );

		UnmakeSaveString( startLabel );
		UnmakeSaveString( endLabel );
		UnmakeSaveString( secondaryStartLabel );
		UnmakeSaveString( secondaryEndLabel );
		UnmakeSaveString( package );
		UnmakeSaveString( stereotype );

		SetPackage( package );
		SetStereotype( stereotype );
		SetLink( LINK_START, startLink );
		SetLink( LINK_END, endLink );
		SetLinkType( LINK_START, startLinkType );
		SetLinkType( LINK_END, endLinkType );
		SetStyle( style );
		SetFont( fontName );
		SetBkColor( static_cast< COLORREF >( bkColor ) );
		SetStartLabel( startLabel );
		SetEndLabel( endLabel );
		SetOffset( LINK_START, startOffset );
		SetOffset( LINK_END, endOffset );
		SetSecondaryStartLabel( secondaryStartLabel );
		SetSecondaryEndLabel( secondaryEndLabel );

		result = TRUE;

	}

	return result;

}

CString CUMLLineSegment::GetString() const
/* ============================================================
	Function :		CUMLLineSegment::GetString
	Description :	Get the object as a string for saving.
	Access :		Public

	Return :		CString	-	Object as a string
	Parameters :	none

	Usage :			Called from the save functionality.

   ============================================================*/
{

	CString str;

	CString package = GetPackage();
	CString stereotype = GetStereotype();
	CString startLabel1 = GetStartLabel();
	CString startLabel2 = GetSecondaryStartLabel();
	CString endLabel1 = GetEndLabel();
	CString endLabel2 = GetSecondaryEndLabel();

	MakeSaveString( package );
	MakeSaveString( stereotype );
	MakeSaveString( startLabel1 );
	MakeSaveString( startLabel2 );
	MakeSaveString( endLabel1 );
	MakeSaveString( endLabel2 );

	str.Format( _T( ",%s,%s,%s,%s,%i,%i,%i,%s,%i,%s,%s,%i,%i,%s,%s;" ), 
			package,
			stereotype,
			GetLink( LINK_START ), 
			GetLink( LINK_END ), 
			GetLinkType( LINK_START ), 
			GetLinkType( LINK_END ),
			GetStyle(),
			GetFont(),
			static_cast< int >( GetBkColor() ),
			startLabel1,
			endLabel1,
			GetOffset( LINK_START ),
			GetOffset( LINK_END ),
			startLabel2,
			endLabel2
		);

	str = GetDefaultGetString() + str;
	return str;

}

void CUMLLineSegment::DrawDiamond( CDC* dc, const CRect& rect )
/* ============================================================
	Function :		CUMLLineSegment::DrawDiamond
	Description :	Draws the composition diamond.
	Access :		Private
					
	Return :		void
	Parameters :	CDC* dc				-	The "CDC" to draw to
					const CRect& rect	-	The rect of the diamond
					
	Usage :			Called from "Draw".

   ============================================================*/
{

	dc->SelectStockObject( BLACK_PEN );
	dc->SelectStockObject( BLACK_BRUSH );

	POINT pts[4];
	pts[0].x = rect.left + ( ( rect.right - rect.left ) / 2 );
	pts[0].y = rect.top;
	pts[1].x = rect.right;
	pts[1].y = rect.top + ( ( rect.bottom - rect.top ) / 2 );
	pts[2].x = pts[0].x;
	pts[2].y = rect.bottom;
	pts[3].x = rect.left;
	pts[3].y = pts[1].y;

	dc->Polygon( pts, 4 );

}

CString CUMLLineSegment::GetStartLabel() const
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Gets the start label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Gets the top or left label at the line
					start.

   ============================================================*/
{

	return m_startLabel;

}

CString CUMLLineSegment::GetEndLabel() const
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Gets the end label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Gets the top or left label at the line
					end. 

   ============================================================*/
{

	return m_endLabel;

}

CString CUMLLineSegment::GetSecondaryStartLabel() const
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Gets the secondary start label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Gets the bottom or right label at the line
					start. 

   ============================================================*/
{

	return m_secondaryStartLabel;

}

CString CUMLLineSegment::GetSecondaryEndLabel() const
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Gets the secondary end label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Gets the bottom or right label at the line
					end. 

   ============================================================*/
{

	return m_secondaryEndLabel;

}

void CUMLLineSegment::SetStartLabel( const CString& label )
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Sets the start label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Sets the top or left label at the line
					start. 

   ============================================================*/
{

	m_startLabel = label;

}

void CUMLLineSegment::SetEndLabel( const CString& label )
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Sets the end label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Sets the top or left label at the line
					end. 

   ============================================================*/
{

	m_endLabel = label;

}

void CUMLLineSegment::SetSecondaryStartLabel( const CString& label )
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Sets the secondary start label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Sets the bottom or right label at the line
					start. 

   ============================================================*/
{

	m_secondaryStartLabel = label;

}

void CUMLLineSegment::SetSecondaryEndLabel( const CString& label )
/* ============================================================
	Function :		CUMLLineSegment::SetSecondaryEndLabel
	Description :	Sets the secondary end label.
	Access :		Public
					
	Return :		void
	Parameters :	const CString& label	-	The label
					
	Usage :			Sets the bottom or right label at the line
					end. 

   ============================================================*/
{

	m_secondaryEndLabel = label;

}

BOOL CUMLLineSegment::IsHorizontal() const
/* ============================================================
	Function :		CUMLLineSegment::IsHorizontal
	Description :	Check if the line is horizontal
	Access :		Public
					
	Return :		BOOL	-	"TRUE" if horizontal
	Parameters :	none

	Usage :			Call to see if the segment is horizontal.

   ============================================================*/
{

	return ( GetTop() == GetBottom() );

}

void CUMLLineSegment::SetRect( double left, double top, double right, double bottom )
/* ============================================================
	Function :		CUMLLineSegment::SetRect
	Description :	Sets the object rectangle.
	Access :		Public
					
	Return :		void
	Parameters :	double left		-	Left pos
					double top		-	Top pos
					double right	-	Right pos
					double bottom	-	Bottom pos.
					
	Usage :			Overridden to force the line to be 
					orthogonal.

   ============================================================*/
{

	if( GetLeft() - GetRight() != 0 || GetTop() - GetBottom() != 0 )
	{
		if( IsHorizontal() )
		{
			if( top == GetTop() )
				bottom = top;
			else
				top = bottom;
		}
		else
		{
			if( left == GetLeft() )
				right = left;
			else
				left = right;
		}
	}

	CDiagramEntity::SetRect( left, top, right, bottom );

}

void CUMLLineSegment::Copy( CDiagramEntity* obj )
/* ============================================================
	Function :		CUMLLineSegment::Copy
	Description :	Copies from obj to this
	Access :		Public
					
	Return :		void
	Parameters :	CDiagramEntity* obj	-	Object to copy from
					
	Usage :			Overridden to copy the rest of the attributes.

   ============================================================*/
{

	CUMLEntity::Copy( obj );

	CUMLLineSegment* uml = dynamic_cast< CUMLLineSegment* >( obj );
	if( uml )
	{

		SetStyle( uml->GetStyle() );
		SetStartLabel( uml->GetStartLabel() );
		SetEndLabel( uml->GetEndLabel() );
		SetOffset( LINK_START, uml->GetOffset( LINK_START ) );
		SetOffset( LINK_END, uml->GetOffset( LINK_END ) );
		SetLink( LINK_START, uml->GetLink( LINK_START ) );
		SetLink( LINK_END, uml->GetLink( LINK_END ) );
		SetLinkType( LINK_START, uml->GetLinkType( LINK_START ) );
		SetLinkType( LINK_END, uml->GetLinkType( LINK_END ) );

	}

}

int CUMLLineSegment::GetLineStyle() const
/* ============================================================
	Function :		CUMLLineSegment::GetLineStyle
	Description :	Returns the style for this and all the 
					other segments making up this line.
	Access :		Public
					
	Return :		int		-	The line style.
	Parameters :	none

	Usage :			Call to get the line style. The line style can be ORed from the following:
						"STYLE_NONE" No special style
						"STYLE_ARROWHEAD" Inheritance (empty arrowhead)
						"STYLE_FILLED_ARROWHEAD" Direction (filled arrowhead)
						"STYLE_CIRCLECROSS" Part-of circle (circle with cross)
						"STYLE_FILLED_DIAMOND" Composition (filled diamond)
						"STYLE_DASHED" Dependency (dashed line)
						"STYLE_INVISIBLE" Invisible (to connect objects)


   ============================================================*/
{

	int result = m_style;
	CUMLEntityContainer* objs = GetUMLContainer();
	if( objs )
	{

		CUMLLineSegment* start = objs->GetStartSegment( ( CUMLLineSegment *const ) this );
		CUMLLineSegment* end = objs->GetEndSegment( ( CUMLLineSegment *const ) this );

		result |= start->GetStyle();
		result |= end->GetStyle();

	}

	return result;

}

void CUMLLineSegment::SetLink( int type, const CString& name )
/* ============================================================
	Function :		CUMLLineSegment::SetLink
	Description :	Set that name of the object that is 
					attached to the start or end of this line 
					segment.
	Access :		Public
					
	Return :		void
	Parameters :	int type			-	"LINK_START" or "LINK_END"
					const CString& name	-	Name of object
					
	Usage :			Call to attach an object to this line segment.

   ============================================================*/
{

	switch( type )
	{
		case LINK_START:
			m_start = name;
			break;
		case LINK_END:
			m_end = name;
			break;
	}

}

CString CUMLLineSegment::GetLink( int type ) const
/* ============================================================
	Function :		CUMLLineSegment::GetLink
	Description :	Get the name of the object attached to the 
					start or end of this line segment.
	Access :		Public
					
	Return :		CString		-	Name of object, or empty if 
									none.
	Parameters :	int type	-	"LINK_START" or "LINK_END"
					
	Usage :			Call to get the name of the object attached 
					to either end of the line segment.

   ============================================================*/
{

	CString result;

	switch( type )
	{
		case LINK_START:
			result = m_start;
			break;
		case LINK_END:
			result = m_end;
			break;
	}

	return result;

}

void CUMLLineSegment::SetLinkType( int type, int targetType )
/* ============================================================
	Function :		CUMLLineSegment::SetLinkType
	Description :	Set the link type for the start or end of 
					the line segment.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -