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

📄 umlentitycontainer.cpp

📁 uml编辑器很牛
💻 CPP
📖 第 1 页 / 共 5 页
字号:
						else
							local->SetErrorMessage( cdo.GetErrorMessage() );
					}
				}
			}
		}
	}
	else
		local->SetErrorMessage( cdo.GetErrorMessage() );

	local->SetPackage( current );

}

void CUMLEntityContainer::ExportH() const
/* ============================================================
	Function :		CUMLEntityContainer::ExportH
	Description :	Exports the current data in the container 
					to c++ header-files.
	Access :		Private

	Return :		void
	Parameters :	none

	Usage :			Call to export the data in the array to 
					header files.

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

	CUMLEntityContainer* const local = const_cast<CUMLEntityContainer* const>(this);
	CString current = GetPackage();
	local->SetPackage( _T( "all" ) );

	CString str;
	int max = GetSize();
	CString location = GetProjectLocation() + _T( "\\" ) + GetProjectName();
	CDiskObject cdo;
	if( cdo.CreateDirectory( location ) )
	{
		for( int t = 0 ; t < max ; t++ )
		{
			CUMLEntityClass* obj = dynamic_cast< CUMLEntityClass* >( GetAt( t ) );
			if( obj )
			{
				CString title = obj->GetTitle();
				if( title.GetLength() )
				{
					CStringArray baseClassArray;
					CStringArray baseClassAccessArray;
					GetBaseClassArray( obj, baseClassArray, baseClassAccessArray );
					CStringArray baseClassFilenameArray;
					baseClassFilenameArray.Append( baseClassArray );

					if( GetStripLeadingClassCharacter() )
					{
						title = title.Right( title.GetLength() - 1 );
						int size = baseClassFilenameArray.GetSize();
						for( int i = 0 ; i < size ; i++ )
						{
							CString baseClassFilename = baseClassFilenameArray[ i ].Right( baseClassFilenameArray[ i ].GetLength() - 1 );
							baseClassFilenameArray[ i ] = baseClassFilename;
						}
					}

					obj->SetBaseClassArray( baseClassArray, baseClassAccessArray );

					CString path = GetObjectPath( obj );
					path.Replace( _TCHAR( ':' ), _TCHAR( '\\' ) );
					if( path.GetLength() )
					{
						if( path [ 0 ] != _TCHAR( '\\' ) )
							path = _T( "\\" ) + path;
					}

					CString filename = location + path + _T( "\\" ) + title;
					obj->SetFilename( title );
					filename += _T( ".h" );
					obj->SetBaseClassFilenameArray( baseClassFilenameArray );
					str = obj->Export( EXPORT_H );

					if( cdo.CreateFile( filename ) ) 
					{
						CTextFile file( _T( "" ), _T( "\n" ) );;
						if( !file.WriteTextFile( filename, str ) )
							AfxMessageBox( file.GetErrorMessage() );
					}
					else
						local->SetErrorMessage( cdo.GetErrorMessage() );
				}
			}
		}
	}
	else
		AfxMessageBox( cdo.GetErrorMessage() );

	local->SetPackage( current );

}

void CUMLEntityContainer::GetBaseClassArray( CUMLEntityClass* obj, CStringArray& array, CStringArray& arrayAccess ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetBaseClass
	Description :	Returns the base classes for "obj"
	Access :		Private

	Return :		CString					-	The base class or empty
	Parameters :	CUMLEntityClass* obj	-	The object to check
					CStringArray& array		-	Array to fill with base classes
					
	Usage :			Call to get the base classes for an object.

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

	CStringArray result;
	CStringArray accessArray;
	CString baseClass = obj->GetProperties()->GetPropertyValue( _T( "baseClass" ) );
	if( baseClass.GetLength() )
	{
		CTokenizer tok( baseClass, " " );
		int max = tok.GetSize();
		for( int t = 0 ; t < max ; t++ )
		{
			CString value;
			tok.GetAt( t, value );
			result.Add ( value );
		}
	}
	else
	{
		int max = GetSize();
		for( int t = 0 ; t < max ; t++ )
		{
			CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
			if( line )
			{
				if( line->GetLink( LINK_START ) == obj->GetName() )
				{
					// Check if this is an inherited class
					CUMLLineSegment* seg = GetEndSegment( line );
					if( seg && seg->GetStyle() & STYLE_ARROWHEAD )
					{
						CUMLEntityClass* node = dynamic_cast< CUMLEntityClass* >( GetEndNode( seg ) );
						if( node )
							result.Add( node->GetTitle() );
						else
						{
							// Might be a 
							CUMLEntityInterface* node = dynamic_cast< CUMLEntityInterface* >( GetEndNode( seg ) );
							if( node )
								result.Add( node->GetTitle() );
						}
					}

				}

				// If we have a multi-segment line, it might be flipped
				if( GetNextSegment( line ) || GetPrevSegment( line ) )
				{
					if( line->GetLink( LINK_END ) == obj->GetName() )
					{
						// Check if this is an inherited class
						CUMLLineSegment* seg = GetStartSegment( line );
						if( seg && seg->GetStyle() & STYLE_ARROWHEAD )
						{
							CUMLEntityClass* node = dynamic_cast< CUMLEntityClass* >( GetStartNode( seg ) );
							if( node )
								result.Add( node->GetTitle() );
						}

					}
				}

			}
		}
	}

	int max = result.GetSize();
	for( int t = 0 ; t < max ; t++ )
	{

		CString access( _T( "public" ) );
		CUMLEntity* base = GetTitledObject( result[ t ] );
		if( base )
		{

			// Try to find a link between obj and base
			CUMLLineSegment* seg = GetLinkBetween( obj, base );
			if( seg )
			{

				// Is any segment either private or protected?
				if( IsPrivateLink( seg ) )
					access = _T( "private" );
				if( IsProtectedLink( seg ) )
					access = _T( "protected" );

			}
		}
		accessArray.Add( access );

	}

	array.RemoveAll();
	array.Append( result );

	arrayAccess.RemoveAll();
	arrayAccess.Append( accessArray );

}

void CUMLEntityContainer::SetStripLeadingClassCharacter( BOOL stripLeadingClassLetter )
/* ============================================================
	Function :		CUMLEntityContainer::SetStripLeadingClassCharacter
	Description :	Sets if leading character in the class name 
					should be stripped from the filename when 
					generating to c++.
	Access :		Public

	Return :		void
	Parameters :	BOOL stripLeadingClassLetter	-	"TRUE" if letter should be stripped.
					
	Usage :			Call to set if the first character should 
					be stripped from the class name when 
					creating c++ filenames.

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

	m_stripLeadingClassLetter = stripLeadingClassLetter;

}

BOOL CUMLEntityContainer::GetStripLeadingClassCharacter() const
/* ============================================================
	Function :		CUMLEntityContainer::GetStripLeadingClassCharacter
	Description :	Checks if the leading character in the class name 
					should be stripped from the filename when 
					generating data to c++.
	Access :		Public

	Return :		BOOL	-	"TRUE" if it should be stripped.
	Parameters :	none

	Usage :			The generation mechanism can strip the 
					leading character from a classname when 
					generating cpp/h-files.

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

	return m_stripLeadingClassLetter;

}

BOOL CUMLEntityContainer::IsLinkSelected() const
/* ============================================================
	Function :		CUMLEntityContainer::IsLinkSelected
	Description :	Checks if a single line segment is selected.
	Access :		Public

	Return :		BOOL	-	"TRUE" is only a single segment is selected.
	Parameters :	none

	Usage :			Call in - for example - a command enabler.

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

	if( GetSelectCount() == 1 )
	{
		CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( GetSelectedObject() );
		if( line )
			return TRUE;
	}
		
	return FALSE;

}

void CUMLEntityContainer::FlipLink()
/* ============================================================
	Function :		CUMLEntityContainer::FlipLink
	Description :	Flips the currently selected line.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to flip the currently selected line 
					(if any). Will only flip if there is one 
					(and only one) link segment selected in the 
					editor.

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

	if( GetSelectCount() == 1 )
	{
		CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( GetSelectedObject() );
		if( line )
		{
			if( line->IsSingleLineSegment() )
			{
				line->Flip();
			}
			else
			{
				CUMLLineSegment* start = GetStartSegment( line );
				CUMLLineSegment* end = GetEndSegment( line );
				if( start && end )
				{

					int style = end->GetStyle();
					end->SetStyle( start->GetStyle() );
					start->SetStyle( style );

				}
			}
		}
	}

}

CDiagramEntity* CUMLEntityContainer::GetSelectedObject() const
/* ============================================================
	Function :		CUMLEntityContainer::GetSelectedObject
	Description :	Returns the top selected object in the 
					container.
	Access :		Public
					
	Return :		CDiagramEntity*	-	The top selected object, 
										or "NULL" if none.
	Parameters :	none

	Usage :			Call to get the currently selected object. 
					Note that this function will return a single 
					object (top in the z-order) even if several 
					are selected.

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

	int count = 0;
	CDiagramEntity* obj;

	while( ( obj = GetAt( count++ ) ) )
		if( obj->IsSelected() )
			return obj;

	return NULL;

}

void CUMLEntityContainer::Import()
/* ============================================================
	Function :		CUMLEntityContainer::Import
	Description :	Imports content into the currently selected 
					object from a h-file.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to import information from a h-file 
					into an object.

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

	SendMessageToObjects( CMD_IMPORT, TRUE );

}

void CUMLEntityContainer::GetIncludeList( CUMLEntityClass* inobj, CStringArray& stringarray ) const
/* ============================================================
	Function :		CUMLEntityContainer::GetIncludeList
	Description :	Get a list of the "inobj" class inlcudes.
	Access :		Private
					
	Return :		void
	Parameters :	CUMLEntityClass* inobj		-	The object to get
													includes for
					CStringArray& stringarray	-	Results
					
	Usage :			Call to get a list of the classes "inobj" 
					is composed of. This is a list that will be 
					used to generate includes and forward 
					declarations for a h-file. Strings prefixed
					with a hash-mark should be converted to a forward
					declaration.

					The list is created from both connections,
					class members and operation parameters

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

	CStringArray stra;
	int max = GetSize();
	CStringArray classes;
	GetClassList( classes );

	CStringArray baseClassArray;
	CStringArray baseClassAccessArray;
	GetBaseClassArray( inobj, baseClassArray, baseClassAccessArray );
	int size = baseClassArray.GetSize();
	for( int t = 0 ; t < size ; t++ )
	{
		if( InClasslist( baseClassArray[ t ], classes ) )
			stra.Add( baseClassArray[ t ] );
	}

	for( t = 0 ; t < max ; t++ )
	{
		CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
		if( line )
		{
			if( line->IsSingleLineSegment() )
			{
				if( line->GetLink( LINK_END ) == inobj->GetName() )
				{
					if( line->GetStyle() & STYLE_FILLED_DIAMOND )
					{
						CUMLEntityClass* node = NULL;
						node = dynamic_cast< CUMLEntityClass*>( GetStartNode( line ) );

						if( node && node != inobj )
						{
							CString title = node->GetTitle();
							AddString( title, stra );

						}
					}
				}
			}
			else
			{
				if( line->GetLink( LINK_END ) == inobj->GetName() || line->GetLink( LINK_START ) == inobj->GetName() )
				{
					if( line->GetStyle() & STYLE_FILLED_DIAMOND )
					{
						CUMLEntityClass* node = NULL;
						if( line->GetLink( LINK_END ) == inobj->GetName() )
							node = dynamic_cast< CUMLEntityClass*>( GetStartNode( line ) );
						else
							node = dynamic_cast< CUMLEntityClass*>( GetEndNode( line ) );

						if( node && node != inobj )
						{
							CString title = node->GetTitle();
							AddString( title, stra );

						}
					}
				}
			}
		}
	}

	max = classes.GetSize();
	size = inobj->GetOperations();

	CString cls( inobj->GetTitle() );
	for( t = 0 ; t < size ; t++ )
	{
		COperation* op = inobj->GetOperation( t );
		int params = op->parameters.GetSize();
		for( int i = 0 ; i < params ; i++ )
		{
			CParameter* param = op->parameters.GetAt( i );
			CString title( param->type );
			title.Remov

⌨️ 快捷键说明

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