📄 flowchartentitycontainer.cpp
字号:
}
void CFlowchartEntityContainer::RemoveAt( int index )
/* ============================================================
Function : CFlowchartEntityContainer::RemoveAt
Description : Removes the object at index. Will also
remove all links refering to this object.
Return : void
Parameters : int index - Index for object to remove.
Usage : Overridden to remove links as well.
============================================================*/
{
CDiagramEntity* obj = GetAt( index );
if( obj )
{
CString name = obj->GetName();
CDiagramEntityContainer::RemoveAt( index );
int max = m_links.GetUpperBound();
for( int t = max; t >= 0 ; t-- )
{
CFlowchartLink* link = static_cast< CFlowchartLink* >( m_links.GetAt( t ) );
if( link->to == name || link->from == name )
{
delete link;
m_links.RemoveAt( t );
}
}
}
}
void CFlowchartEntityContainer::AddLink( CFlowchartLink* link )
/* ============================================================
Function : CFlowchartEntityContainer::AddLink
Description : Adds a links to the link array.
Return : void
Parameters : CFlowchartLink* link - Link to add
Usage : Call to add a link to the link array.
============================================================*/
{
m_links.Add( link );
}
CFlowchartLink* CFlowchartEntityContainer::FindLink( CDiagramEntity* obj1, CDiagramEntity* obj2 )
/* ============================================================
Function : CFlowchartEntityContainer::FindLink
Description : Finds a link between obj1 and obj2.
Return : CFlowchartLink* - Link between obj1
and obj2, or NULL
if they are not
linked.
Parameters : CDiagramEntity* obj1 - First object to
test.
CDiagramEntity* obj2 - Second object
to test.
Usage : Call to get the link between obj1 and obj2,
or to check if obj1 and obj2 are linked.
============================================================*/
{
CFlowchartLink* result = NULL;
if( obj1 && obj2 )
{
int max = m_links.GetUpperBound();
for( int t = max; t >= 0 ; t-- )
{
CFlowchartLink* link = static_cast< CFlowchartLink* >( m_links.GetAt( t ) );
if( ( link->from == obj1->GetName() && link->to == obj2->GetName() ) || ( link->from == obj2->GetName() && link->to == obj1->GetName() ) )
result = link;
}
}
return result;
}
void CFlowchartEntityContainer::DeleteLink( CFlowchartLink* inlink )
/* ============================================================
Function : CFlowchartEntityContainer::DeleteLink
Description : Finds and deletes inlink from the internal
link array.
Return : void
Parameters : CFlowchartLink* inlink - Link to delete
Usage : Call to delete a link from the link array.
============================================================*/
{
int max = m_links.GetUpperBound();
for( int t = max; t >= 0 ; t-- )
{
CFlowchartLink* link = static_cast< CFlowchartLink* >( m_links.GetAt( t ) );
if( link == inlink )
{
delete link;
m_links.RemoveAt( t );
}
}
}
void CFlowchartEntityContainer::Undo()
/* ============================================================
Function : CFlowchartEntityContainer::Undo
Description : Undo the latest operation
Return : void
Parameters : none
Usage : Overridden to also undo link operations.
============================================================*/
{
CDiagramEntityContainer::Undo();
if( m_undoLinks.GetSize() )
{
CObArray* undo = static_cast< CObArray* >( m_undoLinks.GetAt( m_undoLinks.GetUpperBound() ) );
int count = undo->GetSize();
for( int t = 0 ; t < count ; t++ )
{
CFlowchartLink* obj = static_cast< CFlowchartLink* >( undo->GetAt( t ) );
AddLink( obj->Clone() );
}
int max = undo->GetSize();
for( t = max - 1 ; t >= 0 ; t-- )
delete undo->GetAt( t );
undo->RemoveAll();
delete undo;
m_undoLinks.RemoveAt( m_undoLinks.GetUpperBound() );
}
}
void CFlowchartEntityContainer::Snapshot()
/* ============================================================
Function : CFlowchartEntityContainer::Snapshot
Description : Creates a snapshot of the current data
state for the undo-functionality.
Return : void
Parameters : none
Usage : Overridden to save the link state as well.
============================================================*/
{
CDiagramEntityContainer::Snapshot();
if( GetUndoStackSize() > 0 && m_undoLinks.GetSize() == GetUndoStackSize() )
{
delete m_undoLinks.GetAt( 0 );
m_undoLinks.RemoveAt( 0 );
}
CObArray* undo = new CObArray;
while( !undo && m_undoLinks.GetSize() )
{
delete m_undoLinks.GetAt( 0 );
m_undoLinks.RemoveAt( 0 );
undo = new CObArray;
}
if( undo )
{
// Save all objects
int count = m_links.GetSize();
for( int t = 0 ; t < count ; t++ )
undo->Add( GetLinkAt( t )->Clone() );
// Add to undo stack
m_undoLinks.Add( undo );
}
}
void CFlowchartEntityContainer::ClearUndo()
/* ============================================================
Function : CFlowchartEntityContainer::ClearUndo
Description : Clears the undo-array
Return : void
Parameters : none
Usage : Overridden to also clear the link undo
states.
============================================================*/
{
CDiagramEntityContainer::ClearUndo();
int count = m_undoLinks.GetSize() - 1;
for( int t = count ; t >= 0 ; t-- )
{
CObArray* undo = static_cast< CObArray* >( m_undoLinks.GetAt(t) );
// Remove all objects in the stack entry
int max = undo->GetSize();
for( int i = 0; i < max ; i++ )
delete undo->GetAt( i );
undo->RemoveAll();
// Remove the stack entry itself.
delete undo;
}
m_undoLinks.RemoveAll();
}
void CFlowchartEntityContainer::ClearLinks()
/* ============================================================
Function : CFlowchartEntityContainer::ClearLinks
Description : Clears the link array.
Return : void
Parameters : none
Usage : Call to remove all links.
============================================================*/
{
int max = m_links.GetSize();
for( int t = 0 ; t < max ; t++ )
delete m_links[ t ];
m_links.RemoveAll();
}
double CFlowchartEntityContainer::Dist( CPoint point1, CPoint point2 )
/* ============================================================
Function : CFlowchartEntityContainer::Dist
Description : Calculates the distance between point1 and
point2.
Return : double - Resulting distance
Parameters : CPoint point1 - First point to test
CPoint point2 - Second point to test
Usage : Used to find the closest link points between
two objects.
============================================================*/
{
double width = abs( point1.x - point2.x );
double height = abs( point1.y - point2.y );
double hyp = _hypot( width, height );
return hyp;
}
CFlowchartEntity* CFlowchartEntityContainer::GetPrimaryLink()
/* ============================================================
Function : CFlowchartEntityContainer::GetPrimaryLink
Description : Returns the primary object of the two
currently selected and linked.
Return : CFlowchartEntity* - Primary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected, or they are not linked.
============================================================*/
{
CFlowchartEntity* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
CFlowchartEntity* primary = NULL;
CFlowchartEntity* secondary = NULL;
for( int t = 0 ; t < max ; t++ )
{
CFlowchartEntity* obj = dynamic_cast< CFlowchartEntity* >( GetAt( t ) );
if( obj && obj->IsSelected() )
{
if( primary == NULL )
primary = obj;
else
secondary = obj;
}
}
if( primary && secondary )
{
CFlowchartLink* link = FindLink( primary, secondary );
if( link )
{
if( primary->GetName() == link->from )
result = primary;
else
result = secondary;
}
}
}
return result;
}
CFlowchartEntity* CFlowchartEntityContainer::GetSecondaryLink()
/* ============================================================
Function : CFlowchartEntityContainer::GetSecondaryLink
Description : Returns the secondary object of the two
currently selected and linked.
Return : CFlowchartEntity* - Secondary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected, or they are not linked.
============================================================*/
{
CFlowchartEntity* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
CFlowchartEntity* primary = NULL;
CFlowchartEntity* secondary = NULL;
for( int t = 0 ; t < max ; t++ )
{
CFlowchartEntity* obj = dynamic_cast< CFlowchartEntity* >( GetAt( t ) );
if( obj && obj->IsSelected() )
{
if( primary == NULL )
primary = obj;
else
secondary = obj;
}
}
if( primary && secondary )
{
CFlowchartLink* link = FindLink( primary, secondary );
if( link )
{
if( primary->GetName() == link->from )
result = secondary;
else
result = primary;
}
}
}
return result;
}
CFlowchartEntity* CFlowchartEntityContainer::GetPrimarySelected()
/* ============================================================
Function : CFlowchartEntityContainer::GetPrimarySelected
Description : Returns the primary object of the two
currently selected.
Return : CFlowchartEntity* - Primary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected.
============================================================*/
{
CFlowchartEntity* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
for( int t = 0 ; t < max ; t++ )
{
CFlowchartEntity* obj = dynamic_cast< CFlowchartEntity* >( GetAt( t ) );
if( obj && obj->IsSelected() )
{
if( result == NULL )
result = obj;
}
}
}
return result;
}
CFlowchartEntity* CFlowchartEntityContainer::GetSecondarySelected()
/* ============================================================
Function : CFlowchartEntityContainer::GetSecondarySelected
Description : Returns the secondary object of the two
currently selected.
Return : CFlowchartEntity* - secondary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected.
============================================================*/
{
CFlowchartEntity* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
for( int t = 0 ; t < max ; t++ )
{
CFlowchartEntity* obj = dynamic_cast< CFlowchartEntity* >( GetAt( t ) );
if( obj && obj->IsSelected() )
result = obj;
}
}
return result;
}
int CFlowchartEntityContainer::GetSelectCount()
/* ============================================================
Function : int CFlowchartEntityContainer::GetSelectCount
Description : Returns the number of currently selected
objects.
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++ )
{
CFlowchartEntity* obj = dynamic_cast< CFlowchartEntity* >( GetAt( t ) );
if( obj && obj->IsSelected() )
count++;
}
return count;
}
BOOL CFlowchartEntityContainer::IsLinked()
/* ============================================================
Function : CFlowchartEntityContainer::IsLinked
Description : Check if exactly two objects are selected
and linked.
Return : BOOL - TRUE if two objects are
selected and linked.
Parameters : none
Usage : Call as a command enabler for commands
where the selected items must be two and
linked (such as Flip link direction).
============================================================*/
{
BOOL result = FALSE;
if( GetSelectCount() == 2 )
{
CFlowchartEntity* primary = GetPrimaryLink();
CFlowchartEntity* secondary = GetSecondaryLink();
result = ( primary && secondary );
}
return result;
}
BOOL CFlowchartEntityContainer::CanLink()
/* ============================================================
Function : CFlowchartEntityContainer::CanLink
Description : Returns TRUE if two objects are selected,
but not linked and it is possible to link
them.
Return : BOOL - TRUE if two objects are
selected and can be linked.
Parameters : none
Usage : Call as a command enabler for the Link
command.
============================================================*/
{
BOOL result = FALSE;
if( GetSelectCount() == 2 )
{
CFlowchartEntity* primary = GetPrimarySelected();
CFlowchartEntity* secondary = GetSecondarySelected();
if( primary && secondary )
result = !HasLinks( primary, secondary );
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -