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

📄 umlentitycontainer.cpp

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

	Author :		Johan Rosengren, Abstrakt Mekanik AB

	Date :			2004-04-29

	Purpose :		"CUMLEntityContainer" is a "CDiagramEntityContainer"-
					derived class, holding the data for a "CUMLEditor". 
					In addition to "CDiagramEntityContainer", this class keeps 
					and manages links. This includes copy/paste and 
					undo-handling.

	Description :	The class uses a derived "CDiagramClipboardHandler".

	Usage :			Use as a normal "CDiagramEntityContainer" class.

   ========================================================================
	Changes:		27/6 2004	Added Load function.
					8/7 2004	Changed base class handling in c++-export 
								from "CString" to "CStringArray" to support 
								multiple inheritance
					8/7 2004	Corrected bug in path name creation (double 
								slashes) in the cpp/h-export.
   ========================================================================
					5/8 2004	Added support for private and protected 
								base classes through line stereotypes.
   ========================================================================*/

#include "stdafx.h"
#include "UMLEntityContainer.h"
#include "UMLControlFactory.h"
#include "DiskObject/DiskObject.h"
#include "TextFile/TextFile.h"
#include "UMLEntityInterface.h"

#include <math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#pragma warning( disable : 4706 )

CUMLEntityContainer::CUMLEntityContainer()
/* ============================================================
	Function :		CUMLEntityContainer::CUMLEntityContainer
	Description :	Constructor
	Access :		Public
					
	Return :		void
	Parameters :	none

	Usage :			Create and attach to a "CUMLEditor".

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

	m_displayOptions = 0;
	m_color = RGB( 0, 0, 0 );

	SetUndoStackSize( 10 );

}

CUMLEntityContainer::~CUMLEntityContainer()
/* ============================================================
	Function :		CUMLEntityContainer::~CUMLEntityContainer
	Description :	Destructor
	Access :		Public
					
	Return :		void
	Parameters :	none

	Usage :			

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

	ClearUndo();

}


void CUMLEntityContainer::RemoveAt( int index )
/* ============================================================
	Function :		CUMLEntityContainer::RemoveAt
	Description :	Removes the object at "index". Will also 
					remove all linked lines refering to this 
					object if it is a segment itself.
	Access :		Public

	Return :		void
	Parameters :	int index	-	Index for object to remove.

	Usage :			Overridden to remove linked segments as well.

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

	CUMLEntity* obj = GetObjectAt( index );
	if( obj )
	{

		CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( obj );

		if( line )
		{
			DeleteLine( line );
		}
		else
		{
			CString link;

			link = obj->GetName();
			for( int t = GetSize() - 1 ; t >= 0 ; t-- )
			{
				CUMLLineSegment* del = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
				if( del )
				{
					if( del->GetLink( LINK_START ) == link || 
						del->GetLink( LINK_END ) == link )
					{
						Remove( del );
						t = GetSize() - 1;
					}
				}
			}

			index = Find( obj );
			if( index != -1 )
			{
				GetData()->RemoveAt( index );
				delete obj;
			}

		}

	}

}


CUMLLineSegment* CUMLEntityContainer::GetNextSegment( CUMLLineSegment* from ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetNextSegment
	Description :	Gets the next segment in the line from 
					the "from" line segment.
	Access :		Public

	Return :		CUMLLineSegment*	-	The next segment, or "NULL"
	Parameters :	CUMLLineSegment* from	-	The segment to start from.
					
	Usage :			Call to get the next segment in a segmented 
					line.

   ============================================================*/
{
	CUMLLineSegment* result = NULL;
	CString name = from->GetLink( LINK_END );
	if( name.GetLength() )
		result = dynamic_cast< CUMLLineSegment* >( GetNamedObject( name ) );
	else
	{
		name = from->GetName();
		CUMLLineSegment* obj = NULL;
		int max = GetSize();
		for( int t = 0 ; t < max && result == NULL ; t++ )
		{
			obj = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
			if( obj && obj->GetLink( LINK_START) == name )
				return obj;
		}
	}

	return result;
}

CUMLLineSegment* CUMLEntityContainer::GetPrevSegment( CUMLLineSegment* from ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetPrevSegment
	Description :	Gets the previous segment in the line from 
					the "from" line segment.

	Access :		Public

	Return :		CUMLLineSegment*		-	Previsous segment or "NULL"
	Parameters :	CUMLLineSegment* from	-	Segment to start from
					
	Usage :			Call to get the previous segment in a 
					segmented line.

   ============================================================*/
{
	CUMLLineSegment* result = NULL;
	CString name = from->GetLink( LINK_START );
	if( name.GetLength() )
		result = dynamic_cast< CUMLLineSegment* >( GetNamedObject( name ) );
	else
	{
		name = from->GetName();
		CUMLLineSegment* obj = NULL;
		int max = GetSize();
		for( int t = 0 ; t < max && result == NULL ; t++ )
		{
			obj = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
			if( obj && obj->GetLink( LINK_END ) == name )
				return obj;
		}
	}

	return result;
}

CUMLLineSegment* CUMLEntityContainer::GetStartSegment( CUMLLineSegment* from ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetStartSegment
	Description :	Gets the start segment in the line 
					containing the line segment "from".
	Access :		Public

	Return :		CUMLLineSegment*	-	Start segment. Might be identical to "from"
	Parameters :	CUMLLineSegment* from	-	Segment in the line to check.
					
	Usage :			Call to get the starting segment in a line 
					containing the segment "from".

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

	CUMLLineSegment* result = from;
	CUMLLineSegment* test = GetPrevSegment( from );

	while( test )
	{
		result = test;
		test = GetPrevSegment( test );
	}

	return result;

}

CUMLLineSegment* CUMLEntityContainer::GetEndSegment( CUMLLineSegment* from ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetEndSegment
	Description :	Gets the end segment in the line 
					containing the segment "from".
	Access :		Public

	Return :		CUMLLineSegment*	-	End segment. Might be identical to "from"
	Parameters :	CUMLLineSegment* from	-	Segment in the line to check.
					
	Usage :			Call to get the ending segment in a line 
					containing the segment "from".

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

	CUMLLineSegment* result = from;
	CUMLLineSegment* test = GetNextSegment( from );

	while( test )
	{
		result = test;
		test = GetNextSegment( test );
	}

	return result;

}

void CUMLEntityContainer::DeleteLine( CUMLLineSegment* from )
/* ============================================================
	Function :		CUMLEntityContainer::DeleteLine
	Description :	Deletes all segments in the line containing 
					the line segment "from".
	Access :		Private

	Return :		void
	Parameters :	CUMLLineSegment* from	-	Segment in the line to delete
					
	Usage :			Call to delete a complete line. Will 
					recalculate the restraints for attached 
					objects.

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

	CUMLEntity* start = GetStartNode( from );
	CUMLEntity* end = GetEndNode( from );
	CUMLLineSegment* obj = GetStartSegment( from );
	CUMLLineSegment* next = NULL;
	while( obj )
	{
		int index = Find( obj );
		next = GetNextSegment( obj );
		GetData()->RemoveAt( index );
		delete obj;
		obj = next;
	}

	if( start )
		start->CalcRestraints();
	if( end )
		end->CalcRestraints();

}

CUMLEntity* CUMLEntityContainer::GetNamedObject( const CString& name ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetNamedObject
	Description :	Gets the object with the name "name" from 
					the data container.
	Access :		Public

	Return :		CUMLEntity*			-	Result, "NULL" if not found.
	Parameters :	const CString& name	-	Name to search for.
					
	Usage :			Call to get the pointer to an object given 
					its name.

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

	CUMLEntity* test;
	int max = GetSize();
	for( int t = 0 ; t < max ; t++ )
	{
		test = GetObjectAt( t );
		if( test->GetName() == name )
			return test;
	}

	return NULL;

}

CUMLEntity* CUMLEntityContainer::GetTitledObject( const CString& name ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetTitledObject
	Description :	Gets the object with the title "name" from 
					the data container.
	Access :		Public

	Return :		CUMLEntity*			-	Result, "NULL" if not found.
	Parameters :	const CString& name	-	Title to search for.
					
	Usage :			Call to get the pointer to an object given 
					its title.

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

	CUMLEntity* test;
	int max = GetSize();
	for( int t = 0 ; t < max ; t++ )
	{

		test = GetObjectAt( t );
		if( test->GetTitle() == name )
			return test;

	}

	return NULL;

}

void CUMLEntityContainer::RemoveAllSelected()
/* ============================================================
	Function :		CUMLEntityContainer::RemoveAllSelected
	Description :	Removes all selected objects in the 
					container.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to delete all selected objects in the 
					container. The function will also remove 
					attached links.

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

	for( int t = GetSize() - 1; t >= 0 ; t-- )
	{
		if( GetAt( t )->IsSelected() )
		{
			RemoveAt( t );
			t = GetSize();
		}
	}

}

CUMLEntity* CUMLEntityContainer::GetStartNode( CUMLLineSegment* from ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetStartNode
	Description :	Gets the object attached to the start 
					segment of the line containing the 
					segment "from"
	Access :		Public

	Return :		CUMLEntity*	-	
	Parameters :	CUMLLineSegment* from	-	Segment in the line
					
	Usage :			Call to get the starting object of the line.

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

	CUMLEntity* result = NULL;
	CUMLLineSegment* line = GetStartSegment( from );
	if( line )
	{
		CString start = line->GetLink( LINK_START );
		result = GetNamedObject( start );
	}
	return result;

}

CUMLEntity* CUMLEntityContainer::GetEndNode( CUMLLineSegment* from ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetEndNode
	Description :	Gets the object attached to the end 
					segment of the line containing the 
					segment "from"
	Access :		Public

	Return :		CUMLEntity*				-	The object attached 
												to the end of the line.
	Parameters :	CUMLLineSegment* from	-	Segment in the line
					
	Usage :			Call to get the ending object of the line.

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

	CUMLEntity* result = NULL;
	CUMLLineSegment* line = GetEndSegment( from );
	if( line )
	{
		CString end = line->GetLink( LINK_END );
		result = GetNamedObject( end );
	}
	return result;

}

int	CUMLEntityContainer::GetSelectCount() const
/* ============================================================
	Function :		int	CUMLEntityContainer::GetSelectCount
	Description :	Returns the number of currently selected 
					objects.
	Access :		Public
					
	Return :		int		-	The number of selected objects.
	Parameters :	none

	Usage :			Call to see how many objects are selected.

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

	int count = 0;
	int max = GetSize();

	for( int t = 0 ; t < max ; t++ )
		if( GetAt( t )->IsSelected() )
			count++;

	return count;

⌨️ 快捷键说明

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