void FlowPart::updateAttachedPositioning() { if (b_deleted) return; //BEGIN Rearrange text if appropriate const QRect textPos[4] = { QRect(offsetX() + width(), 6, 40, 16), QRect(0, offsetY() - 16, 40, 16), QRect(offsetX() - 40, 6, 40, 16), QRect(0, offsetY() + height(), 40, 16) }; NodeInfo *stdOutputInfo = m_stdOutput ? &m_nodeMap["stdoutput"] : 0; NodeInfo *altOutputInfo = m_altOutput ? &m_nodeMap["altoutput"] : 0; Text *outputTrueText = m_textMap.contains("output_true") ? m_textMap["output_true"] : 0; Text *outputFalseText = m_textMap.contains("output_false") ? m_textMap["output_false"] : 0; if (stdOutputInfo && outputTrueText) outputTrueText->setOriginalRect(textPos[ nodeDirToPos(stdOutputInfo->orientation)]); if (altOutputInfo && outputFalseText) outputFalseText->setOriginalRect(textPos[ nodeDirToPos(altOutputInfo->orientation)]); const TextMap::iterator textMapEnd = m_textMap.end(); for (TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it) { QRect pos = it.data()->recommendedRect(); it.data()->move(pos.x() + x(), pos.y() + y()); it.data()->setGuiPartSize(pos.width(), pos.height()); } //END Rearrange text if appropriate const NodeInfoMap::iterator end = m_nodeMap.end(); for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) { if (!it.data().node) { kdError() << k_funcinfo << "Node in nodemap is null" << endl; continue; } double nx = it.data().x; double ny = it.data().y; #define round_8(x) (((x) > 0) ? int(((x)+4)/8)*8 : int(((x)-4)/8)*8) nx = round_8(nx); ny = round_8(ny); #undef round_8 it.data().node->move(int(nx + x()), int(ny + y())); it.data().node->setOrientation(it.data().orientation); } }
Node *CNItem::getClosestNode( const QPoint &pos ) { // Work through the nodes, finding the one closest to the (x, y) position Node *shortestNode = 0L; double shortestDistance = 1e10; // Nice large distance :-) const NodeInfoMap::iterator end = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it ) { Node *node = p_icnDocument->nodeWithID(it.data().id); if (node) { // Calculate the distance // Yeah, it's actually the distance squared; but it's all relative, so doesn't matter double distance = std::pow(node->x()-pos.x(),2) + std::pow(node->y()-pos.y(),2); if ( distance < shortestDistance ) { shortestDistance = distance; shortestNode = node; } } } return shortestNode; }
void CNItem::setVisible( bool yes ) { if (b_deleted) { Item::setVisible(false); return; } Item::setVisible(yes); const TextMap::iterator textMapEnd = m_textMap.end(); for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it ) { it.data()->setVisible(yes); } const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it ) { it.data().node->setVisible(yes); } CNItem::setDrawWidgets(yes); if (!yes) updateConnectorPoints(false); }
ConnectorList CNItem::connectorList() { ConnectorList list; const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it ) { Node *node = p_icnDocument->nodeWithID(it.data().id); if (node) { ConnectorList nodeList = node->getAllConnectors(); ConnectorList::iterator end = nodeList.end(); for ( ConnectorList::iterator it = nodeList.begin(); it != end; ++it ) { if ( *it && !list.contains(*it) ) { list.append(*it); } } } } return list; }
bool CNItem::removeNode( const QString &name ) { NodeInfoMap::iterator it = m_nodeMap.find(name); if ( it == m_nodeMap.end() ) { return false; } it.data().node->removeNode(); p_icnDocument->flushDeleteList(); m_nodeMap.erase(it); return true; }
void FlowPart::updateNodePositions() { if (m_orientation > 7) { kdWarning() << k_funcinfo << "Invalid orientation: " << m_orientation << endl; return; } NodeInfo *stdInputInfo = m_stdInput ? &m_nodeMap["stdinput"] : 0; NodeInfo *stdOutputInfo = m_stdOutput ? &m_nodeMap["stdoutput"] : 0; NodeInfo *altOutputInfo = m_altOutput ? &m_nodeMap["altoutput"] : 0; if (m_stdInput && m_stdOutput && m_altOutput) { stdInputInfo->orientation = diamondNodePositioning[m_orientation][0]; stdOutputInfo->orientation = diamondNodePositioning[m_orientation][1]; altOutputInfo->orientation = diamondNodePositioning[m_orientation][2]; } else if (m_stdInput && m_stdOutput) { stdInputInfo->orientation = inOutNodePositioning[m_orientation][0]; stdOutputInfo->orientation = inOutNodePositioning[m_orientation][1]; } else if (m_orientation < 4) { if (stdInputInfo) stdInputInfo->orientation = inNodePositioning[m_orientation]; else if (stdOutputInfo) stdOutputInfo->orientation = outNodePositioning[m_orientation]; } else { kdWarning() << k_funcinfo << "Invalid orientation: " << m_orientation << endl; return; } const NodeInfoMap::iterator end = m_nodeMap.end(); for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != end; ++it) { if (!it.data().node) kdError() << k_funcinfo << "Node in nodemap is null" << endl; else { switch (it.data().orientation) { case 0: it.data().x = offsetX() + width() + 8; it.data().y = 0; break; case 270: it.data().x = 0; it.data().y = offsetY() - 8; break; case 180: it.data().x = offsetX() - 8; it.data().y = 0; break; case 90: it.data().x = 0; it.data().y = offsetY() + height() + 8;; break; } } } updateAttachedPositioning(); }
void CNItem::updateZ( int baseZ ) { Item::updateZ(baseZ); double _z = z(); const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it ) it.data().node->setZ( _z + 0.5 ); const WidgetMap::iterator widgetMapEnd = m_widgetMap.end(); for ( WidgetMap::iterator it = m_widgetMap.begin(); it != widgetMapEnd; ++it ) it.data()->setZ( _z + 0.5 ); const TextMap::iterator textMapEnd = m_textMap.end(); for ( TextMap::iterator it = m_textMap.begin(); it != textMapEnd; ++it ) it.data()->setZ( _z + 0.5 ); }
void CNItem::updateNodeLevels() { int l = level(); // Tell our nodes about our level const NodeInfoMap::iterator nodeMapEnd = m_nodeMap.end(); for ( NodeInfoMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it ) { it.data().node->setLevel(l); } const ItemList::iterator end = m_children.end(); for ( ItemList::iterator it = m_children.begin(); it != end; ++it ) { if ( CNItem *cnItem = dynamic_cast<CNItem*>((Item*)*it) ) cnItem->updateNodeLevels(); } }
FlowPartList FlowPart::inputParts() { FlowPartList list; const NodeInfoMap::iterator nEnd = m_nodeMap.end(); for (NodeInfoMap::iterator it = m_nodeMap.begin(); it != nEnd; ++it) { Node *node = m_pFlowCodeDocument->nodeWithID(it.data().id); FlowPartList newList; if (FPNode *fpNode = dynamic_cast<FPNode*>(node)) newList = fpNode->inputFlowParts(); const FlowPartList::iterator nlEnd = newList.end(); for (FlowPartList::iterator it = newList.begin(); it != nlEnd; ++it) { if (*it) list.append(*it); } } return list; }
QString CNItem::nodeId( const QString &internalNodeId ) { NodeInfoMap::iterator it = m_nodeMap.find(internalNodeId); if ( it == m_nodeMap.end() ) return ""; else return it.data().id; }