📄 umlshow.cs
字号:
{
ElementData elementData = (ElementData)codeElementsData.Element[nElementIndex];
// That's means we must calculate it's first position
if( elementData.ExtendDataObject == null )
{
ItemDrawState itemDrawState = new ItemDrawState();
int LeftEdge = spaceCount;
for( int nIndex = 0; nIndex < currentDisplayElementList.Count; nIndex ++ )
{
ElementData tempData = (ElementData) currentDisplayElementList[nIndex];
ItemDrawState tempState = (ItemDrawState)tempData.ExtendDataObject;
LeftEdge += (int) tempState.GetSize( tempData.ElementType ).Width + spaceCount;
}
itemDrawState.Position.X = LeftEdge;
itemDrawState.Position.Y = spaceCount;
elementData.ExtendDataObject = itemDrawState;
AutoCalculateElementSize( g, elementData );
}
///**********************MODIFY*****************///
///For prevent display more same namespace
bool bFind = false;
for( int i = 0; i < currentDisplayElementList.Count ; i ++ )
{
if( ((ElementData)currentDisplayElementList[i]).Name == elementData.Name )
bFind = true;
}
if( !bFind )
{
ItemDrawState temp = (ItemDrawState) elementData.ExtendDataObject;
if( nMaxX < (temp.Position.X + (int)temp.GetSize(elementData.ElementType).Width) )
nMaxX = (temp.Position.X + (int)temp.GetSize(elementData.ElementType).Width);
if( nMaxY < (temp.Position.Y + (int)temp.GetSize(elementData.ElementType).Height) )
nMaxY = (temp.Position.Y + (int)temp.GetSize(elementData.ElementType).Height);
this.currentDisplayElementList.Add( elementData );
}
}
}
}
}
// Set the range
parentForm.AutoScrollMinSize = new Size( nMaxX + spaceCount, nMaxY + spaceCount );
currentDisplayPackage = codeData;
}
}
/// <summary>
/// Draw a elements
/// </summary>
/// <param name="g"></param>
/// <param name="elementData"></param>
public void DrawItem( Graphics g, ElementData elementData, Point ptOffset )
{
/// Check if this element has draw state descirpting
if( elementData.ExtendDataObject == null )
return;
// Dispatch Draw
if( elementData.ElementType == enumElementType.elementTypeClass ||
elementData.ElementType == enumElementType.elementTypeStruct )
{
ItemDrawState itemState = (ItemDrawState)elementData.ExtendDataObject;
itemState.Position.X += ptOffset.X;
itemState.Position.Y += ptOffset.Y;
DrawClassItem( g, elementData, ptOffset );
itemState.Position.X -= ptOffset.X;
itemState.Position.Y -= ptOffset.Y;
}
else if( elementData.ElementType == enumElementType.elementTypeInterface )
{
ItemDrawState itemState = (ItemDrawState)elementData.ExtendDataObject;
itemState.Position.X += ptOffset.X;
itemState.Position.Y += ptOffset.Y;
DrawInterfaceItem( g, elementData, ptOffset );
itemState.Position.X -= ptOffset.X;
itemState.Position.Y -= ptOffset.Y;
}
else if( elementData.ElementType == enumElementType.elementTypeNameSpace )
{
ItemDrawState itemState = (ItemDrawState)elementData.ExtendDataObject;
itemState.Position.X += ptOffset.X;
itemState.Position.Y += ptOffset.Y;
DrawNamespaceItem( g, elementData, ptOffset );
itemState.Position.X -= ptOffset.X;
itemState.Position.Y -= ptOffset.Y;
}
}
/// <summary>
/// Draw the class's relationship
/// </summary>
/// <param name="g"></param>
/// <param name="ptOffset"></param>
private void DrawRelationShip( Graphics g, Point ptOffset )
{
//check to see if the object hasn't been initializated
if( this.codeData == null || this.currentDisplayElementList.Count <= 0 || this.currentDisplayPackage == null )
return;
Pen penForeground = new Pen( Color.Black );
penForeground.DashStyle = DashStyle.Solid;
//Try to find all the object
for( int nIndex = 0; nIndex < this.currentDisplayElementList.Count; nIndex ++ )
{
ElementData elementData = (ElementData) this.currentDisplayElementList[nIndex];
if( elementData.ElementType == enumElementType.elementTypeClass )
{
ClassData itemData = (ClassData) elementData;
// First try to find the base class
for( int nBaseIndex = 0; nBaseIndex < itemData.BaseList.Count; nBaseIndex ++ )
{
String baseClassName = (String) itemData.BaseList[nBaseIndex];
// Search the display list to find the base class
for( int nDispListIndex = 0; nDispListIndex < this.currentDisplayElementList.Count; nDispListIndex ++ )
{
ElementData tempData = (ElementData)this.currentDisplayElementList[nDispListIndex];
if( baseClassName == tempData.Name )
{
// Find it, draw a line
ItemDrawState currentObjectState = (ItemDrawState) itemData.ExtendDataObject;
ItemDrawState tempState = (ItemDrawState) tempData.ExtendDataObject;
Rectangle rectBase = new Rectangle( tempState.Position, tempState.GetSize(tempData.ElementType).ToSize() );
Point ptCenterOfBase = new Point( rectBase.X + rectBase.Width/2, rectBase.Y + rectBase.Height/2 );
Point ptCurrentObject= new Point( currentObjectState.Position.X + (int) currentObjectState.GetSize(itemData.ElementType).Width/2,
currentObjectState.Position.Y + (int) currentObjectState.GetSize(itemData.ElementType).Height/2 );
Point ptCross = this.CalculateCrossPoint( rectBase, ptCenterOfBase, ptCurrentObject );
ptCurrentObject.Offset(ptOffset.X,ptOffset.Y);
ptCenterOfBase.Offset(ptOffset.X,ptOffset.Y);
ptCross.Offset(ptOffset.X,ptOffset.Y);
g.DrawLine( penForeground, ptCurrentObject, ptCenterOfBase );
}
}
}
}
}
}
/// <summary>
/// Help function
/// Help to calculte the cross point between the rectangle and the line
/// </summary>
/// <param name="rect">the object rectangle</param>
/// <param name="ptStart">the center of the object</param>
/// <param name="ptEnd">another object's center point</param>
/// <returns></returns>
private Point CalculateCrossPoint( Rectangle rect, Point ptStart, Point ptEnd )
{
Point ptResult = new Point( 0, 0 );
// Right Top
if( (ptEnd.X >= ptStart.X) && (ptEnd.Y <= ptStart.Y) )
{
// calculate the horizontal point
ptResult.Y = rect.Location.Y;
ptResult.X = ( (ptStart.X - ptEnd.X)/(ptStart.Y - ptEnd.Y)*(ptResult.Y - ptEnd.Y) )+ptEnd.X;
if( (ptResult.X >= ptStart.X) && (ptResult.X <= ptEnd.X ) )
return ptResult;
// otherwise try to find another vertical
ptResult.X = rect.Location.X + rect.Width;
ptResult.Y = ( (ptEnd.Y - ptStart.Y)/(ptEnd.X - ptStart.X)*(ptResult.X - ptStart.X ) )+ptStart.Y;
return ptResult;
}
// Left down
else if( (ptEnd.X <= ptStart.X) && (ptEnd.Y >= ptEnd.Y) )
{
// calculate the horizontal point
ptResult.Y = rect.Location.Y;
ptResult.X = ( (ptEnd.X - ptStart.X)/(ptEnd.Y - ptStart.Y)*(ptResult.Y - ptStart.Y) )+ptStart.X;
if( (ptResult.X >= ptEnd.X ) && ( ptResult.X <= ptStart.X) )
return ptResult;
// otherwise try to find another vertical
ptResult.X = rect.Location.X + rect.Width;
ptResult.Y = ( (ptEnd.Y - ptStart.Y)/(ptEnd.X - ptStart.X)*(ptResult.X - ptStart.X ) )+ptStart.Y;
return ptResult;
}
// left up
else if( (ptEnd.X <= ptStart.X ) && (ptEnd.Y <= ptEnd.Y) )
{
// calculate the horizontal point
ptResult.Y = rect.Location.Y;
ptResult.X = ( (ptEnd.X - ptStart.X)/(ptEnd.Y - ptStart.Y)*(ptResult.Y - ptStart.Y) )+ptStart.X;
if( (ptResult.X >= ptEnd.X ) && ( ptResult.X <= ptStart.X) )
return ptResult;
// otherwise try to find another vertical
ptResult.X = rect.Location.X;
ptResult.Y = ( (ptEnd.Y - ptStart.Y)/(ptEnd.X - ptStart.X)*(ptResult.X - ptStart.X ) )+ptStart.Y;
return ptResult;
}
else
{
// right down
// calculate the horizontal point
ptResult.Y = rect.Location.Y + rect.Height;
ptResult.X = ( (ptEnd.X - ptStart.X)/(ptEnd.Y - ptStart.Y)*(ptResult.Y - ptStart.Y) )+ptStart.X;
if( (ptResult.X >= ptStart.X ) && ( ptResult.X <= ptEnd.X) )
return ptResult;
// otherwise try to find another vertical
ptResult.X = rect.Location.X + rect.Width;
ptResult.Y = ( (ptEnd.Y - ptStart.Y)/(ptEnd.X - ptStart.X)*(ptResult.X - ptStart.X ) )+ptStart.Y;
return ptResult;
}
}
/// <summary>
/// Draw a class or struct....
/// </summary>
/// <param name="g"></param>
/// <param name="elementData"></param>
private void DrawClassItem( Graphics g, ElementData elementData, Point ptOffset )
{
ElementData drawData = elementData;
ItemDrawState itemState = (ItemDrawState) drawData.ExtendDataObject;
SolidBrush brushFront = new SolidBrush( itemState.FrontColor );
SolidBrush brushBack = new SolidBrush( itemState.BackColor );
Pen penFront = new Pen( itemState.FrontColor );
const int heightSpaceCount = 6;
/// *************Draw Background******************///
///
AutoCalculateClassElementSize( g, elementData );
g.FillRectangle( brushBack, itemState.Position.X, itemState.Position.Y,
itemState.nameSize.Width + heightSpaceCount/2, itemState.nameSize.Height );
g.FillRectangle( brushBack, itemState.Position.X, itemState.Position.Y + itemState.nameSize.Height,
itemState.variablesSize.Width + heightSpaceCount/2, itemState.variablesSize.Height );
g.FillRectangle( brushBack, itemState.Position.X, itemState.Position.Y + itemState.nameSize.Height + itemState.variablesSize.Height,
itemState.operationsSize.Width + heightSpaceCount/2, itemState.operationsSize.Height );
g.DrawRectangle( penFront, itemState.Position.X, itemState.Position.Y,
itemState.nameSize.Width + heightSpaceCount/2, itemState.nameSize.Height );
g.DrawRectangle( penFront, itemState.Position.X, itemState.Position.Y + itemState.nameSize.Height,
itemState.variablesSize.Width + heightSpaceCount/2, itemState.variablesSize.Height );
g.DrawRectangle( penFront, itemState.Position.X, itemState.Position.Y + itemState.nameSize.Height + itemState.variablesSize.Height,
itemState.operationsSize.Width + heightSpaceCount/2, itemState.operationsSize.Height );
// ****** Draw first name ***** //
// Calculate item size
SizeF sizeFontItem = new SizeF();
sizeFontItem = g.MeasureString( drawData.Name, itemState.ItemFont );
// ****** Draw Variable ***** //
Point variableStartPosition = new Point( (int)itemState.Position.X, (int)itemState.Position.Y + (int)itemState.nameSize.Height + heightSpaceCount/2 );
Point variablePosition = new Point( variableStartPosition.X, variableStartPosition.Y );
if( ! ( (int)( itemState.DrawState & enumDrawState.drawStateSuppressAttributes ) > 0 ) )
{
if( (int)( itemState.DrawState & enumDrawState.drawStateShowAttributes ) > 0 )
{
if( drawData.Element.Count > 0 )
{
for( int i = 0 ; i < drawData.Element.Count ; i ++ )
{
ElementData itemData = (ElementData) drawData.Element[i];
if( itemData.ElementType == enumElementType.elementTypeVariable )
{
if( (int)( itemState.DrawState & enumDrawState.drawStateShowVisibility ) > 0 )
{
Icon ico;
variablePosition.X = variableStartPosition.X;
// Load ico
if( itemData.AccessType == enumElementAccessType.accessTypePrivate ||
itemData.AccessType == enumElementAccessType.accessTypeProjectOrProtected ||
itemData.AccessType == enumElementAccessType.accessTypeProtected )
{
ico = iconVariablePrv;
}
else ico = iconVariablePub;
// Draw Item
Point ptIcon = new Point( variablePosition.X, variablePosition.Y - 8 );
g.DrawIconUnstretched( ico, new Rectangle( ptIcon, ico.Size ) );
variablePosition.X += ico.Size.Width;
}
// Prepare string...
String showString = itemData.Name + " : " +
itemData.PhotoType.phototypeType.Split(' ')[0];
// Draw String
g.DrawString( showString, itemState.ItemFont, brushFront, variablePosition );
variablePosition.Y += (int)sizeFontItem.Height;
}
else if( itemData.ElementType == enumElementType.elementTypeProperty )
{
if( (int)(itemState.DrawState & enumDrawState.drawStateShowVisibility) > 0 )
{
Icon ico;
variablePosition.X = variableStartPosition.X;
// Load ico
ico = iconProperty;
// Draw Item
Point ptIcon = new Point( variablePosition.X, variablePosition.Y - 8 );
g.DrawIconUnstretched( ico, new Rectangle( ptIcon, ico.Size ) );
variablePosition.X += ico.Size.Width;
}
// Prepare string...
String showString = itemData.Name + " : " +
itemData.PhotoType.phototypeType.Split(' ')[0];
// Draw String
g.DrawString( showString, itemState.ItemFont, brushFront, variablePosition );
variablePosition.Y += (int)sizeFontItem.Height;
}
}
}
}
}
// Draw operation
// ****** Draw operation ***** //
Point operationsStartPosition = new Point( (int)itemState.Position.X, (int)itemState.Position.Y + (int)itemState.nameSize.Height + (int) itemState.variablesSize.Height + heightSpaceCount/2 );
Point operationsPosition = new Point( operationsStartPosition.X, operationsStartPosition.Y );
if( ! ( (int)( itemState.DrawState & enumDrawState.drawStateSuppressOperations ) > 0 ) )
{
if( (int)( itemState.DrawState & enumDrawState.drawStateShowOperations ) > 0 )
{
if( drawData.Element.Count > 0 )
{
for( int i = 0 ; i < drawData.Element.Count ; i ++ )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -