void ribi::cmap::QtConceptMap::mouseDoubleClickEvent(QMouseEvent *event) { CheckInvariants(); const QPointF pos = mapToScene(event->pos()); //Do not create new nodes when double-clicking on an existing one if (this->scene()->itemAt(pos, QTransform())) return; //Create new node at the mouse cursor its position try { this->DoCommand( new CommandCreateNewNode( m_conceptmap, m_mode, scene(), m_tools, pos.x(), pos.y() ) ); } catch (std::logic_error& ) {} UpdateExamplesItem(); CheckInvariants(); }
NS_IMETHODIMP nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue, const nsAString& aComment, const nsAString& aImage, const nsAString& aStyle, const nsAString& aFinalCompleteValue) { CheckInvariants(); if (! mValues.AppendElement(aValue)) return NS_ERROR_OUT_OF_MEMORY; if (! mComments.AppendElement(aComment)) { mValues.RemoveElementAt(mValues.Length() - 1); return NS_ERROR_OUT_OF_MEMORY; } if (! mImages.AppendElement(aImage)) { mValues.RemoveElementAt(mValues.Length() - 1); mComments.RemoveElementAt(mComments.Length() - 1); return NS_ERROR_OUT_OF_MEMORY; } if (! mStyles.AppendElement(aStyle)) { mValues.RemoveElementAt(mValues.Length() - 1); mComments.RemoveElementAt(mComments.Length() - 1); mImages.RemoveElementAt(mImages.Length() - 1); return NS_ERROR_OUT_OF_MEMORY; } if (!mFinalCompleteValues.AppendElement(aFinalCompleteValue)) { mValues.RemoveElementAt(mValues.Length() - 1); mComments.RemoveElementAt(mComments.Length() - 1); mImages.RemoveElementAt(mImages.Length() - 1); mStyles.RemoveElementAt(mStyles.Length() - 1); return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; }
void ribi::cmap::QtConceptMap::DoCommand(Command * const command) noexcept { CheckInvariants(); m_undo.push(command); CheckInvariants(); this->UpdateConceptMap(); CheckInvariants(); qApp->processEvents(); CheckInvariants(); }
NS_IMETHODIMP nsAutoCompleteSimpleResult::GetMatchCount(uint32_t *aMatchCount) { CheckInvariants(); *aMatchCount = mValues.Length(); return NS_OK; }
inline Mutation::Mutation(MutationType type, int start, int end, std::string newBases) : type_(type), start_(start), end_(end), newBases_(newBases) { if (!CheckInvariants()) throw InvalidInputError(); }
NS_IMETHODIMP nsAutoCompleteSimpleResult::GetStyleAt(int32_t aIndex, nsAString& _retval) { NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mStyles.Length()), NS_ERROR_ILLEGAL_VALUE); CheckInvariants(); _retval = mStyles[aIndex]; return NS_OK; }
NS_IMETHODIMP nsAutoCompleteSimpleResult::GetImageAt(PRInt32 aIndex, nsAString& _retval) { NS_ENSURE_TRUE(aIndex >= 0 && aIndex < PRInt32(mImages.Length()), NS_ERROR_ILLEGAL_VALUE); CheckInvariants(); _retval = mImages[aIndex]; return NS_OK; }
DenseMatrix::DenseMatrix(int rows, int cols) : boost_dense_matrix(rows, cols), usedRanges_(cols, std::make_pair(0, 0)), columnBeingEdited_(-1) { for (int j = 0; j < cols; j++) { CheckInvariants(j); } }
MultiReadMutationScorer<R>::MultiReadMutationScorer(const QuiverConfig& quiverConfig, std::string tpl) : recursor_(quiverConfig.MovesAvailable, quiverConfig.Banding), quiverConfig_(quiverConfig), fwdTemplate_(tpl), revTemplate_(ReverseComplement(tpl)), scorerForRead_() { DEBUG_ONLY(CheckInvariants()); }
inline Mutation::Mutation(MutationType type, int position, char base) : type_(type), start_(position) { if (type == INSERTION) { end_ = position; } else { end_ = position + 1; } newBases_ = (type == DELETION ? "" : std::string(1, base)); if (!CheckInvariants()) throw InvalidInputError(); }
void SmoothHeightMesh::MakeSmoothMesh() { ScopedOnceTimer timer("SmoothHeightMesh::MakeSmoothMesh"); // info: // height-value array has size <maxx + 1> * <maxy + 1> // and represents a grid of <maxx> cols by <maxy> rows // maximum legal index is ((maxx + 1) * (maxy + 1)) - 1 // // row-width (number of height-value corners per row) is (maxx + 1) // col-height (number of height-value corners per col) is (maxy + 1) // // 1st row has indices [maxx*( 0) + ( 0), maxx*(1) + ( 0)] inclusive // 2nd row has indices [maxx*( 1) + ( 1), maxx*(2) + ( 1)] inclusive // 3rd row has indices [maxx*( 2) + ( 2), maxx*(3) + ( 2)] inclusive // ... // Nth row has indices [maxx*(N-1) + (N-1), maxx*(N) + (N-1)] inclusive // const size_t size = (this->maxx + 1) * (this->maxy + 1); // use sliding window of maximums to reduce computational complexity const int intrad = smoothRadius / resolution; const int smoothrad = 3; assert(mesh.empty()); mesh.resize(size); std::vector<float> colsMaxima(maxx + 1, -std::numeric_limits<float>::max()); std::vector<int> maximaRows(maxx + 1, -1); std::vector<float> smoothed(size); FindMaximumColumnHeights(maxx, maxy, intrad, resolution, colsMaxima, maximaRows); for (int y = 0; y <= maxy; ++y) { AdvanceMaximaRows(y, maxx, resolution, colsMaxima, maximaRows); FindRadialMaximum(y, maxx, intrad, resolution, colsMaxima, mesh); FixRemainingMaxima(y, maxx, maxy, intrad, resolution, colsMaxima, maximaRows); #ifdef _DEBUG CheckInvariants(y, maxx, maxy, intrad, resolution, colsMaxima, maximaRows); #endif } // actually smooth with approximate Gaussian blur passes for (int numBlurs = 3; numBlurs > 0; --numBlurs) { BlurHorizontal(maxx, maxy, smoothrad, resolution, mesh, smoothed); mesh.swap(smoothed); BlurVertical(maxx, maxy, smoothrad, resolution, mesh, smoothed); mesh.swap(smoothed); } // `mesh` now contains the smoothed heightmap, save it in origMesh origMesh.resize(size); std::copy(mesh.begin(), mesh.end(), origMesh.begin()); }
/** * Determine if this linker pair is the default * @return true is this is a default pair. We only check the linker because CheckInvariants rules out bogus combinations */ FORCEINLINE bool IsDefault() { CheckInvariants(); return Linker == NULL; }
void ribi::cmap::QtConceptMap::SetConceptMap(const ConceptMap& conceptmap) { RemoveConceptMap(); m_conceptmap = conceptmap; assert(GetConceptMap() == conceptmap); assert(this->scene()); //This std::vector keeps the QtNodes in the same order as the nodes in the concept map //You cannot rely on Collect<QtConceptMapNodeConcept*>(scene), as this shuffles the order //std::vector<QtNode*> qtnodes; assert(Collect<QtNode>(scene()).empty()); //Add the nodes to the scene, if there are any const auto vip = vertices(m_conceptmap); for(auto i=vip.first; i!=vip.second; ++i) { assert(boost::num_vertices(m_conceptmap)); const auto pmap = get(boost::vertex_custom_type, m_conceptmap); const Node node = get(pmap, *i); const bool is_focal_node{i == vip.first}; QtNode * const qtnode{new QtNode(node)}; if (is_focal_node) { qtnode->setFlags(0); } assert(qtnode); assert(!qtnode->scene()); scene()->addItem(qtnode); assert(qtnode->scene()); assert(FindQtNode(node.GetId(), scene())); } //Add the Edges const auto eip = edges(m_conceptmap); for(auto i = eip.first; i != eip.second; ++i) { assert(boost::num_edges(m_conceptmap)); const VertexDescriptor vd_from = boost::source(*i, m_conceptmap); const VertexDescriptor vd_to = boost::target(*i, m_conceptmap); assert(vd_from != vd_to); const auto vertex_map = get(boost::vertex_custom_type, m_conceptmap); const Node from = get(vertex_map, vd_from); const Node to = get(vertex_map, vd_to); assert(from.GetId() != to.GetId()); QtNode * const qtfrom = FindQtNode(from.GetId(), scene()); QtNode * const qtto = FindQtNode(to.GetId(), scene()); assert(qtfrom != qtto); const auto edge_map = get(boost::edge_custom_type, m_conceptmap); const Edge edge = get(edge_map, *i); QtEdge * const qtedge{new QtEdge(edge,qtfrom,qtto)}; if (qtfrom->GetNode().IsCenterNode() || qtto->GetNode().IsCenterNode()) { qtedge->GetQtNode()->setVisible(false); } assert(!qtedge->scene()); assert(!qtedge->GetQtNode()->scene()); assert(!qtedge->GetArrow()->scene()); scene()->addItem(qtedge); //scene()->addItem(qtedge->GetQtNode()); //Get these for free //scene()->addItem(qtedge->GetArrow()); //Get these for free assert(qtedge->scene()); assert(qtedge->GetQtNode()->scene()); assert(qtedge->GetArrow()->scene()); } assert(GetConceptMap() == conceptmap); CheckInvariants(); }
void ribi::cmap::QtConceptMap::keyPressEvent(QKeyEvent *event) { CheckInvariants(); UpdateConceptMap(); CheckInvariants(); switch (event->key()) { case Qt::Key_F1: case Qt::Key_F2: { const auto items = scene()->selectedItems(); if (items.size() != 1) { break; } if (QtNode * const qtnode = dynamic_cast<QtNode*>(items.front())) { OnNodeKeyDownPressed(qtnode, event->key()); } } break; #ifndef NDEBUG case Qt::Key_F9: { throw std::runtime_error("Exception forced by user"); } #endif case Qt::Key_Delete: { UpdateConceptMap(); if (GetVerbosity()) { TRACE("Pressing delete"); } try { DoCommand(new CommandDeleteSelected(m_conceptmap, scene(), m_tools)); } catch (std::logic_error& e) { if (GetVerbosity()) { TRACE(e.what()); } } } return; case Qt::Key_Escape: { if (GetVerbosity()) { TRACE("Pressing Escape"); } //Only remove the 'new arrow' if present if (m_arrow->isVisible()) { if (GetVerbosity()) { TRACE("Remove the new arrow"); } m_arrow->hide(); assert(!m_arrow->isVisible()); return; } } break; case Qt::Key_Equal: if (GetVerbosity()) { TRACE("Pressing Qt::Key_Equal"); } this->scale(1.1,1.1); break; case Qt::Key_Minus: if (GetVerbosity()) { TRACE("Pressing Qt::Key_Minus"); } this->scale(0.9,0.9); break; case Qt::Key_E: if (event->modifiers() & Qt::ControlModifier) { if (GetVerbosity()) { TRACE("Pressing CTRL-E"); } try { this->DoCommand(new CommandCreateNewEdgeBetweenTwoSelectedNodes(GetConceptMap(),m_mode,scene(),m_tools)); } catch (std::logic_error& ) {} } return; case Qt::Key_T: if (event->modifiers() & Qt::ControlModifier) { if (GetVerbosity()) { TRACE("Pressing CTRL-T"); } try { const auto cmd = new CommandToggleArrowTail(GetConceptMap(), scene()); this->DoCommand(cmd); } catch (std::logic_error& e) {} } return; case Qt::Key_H: if (event->modifiers() & Qt::ControlModifier) { if (GetVerbosity()) { TRACE("Pressing CTRL-H"); } try { const auto cmd = new CommandToggleArrowHead(GetConceptMap(), scene()); this->DoCommand(cmd); } catch (std::logic_error& e) {} } return; case Qt::Key_N: if (event->modifiers() & Qt::ControlModifier) { if (GetVerbosity()) { TRACE("Pressing CTRL-N"); } try { this->DoCommand(new CommandCreateNewNode(m_conceptmap,m_mode,scene(),m_tools,0.0,0.0)); } catch (std::logic_error& ) {} } return; case Qt::Key_Z: if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ShiftModifier) { this->m_undo.redo(); } else { this->m_undo.undo(); } } return; case Qt::Key_Question: if (GetVerbosity()) { TRACE("Pressing Qt::Key_Question"); } UpdateConceptMap(); break; } for (auto qtedge: GetSelectedQtEdges(*GetScene())) { qtedge->keyPressEvent(event); qtedge->update(); } QtKeyboardFriendlyGraphicsView::keyPressEvent(event); UpdateConceptMap(); CheckInvariants(); }
ribi::cmap::QtConceptMap::QtConceptMap(QWidget* parent) : QtKeyboardFriendlyGraphicsView(parent), m_arrow{new QtNewArrow}, m_conceptmap{}, m_examples_item(new QtExamplesItem), m_highlighter{new QtItemHighlighter}, m_mode{Mode::uninitialized}, m_tools{new QtTool} { #ifndef NDEBUG this->SetVerbosity(false); #endif this->setScene(new QGraphicsScene(this)); assert(!m_highlighter->GetItem()); //Add QtNewArrow assert(!m_arrow->scene()); scene()->addItem(m_arrow); //Add the QtNewArrow so it has a parent assert(m_arrow->scene()); m_arrow->hide(); assert(!m_arrow->isVisible()); //Add QtExamplesItem assert(!m_examples_item->scene()); scene()->addItem(m_examples_item); //Add the examples so it has a parent assert(m_examples_item->scene()); //Add QtTool assert(!m_tools->scene()); this->scene()->addItem(m_tools); assert(m_tools->scene()); //Responds when selectionChanged is triggered assert(Collect<QtNode>(scene()).empty()); //Without this line, mouseMoveEvent won't be called this->setMouseTracking(true); { assert(this->scene()); QLinearGradient linearGradient(-500,-500,500,500); linearGradient.setColorAt(0.0,QColor(214,214,214)); linearGradient.setColorAt(1.0,QColor(255,255,255)); this->scene()->setBackgroundBrush(linearGradient); //this->scene()->setBackgroundBrush(QBrush(QColor(255,255,255))); } //Connect the scene #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) QObject::connect(scene(),SIGNAL(focusItemChanged(QGraphicsItem*,QGraphicsItem*,Qt::FocusReason)),this,SLOT(onFocusItemChanged(QGraphicsItem*,QGraphicsItem*,Qt::FocusReason))); #else #endif QObject::connect(scene(),SIGNAL(selectionChanged()),this,SLOT(onSelectionChanged())); m_examples_item->SetCenterPos(123,456); //Irrelevant where CheckInvariants(); { QTimer * const timer{new QTimer(this)}; QObject::connect(timer, SIGNAL(timeout()), this, SLOT(onCheckCollision())); timer->start(10); } }
/** * Constructor * @param InLinker linker to assign * @param InLinkerIndex linker index to assign */ FLinkerIndexPair(FLinkerLoad* InLinker, int32 InLinkerIndex) : Linker(InLinker), LinkerIndex(InLinkerIndex) { CheckInvariants(); }
/** * Determine if this linker pair is the default * @return true is this is a default pair. We only check the linker because CheckInvariants rules out bogus combinations */ FORCEINLINE bool IsDefault() { CheckInvariants(); return Linker == nullptr; }
/** * default contructor * Default constructor must be the default item */ FLinkerIndexPair() : Linker(NULL), LinkerIndex(INDEX_NONE) { CheckInvariants(); }