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

📄 diagramentitycontainer.cpp

📁 So you wanted to add a forms editor to your application? A dialog editor? Something that allows draw
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			// Save current virtual size
			item->pt = GetVirtualSize();

			// Save all objects
			int count = m_objs.GetSize();
			for( int t = 0 ; t < count ; t++ )
				( item->arr ).Add( GetAt( t )->Clone() );

			// Add to undo stack
			arr.Add( item );

		}
	}
}

void CDiagramEntityContainer::ClearUndo()
/* ============================================================
	Function :		CDiagramEntityContainer::ClearUndo
	Description :	Remove all undo arrays from the undo stack
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to clear the undo-stack. All memory will 
					be deleted.

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

	while( m_undo.GetSize() )
	{
		delete m_undo.GetAt( 0 );
		m_undo.RemoveAt( 0 );
	}

}

void CDiagramEntityContainer::ClearRedo()
/* ============================================================
	Function :		CDiagramEntityContainer::ClearRedo
	Description :	Remove all redo arrays from the redo stack
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to clear the redo-stack. All memory will 
					be deleted.

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

	while( m_redo.GetSize() )
	{
		delete m_redo.GetAt( 0 );
		m_redo.RemoveAt( 0 );
	}

}

BOOL CDiagramEntityContainer::IsUndoPossible() const
/* ============================================================
	Function :		CDiagramEntityContainer::IsUndoPossible
	Description :	Check if it is possible to undo.
	Access :		Public

	Return :		BOOL	-	"TRUE" if undo is possible.
	Parameters :	none

	Usage :			Use this call for command enabling

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

	return ( BOOL ) ( m_undo.GetSize() );

}

BOOL CDiagramEntityContainer::IsRedoPossible() const
/* ============================================================
	Function :		CDiagramEntityContainer::IsUndoPossible
	Description :	Check if it is possible to redo.
	Access :		Public

	Return :		BOOL	-	"TRUE" if redo is possible.
	Parameters :	none

	Usage :			Use this call for command enabling

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

	return ( BOOL ) ( m_redo.GetSize() );

}

void CDiagramEntityContainer::SetUndoStackSize( int maxstacksize )
/* ============================================================
	Function :		CDiagramEntityContainer::SetUndoStackSize
	Description :	Sets the size of the undo stack.
	Access :		Public

	Return :		void
	Parameters :	int maxstacksize	-	New size. -1 means 
											no limit, 0 no undo.
					
	Usage :			Call to set the max undo stack size.

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

	m_maxstacksize = maxstacksize;

}

int CDiagramEntityContainer::GetUndoStackSize() const
/* ============================================================
	Function :		CDiagramEntityContainer::GetUndoStackSize
	Description :	Returns the size of the undo-stack
	Access :		Public

	Return :		int	-	Current size
	Parameters :	none

	Usage :			Call to get the max undo stack size.

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

	return m_maxstacksize;

}

void CDiagramEntityContainer::PopUndo()
/* ============================================================
	Function :		CUMLEntityContainer::PopUndo
	Description :	Pops the undo stack (removes the last stack
					item)
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call do undo the last Snapshot

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

	int size = m_undo.GetSize();
	if( size )
	{
		delete m_undo.GetAt( size - 1 );
		m_undo.RemoveAt( size - 1 );
	}

}

CObArray* CDiagramEntityContainer::GetData() 
/* ============================================================
	Function :		CDiagramEntityContainer::GetData
	Description :	Accessor for the internal data array
	Access :		Public

	Return :		CObArray*	-	A pointer to the internal 
									data array.
	Parameters :	none

	Usage :			Call to access the internal data array. To 
					be used in derived classes.

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

	return &m_objs; 

}

CObArray* CDiagramEntityContainer::GetPaste()	
/* ============================================================
	Function :		CDiagramEntityContainer::GetPaste
	Description :	Accessor for the internal paste array
	Access :		Protected

	Return :		CObArray*	-	A pointer to the paste 
									array
	Parameters :	none

	Usage :			Call to access the internal paste array. To 
					be used in derived classes.

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

	CObArray* arr = NULL;
	if( m_clip )
		arr = m_clip->GetData();

	return arr;

}

CObArray* CDiagramEntityContainer::GetUndo()
/* ============================================================
	Function :		CDiagramEntityContainer::GetUndo
	Description :	Accessor for the internal undo array
	Access :		Protected

	Return :		CObArray*	-	A pointer to the undo 
									array
	Parameters :	none

	Usage :			Call to access the internal undo array. To 
					be used in derived classes.

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

	return &m_undo;

}

void CDiagramEntityContainer::Group()
/* ============================================================
	Function :		CDiagramEntityContainer::Group
	Description :	Groups the currently selected objects into 
					the same group.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to group all selected items into the 
					same group.
					Grouped objects can be moved as a 
					single entity. Technically, when one object 
					in a group is selected, all other objects 
					are also selected automatically.

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

	CDiagramEntity* obj;
	int count = 0;
	int group = CGroupFactory::GetNewGroup();
	while( ( obj = GetAt( count ) ) )
	{
		if( obj->IsSelected() )
			obj->SetGroup( group );
		count++;
	}

}

void CDiagramEntityContainer::Ungroup()
/* ============================================================
	Function :		CDiagramEntityContainer::Ungroup
	Description :	Ungroups the currently selected objects.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to ungroup all selected items. 
					Grouped objects can be moved as a 
					single entity. Technically, when one object 
					in a group is selected, all other objects 
					are also selected automatically.

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

	CDiagramEntity* obj;
	int count = 0;
	while( ( obj = GetAt( count ) ) )
	{
		if( obj->IsSelected() )
			obj->SetGroup( 0 );
		count++;
	}

}

CSize CDiagramEntityContainer::GetTotalSize()
/* ============================================================
	Function :		CDiagramEntityContainer::GetTotalSize
	Description :	Gets the minimum bounding size for the 
					objects in the container.
	Access :		

	Return :		CSize	-	Minimum bounding size
	Parameters :	none

	Usage :			Call to get the screen size of the objects 
					in the container.

   ============================================================*/
{
	CPoint start = GetStartPoint();
	double width = 0;
	double height = 0;

	CDiagramEntity* obj;
	int count = 0;
	while( ( obj = GetAt( count ) ) )
	{

		width = max( width, obj->GetLeft() );
		width = max( width, obj->GetRight() );
		height = max( height, obj->GetTop() );
		height = max( height, obj->GetBottom() );

		count++;

	}

	return CSize( round( width - start.x ), round( height - start.y ) );

}

CPoint CDiagramEntityContainer::GetStartPoint()
/* ============================================================
	Function :		CDiagramEntityContainer::GetStartPoint
	Description :	Gets the starting screen position of the 
					objects in the container (normally the 
					top-left corner of the top-left object).
	Access :		

	Return :		CPoint	-	Top-left position of the 
								objects.
	Parameters :	none

	Usage :			Call to get the starting point on screen of 
					the objects.

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

	double startx = 2000.0;
	double starty = 2000.0;

	CDiagramEntity* obj;
	int count = 0;

	while( ( obj = GetAt( count ) ) )
	{

		startx = min( startx, obj->GetLeft() );
		startx = min( startx, obj->GetRight() );
		starty = min( starty, obj->GetTop() );
		starty = min( starty, obj->GetBottom() );

		count++;

	}

	return CPoint( round( startx ), round( starty ) );

}

int	CDiagramEntityContainer::GetSelectCount() const
/* ============================================================
	Function :		int	CDiagramEntityContainer::GetSelectCount
	Description :	Gets the number of currently selected 
					objects in the container.
	Access :		

	Return :		int		-	Currently selected objects.
	Parameters :	none

	Usage :			Call to get the number of selected objects.

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

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

	return count;

}

void CDiagramEntityContainer::SelectAll()
/* ============================================================
	Function :		void CDiagramEntityContainer::SelectAll
	Description :	Selects all objects in the container
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to select all objects in the container

   ============================================================*/
{
	int max = GetSize();
	for( int t = 0 ; t < max ; t++ )
		Select( t, TRUE );
}

void CDiagramEntityContainer::UnselectAll()
/* ============================================================
	Function :		void CDiagramEntityContainer::
	Description :	Unselects all objects in the container
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to unselect all objects int eh container

   ============================================================*/
{
	int max = GetSize();
	for( int t = 0 ; t < max ; t++ )
		Select( t, FALSE );
}

void CDiagramEntityContainer::Select( int index, BOOL select )
/* ============================================================
	Function :		void CDiagramEntityContainer::Select
	Description :	Selects "obj"
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to select "obj"

   ============================================================*/
{
	if( index < GetSize() )
		Select( GetAt( index ), select );
}

void CDiagramEntityContainer::Select( CDiagramEntity* obj, BOOL select )
/* ============================================================
	Function :		void CDiagramEntityContainer::Select
	Description :	Selects "obj"
	Access :		Public

	Return :		void
	Parameters :	CDiagramEntity* obj	-	Object to select
					BOOL select			-	"TRUE" to select, 
											"FALSE" to unselect.

	Usage :			Call to select "obj"

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

	if( obj )
		obj->Select( select );

}

void CDiagramEntityContainer::PasteToPosition( const CPoint& pos )
/* ============================================================
	Function :		void CDiagramEntityContainer::PasteToPosition
	Description :	Pastes the content of the internal clipboard 
					to "pos"
	Access :		Public

	Return :		void
	Parameters :	const CPoint& obj	-	Position (in virtual 
											coordinates) to paste 
											the clipboard objects to

	Usage :			Call to paste the contents of the clipboard to 
					a specific position. Note that we need to take 
					the 10, 10 offset of the objects added to the 
					clipboard object positions in this function. 

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

	CObArray* arr = GetPaste();

	if( arr ) 
	{
		int max = arr->GetSize();
		if( max )
		{
			double left = 0;
			double top = 0;

			// Find the top-left corner object and position in the private clipboard
			for( int t = 0 ; t < max ; t++ )
			{
				CDiagramEntity* entity = static_cast< CDiagramEntity* >( arr->GetAt( t ) );
				if( entity )
				{
					entity->SetParent( this );
					CRect rect = entity->GetRect();
					rect.OffsetRect( -10, -10 ); // The copied object is already offset 10 px from the original
					if( t == 0 )
					{
						left = rect.left;
						top = rect.top;
					}
					else
					{
						left = min( left, rect.left );
						top = min( top, rect.top );
					}
				}
			};

			// Calculate difference between desired and current position
			double diffx = ( pos.x - left ) - 10;
			double diffy = ( pos.y - top ) - 10;

			// Loop the clipboard, copying to new, applying difference
			for( t = 0 ; t < max ; t++ )
			{
				CDiagramEntity* entity = static_cast< CDiagramEntity* >( arr->GetAt( t ) );
				if( entity )
				{
					CDiagramEntity* newentity = entity->Clone();
					CRect rect = newentity->GetRect();
					rect.OffsetRect( ( int ) diffx, ( int ) diffy );
					newentity->SetRect( rect );
					GetData()->Add( newentity );
				}
			}
		}
	}
}

#pragma warning( default : 4706 )

⌨️ 快捷键说明

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