Grapher > グラファー・パッケージの機能 > グラファーのリンク > 接続ピン
 
接続ピン
接続ピンにより、グラファー・ノードのリンク終点の正確な位置を制御できます。リンクが接続ピンに付加されると、接続点は開始ノードと終了ノードの相対的な位置を問わず、同じ場所に固定されます。
このセクションでは、次の項目を説明します。
*接続ピン管理クラス
*多目的 IlvGrapherPin サブクラス
*IlvGrapherPin クラスの拡張
接続ピン管理クラス
IlvGrapherPin抽象クラスは、接続ピンの集合を処理するためのものです。1 つ目の目標は、リンクとピンの結合を維持することです。そのため、ピンはインデックスにより参照されます。IlvGrapherPin::setPinIndex メソッドにより、特定の接続ピンへリンクを接続できます。
IlvLinkImage* link = ?;
//== Recover the IlvGrapherPin instance associated with the starting node
IlvGrapherPin* pin = IlvGrapherPin::Get(link->getFrom());
//== Connect the link to the pin whose index is 0
pin->setPinIndex(link,0,IlvTrue);
同様に、IlvGrapherPin::getPinIndex メソッドを使用して、リンクの付加されている接続ピンのインデックスを復元できます。
IlvGrapherPin クラスの 2 つ目の目的は、特定のノードで使用できる接続点の座標を問い合わせるインターフェースを提供することです。それぞれの具体的なサブクラスは、IlvGrapherPin::getCardinal メソッドと getLocation メソッドの実装を提供する必要があります。
virtual IlvUInt getCardinal(const IlvGraphic* node,
const IlvTransformer* t) const;
このメソッドは、トランスフォーマー t で表示されるときに指定されたノード node のインスタンスが処理する接続ピンの数を返します。
virtual IlvBoolean getLocation(IlvUInt pinIndex,
const IlvGraphic* node,
const IlvTransformer* t,
IlvPoint& where) const;
このメソッドは where パラメーターに、トランスフォーマー t. で表示されるときにノード node のインデックス pinIndex で指定される接続ピンの座標を返します。
このインターフェースのその他のメソッド (getClosestIlvGrapherPin::getLinkLocation など) には、オーバーロード可能なデフォルト実装があります。たとえば、getClosest メソッドは使用可能なすべての接続ピンを考慮し、getLocation メソッドを使用します。このメソッドを次のように変更できます。
*より迅速に実装を提供する (getLocation には、getClosest でしか実行できない演算が含まれる可能性があります)。
*もっとも距離が近いものではなく最初の未使用のピンを返す。
多目的 IlvGrapherPin サブクラス
IlvGenericPin クラスは IlvGrapherPin の定義済みの具体的なサブクラスで、これにより接続ピンをノードに動的に定義できます。新しい接続ピンは、特定のトランスフォーマーによって表示されるときに、ノード上の希望位置に指定されます。この位置が格納されると、IlvGenericPin クラスは適用されたトランスフォーマーとは関係なく、接続ピンを正確に位置決めするためにオブジェクトの形状を使用します。
このクラスを使用してノードのバウンディング・ボックスの 4 隅に接続ピンを追加する方法の例は以下の通りです。
IlvGraphic* node = ...;
//== Create an empty instance of IlvGenericPin
IlvGenericPin* pin = new IlvGenericPin();
//== Add the four connecting points
IlvRect bbox;
node->boundingBox(bbox,0);
pin->addPin(node,IlvPoint(bbox.x(),bbox.y()),0);
pin->addPin(node,IlvPoint(bbox.x()+bbox.w()-1,bbox.y()),0);
pin->addPin(node,IlvPoint(bbox.x()+bbox.w()-1,bbox.y()+bbox.h()-1),0);
pin->addPin(node,IlvPoint(bbox.x(),bbox.y()+bbox.h()-1),0);
//== Attach the IlvGenericPin instance to the node
pin->set(node);
メモ: この例では、トランスフォーマーが適用されないときにオブジェクト座標系に点が指定されます。
IlvGrapherPin クラスの拡張
ここでは、ノードのバウンディング・ボックスの中央で単一の接続ピンを処理する、具体的な IlvGrapherPin サブクラスの例を示します。この CenterPin と呼ばれるクラスは、以下のように宣言されます。
#include <ilviews/grapher/pin.h>
 
class CenterPin
: public IlvGrapherPin
{
public:
CenterPin() {}
virtual IlvUInt getCardinal(const IlvGraphic*,
const IlvTransformer*) const;
virtual IlvBoolean getLocation(IlvUInt,
const IlvGraphic*,
const IlvTransformer* t,
IlvPoint&) const;
DeclarePropertyInfoRO();
DeclarePropertyIOConstructors(CenterPin);
};
CenterPin クラスは情報を一切格納しないため、このクラスのコンストラクターは何も行いません。CenterPin クラスの永続化には、DeclarePropertyInfoRO マクロと DeclarePropertyIOConstructors マクロが使用されます。他の IlvGrapherPin メソッドの実装は変更の必要がないため、getCardinal メソッドと getLocation メソッドのみがオーバーロードされます。CenterPin クラスのソース・ファイルは以下のメソッドを定義します。
#include <centerpin.h>
 
// -------------------------------------------------------------------------
// - IO Constructors
CenterPin::CenterPin(IlvInputFile& input, IlvSymbol* s)
: IlvGrapherPin(input, s) {}
 
CenterPin::CenterPin(const CenterPin& src)
: IlvGrapherPin(src) {}
// -------------------------------------------------------------------------
IlvUInt
CenterPin::getCardinal(const IlvGraphic*,
const IlvTransformer*) const
{
return 1;
}
 
// -------------------------------------------------------------------------
IlvBoolean
CenterPin::getLocation(IlvUInt,
const IlvGraphic* node,
const IlvTransformer* t,
IlvPoint& where) const
{
IlvRect bbox;
node->boundingBox(bbox, t);
where.move(bbox.centerx(), bbox.centery());
return IlvTrue;
}
 
// -------------------------------------------------------------------------
// - Macros to register the class and make it persistent
IlvPredefinedPropertyIOMembers(CenterPin)
IlvRegisterPropertyClass(CenterPin, IlvGrapherPin);
getCardinal メソッドの実装は単純で、あらゆるノードとトランスフォーマーに 1 を返します。getLocation メソッドは、ノードの変換済みバウンディング・ボックスを問い合わせ、その中心を返すだけです(このクラスはただ 1 つの接続ピンしか定義しないため、接続ピンのインデックスは使用されません)。CenterPin クラスの宣言は、ファイル <ILVHOME>/samples/grapher/include/centerpin.h にあります。この実装は、ファイル <ILVHOME>/samples/grapher/src/centerpin.cpp にあります。

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