Grapher > グラファー・パッケージの機能 > グラファーのリンク > カスタム・グラファー・リンクの作成
 
カスタム・グラファー・リンクの作成
このセクションでは、以下の要件を満たすグラファー・リンクを作成するために IlvLinkImage をサブククラス化します。
*リンクは常に 2 つのノード間の直線として描画されます。
*開始点は接続ピンで定義されているか、または開始ノードの中央にあります。
*終点は、開始点にもっとも近い終了ノードの接面に対してリンクが直角に保たれる位置とします。これができなければ、終点はノード・バウンディング・ボックスのもっとも近い角に置かれます。
リンクはベース・クラス IlvLinkImage と同じ方法で描画されます。そのため、IlvGraphic から継承された関連メソッドは変更されずに残ります。また、リンクの形状を定義する点は 2 つしかありません (2 つの終点。中間点はなし)。リンク定義には 2 つの方法があります。IlvLinkImage::getLinkPoints メソッドまたは IlvLinkImage::computePoints メソッドをオーバーロードします。この例では
2 番目の方法を使っています。
void
MyLink::computePoints(IlvPoint& src,
IlvPoint& dst,
const IlvTransformer* t) const
{
//== [1] ==
IlvGrapherPin* pin = IlvGrapherPin::Get(getFrom());
if (!pin || !pin->getLinkLocation(getFrom(),this,t,src)) {
IlvRect bbox;
getFrom()->boundingBox(bbox,t);
src.move(bbox.centerx(),bbox.centery());
}
 
//== [2] ==
IlvRect toBBox;
getTo()->boundingBox(toBBox,t);
if (src.x()<toBBox.x()) {
if (src.y() < toBBox.y()) // Upper left quadrant
dst.move(toBBox.x(),
toBBox.y());
else if (src.y() >= toBBox.bottom()) // Lower left quadrant
dst.move(toBBox.x(),
toBBox.y()+toBBox.h()-1);
else // Left quadrant
dst.move(toBBox.x(),
src.y());
} else if (src.x()>=toBBox.right()) {
if (src.y() < toBBox.y()) // Upper right quadrant
dst.move(toBBox.x()+toBBox.w()-1,
toBBox.y());
else if (src.y() >= toBBox.bottom()) // Lower right quadrant
dst.move(toBBox.x()+toBBox.w()-1,
toBBox.y()+toBBox.h()-1);
else // Right quadrant
dst.move(toBBox.x()+toBBox.w()-1,
src.y());
} else {
if (src.y() < toBBox.y()) // Upper quadrant
dst.move(src.x(),
toBBox.y());
else if (src.y() >= toBBox.bottom()) // Lower quadrant
dst.move(src.x(),
toBBox.y()+toBBox.h()-1);
else // src inside toBBox
dst.move(toBBox.centerx(),toBBox.centery());
}
}
コードの最初の部分 ([1]) で、この開始ノードに定義されている接続ピンにリンクが付加されているかどうかの検証が行われます。付加されていない場合には、このノードのバウンディング・ボックスの中央を返します。
開始点の位置が計算されると、終了ノードのバウンディング・ボックスに対する開始点の位置が検証されます ([2])。可能なパターンは 9 つあり (toBBox で定義される 8 つの四分円と、開始点が toBBox の中にある場合)、それぞれは独自の位置を定義します。

Version 6.0
Copyright © 2015, Rogue Wave Software, Inc. All Rights Reserved.