📄 gtwin.cpp
字号:
if( _currNode ) {
_currNode->enableParents( TRUE );
arrangeAll();
}
}
/*
* hide all of a nodes parents
*/
void TreeWindow::hideParents()
//----------------------------
// DEAD
{
if( _currNode ) {
_currNode->enableParents( FALSE );
_currNode->setEnable( TreeNode::Visible );
if( _autoArrange ) {
arrangeAll();
} else {
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->sortEdges();
_roots[ i - 1 ]->needsUpdating();
}
invalidate();
}
}
}
/* show the immediate parents and kids of the active node
*/
void TreeWindow::showOnlyPrtKids()
//--------------------------------
// DEAD
{
int i;
if( _currNode ) {
for( i = _currNode->getCount( TreeNode::FlatList ); i > 0; i -= 1 ) {
TreeNode * node;
node = _currNode->getNode( TreeNode::FlatList, i - 1 );
node->setEnable( TreeNode::Hidden );
}
_currNode->setEnable( TreeNode::Visible );
for( i = _currNode->getCount( TreeNode::ParentList ); i > 0; i -= 1 ) {
TreeNode * node;
node = _currNode->getNode( TreeNode::ParentList, i - 1 );
node->setEnable( TreeNode::Visible );
}
for( i = _currNode->getCount( TreeNode::ChildList ); i > 0; i -= 1 ) {
TreeNode * node;
node = _currNode->getNode( TreeNode::ChildList, i - 1 );
node->setEnable( TreeNode::Visible );
}
arrangeAll();
}
}
#endif
/*
* switch from straight edges to square or vice versa
*/
void TreeWindow::toggleEdges()
//----------------------------
{
int i;
ASSERTION( _edgeType != optManager()->getEdgeType() );
_edgeType = optManager()->getEdgeType();
if( _edgeType == EdgesSquare ) {
for( i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->wrapRings();
}
} else {
for( i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->unWrapRings();
}
}
for( i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->sortEdges();
_roots[ i - 1 ]->needsUpdating();
}
TreeRoot::sortRoots( _roots );
invalidate();
}
void TreeWindow::toggleAutoArrange()
//----------------------------------
{
ASSERTION( _autoArrange != optManager()->getTreeAutoArrange() );
_autoArrange = optManager()->getTreeAutoArrange();
arrangeAll();
}
/* change tree direction
*/
void TreeWindow::changeDirection()
//--------------------------------
/*
* This is pretty much the same as arrangeAll() and
* arrangeAllSelectRoots(), except some
* extra work has to be done because of the change in direction.
* Integrating the three functions would result in some code
* size savings, but would make it pretty messy.
*/
{
TreeDirection oldDirection;
oldDirection = _direction;
ASSERTION( _direction != optManager()->getTreeDirection() );
/*
* We want to keep the window positioned at roughly the same
* place, even after changing the orientation of the tree.
* So we save the old position and which tree was being looked at.
* Note : use sibSep + 1 as width and height because each root's
* bounding rectangle is separated from other roots by sibSep
*/
TreeRect oldPos( getXOff(), getYOff(), sibSep + 1, sibSep + 1 );
TreeRect oldRootPos;
TreeRoot ** ppRoot;
ppRoot = _roots.search( &oldPos, (TComp) TreeRoot::rootRectComp );
if( ppRoot != NULL ) {
oldRootPos = (*ppRoot)->getBound();
}
_direction = optManager()->getTreeDirection();
rePlaceAll();
ScreenDev dev;
BusyNotice busy( "Arranging Graph..." );
dev.open( this );
TreeNode::arrangeAll( getDirection(), _roots, _world, &dev );
dev.close();
if( ppRoot != NULL ) {
setCurrentPosition( *ppRoot, &oldPos, &oldRootPos, TRUE );
} else {
scrollTo( 0, 0 );
}
TreeRoot::sortRoots( _roots );
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->needsUpdating();
}
invalidate();
resetScrollRange();
}
#ifdef DEBUGTREE
void TreeWindow::showDebug()
//--------------------------
{
TreeRoot * root = _roots[ 0 ];
for( int i = _roots.count(); i > 0; i -= 1 ) {
if( _roots[ i - 1 ]->isRelated( _currNode ) ) {
root = _roots[ i - 1 ];
}
}
_currNode->debugInfo( root );
}
void TreeWindow::showSib()
//------------------------
{
_currNode->sibWidth();
}
#endif
/* clear the window, re-arrange all nodes and re-display
*/
void TreeWindow::arrangeAll()
//---------------------------
{
ScreenDev dev;
BusyNotice busy( "Arranging Graph..." );
rePlaceAll();
dev.open( this );
TreeNode::arrangeAll( getDirection(), _roots, _world, &dev );
dev.close();
resetScrollRange();
TreeRoot::sortRoots( _roots );
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->needsUpdating();
}
invalidate();
}
void TreeWindow::arrangeAllSelectRoots()
//--------------------------------------
// Arranges everything, plus resets the scroll bars
{
BusyNotice busy( "Arranging Graph..." );
/*
* We want to keep the window positioned at roughly the same
* place, even after changing the orientation of the tree.
* So we save the old position and which tree was being looked at.
*/
TreeRect oldPos( getXOff(), getYOff(), sibSep + 1, sibSep + 1 );
TreeRect oldRootPos;
TreeRoot ** ppRoot;
ppRoot = _roots.search( &oldPos, (TComp) TreeRoot::rootRectComp );
if( ppRoot != NULL ) {
oldRootPos = (*ppRoot)->getBound();
}
rePlaceAll();
ScreenDev dev;
dev.open( this );
TreeNode::arrangeAll( getDirection(), _roots, _world, &dev );
dev.close();
resetScrollRange();
if( ppRoot != NULL ) {
setCurrentPosition( *ppRoot, &oldPos, &oldRootPos, FALSE );
} else {
scrollTo( 0, 0 );
}
TreeRoot::sortRoots( _roots );
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->needsUpdating();
}
invalidate();
}
void TreeWindow::setCurrentPosition( TreeRoot * pRoot, TreeRect *oldPos,
TreeRect *oldRootPos,
bool changeDirection )
//---------------------------------------------------------------------------
// pRoot -- pointer of root to scroll to
// oldPos -- old position before arranging tree
// oldRootPos -- old bounding rectangle of root to scroll to
// changeDirection -- TRUE if direction of trees has changed horiz.<->vert.
{
TreeCoord nx;
TreeCoord ny;
if( pRoot->enabled() ) {
TreeRect newRootPos;
TreeCoord oldDeltaX;
TreeCoord oldDeltaY;
newRootPos = pRoot->getBound();
oldDeltaX = oldPos->x() - oldRootPos->x();
oldDeltaY = oldPos->y() - oldRootPos->y();
if( changeDirection ) {
nx = ( newRootPos.x() +
(oldDeltaY * newRootPos.w()) / oldRootPos->h() );
ny = ( newRootPos.y() +
(oldDeltaX * newRootPos.h()) / oldRootPos->w() );
} else {
if( newRootPos.x() != oldRootPos->x() ) {
nx = ( newRootPos.x() + (oldDeltaX * newRootPos.w())
/ oldRootPos->w());
} else {
nx = newRootPos.x();
}
if( newRootPos.y() != oldRootPos->y() ) {
ny = ( newRootPos.y() + (oldDeltaY * newRootPos.h())
/ oldRootPos->h() );
} else {
ny = newRootPos.y();
}
}
} else {
nx = 0;
ny = 0;
}
scrollTo( nx, ny );
}
bool TreeWindow::keyDown( WKeyCode code, WKeyState st )
//-----------------------------------------------------
{
if( code == WKeyEnter ) {
showDetail();
return( TRUE );
} else {
return key( code, st );
}
}
bool TreeWindow::paint()
//----------------------
{
ScreenDev dev;
WRect rect;
int i;
bool setRange = FALSE; // should scroll range be set?
dev.open( this );
if( !_rootsLoaded ) {
BusyNotice busy( "Loading..." );
_rootsLoaded = TRUE;
fillRoots();
_empty = (_roots.count() == 0 );
if( !_empty ) {
BusyNotice busy( "Arranging Graph..." );
TreeNode::arrangeAll( getDirection(), _roots, _world, &dev );
TreeRoot::sortRoots( _roots );
TreeRoot::addRootPtrToNodes( _roots );
if( getSmartEdges() ) {
for( i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->wrapRings();
}
}
}
setRange = TRUE;
}
_empty = TRUE;
for( i = 0; i < _roots.count(); i += 1 ) {
if( _roots[ i ]->enabled() ) {
_empty = FALSE;
break;
}
}
if( _empty ) {
dev.drawText( WPoint( 0, 0 ), emptyText() );
} else {
getPaintRect( rect );
TreeRect r( getXOff() + rect.x(),
getYOff() + rect.y(),
(TreeCoord) rect.w(), (TreeCoord) rect.h() );
TreeRoot::paint( _roots, &dev, &r );
}
dev.close();
if( setRange ) {
resetScrollRange();
}
return FALSE;
}
#if 0
TreeCoord TreeWindow::getMaxXOff()
//--------------------------------
// Gets the maximum x-offset on the scroll bar
{
TreeCoord maxX;
maxX = _world.w() / _hScrollFactor;
if( maxX < 0 ){
maxX = 0;
}
return maxX;
}
TreeCoord TreeWindow::getMaxYOff()
//--------------------------------
// Gets the maximum y-offset on the scroll bar
{
TreeCoord maxY;
maxY = _world.h() / _vScrollFactor;
if( maxY < 0 ) {
maxY = 0;
}
return maxY;
}
bool TreeWindow::fixOffsets()
//---------------------------
// Adjust the _xOffset and _yOffset so that we don't go off the world
{
TreeCoord maxX;
TreeCoord maxY;
bool changed;
changed = FALSE;
maxX = _world.w() / _hScrollFactor /* getMaxXOff() */;
maxY = _world.h() / _vScrollFactor /* getMaxYOff() */;
if( _xOffset > maxX ) {
_xOffset = maxX;
changed = TRUE;
} else if( _xOffset < 0 ) {
_xOffset = 0;
changed = TRUE;
}
if( _yOffset > maxY ) {
_yOffset = maxY;
changed = TRUE;
} else if( _yOffset < 0 ) {
_yOffset = 0;
changed = TRUE;
}
return changed;
}
#endif
TreeDirection TreeWindow::getDirection() const
//--------------------------------------------
{
return _direction;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -