📄 flowcharteditor.cpp
字号:
Return : void
Parameters : UINT nChar - Not used
UINT nRepCnt - Not used
UINT nFlags - Not used
Usage : Called from MFC
============================================================*/
{
SetRedraw( FALSE );
CDiagramEditor::OnKeyDown( nChar, nRepCnt, nFlags );
ModifyLinkedPositions();
SetRedraw( TRUE );
RedrawWindow();
}
/////////////////////////////////////////////////////////////////////////////
// CFlowchartEditor private helpers
void CFlowchartEditor::ModifyLinkedPositions()
/* ============================================================
Function : CFlowchartEditor::ModifyLinkedPositions
Description : Will modify the position of all unselected
items linked to a selected one, with the
difference between start and current as
offset. Movement direction is dependent on
the link type.
Return : void
Parameters : none
Usage : Should be called after all operations that
might move an object.
============================================================*/
{
int max = GetObjectCount();
CFlowchartEntity* obj;
for( int t = 0 ; t < max ; t++ )
{
obj = dynamic_cast< CFlowchartEntity* >( GetObject( t ) );
if( obj && obj->IsSelected() )
AdjustLinkedObjects( obj );
}
max = GetObjectCount();
for( t = 0 ; t < max ; t++ )
{
obj = dynamic_cast< CFlowchartEntity* >( GetObject( t ) );
if( obj )
obj->SetMoved( FALSE );
}
}
void CFlowchartEditor::AdjustLinkedObjects( CFlowchartEntity* parent, CFlowchartEntity* filter )
/* ============================================================
Function : CFlowchartEditor::AdjustLinkedObjects
Description : The function adjusts all objects attached
to parent, except filter (filter is assumed
to be last iteration's parent).
Return : void
Parameters : CFlowchartEntity* parent - The object to
find attached
links to.
CFlowchartEntity* filter - Object attached
to parent that
is not to be
moved.
Usage : The function is called to recursively adjust
the positions of objects attached to an
object being moved.
============================================================*/
{
parent->SetMoved( TRUE );
BOOL moved = FALSE;
CString name1 = parent->GetName();
CString name2;
double sizediff = 0.0;
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
if( objs )
{
int max = objs->GetLinks();
for( int t = 0 ; t < max ; t++ )
{
CFlowchartLink* link = objs->GetLinkAt( t );
if( link )
{
int fromtype = link->fromtype;
int totype = link->totype;
name2= _T( "" );
if( link->from == parent->GetName() )
name2 = link->to;
else if( link->to == parent->GetName() )
{
fromtype = link->totype;
totype = link->fromtype;
name2 = link->from;
}
if( name2.GetLength() )
{
CFlowchartEntity* obj = GetNamedObject( name2 );
if( obj && obj != filter && !obj->GetMoved() )
{
CPoint source;
CPoint target;
source = parent->GetLinkPosition( fromtype );
target = obj->GetLinkPosition( totype );
moved = FALSE;
switch( fromtype )
{
case LINK_LEFT:
sizediff = source.y - target.y;
obj->MoveRect( 0, source.y - target.y );
break;
case LINK_RIGHT:
sizediff = source.y - target.y;
obj->MoveRect( 0, source.y - target.y );
break;
case LINK_TOP:
sizediff = source.x - target.x;
obj->MoveRect( source.x - target.x, 0 );
break;
case LINK_BOTTOM:
sizediff = source.x - target.x;
obj->MoveRect( source.x - target.x, 0 );
break;
default:
switch( totype )
{
case LINK_LEFT:
sizediff = source.y - target.y;
obj->MoveRect( 0, source.y - target.y );
break;
case LINK_RIGHT:
sizediff = source.y - target.y;
obj->MoveRect( 0, source.y - target.y );
break;
case LINK_TOP:
sizediff = source.x - target.x;
obj->MoveRect( source.x - target.x, 0 );
break;
case LINK_BOTTOM:
sizediff = source.x - target.x;
obj->MoveRect( source.x - target.x, 0 );
break;
}
break;
}
if( sizediff )
AdjustLinkedObjects( obj, parent );
}
}
}
}
}
}
CFlowchartEntity* CFlowchartEditor::GetNamedObject( const CString& name ) const
/* ============================================================
Function : CFlowchartEditor::GetNamedObject
Description : Returns the object with the name attribute
name.
Return : CFlowchartEntity* - The object, or NULL
if not found.
Parameters : const CString& name - The name of the
object to find.
Usage : Call to get the object with the name name,
if it exists.
============================================================*/
{
CDiagramEntity* result = NULL;
int count = GetObjectCount();
CDiagramEntity* obj;
for( int t = 0 ; t < count ; t++ )
{
obj = GetObject( t );
if( obj && obj->GetName() == name )
result = obj;
}
return dynamic_cast< CFlowchartEntity* >( result );
}
/////////////////////////////////////////////////////////////////////////////
// CFlowchartEditor command handlers
void CFlowchartEditor::OnLink()
/* ============================================================
Function : CFlowchartEditor::OnLink
Description : Command handler for the Link command.
Return : void
Parameters : none
Usage : Called internally.
============================================================*/
{
if( CanLink() )
{
// Get the two selected objects
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
CFlowchartEntity* primary = objs->GetPrimarySelected();
CFlowchartEntity* secondary = objs->GetSecondarySelected();
if( primary && secondary )
{
GetDiagramEntityContainer()->Snapshot();
// Link them
if( objs->CreateLink( primary, secondary, _T( "" ) ) )
{
// Move other objects already linked to the secondary
AdjustLinkedObjects( primary );
int max = GetObjectCount();
for( int t = 0 ; t < max ; t++ )
{
CFlowchartEntity* obj = dynamic_cast< CFlowchartEntity* >( GetObject( t ) );
if( obj )
obj->SetMoved( FALSE );
}
RedrawWindow();
}
}
}
}
void CFlowchartEditor::OnUnlink()
/* ============================================================
Function : CFlowchartEditor::OnUnlink
Description : Command handler for the Break link command.
Return : void
Parameters : none
Usage : Called internally.
============================================================*/
{
if( IsLinked() )
{
// Get the two selected objects
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
CDiagramEntity* primary = objs->GetPrimaryLink();;
CDiagramEntity* secondary = objs->GetSecondaryLink();
if( primary && secondary )
{
CFlowchartLink* link = objs->FindLink( primary, secondary );
if( link )
{
GetDiagramEntityContainer()->Snapshot();
objs->DeleteLink( link );
RedrawWindow();
}
}
}
}
void CFlowchartEditor::OnLinkDirection()
/* ============================================================
Function : CFlowchartEditor::OnLinkDirection
Description : Command handler for the Flip link direction
command.
Return : void
Parameters : none
Usage : Called internally.
============================================================*/
{
if( IsLinked() )
{
// Get the two selected objects
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
CFlowchartEntity* primary = objs->GetPrimaryLink();
CFlowchartEntity* secondary = objs->GetSecondaryLink();
if( primary && secondary )
{
CFlowchartLink* link = objs->FindLink( primary, secondary );
if( link )
{
GetDiagramEntityContainer()->Snapshot();
CString saved = link->from;
link->from = link->to;
link->to = saved;
int fromtype = link->fromtype;
int totype = link->totype;
link->fromtype = totype;
link->totype = fromtype;
RedrawWindow();
}
}
}
}
void CFlowchartEditor::OnLinkProperties()
/* ============================================================
Function : CFlowchartEditor::OnLinkProperties
Description : Command handler for the Link title command.
Return : void
Parameters : none
Usage : Called internally.
============================================================*/
{
if( IsLinked() )
{
// Get the two selected objects
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
CFlowchartEntity* primary = objs->GetPrimaryLink();
CFlowchartEntity* secondary = objs->GetSecondaryLink();
if( primary && secondary )
{
CFlowchartLink* link = objs->FindLink( primary, secondary );
if( link )
{
CFlowchartLinkPropertiesDialog dlg;
dlg.m_linkTitle = link->title;
if( dlg.DoModal() )
{
GetDiagramEntityContainer()->Snapshot();
link->title = dlg.m_linkTitle;
RedrawWindow();
SetFocus();
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CFlowchartEditor implementation
BOOL CFlowchartEditor::CanLink()
/* ============================================================
Function : CFlowchartEditor::CanLink
Description : Will check if the currently selected items
can be linked to each other.
Return : BOOL - TRUE if the currently selected
items can be linked.
Parameters : none
Usage : Call from - for example - a command enabler
to see if linking is currently possible.
============================================================*/
{
BOOL result = FALSE;
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
if( objs )
result = objs->CanLink();
return result;
}
BOOL CFlowchartEditor::IsLinked()
/* ============================================================
Function : CFlowchartEditor::IsLinked
Description : Checks if the currently selected items are
linked to each other.
Return : BOOL - TRUE if they are linked.
Parameters : none
Usage : Call from - for example - a command enabler
to see if the currently selected items are
linked.
============================================================*/
{
BOOL result = FALSE;
CFlowchartEntityContainer* objs = dynamic_cast< CFlowchartEntityContainer * >( GetDiagramEntityContainer() );
if( objs )
result = objs->IsLinked();
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -