📄 umlentitycontainer.cpp
字号:
}
void CUMLEntityContainer::DeleteDanglingLines()
/* ============================================================
Function : CUMLEntityContainer::DeleteDanglingLines
Description : Deletes all non-attached lines in the
container.
Access : Public
Return : void
Parameters : none
Usage : Call to clean up all non-attached lines.
Lines are not allowed to be unlinked in
either end. This function makes sure that
no lines are left unattached.
============================================================*/
{
for( int t = 0 ; t < GetSize() ; t++ )
{
CUMLLineSegment* obj = dynamic_cast< CUMLLineSegment* >( GetAt( t ) );
if( obj )
{
CUMLEntity* end = GetEndNode( obj );
CUMLEntity* start = GetStartNode( obj );
if( !end || !start )
{
Remove( obj );
t = 0;
}
}
}
}
CDiagramEntity* CUMLEntityContainer::GetAt( int index ) const
/* ============================================================
Function : CUMLEntityContainer::GetAt
Description : Gets the object at "index"
Access : Public
Return : CDiagramEntity* - Object, or "NULL" if out of bounds.
Parameters : int index - Index to get object from
Usage : Call to get the object at "index". The
function will only return objects in the
current package, unless the package name
is set to 'all'.
If the object at this index resides in
another package, a pointer to a
"CUMLEntityDummy"-object will be returned.
============================================================*/
{
CUMLEntityContainer* const local = const_cast<CUMLEntityContainer* const>(this);
CObArray* objs = local->GetData();
CUMLEntity* result = NULL;
if( index < objs->GetSize() && index >= 0 )
{
result = static_cast< CUMLEntity* >( objs->GetAt( index ) );
if( GetPackage() != _T( "all" ) && result->GetPackage() != GetPackage() )
result = &( local->m_dummy );
}
return result;
}
void CUMLEntityContainer::SetPackage( const CString& package )
/* ============================================================
Function : CUMLEntityContainer::SetPackage
Description : Sets the current package.
Access : Public
Return : void
Parameters : const CString& package - New package
Usage : Call to set the current package. Many
operations only work on things in the
current package. Note that if the package
is set to 'all', all objects are accessible.
============================================================*/
{
m_package = package;
}
CString CUMLEntityContainer::GetPackage() const
/* ============================================================
Function : CUMLEntityContainer::GetPackage
Description : Gets the current package.
Access : Public
Return : CString - Current package
Parameters : none
Usage : Call to get the current package. Many
operations only work on things in the
current package. Note that if the package
is set to 'all', all objects are accessible.
============================================================*/
{
return m_package;
}
CUMLEntity* CUMLEntityContainer::GetObjectAt( int index ) const
/* ============================================================
Function : CUMLEntityContainer::GetObjectAt
Description : Convenience function to get the object at
"index", already cast to a "CUMLEntity"
pointer.
Access : Public
Return : CUMLEntity* - Object at "index", or "NULL" if out of bounds.
Parameters : int index - Index to get object from
Usage : Call to get the object at "index".
============================================================*/
{
CUMLEntity* result = static_cast< CUMLEntity* >( GetAt( index ) );
return result;
}
void CUMLEntityContainer::AdjustLinkedObjects( CUMLEntity* in, CUMLEntity* filter )
/* ============================================================
Function : CUMLEntityContainer::AdjustLinkedObjects
Description : Moves all objects in relation to "in",
skipping "filter".
Access : Public
Return : void
Parameters : CUMLEntity* in - Object to move in relation to
CUMLEntity* filter - Optional object to skip.
Usage : Call to adjust the positions of objects
attached to "in" when it is moved.
============================================================*/
{
CPoint point;
CPoint objpoint;
double posdiff = 0.0;
CString name = in->GetName();
CString link;
int linktype;
CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( in );
if( line )
{
link = line->GetLink( LINK_END );
if( link.GetLength() && link != name )
{
CUMLEntity* obj = static_cast< CUMLEntity* >( GetNamedObject( link ) );
if( obj && obj != filter && !obj->IsSelected() )
{
objpoint = line->GetLinkPosition( LINK_END );
linktype = line->GetLinkType( LINK_END );
if( linktype == LINK_TOP )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.x - linkpoint.x;
if( posdiff )
{
obj->MoveRect( posdiff, 0 );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_BOTTOM )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.x - linkpoint.x;
if( posdiff )
{
obj->MoveRect( posdiff, 0 );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_RIGHT )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.y - linkpoint.y;
if( posdiff )
{
obj->MoveRect( 0, posdiff );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_LEFT )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.y - linkpoint.y;
if( posdiff )
{
obj->MoveRect( 0, posdiff );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_START )
{
CRect first = obj->GetRect();
obj->SetLeft( objpoint.x );
obj->SetTop( objpoint.y );
if( static_cast< CUMLLineSegment* >( obj )->IsHorizontal() )
obj->SetBottom( obj->GetTop() );
else
obj->SetRight( obj->GetLeft() );
if( first != obj->GetRect() )
AdjustLinkedObjects( obj, in );
}
if( linktype == LINK_END )
{
CRect first = obj->GetRect();
obj->SetRight( objpoint.x );
obj->SetBottom( objpoint.y );
if( static_cast< CUMLLineSegment* >( obj )->IsHorizontal() )
obj->SetTop( obj->GetBottom() );
else
obj->SetLeft( obj->GetRight() );
if( first != obj->GetRect() )
AdjustLinkedObjects( obj, in );
}
}
}
link = line->GetLink( LINK_START );
if( link.GetLength() && link != name )
{
CUMLEntity* obj = static_cast< CUMLEntity* >( GetNamedObject( link ) );
if( obj && obj != filter && !obj->IsSelected() )
{
objpoint = line->GetLinkPosition( LINK_START );
linktype = line->GetLinkType( LINK_START );
if( linktype == LINK_TOP )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.x - linkpoint.x;
if( posdiff )
{
obj->MoveRect( posdiff, 0 );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_BOTTOM )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.x - linkpoint.x;
if( posdiff )
{
obj->MoveRect( posdiff, 0 );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_RIGHT )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.y - linkpoint.y;
if( posdiff )
{
obj->MoveRect( 0, posdiff );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_LEFT )
{
CPoint linkpoint = GetLinkPosition( obj, line );
posdiff = objpoint.y - linkpoint.y;
if( posdiff )
{
obj->MoveRect( 0, posdiff );
AdjustLinkedObjects( obj, in );
}
}
if( linktype == LINK_START )
{
CRect first = obj->GetRect();
obj->SetLeft( objpoint.x );
obj->SetTop( objpoint.y );
if( static_cast< CUMLLineSegment* >( obj )->IsHorizontal() )
obj->SetBottom( obj->GetTop() );
else
obj->SetRight( obj->GetLeft() );
if( first != obj->GetRect() )
AdjustLinkedObjects( obj, in );
}
if( linktype == LINK_END )
{
CRect first = obj->GetRect();
obj->SetRight( objpoint.x );
obj->SetBottom( objpoint.y );
if( static_cast< CUMLLineSegment* >( obj )->IsHorizontal() )
obj->SetTop( obj->GetBottom() );
else
obj->SetLeft( obj->GetRight() );
if( first != obj->GetRect() )
AdjustLinkedObjects( obj, in );
}
}
}
}
else
{
CUMLEntity* obj = NULL;
int count = 0;
while( ( obj = GetObjectAt( count++ ) ) )
{
if( obj->GetPackage() == GetPackage() )
{
if( obj != in )
{
CUMLLineSegment* line = dynamic_cast< CUMLLineSegment* >( obj );
if( line )
{
link = line->GetLink( LINK_START );
if( link == name )
{
if( line && line != filter && !line->IsSelected() )
{
linktype = line->GetLinkType( LINK_START );
objpoint = GetLinkPosition( in, line );
CRect first = line->GetRect();
if( linktype == LINK_RIGHT || linktype == LINK_LEFT )
{
line->SetTop( objpoint.y );
line->SetLeft( objpoint.x );
line->SetBottom( objpoint.y );
}
if( linktype == LINK_TOP || linktype == LINK_BOTTOM )
{
line->SetTop( objpoint.y );
line->SetLeft( objpoint.x );
line->SetRight( objpoint.x );
}
if( linktype == LINK_END )
{
line->SetLeft( objpoint.x );
line->SetTop( objpoint.y );
if( line->IsHorizontal() )
line->SetBottom( objpoint.y );
else
line->SetRight( objpoint.x );
}
if( linktype == LINK_START )
{
line->SetRight( objpoint.x );
line->SetBottom( objpoint.y );
if( line->IsHorizontal() )
line->SetTop( objpoint.y );
else
line->SetLeft( objpoint.x );
}
if( first != line->GetRect() )
AdjustLinkedObjects( line, in );
}
}
link = line->GetLink( LINK_END );
if( link == name )
{
if( line && line != filter && !line->IsSelected() )
{
objpoint = GetLinkPosition( in, line );
linktype = line->GetLinkType( LINK_END );
CRect first = line->GetRect();
if( linktype == LINK_RIGHT || linktype == LINK_LEFT )
{
line->SetBottom( objpoint.y );
line->SetRight( objpoint.x );
line->SetTop( objpoint.y );
}
if( linktype == LINK_TOP || linktype == LINK_BOTTOM )
{
line->SetBottom( objpoint.y );
line->SetRight( objpoint.x );
line->SetLeft( objpoint.x );
}
if( linktype == LINK_END )
{
line->SetLeft( objpoint.x );
line->SetTop( objpoint.y );
if( line->IsHorizontal() )
line->SetBottom( objpoint.y );
else
line->SetRight( objpoint.x );
}
if( linktype == LINK_START )
{
line->SetRight( objpoint.x );
line->SetBottom( objpoint.y );
if( line->IsHorizontal() )
line->SetTop( objpoint.y );
else
line->SetLeft( objpoint.x );
}
if( first != line->GetRect() )
AdjustLinkedObjects( line, in );
}
}
}
}
}
}
}
}
void CUMLEntityContainer::ReduceLine( CUMLLineSegment* line )
/* ============================================================
Function : CUMLEntityContainer::ReduceLine
Description : Removes adjacent line segments with the
same orientation.
Access : Public
Return : void
Parameters : CUMLLineSegment* line - Line to check
Usage : Expands segments to cover a complete
horizontal or vertical stretch.
============================================================*/
{
SetDefaultLineStyle( line );
CUMLLineSegment* test = GetPrevSegment( line );
if( test )
{
if( ( line->IsHorizontal() && test->IsHorizontal() ) ||
( !line->IsHorizontal() && !test->IsHorizontal() ) )
{
// We have found two lines with the same orientation
// attached to each other. The second line should
// swallow the first one
// Setting start values from test to line
line->SetLeft( test->GetLeft() );
line->SetTop( test->GetTop() );
// Assign the start link from test to line
line->SetLink( LINK_START, test->GetLink( LINK_START ) );
line->SetLinkType( LINK_START, test->GetLinkType( LINK_START ) );
line->SetOffset( LINK_START, test->GetOffset( LINK_START ) );
// If we have an end link to test,
// we must rename it as well
CUMLLineSegment* prev = GetPrevSegment( test );
if( prev )
prev->SetLink( LINK_END, line->GetName() );
// Remove test
int index = Find( test );
GetData()->RemoveAt( index );
delete test;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -