Home | Products | Download | Purchase | Support 


   

LayoutPath Sample

 

The LayoutPath sample demonstrates how to load data from XML File and draw them on the canvas, then you can use the layer layout tool for layouting.

Steps:
// Line object
struct FOP_LINK_DATA
{

CString startid;
CString endid;
};


CFODrawShape *CLayoutPathView::FindShapeWithValue(const CString &strValue)
{

int
nCount = GetCurrentModel()->GetShapes()->GetCount();
for
(int x = 0; x < nCount; x++)
{

CFODrawShape *pShape = (CFODrawShape *)GetCurrentModel()->GetShapes()->GetObject(x);
if
(pShape->GetObjectName() == strValue)
{

return
pShape;
}
}


return
NULL;
}


CFODrawShape *CLayoutPathView::GetNode(const CPoint &ptStart, const CString &strNode)
{

CFORoundRectShape *pRect = new CFORoundRectShape;
pRect->AddRef();
CRect rc(ptStart, CSize(200, 100));
pRect->Create(rc);
pRect->SetObjectCaption(strNode);
pRect->SetObjectName(strNode);
pRect->SetShowLabelAtFirst(TRUE);
pRect->SetMultiLine(TRUE);
pRect->AllowTextWrap(TRUE);
pRect->SetPointSize(10);
pRect->SetBrushType(1);
pRect->SetLineColor(RGB(0,123,0));
pRect->SetLineWidth(2);
pRect->SetWeight(700);
pRect->SetFontColor(RGB(0,128,255));

return
pRect;
}


CFOLinkShape *CLayoutPathView::AddLinkShapeNoUndo(CFODrawPortsShape *pFirst,CFODrawPortsShape *pSecond,
  const
int &nLinkType, const int &nArrowType)
{

CFOPortShape *pStart = pFirst->GetCenterPort();
CFOPortShape *pEnd = pSecond->GetCenterPort();

if
(pStart == NULL || pEnd == NULL)
{

return
NULL;
}


CFOLinkShape * pLinkComp = NULL;


switch
(nLinkType)
{

case
FO_COMP_LINK: //CFOLinkShape
{
pLinkComp = new CFOLinkShape;
}

break
;

case
FOP_COMP_TURNCORNERLINK:
{

pLinkComp = new CFOTurnCornerLinkShape;
}

break
;

case
FOP_ROUND_TURNCORNER_LINKSHAPE:
{

pLinkComp = new CFORoundTurnCornerLinkShape;
}

break
;

case
FOP_COMP_BREAKCENTERLINK:
{

pLinkComp = new CFOPBreakCenterLinkShape;
}

break
;

case
FO_COMP_UPRIGHTLINK://CFOUpRightLinkShape
{
pLinkComp = new CFOUpRightLinkShape;
}

break
;

case
FOP_ROUND_UPRIGHT_LINKSHAPE://CFOPRoundUpRightLinkShape
{
pLinkComp = new CFOPRoundUpRightLinkShape;
}

break
;

case
FO_COMP_CORNERLINK://CFOCornerLinkShape
{
pLinkComp = new CFOCornerLinkShape;
}

break
;

case
FO_COMP_EXT_CORNERLINK://CFOPExtCornerLinkShape
{
pLinkComp = new CFOPExtCornerLinkShape;
}

break
;

case
FO_COMP_BEZIERLINK://CFOBezierLinkShape
{
pLinkComp = new CFOBezierLinkShape;
}

break
;

case
FOP_NEW_SINGLEARROW_LINKSHAPE://CFOPNewSingleArrowLinkShape
{
pLinkComp = new CFOPNewSingleArrowLinkShape;
}

break
;

case
FOP_NEW_REVERSE_SINGLEARROW_LINKSHAPE://CFOPNewReverseSingleArrowLinkShape
{
pLinkComp = new CFOPNewReverseSingleArrowLinkShape;
}

break
;

case
FOP_NEW_DOUBLEARROW_LINKSHAPE://CFOPNewDoubleArrowLinkShape
{
pLinkComp = new CFOPNewDoubleArrowLinkShape;
}

break
;

case
FOP_NEW_SIMPLE_LINKSHAPE:
{

pLinkComp = new CFOPNewSimpleLinkShape;

}

break
;

case
FOP_NEW_LINEAR_LINKSHAPE://CFOPNewLinearLinkShape
{
pLinkComp = new CFOPNewLinearLinkShape;
}

break
;

case
FOP_NEW_CURVE_LINKSHAPE://CFOPNewCurveLinkShape
{
pLinkComp = new CFOPNewCurveLinkShape;
}

break
;

case
FOP_NEW_COMM_LINKSHAPE://CFOPCommLinkShape
{
pLinkComp = new CFOPCommLinkShape;
}

break
;

case
FOP_COMP_EXTLINKSHAPE:
{

pLinkComp = new CFOPExtLinkShape;
}

break
;

default
:
{

pLinkComp = new CFOLinkShape;
}

break
;
}

pLinkComp->AddRef();
CPoint ptPoints[2];
ptPoints[0] = pStart->GetLinkPoint();
ptPoints[1] = pEnd->GetLinkPoint();
pLinkComp->Create(ptPoints,2);

pLinkComp->SetFromPort(pStart);
pLinkComp->SetToPort(pEnd);

pLinkComp->SetLineWidth(2);
pLinkComp->SetShadow(FALSE);
pLinkComp->SetLineColor(RGB(0,0,51));

pStart->AddLinkShape(pLinkComp);
pEnd->AddLinkShape(pLinkComp);

// Set arrow type.
int nType = nArrowType;
pLinkComp->SetEndArrowType(nType);
GetCurrentModel()->AddChildAtTail(pLinkComp);
pLinkComp->UpdateComp();
pLinkComp->RelayoutPoints();
pLinkComp->Release();

return
pLinkComp;
}


void
CLayoutPathView::OnFoAddNewpage()
{

// TODO: Add your command handler code here
CExtDataModel *pDataModel = (CExtDataModel *)GetCurrentModel();
if
(NULL == pDataModel)
return
;

OnFOPEditClearAll();

AfxGetApp()->BeginWaitCursor();
// TODO: Add your command handler code here
CFODrawShapeSet setNodes;

CString strXMLFile;
CString strPathX = AfxGetApp()->m_pszHelpFilePath;
strPathX = strPathX.Left(strPathX.ReverseFind('\\'));
CString strOtherFile;
strXMLFile = strPathX+_T("\\data.xml");
CArray<FOP_LINK_DATA,FOP_LINK_DATA> m_arLinks;
CXDXml xml;
if
(TRUE == xml.Load(strXMLFile))
{

BOOL bFirst = TRUE;
int
nOffset = 20;
CPoint ptStart = CPoint(20,20);
CFODrawShape *pFirst = NULL;
CXDXmlNode xmlNode2 = xml.GetNode(_T("graph"));
CXDXmlNode xmlNode = xmlNode2.GetNodeList(_T("b"));
for
(int i = 0; i<xmlNode.GetNodeListSize(); i++)
{

CXDNamedNode nameNode = xmlNode.GetNamedNode();
CString strName = nameNode.GetNodeText("w");
CString strStart = nameNode.GetNodeText("l");

CFODrawShape *pFirst = FindShapeWithValue(strName);
if
(pFirst == NULL)
{

pFirst = GetNode(ptStart, strName);
GetCurrentModel()->GetShapes()->AddTail(pFirst);
pFirst->Release();
}


CFODrawShape *pSecond = FindShapeWithValue(strStart);
if
(pSecond == NULL)
{

pSecond = GetNode(ptStart, strStart);
GetCurrentModel()->GetShapes()->AddTail(pSecond);
pSecond->Release();
}


FOP_LINK_DATA linkdata;
linkdata.startid = strName;
linkdata.endid = strStart;
m_arLinks.Add(linkdata);

ptStart += CPoint(nOffset, nOffset);

xmlNode.GetNextNode();
}


for
(int x = 0; x < m_arLinks.GetSize(); x++)
{

FOP_LINK_DATA linkdata = m_arLinks.GetAt(x);
CString nStartId = linkdata.startid;
CString nEndId = linkdata.endid;

CFODrawPortsShape *pStart = (CFODrawPortsShape *)FindShapeWithValue(nStartId);
CFODrawPortsShape *pEnd = (CFODrawPortsShape *)FindShapeWithValue(nEndId);

if
(pStart != NULL && pEnd != NULL)
{

AddLinkShapeNoUndo(pStart, pEnd, FO_COMP_LINK, 1);
}
}


// ptCenter = pFirst->GetCenterPoint();

// SelectNewShape(pFirst);


}


SetLogCenter(500,200);

AfxGetApp()->EndWaitCursor();
}


void
CLayoutPathView::OnFoRemovePage()
{

// TODO: Add your command handler code here
CFOPLayeredLayout layout1;
layout1.Initialize(GetCurrentModel(), *GetCurrentModel()->GetFormObjects());
layout1.DoLayoutNew();

CFODrawShape *pShow = NULL;
BOOL bFirst = TRUE;
int
nCount = GetCurrentModel()->GetShapes()->GetCount();
for
(int x2 = 0; x2 < nCount; x2++)
{

CFODrawShape *pShape = (CFODrawShape *)GetCurrentModel()->GetShapes()->GetObject(x2);
pShape->OffsetAllPoints(40,100);
if
(bFirst)
{

pShow = pShape;
bFirst = FALSE;
}
}


if
(pShow)
{

SetLogCenter(pShow->GetSnapRect().CenterPoint().x, pShow->GetSnapRect().CenterPoint().y
);
}
}

 

 


[ Home | Products | Download Area | Purchase | SupportContact us ]


Copyright ?1998-2007 UCanCode.Net Software, all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.com