📄 networkentitycontainer.cpp
字号:
BOOL CNetworkEntityContainer::IsLinked()
/* ============================================================
Function : CNetworkEntityContainer::IsLinked
Description : Returns the current link-state of the data.
Return : BOOL - TRUE if two exactly objects are
selected and linked.
Parameters : none
Usage : Intended as a command enabler for an Unlink
command.
============================================================*/
{
BOOL result = FALSE;
if( GetSelectCount() == 2 )
{
CNetworkSymbol* primary = GetPrimaryLink();
CNetworkSymbol* secondary = GetSecondaryLink();
result = ( primary && secondary );
}
return result;
}
CNetworkLink* CNetworkEntityContainer::GetLinkAt( int index )
/* ============================================================
Function : CNetworkEntityContainer::GetLinkAt
Description : Returns the link object at position index
in the link array.
Return : CNetworkLink* - Pointer to the link, or
NULL if out of bounds.
Parameters : int index - Index to get link from.
Usage : Call to get the link at a specific index in
the array.
============================================================*/
{
CNetworkLink* link = NULL;
if( index < GetLinks() )
link = dynamic_cast< CNetworkLink* >( m_links.GetAt( index ) );
return link;
}
CNetworkLink* CNetworkEntityContainer::FindLink( CDiagramEntity* obj1, CDiagramEntity* obj2 )
/* ============================================================
Function : CNetworkEntityContainer::FindLink
Description : Finds a link between obj1 and obj2.
Return : CNetworkLink* - 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.
============================================================*/
{
CNetworkLink* result = NULL;
if( obj1 && obj2 )
{
int max = m_links.GetUpperBound();
for( int t = max; t >= 0 ; t-- )
{
CNetworkLink* link = static_cast< CNetworkLink* >( 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 CNetworkEntityContainer::ClearLinks()
/* ============================================================
Function : CNetworkEntityContainer::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();
}
CNetworkSymbol* CNetworkEntityContainer::GetPrimaryLink()
/* ============================================================
Function : CNetworkEntityContainer::GetPrimaryLink
Description : Returns the primary object of the two
currently selected and linked.
Return : CNetworkSymbol* - Primary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected, or they are not linked.
============================================================*/
{
CNetworkSymbol* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
CNetworkSymbol* primary = NULL;
CNetworkSymbol* secondary = NULL;
for( int t = 0 ; t < max ; t++ )
{
CNetworkSymbol* obj = dynamic_cast< CNetworkSymbol* >( GetAt( t ) );
if( obj && obj->IsSelected() )
{
if( primary == NULL )
primary = obj;
else
secondary = obj;
}
}
if( primary && secondary )
{
CNetworkLink* link = FindLink( primary, secondary );
if( link )
{
if( primary->GetName() == link->from )
result = primary;
else
result = secondary;
}
}
}
return result;
}
CNetworkSymbol* CNetworkEntityContainer::GetPrimarySelected()
/* ============================================================
Function : CNetworkEntityContainer::GetPrimarySelected
Description : Returns the primary object of the two
currently selected.
Return : CNetworkSymbol* - Primary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected.
============================================================*/
{
CNetworkSymbol* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
for( int t = 0 ; t < max ; t++ )
{
CNetworkSymbol* obj = dynamic_cast< CNetworkSymbol* >( GetAt( t ) );
if( obj && obj->IsSelected() )
{
if( result == NULL )
result = obj;
}
}
}
return result;
}
CNetworkSymbol* CNetworkEntityContainer::GetSecondarySelected()
/* ============================================================
Function : CNetworkEntityContainer::GetSecondarySelected
Description : Returns the secondary object of the two
currently selected.
Return : CNetworkSymbol* - secondary object or
NULL if none.
Parameters : none
Usage : Returns NULL if not exactly two objects are
selected.
============================================================*/
{
CNetworkSymbol* result = NULL;
if( GetSelectCount() == 2 )
{
int max = GetSize();
for( int t = 0 ; t < max ; t++ )
{
CNetworkSymbol* obj = dynamic_cast< CNetworkSymbol* >( GetAt( t ) );
if( obj && obj->IsSelected() )
result = obj;
}
}
return result;
}
int CNetworkEntityContainer::GetSelectCount()
/* ============================================================
Function : int CNetworkEntityContainer::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++ )
{
CNetworkSymbol* obj = dynamic_cast< CNetworkSymbol* >( GetAt( t ) );
if( obj && obj->IsSelected() )
count++;
}
return count;
}
void CNetworkEntityContainer::AddLink( CNetworkLink* link )
/* ============================================================
Function : CNetworkEntityContainer::AddLink
Description : Adds a links to the link array.
Return : void
Parameters : CNetworkLink* link - Link to add
Usage : Call to add a link to the link array.
============================================================*/
{
m_links.Add( link );
}
BOOL CNetworkEntityContainer::CreateLink( CNetworkSymbol* from, CNetworkSymbol* to )
/* ============================================================
Function : CNetworkEntityContainer::CreateLink
Description : Creates a link between from and to and
puts it into the link-array.
Return : BOOL - TRUE if ok.
Parameters : CNetworkSymbol* from - From-object.
CNetworkSymbol* to - To-object.
Usage : Call to create a link between from and to.
============================================================*/
{
BOOL result = FALSE;
if( CanLink() )
{
CNetworkLink* link = new CNetworkLink;
link->from = from->GetName();
link->to = to->GetName();
m_links.Add( link );
result = TRUE;
}
return result;
}
void CNetworkEntityContainer::DeleteLink( CNetworkLink* inlink )
/* ============================================================
Function : CNetworkEntityContainer::DeleteLink
Description : Finds and deletes inlink from the internal
link array.
Return : void
Parameters : CNetworkLink* 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-- )
{
CNetworkLink* link = static_cast< CNetworkLink* >( m_links.GetAt( t ) );
if( link == inlink )
{
delete link;
m_links.RemoveAt( t );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -