mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
improved networkview. It now displays GPG connexions from p3disc, and accepts dynamic friend level modification. Needs full recompilation.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3793 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1597bd9136
commit
2094734391
@ -42,7 +42,8 @@ class RsDisc
|
||||
RsDisc() { return; }
|
||||
virtual ~RsDisc() { return; }
|
||||
|
||||
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends) = 0;
|
||||
virtual bool getDiscFriends(std::string id, std::list<std::string>& friends) = 0;
|
||||
virtual bool getDiscGPGFriends(std::string id, std::list<std::string>& gpg_friends) = 0;
|
||||
virtual bool getDiscVersions(std::map<std::string, std::string> &versions) = 0;
|
||||
|
||||
};
|
||||
|
@ -29,6 +29,14 @@
|
||||
|
||||
RsDisc *rsDisc = NULL;
|
||||
|
||||
bool p3Discovery::getDiscGPGFriends(std::string id, std::list<std::string>& gpg_friends)
|
||||
{
|
||||
if (mDisc)
|
||||
{
|
||||
return mDisc->potentialGPGproxies(id, gpg_friends);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool p3Discovery::getDiscFriends(std::string id, std::list<std::string> &friends)
|
||||
{
|
||||
if (mDisc)
|
||||
|
@ -38,6 +38,7 @@ class p3Discovery: public RsDisc
|
||||
virtual ~p3Discovery() { return; }
|
||||
|
||||
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends);
|
||||
virtual bool getDiscGPGFriends(std::string id, std::list<std::string> &gpg_friends);
|
||||
virtual bool getDiscVersions(std::map<std::string, std::string> &versions);
|
||||
|
||||
private:
|
||||
|
@ -615,7 +615,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
||||
{
|
||||
bool new_info ;
|
||||
addDiscoveryData(item->PeerId(), pitem->pid, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL),new_info);
|
||||
addDiscoveryData(item->PeerId(), pitem->pid,rsPeers->getGPGId(item->PeerId()),item->aboutId, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL),new_info);
|
||||
|
||||
if(new_info)
|
||||
should_notify_discovery = true ;
|
||||
@ -895,11 +895,14 @@ void p3disc::setGPGOperation(AuthGPGOperation *operation)
|
||||
/*************************************************************************************/
|
||||
/* Storing Network Graph */
|
||||
/*************************************************************************************/
|
||||
int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct sockaddr_in laddr, struct sockaddr_in raddr, uint32_t flags, time_t ts,bool& new_info)
|
||||
int p3disc::addDiscoveryData(const std::string& fromId, const std::string& aboutId,const std::string& from_gpg_id,const std::string& about_gpg_id, const struct sockaddr_in& laddr, const struct sockaddr_in& raddr, uint32_t flags, time_t ts,bool& new_info)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
new_info = false ;
|
||||
|
||||
gpg_neighbors[from_gpg_id].insert(about_gpg_id) ;
|
||||
|
||||
std::cerr << "Adding discovery data " << fromId << " - " << aboutId << std::endl ;
|
||||
/* Store Network information */
|
||||
std::map<std::string, autoneighbour>::iterator it;
|
||||
@ -963,7 +966,7 @@ int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct soc
|
||||
/*************************************************************************************/
|
||||
/* Extracting Network Graph Details */
|
||||
/*************************************************************************************/
|
||||
bool p3disc::potentialproxies(std::string id, std::list<std::string> &proxyIds)
|
||||
bool p3disc::potentialproxies(const std::string& id, std::list<std::string> &proxyIds)
|
||||
{
|
||||
/* find id -> and extract the neighbour_of ids */
|
||||
|
||||
@ -979,13 +982,31 @@ bool p3disc::potentialproxies(std::string id, std::list<std::string> &proxyIds)
|
||||
return false;
|
||||
}
|
||||
|
||||
for(sit = it->second.neighbour_of.begin();
|
||||
sit != it->second.neighbour_of.end(); sit++)
|
||||
for(sit = it->second.neighbour_of.begin(); sit != it->second.neighbour_of.end(); sit++)
|
||||
{
|
||||
proxyIds.push_back(sit->first);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool p3disc::potentialGPGproxies(const std::string& gpg_id, std::list<std::string> &proxyGPGIds)
|
||||
{
|
||||
/* find id -> and extract the neighbour_of ids */
|
||||
|
||||
if(gpg_id == rsPeers->getGPGOwnId()) // SSL id // This is treated appart, because otherwise we don't receive any disc info about us
|
||||
return rsPeers->getGPGAcceptedList(proxyGPGIds) ;
|
||||
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, std::set<std::string> >::iterator it = gpg_neighbors.find(gpg_id) ;
|
||||
|
||||
if(it == gpg_neighbors.end())
|
||||
return false;
|
||||
|
||||
for(std::set<std::string>::const_iterator sit(it->second.begin()); sit != it->second.end(); ++sit)
|
||||
proxyGPGIds.push_back(*sit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3disc::getversions(std::map<std::string, std::string> &versions)
|
||||
{
|
||||
|
@ -89,7 +89,8 @@ virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
int tick();
|
||||
|
||||
/* GUI requires access */
|
||||
bool potentialproxies(std::string id, std::list<std::string> &proxyIds);
|
||||
bool potentialGPGproxies(const std::string& id, std::list<std::string> &proxyGPGIds);
|
||||
bool potentialproxies(const std::string& id, std::list<std::string> &proxyIds);
|
||||
void getversions(std::map<std::string, std::string> &versions);
|
||||
|
||||
/************* from AuthGPService ****************/
|
||||
@ -130,8 +131,9 @@ void recvHeartbeatMsg(RsDiscHeartbeat *item);
|
||||
void removeFriend(std::string ssl_id); //keep tracks of removed friend so we're not gonna add them again immediately
|
||||
|
||||
/* handle network shape */
|
||||
int addDiscoveryData(std::string fromId, std::string aboutId,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
int addDiscoveryData(const std::string& fromId, const std::string& aboutId,
|
||||
const std::string& fromGPGId,const std::string& aboutGPGId,
|
||||
const struct sockaddr_in& laddr, const struct sockaddr_in& raddr,
|
||||
uint32_t flags, time_t ts,bool& new_info);
|
||||
|
||||
int idServers();
|
||||
@ -152,6 +154,10 @@ int idServers();
|
||||
|
||||
std::map<std::string, std::list<std::string> > sendIdList;
|
||||
std::list<RsDiscReply*> pendingDiscReplyInList;
|
||||
|
||||
// Neighbors at the gpg level.
|
||||
//
|
||||
std::map<std::string,std::set<std::string> > gpg_neighbors ;
|
||||
};
|
||||
|
||||
|
||||
|
@ -54,11 +54,10 @@ NetworkView::NetworkView(QWidget *parent)
|
||||
setMaxFriendLevel(ui.maxFriendLevelSB->value()) ;
|
||||
|
||||
/* add button */
|
||||
connect( ui.refreshButton, SIGNAL( clicked( void ) ), this, SLOT( updateDisplay( void ) ) );
|
||||
connect( ui.refreshButton, SIGNAL( clicked( void ) ), this, SLOT( redraw( void ) ) );
|
||||
connect( mScene, SIGNAL( changed ( const QList<QRectF> & ) ), this, SLOT ( changedScene( void ) ) );
|
||||
|
||||
/* Hide Settings frame */
|
||||
shownwSettingsFrame(false);
|
||||
connect( ui.maxFriendLevelSB, SIGNAL(valueChanged(int)), this, SLOT(setMaxFriendLevel(int)));
|
||||
connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int)));
|
||||
|
||||
@ -71,6 +70,8 @@ void NetworkView::setEdgeLength(int l)
|
||||
}
|
||||
void NetworkView::setMaxFriendLevel(int m)
|
||||
{
|
||||
ui.graphicsView->snapshotNodesPositions() ;
|
||||
clear() ;
|
||||
_max_friend_level = m ;
|
||||
updateDisplay() ;
|
||||
}
|
||||
@ -78,51 +79,26 @@ void NetworkView::changedFoFCheckBox( )
|
||||
{
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
void NetworkView::clearPeerItems()
|
||||
void NetworkView::redraw()
|
||||
{
|
||||
std::map<std::string, QGraphicsItem *>::iterator pit;
|
||||
|
||||
for(pit = mPeerItems.begin(); pit != mPeerItems.end(); pit++)
|
||||
{
|
||||
mScene->destroyItemGroup((QGraphicsItemGroup *) pit->second);
|
||||
}
|
||||
mPeerItems.clear();
|
||||
ui.graphicsView->clearNodesPositions() ;
|
||||
clear() ;
|
||||
updateDisplay() ;
|
||||
}
|
||||
|
||||
|
||||
void NetworkView::clearOtherItems()
|
||||
void NetworkView::clear()
|
||||
{
|
||||
std::list<QGraphicsItem *>::iterator oit;
|
||||
|
||||
for(oit = mOtherItems.begin(); oit != mOtherItems.end(); oit++)
|
||||
{
|
||||
mScene->removeItem(*oit);
|
||||
delete (*oit);
|
||||
}
|
||||
mOtherItems.clear();
|
||||
}
|
||||
|
||||
|
||||
void NetworkView::clearLineItems()
|
||||
{
|
||||
std::list<QGraphicsItem *>::iterator oit;
|
||||
|
||||
for(oit = mLineItems.begin(); oit != mLineItems.end(); oit++)
|
||||
{
|
||||
mScene->removeItem(*oit);
|
||||
delete (*oit);
|
||||
}
|
||||
mLineItems.clear();
|
||||
ui.graphicsView->clearGraph() ;
|
||||
_node_ids.clear() ;
|
||||
update() ;
|
||||
}
|
||||
|
||||
class NodeInfo
|
||||
{
|
||||
public:
|
||||
NodeInfo(const std::string& _gpg_id,const std::string& _ssl_id,uint32_t lev) : gpg_id(_gpg_id),ssl_id(_ssl_id),friend_level(lev) {}
|
||||
NodeInfo(const std::string& _gpg_id,uint32_t lev) : gpg_id(_gpg_id),friend_level(lev) {}
|
||||
|
||||
std::string gpg_id ;
|
||||
std::string ssl_id ;
|
||||
uint32_t friend_level ;
|
||||
} ;
|
||||
|
||||
@ -139,7 +115,6 @@ void NetworkView::updateDisplay()
|
||||
|
||||
/* add all friends */
|
||||
std::string ownGPGId = rsPeers->getGPGOwnId();
|
||||
std::string ownSSLId = rsPeers->getOwnId();
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "NetworkView::updateDisplay()" << std::endl;
|
||||
#endif
|
||||
@ -149,31 +124,9 @@ void NetworkView::updateDisplay()
|
||||
std::deque<NodeInfo> nodes_to_treat ; // list of nodes to be treated. Used as a queue. The int is the level of friendness
|
||||
std::set<std::string> nodes_considered ; // list of nodes already considered. Eases lookup.
|
||||
|
||||
nodes_to_treat.push_front(NodeInfo(ownGPGId,ownSSLId,0)) ; // initialize queue with own id.
|
||||
nodes_to_treat.push_front(NodeInfo(ownGPGId,0)) ; // initialize queue with own id.
|
||||
nodes_considered.insert(rsPeers->getOwnId()) ;
|
||||
|
||||
// compute the list of GPG friends
|
||||
|
||||
std::set<std::string> gpg_friends ;
|
||||
std::list<std::string> friends ;
|
||||
std::set<std::string> ssl_friends ;
|
||||
|
||||
if(!rsPeers->getFriendList(friends))
|
||||
return ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(friends.begin());it!=friends.end();++it)
|
||||
{
|
||||
RsPeerDetails d ;
|
||||
if(!rsPeers->getPeerDetails(*it,d))
|
||||
continue ;
|
||||
|
||||
gpg_friends.insert(d.gpg_id) ;
|
||||
ssl_friends.insert(d.id) ;
|
||||
}
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "Found " << ssl_friends.size() << " gpg friends." << std::endl ;
|
||||
#endif
|
||||
|
||||
// Put own id in queue, and empty the queue, treating all nodes.
|
||||
//
|
||||
while(!nodes_to_treat.empty())
|
||||
@ -181,85 +134,63 @@ void NetworkView::updateDisplay()
|
||||
NodeInfo info(nodes_to_treat.back()) ;
|
||||
nodes_to_treat.pop_back() ;
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " Poped out of queue: " << info.ssl_id << ", with level " << info.friend_level << std::endl ;
|
||||
std::cerr << " Poped out of queue: " << info.gpg_id << ", with level " << info.friend_level << std::endl ;
|
||||
#endif
|
||||
GraphWidget::NodeType type ;
|
||||
GraphWidget::AuthType auth ;
|
||||
|
||||
switch(info.friend_level)
|
||||
{
|
||||
case 0: type = GraphWidget::ELASTIC_NODE_TYPE_OWN ;
|
||||
break ;
|
||||
case 1: type = GraphWidget::ELASTIC_NODE_TYPE_FRIEND ;
|
||||
break ;
|
||||
case 2: type = GraphWidget::ELASTIC_NODE_TYPE_F_OF_F ;
|
||||
break ;
|
||||
default:
|
||||
type = GraphWidget::ELASTIC_NODE_TYPE_UNKNOWN ;
|
||||
}
|
||||
|
||||
RsPeerDetails detail ;
|
||||
if(!rsPeers->getPeerDetails(info.gpg_id, detail))
|
||||
continue ;
|
||||
|
||||
switch(detail.validLvl)
|
||||
{
|
||||
case GPGME_VALIDITY_MARGINAL: auth = GraphWidget::ELASTIC_NODE_AUTH_MARGINAL ; break;
|
||||
case GPGME_VALIDITY_FULL:
|
||||
case GPGME_VALIDITY_ULTIMATE: auth = GraphWidget::ELASTIC_NODE_AUTH_FULL ; break;
|
||||
case GPGME_VALIDITY_UNKNOWN:
|
||||
case GPGME_VALIDITY_UNDEFINED:
|
||||
case GPGME_VALIDITY_NEVER:
|
||||
default: auth = GraphWidget::ELASTIC_NODE_AUTH_UNKNOWN ; break ;
|
||||
}
|
||||
|
||||
if(info.friend_level <= _max_friend_level && _node_ids.find(info.gpg_id) == _node_ids.end())
|
||||
{
|
||||
_node_ids[info.gpg_id] = ui.graphicsView->addNode(" "+detail.name, detail.name+"@"+detail.gpg_id,type,auth,"",info.gpg_id);
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " inserted node " << info.gpg_id << ", type=" << type << ", auth=" << auth << std::endl ;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::list<std::string> friendList;
|
||||
rsDisc->getDiscFriends(info.ssl_id, friendList);
|
||||
rsDisc->getDiscGPGFriends(info.gpg_id, friendList);
|
||||
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " Got a list of " << friendList.size() << " friends for this peer." << std::endl ;
|
||||
#endif
|
||||
// if(!rsPeers->getPeerDetails(info.gpg_id,detail))
|
||||
// {
|
||||
// std::cerr << "Could not request GPG details for node " << info.gpg_id << std::endl ;
|
||||
// continue ;
|
||||
// }
|
||||
|
||||
// if(info.friend_level <= _max_friend_level && (info.friend_level != 1 || ssl_friends.find(info.ssl_id) != ssl_friends.end()))
|
||||
{
|
||||
GraphWidget::NodeType type ;
|
||||
GraphWidget::AuthType auth ;
|
||||
|
||||
switch(info.friend_level)
|
||||
{
|
||||
case 0: type = GraphWidget::ELASTIC_NODE_TYPE_OWN ;
|
||||
break ;
|
||||
case 1: type = GraphWidget::ELASTIC_NODE_TYPE_FRIEND ;
|
||||
break ;
|
||||
case 2: type = GraphWidget::ELASTIC_NODE_TYPE_F_OF_F ;
|
||||
break ;
|
||||
default:
|
||||
type = GraphWidget::ELASTIC_NODE_TYPE_UNKNOWN ;
|
||||
}
|
||||
|
||||
RsPeerDetails detail ;
|
||||
if (!rsPeers->getPeerDetails(info.ssl_id, detail))
|
||||
continue ;
|
||||
|
||||
switch(detail.validLvl)
|
||||
{
|
||||
case GPGME_VALIDITY_MARGINAL: auth = GraphWidget::ELASTIC_NODE_AUTH_MARGINAL ; break;
|
||||
case GPGME_VALIDITY_FULL:
|
||||
case GPGME_VALIDITY_ULTIMATE: auth = GraphWidget::ELASTIC_NODE_AUTH_FULL ; break;
|
||||
case GPGME_VALIDITY_UNKNOWN:
|
||||
case GPGME_VALIDITY_UNDEFINED:
|
||||
case GPGME_VALIDITY_NEVER:
|
||||
default: auth = GraphWidget::ELASTIC_NODE_AUTH_UNKNOWN ; break ;
|
||||
}
|
||||
|
||||
if(_node_ids.find(info.ssl_id) == _node_ids.end())
|
||||
{
|
||||
_node_ids[info.ssl_id] = ui.graphicsView->addNode(" "+detail.name +"("+detail.location+")", "("+detail.name+","+info.ssl_id+","+detail.gpg_id+")",type,auth,info.ssl_id,info.gpg_id);
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " inserted node " << info.ssl_id << ", type=" << type << ", auth=" << auth << std::endl ;
|
||||
std::cerr << " NetworkView::updateDisplay() Added Friend: " << info.ssl_id << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(info.friend_level+1 <= _max_friend_level)
|
||||
for(std::list<std::string>::const_iterator sit(friendList.begin()); sit != friendList.end(); ++sit)
|
||||
if(nodes_considered.find(*sit) == nodes_considered.end())
|
||||
{
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " adding to queue: " << *sit << ", with level " << info.friend_level+1 << std::endl ;
|
||||
#endif
|
||||
nodes_to_treat.push_front( NodeInfo("unknown",*sit,info.friend_level + 1) ) ;
|
||||
nodes_to_treat.push_front( NodeInfo(*sit,info.friend_level + 1) ) ;
|
||||
nodes_considered.insert(*sit) ;
|
||||
}
|
||||
|
||||
// now insert in list the GPG signers that are not our friends, to get 2nd order peers in the network.
|
||||
//
|
||||
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); ++sit)
|
||||
if(nodes_considered.find(*sit) == nodes_considered.end() && gpg_friends.find(*sit) == gpg_friends.end())
|
||||
{
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " adding to queue: " << *sit << ", with level " << info.friend_level+1 << std::endl ;
|
||||
#endif
|
||||
nodes_to_treat.push_front( NodeInfo(*sit,*sit,info.friend_level + 1) ) ;
|
||||
nodes_considered.insert(*sit) ;
|
||||
gpg_friends.insert(*sit) ;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* iterate through all friends */
|
||||
@ -272,39 +203,20 @@ void NetworkView::updateDisplay()
|
||||
{
|
||||
std::list<std::string> friendList ;
|
||||
|
||||
if(rsDisc->getDiscFriends(it->first,friendList))
|
||||
if(rsDisc->getDiscGPGFriends(it->first,friendList))
|
||||
for(std::list<std::string>::const_iterator sit(friendList.begin()); sit != friendList.end(); sit++)
|
||||
{
|
||||
if(it->first < *sit)
|
||||
{
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "NetworkView: Adding Arrow: ";
|
||||
std::cerr << "NetworkView: Adding Edge: ";
|
||||
std::cerr << *sit << " <-> " << it->first;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if(_node_ids.find(*sit) != _node_ids.end())
|
||||
ui.graphicsView->addEdge(_node_ids[*sit], it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_should_update = false ;
|
||||
}
|
||||
|
||||
/**
|
||||
Toggles the Settings pane on and off, changes toggle button text
|
||||
*/
|
||||
void NetworkView::shownwSettingsFrame(bool show)
|
||||
{
|
||||
if (show) {
|
||||
// ui.viewsettingsframe->setVisible(true);
|
||||
// ui.nviewsettingsButton->setChecked(true);
|
||||
// ui.nviewsettingsButton->setToolTip(tr("Hide Settings"));
|
||||
} else {
|
||||
// ui.viewsettingsframe->setVisible(false);
|
||||
// ui.nviewsettingsButton->setChecked(false);
|
||||
// ui.nviewsettingsButton->setToolTip(tr("Show Settings"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,25 +46,14 @@ class NetworkView : public RsAutoUpdatePage
|
||||
void setEdgeLength(int) ;
|
||||
|
||||
void changedFoFCheckBox( );
|
||||
|
||||
/** Called when Settings button is toggled */
|
||||
void shownwSettingsFrame(bool show);
|
||||
void redraw();
|
||||
|
||||
private:
|
||||
|
||||
void clearPeerItems();
|
||||
void clearOtherItems();
|
||||
void clearLineItems();
|
||||
void clear();
|
||||
|
||||
QGraphicsScene *mScene;
|
||||
|
||||
std::map<std::string, QGraphicsItem *> mPeerItems;
|
||||
std::list<QGraphicsItem *> mOtherItems;
|
||||
|
||||
std::list<QGraphicsItem *> mLineItems;
|
||||
bool mLineChanged;
|
||||
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::NetworkView ui;
|
||||
int _max_friend_level ;
|
||||
|
@ -54,6 +54,9 @@
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Basic</string>
|
||||
@ -73,6 +76,9 @@
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Display mode:</string>
|
||||
</property>
|
||||
@ -84,7 +90,10 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -166,10 +166,34 @@ GraphWidget::NodeId GraphWidget::addNode(const std::string& node_short_string,co
|
||||
node->setToolTip(QString::fromStdString(node_complete_string)) ;
|
||||
_nodes.push_back(node) ;
|
||||
scene()->addItem(node);
|
||||
node->setPos(rand()%1000/53.0f, rand()%1000/53.0f);
|
||||
|
||||
std::map<std::string,QPointF>::const_iterator it(_node_cached_positions.find(gpg_id)) ;
|
||||
if(_node_cached_positions.end() != it)
|
||||
node->setPos(it->second) ;
|
||||
else
|
||||
{
|
||||
qreal x1,y1,x2,y2 ;
|
||||
sceneRect().getCoords(&x1,&y1,&x2,&y2) ;
|
||||
|
||||
float f1 = rand()/(float)RAND_MAX ;
|
||||
float f2 = rand()/(float)RAND_MAX ;
|
||||
|
||||
node->setPos(x1+f1*(x2-x1),y1+f2*(y2-y1));
|
||||
}
|
||||
|
||||
std::cerr << "Added node " << _nodes.size()-1 << std::endl ;
|
||||
return _nodes.size()-1 ;
|
||||
}
|
||||
void GraphWidget::snapshotNodesPositions()
|
||||
{
|
||||
for(uint32_t i=0;i<_nodes.size();++i)
|
||||
_node_cached_positions[_nodes[i]->idString()] = _nodes[i]->mapToScene(QPointF(0,0)) ;
|
||||
}
|
||||
void GraphWidget::clearNodesPositions()
|
||||
{
|
||||
_node_cached_positions.clear() ;
|
||||
}
|
||||
|
||||
GraphWidget::EdgeId GraphWidget::addEdge(NodeId n1,NodeId n2)
|
||||
{
|
||||
std::pair<NodeId,NodeId> ed(std::min(n1,n2),std::max(n1,n2)) ;
|
||||
|
@ -75,6 +75,8 @@ public:
|
||||
NodeId addNode(const std::string& NodeShortText,const std::string& nodeCompleteText,NodeType type,AuthType auth,const std::string& ssl_id,const std::string& gpg_id) ;
|
||||
EdgeId addEdge(NodeId n1,NodeId n2) ;
|
||||
|
||||
void snapshotNodesPositions() ;
|
||||
void clearNodesPositions() ;
|
||||
void clearGraph() ;
|
||||
virtual void itemMoved();
|
||||
|
||||
@ -96,6 +98,7 @@ private:
|
||||
|
||||
std::vector<Node *> _nodes ;
|
||||
std::map<std::pair<NodeId,NodeId>,Edge *> _edges ;
|
||||
std::map<std::string,QPointF> _node_cached_positions ;
|
||||
|
||||
uint32_t _edge_length ;
|
||||
};
|
||||
|
@ -187,8 +187,10 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
||||
|
||||
// now time filter:
|
||||
|
||||
_speedx += xforce / MASS_FACTOR;
|
||||
_speedy += yforce / MASS_FACTOR;
|
||||
float f = (_type == GraphWidget::ELASTIC_NODE_TYPE_OWN)?10.0f:1.0f ;
|
||||
|
||||
_speedx += xforce / (MASS_FACTOR * f);
|
||||
_speedy += yforce / (MASS_FACTOR * f);
|
||||
|
||||
if(_speedx > 10) _speedx = 10.0f ;
|
||||
if(_speedy > 10) _speedy = 10.0f ;
|
||||
@ -203,8 +205,8 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
||||
|
||||
bool Node::advance()
|
||||
{
|
||||
if(_type == GraphWidget::ELASTIC_NODE_TYPE_OWN)
|
||||
return false;
|
||||
// if(_type == GraphWidget::ELASTIC_NODE_TYPE_OWN)
|
||||
// return false;
|
||||
|
||||
float f = std::max(fabs(newPos.x() - pos().x()), fabs(newPos.y() - pos().y())) ;
|
||||
|
||||
|
@ -63,6 +63,7 @@ public:
|
||||
const QList<Edge *>& edges() const;
|
||||
|
||||
int type() const { return Type; }
|
||||
const std::string& idString() const { return _gpg_id ; }
|
||||
|
||||
void calculateForces(const double *data,int width,int height,int W,int H,float x,float y,float speedf);
|
||||
bool advance();
|
||||
|
Loading…
Reference in New Issue
Block a user