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

📄 umllinesegment.cpp

📁 uml编辑器很牛
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* ============================================================
	Function :		CUMLLineSegment::GetHitCode
	Description :	Returns the hit point constant for point.
	Access :		Public
					
	Return :		int				-	The hit point, 
										"DEHT_NONE" if none.
	Parameters :	CPoint point	-	The point to check
					
	Usage :			Call to see in what part of the object point 
					lies. The hit point can be one of the following:
						"DEHT_NONE" No hit-point
						"DEHT_BODY" Inside object body
						"DEHT_TOPLEFT" Top-left corner
						"DEHT_TOPMIDDLE" Middle top-side
						"DEHT_TOPRIGHT" Top-right corner
						"DEHT_BOTTOMLEFT" Bottom-left corner
						"DEHT_BOTTOMMIDDLE" Middle bottom-side
						"DEHT_BOTTOMRIGHT" Bottom-right corner
						"DEHT_LEFTMIDDLE" Middle left-side
						"DEHT_RIGHTMIDDLE" Middle right-side

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

	int result = DEHT_NONE;

	CRect rect = GetRect();

	hitParams hit;
	hit.hit = FALSE;
	hit.x = point.x;
	hit.y = point.y;

	LineDDA(	static_cast< int >( GetLeft() ), 
				static_cast< int >( GetTop() ), 
				static_cast< int >( GetRight() ), 
				static_cast< int >( GetBottom() ), 
				HitTest, 
				(LPARAM) &hit );

	if( hit.hit )
		result = DEHT_BODY;

	CRect rectTest;

	rectTest = GetSelectionMarkerRect( DEHT_TOPLEFT, rect );
	if( rectTest.PtInRect( point ) )
		result = DEHT_TOPLEFT;

	rectTest = GetSelectionMarkerRect( DEHT_BOTTOMRIGHT, rect );
	if( rectTest.PtInRect( point ) )
		result = DEHT_BOTTOMRIGHT;

	return result;

}

HCURSOR CUMLLineSegment::GetCursor( int hit ) const
/* ============================================================
	Function :		CUMLLineSegment::GetCursor
	Description :	Returns the cursor for the given hit point.
	Access :		Public
					
	Return :		HCURSOR	-	The cursor to show
	Parameters :	int hit	-	The hit point constant ("DEHT_") 
								to get the cursor for.

	Usage :			Call to get the cursor for a specific hit 
					point constant.
					"hit" can be one of the following:
						"DEHT_NONE" No hit-point
						"DEHT_BODY" Inside object body
						"DEHT_TOPLEFT" Top-left corner
						"DEHT_TOPMIDDLE" Middle top-side
						"DEHT_TOPRIGHT" Top-right corner
						"DEHT_BOTTOMLEFT" Bottom-left corner
						"DEHT_BOTTOMMIDDLE" Middle bottom-side
						"DEHT_BOTTOMRIGHT" Bottom-right corner
						"DEHT_LEFTMIDDLE" Middle left-side
						"DEHT_RIGHTMIDDLE" Middle right-side

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

	HCURSOR cursor = NULL;
	switch( hit )
	{
		case DEHT_BODY:
		case DEHT_TOPLEFT:
		case DEHT_BOTTOMRIGHT:
		cursor = LoadCursor( NULL, IDC_SIZEALL );
		break;
	}

	return cursor;

}

void CUMLLineSegment::DrawSelectionMarkers( CDC* dc, CRect rect ) const
/* ============================================================
	Function :		CUMLLineSegment::DrawSelectionMarkers
	Description :	Draws the selection markers for the 
					object.
	Access :		Public
					
	Return :		void
	Parameters :	CDC* dc		-	The "CDC" to draw to
					CRect rect	-	The real object rectangle.
					
	Usage :			"rect" is the true rectangle (zoomed) of the 
					object.

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

	CRect rectSelect;

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

	rectSelect = GetSelectionMarkerRect( DEHT_TOPLEFT, rect );
	dc->Rectangle( rectSelect );

	rectSelect = GetSelectionMarkerRect( DEHT_BOTTOMRIGHT, rect );
	dc->Rectangle( rectSelect );


}

void CUMLLineSegment::SetRect( CRect rect )
/* ============================================================
	Function :		CUMLLineSegment::SetRect
	Description :	Sets the rect of the object.
	Access :		Public
					
	Return :		void
	Parameters :	CRect rect	-	Rectangle to set
					
	Usage :			Overriden to avoid normalization and force 
					the line to be orthogonal.

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

	if( GetLeft() - GetRight() != 0 || GetTop() - GetBottom() != 0 )
	{
		if( IsHorizontal() )
		{
			if( rect.top == static_cast< int >( GetTop() ) )
				rect.bottom = rect.top;
			else
				rect.top = rect.bottom;
		}
		else
		{
			if( rect.left == static_cast< int >( GetLeft() ) )
				rect.right = rect.left;
			else
				rect.left = rect.right;
		}
	}

	SetLeft( rect.left );
	SetTop( rect.top );
	SetRight( rect.right );
	SetBottom( rect.bottom );

}

BOOL CUMLLineSegment::BodyInRect( CRect rect ) const
/* ============================================================
	Function :		CUMLLineSegment::BodyInRect
	Description :	Used to see if any part of the object lies 
					in rect.
	Access :		Public
					
	Return :		BOOL		-	"TRUE" if any part of the 
									object lies inside rect.
	Parameters :	CRect rect	-	The rect to check.
					
	Usage :			Call to see if the object overlaps - for 
					example - a selection rubberband.

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

	BOOL result = FALSE;
	hitParamsRect hit;
	hit.rect = rect;
	hit.hit = FALSE;

	LineDDA(	static_cast< int >( GetLeft() ), 
				static_cast< int >( GetTop() ), 
				static_cast< int >( GetRight() ), 
				static_cast< int >( GetBottom() ), 
				HitTestRect, 
				( LPARAM ) &hit );

	if( hit.hit )
		result = TRUE;

	return result;

}

CPoint CUMLLineSegment::GetLinkPosition( int type ) const
/* ============================================================
	Function :		CUMLLineSegment::GetLinkPosition
	Description :	Returns the position of a link.
	Access :		Public
					
	Return :		CPoint		-	The position of the link,
									-1, -1 if the link is not
									allowed.
	Parameters :	int type	-	The type of the link.
					
	Usage :			The possible link types are:
					"LINK_START" Links are allowed to the start of a line (the top-left corner).
					"LINK_END" Links are allowed to the end of a line (the bottom-right corner).

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

	CPoint point( -1, -1 );
	CRect rect = GetRect();

	switch( type )
	{
		case LINK_START:
			point.x = rect.left;
			point.y = rect.top;
			break;
		case LINK_END:
			point.x = rect.right;
			point.y = rect.bottom;
			break;
	}

	return point;

}

void CUMLLineSegment::SetStyle( int style )
/* ============================================================
	Function :		CUMLLineSegment::SetStyle
	Description :	Sets the style for this object.
	Access :		Public

	Return :		void
	Parameters :	int style	-	New style.
					
	Usage :			"style" can be one of the following:
						"STYLE_NONE" Black line
						"STYLE_ARROWHEAD" White arrowhead
						"STYLE_FILLED_ARROWHEAD" Black arrowhead
						"STYLE_CIRCLECROSS" A circle with a cross
						"STYLE_FILLED_DIAMOND" Black diamond
						"STYLE_DASHED" Dashed line
						"STYLE_INVISIBLE" Invisible line

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

	m_style = style;

}

void CUMLLineSegment::SetLineStyle( int style )
/* ============================================================
	Function :		CUMLLineSegment::SetLineStyle
	Description :	Clears the line style and sets "style" to 
					the complete line.
	Access :		Public
					
	Return :		void
	Parameters :	int style	-	Style to set
					
	Usage :			Call to set a style to the complete line.
					"style" can be one of the following:
						"STYLE_NONE" Black line
						"STYLE_ARROWHEAD" White arrowhead
						"STYLE_FILLED_ARROWHEAD" Black arrowhead
						"STYLE_CIRCLECROSS" A circle with a cross
						"STYLE_FILLED_DIAMOND" Black diamond
						"STYLE_DASHED" Dashed line
						"STYLE_INVISIBLE" Invisible line

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

	CUMLEntityContainer* objs = GetUMLContainer();
	if( objs )
	{

		CUMLLineSegment* start = objs->GetStartSegment( this );
		while( start )
		{
			start->m_style = STYLE_NONE;
			start = objs->GetNextSegment( start );
		}

		AddLineStyle( style );

	}
	else
		m_style = style;

}

void CUMLLineSegment::AddLineStyle( int style )
/* ============================================================
	Function :		CUMLLineSegment::AddLineStyle
	Description :	Adds a style to the line.
	Access :		Public
					
	Return :		void
	Parameters :	int style	-	Style to add.
					
	Usage :			Adds the style to the complete line or the 
					appropriate start or end segment.
					"style" can be one of the following:
						"STYLE_NONE" Black line
						"STYLE_ARROWHEAD" White arrowhead
						"STYLE_FILLED_ARROWHEAD" Black arrowhead
						"STYLE_CIRCLECROSS" A circle with a cross
						"STYLE_FILLED_DIAMOND" Black diamond
						"STYLE_DASHED" Dashed line
						"STYLE_INVISIBLE" Invisible line
   ============================================================*/
{

	CUMLEntityContainer* objs = GetUMLContainer();
	if( objs )
	{

		if( style & STYLE_FILLED_ARROWHEAD )
		{
			CUMLLineSegment* start = objs->GetStartSegment( this );
			start->m_style |= style;
		}

		if( style & STYLE_FILLED_DIAMOND || 
			style & STYLE_ARROWHEAD ||
			style & STYLE_CIRCLECROSS )
		{
			CUMLLineSegment* end = objs->GetEndSegment( this );
			end->m_style |= style;
		}

		if( style & STYLE_DASHED || style & STYLE_INVISIBLE )
		{
			CUMLLineSegment* start = objs->GetStartSegment( this );
			while( start )
			{
				start->m_style |= style;
				start = objs->GetNextSegment( start );
			}
		}
	}
	else
		m_style |= style;

}

void CUMLLineSegment::RemoveLineStyle( int style )
/* ============================================================
	Function :		CUMLLineSegment::RemoveLineStyle
	Description :	Removes a style from this and all other 
					segments of the line.
	Access :		Public
					
	Return :		void
	Parameters :	int style	-	Style to remove
					
	Usage :			Call to remove a style from the complete line.
					"style" can be one of the following:
						"STYLE_NONE" Black line
						"STYLE_ARROWHEAD" White arrowhead
						"STYLE_FILLED_ARROWHEAD" Black arrowhead
						"STYLE_CIRCLECROSS" A circle with a cross
						"STYLE_FILLED_DIAMOND" Black diamond
						"STYLE_DASHED" Dashed line
						"STYLE_INVISIBLE" Invisible line
   ============================================================*/
{

	CUMLEntityContainer* objs = GetUMLContainer();
	if( objs )
	{
		if( style & STYLE_FILLED_DIAMOND ||
			style & STYLE_FILLED_ARROWHEAD )
		{
			CUMLLineSegment* start = objs->GetStartSegment( this );
			start->m_style &= ~style;
		}
		if( style & STYLE_ARROWHEAD ||
			style & STYLE_CIRCLECROSS )
		{
			CUMLLineSegment* end = objs->GetEndSegment( this );
			end->m_style &= ~style;
		}

		if( style & STYLE_DASHED || style & STYLE_INVISIBLE )
		{
			CUMLLineSegment* start = objs->GetStartSegment( this );
			while( start )
			{
				start->m_style &= ~style;
				start = objs->GetNextSegment( start );
			}
		}
	}
	else
		m_style &= ~style;

}

int CUMLLineSegment::GetStyle() const
/* ============================================================
	Function :		CUMLLineSegment::GetStyle
	Description :	Gets the style of the line segment
	Access :		Public

	Return :		int	-	Style
	Parameters :	none

	Usage :			"style" can be one of the following:
						"STYLE_NONE" Black line
						"STYLE_ARROWHEAD" White arrowhead
						"STYLE_FILLED_ARROWHEAD" Black arrowhead
						"STYLE_CIRCLECROSS" A circle with a cross
						"STYLE_FILLED_DIAMOND" Black diamond
						"STYLE_DASHED" Dashed line
						"STYLE_INVISIBLE" Invisible line

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

	return m_style;

}

BOOL CUMLLineSegment::FromString( const CString& str )
/* ============================================================
	Function :		CUMLLineSegment::FromString
	Description :	Sets the data fro this object from "str".
	Access :		Public
					
	Return :		BOOL				-	"TRUE" if str represents 
											an object of this type.
	Parameters :	const CString& str	-	String representation
					
	Usage :			Called from the load-functionality.

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

	BOOL result = FALSE;
	CString data( str );

	if( LoadFromString( data ) )
	{

		CTokenizer tok( data );

		CString package;
		CString stereotype;

		CString startLink;
		CString endLink;

		int startLinkType;
		int endLinkType;

		CString	fontName;
		int		bkColor;

		int style;
		CString startLabel;
		CString endLabel;
		CString secondaryStartLabel;
		CString secondaryEndLabel;

		int startOffset;
		int endOffset;

⌨️ 快捷键说明

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