Interface::Interface(KeywordExtractor *extractor, QWidget *parent): QWidget(parent) { _extractor = extractor; _lastDocument = ""; documentPath = new QLineEdit; resultText = new QTextEdit; resultText->setReadOnly(true); browseButton = new QPushButton("Browse"); learnButton = new QPushButton("Learn"); computeButton = new QPushButton("Compute"); leftLayout = new QVBoxLayout; rightLayout = new QVBoxLayout; mainLayout = new QHBoxLayout; leftLayout->addWidget(documentPath); leftLayout->addWidget(resultText); rightLayout->addWidget(browseButton); rightLayout->addWidget(computeButton); rightLayout->addWidget(learnButton); rightLayout->addStretch(); mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); this->setLayout(mainLayout); connect(browseButton, SIGNAL(clicked()), this, SLOT(browseSlot())); connect(learnButton, SIGNAL(clicked()), this, SLOT(learnSlot())); connect(computeButton, SIGNAL(clicked()), this, SLOT(computeSlot())); }
// Adds the item to our hashmap. Returns true if hitpoint was inside the relevant volume or falls otherwise. bool CircularSimulationResult::addItem(hpvec3 point) { // Check whether the point is in our Z range, if not abort if (!isInZRange(point)) { return false; } // Compute the angles of the triangle points to the reference dir hpreal angle = computeAngle(point); hpuint angleSlot = computeAngleSlot(angle); hpuint posZSlot = convertPosZToPosZSlot(point.z); hpuint slot = computeSlot(angleSlot, posZSlot); assert(angleSlot < m_angleSteps); assert(posZSlot < m_posZSteps); hpreal radius = computeRadiusXY(point); hpreal oldRadius = getItem(angleSlot, posZSlot); if (oldRadius > radius) { m_entries->erase(slot); m_entries->insert(std::pair<hpuint,hpreal>(slot, radius)); } return true; }
// -------------------------------------------------- void BoxViewer::selectViewPokemon() // -------------------------------------------------- { // Compute the current cursor slot computeSlot(&cursorBox); // If the cursor isn't in a box slot if (cursorBox.slot == SLOT_NO_SELECTION) { vPkm.pkm = NULL; } // If the cursor is in a box slot else { // Wonder box if (isWonderBox(*cursorBox.box, cursorBox.inBank)) { vPkm.pkm = save->getWPkm(cursorBox.inslot); } else { vPkm.pkm = save->getPkm(*cursorBox.box, cursorBox.inslot, cursorBox.inBank); } populateVPkmData(&vPkm); } }
hpreal CircularSimulationResult::getItem(hpuint angleSlot, hpuint posZSlot) { assert(angleSlot < m_angleSteps); assert(posZSlot < m_posZSteps); hpuint slot = computeSlot(angleSlot, posZSlot); std::unordered_map<hpuint,hpreal>::const_iterator result = m_entries->find(slot); if (result == m_entries->end()) { return INFINITY; } else { return result->second; } }
// -------------------------------------------------- void BoxViewer::selectMovePokemon() // -------------------------------------------------- { // Compute the current cursor slot computeSlot(&cursorBox); // If no Pokémon is currently selected if (!sPkm) { // If the current Pokémon slot isn't empty (to avoid empty slot move) if (!vPkm.emptySlot) { // Select the current Pokémon sPkm = vPkm.pkm; extractBoxSlot(&sSlot, &cursorBox); // If the buttons are used. if (!isPkmDragged) { isPkmHeld = true; } } } // Else if there is a current Pokémon else if (vPkm.pkm) { // If the selected Pokémon isn't the current Pokémon if (sPkm != vPkm.pkm) { // Swap the Pokémon currenlty selected and the current Pokémon, and keep the return value (true: had moved, false: hadn't) bool moved = save->movePkm(sPkm, vPkm.pkm, sSlot.inBank, cursorBox.inBank); // If the Pokémon had moved if (moved) { // Cancel the selection cancelMovePokemon(); } // And populate the Pokémon data populateVPkmData(&vPkm); } else { // Cancel the selection, since it's moved to the same slot cancelMovePokemon(); } } }
// -------------------------------------------------- void BoxViewer::selectViewBox() // -------------------------------------------------- { // Compute the current cursor slot computeSlot(&cursorBox); // Wonder box if (isWonderBox(*cursorBox.box, cursorBox.inBank)) { vBKBox = save->getWBox(); } else { (cursorBox.inBank ? vBKBox : vPCBox) = save->getBox(*cursorBox.box, cursorBox.inBank); } }
hpreal CircularSimulationResult::getItem(hpvec3 point) { // Check whether the point is in our Z range, if not abort and return positive infinity if (!isInZRange(point)) { return INFINITY; } // Compute the angles of the triangle points to the reference dir hpreal angle = computeAngle(point); hpuint angleSlot = computeAngleSlot(angle); hpuint posZSlot = convertPosZToPosZSlot(point.z); hpuint slot = computeSlot(angleSlot, posZSlot); assert(angleSlot < m_angleSteps); assert(posZSlot < m_posZSteps); std::unordered_map<hpuint,hpreal>::const_iterator result = m_entries->find(slot); if (result == m_entries->end()) { return INFINITY; } else { return result->second; } }
// -------------------------------------------------- void BoxViewer::selectMultiMovePokemon(bool check) // -------------------------------------------------- { // Compute the current cursor slot computeSlot(&cursorBox); if (check) { // If there is a real Pokémon to check if (vPkm.pkm && !vPkm.emptySlot) { // If the Pokémon is already checked, uncheck it if (vPkm.pkm->checked) { u8 i; sPkmCount--; vPkm.pkm->checked = false; for (i = 0; sPkms[i] != vPkm.pkm; i++); for (; i < sPkmCount; i++) sPkms[i] = sPkms[i+1]; } // If there is enough place in the checked list else if (sPkmCount < BOX_PKM_COUNT) { vPkm.pkm->checked = true; sPkms[sPkmCount] = vPkm.pkm; sPkmBanked[sPkmCount] = cursorBox.inBank; sPkmCount++; } } } else { u8 vPkmCount = 0; box_s* box = (cursorBox.inBank ? vBKBox : vPCBox); // Count the free slots for (u8 i = 0; i < BOX_PKM_COUNT; i++) { if (save->isPkmEmpty(&box->slot[i])) { vPkmCount++; } } // If there is enough free slot if (vPkmCount >= sPkmCount) { // Move the checked Pokémon to the current box for (u8 i = 0, ii = 0; ii < sPkmCount; ii++) { // Find the next empty slot for (; !save->isPkmEmpty(&box->slot[i]) && i < BOX_PKM_COUNT; i++); save->movePkm(sPkms[ii], &box->slot[i], sPkmBanked[ii], cursorBox.inBank); box->slot[i].checked = false; i++; } cancelMovePokemon(); } } }