void HikingTrailStopAddAction::_setFromParametersMap(const ParametersMap& map) { try { _trail = HikingTrailTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_TRAIL_ID), *_env); } catch(ObjectNotFoundException<HikingTrail>&) { throw ActionException("No such trail"); } const string city(map.get<string>(PARAMETER_CITY)); GeographyModule::CityList cities(GeographyModule::GuessCity(city, 1)); if(cities.empty()) { throw ActionException("City not found"); } const string place(map.get<string>(PARAMETER_NAME)); vector<boost::shared_ptr<StopArea> > stops( cities.front()->search<StopArea>(place, 1) ); if(stops.empty()) { throw ActionException("Place not found"); } _stop = StopAreaTableSync::GetEditable(stops.front()->getKey(), *_env); _rank = map.getOptional<size_t>(PARAMETER_RANK); if(_rank && *_rank > _trail->getStops().size()) { throw ActionException("Rank is too high"); } }
void QtGradientStopsModel::clear() { QList<QtGradientStop *> stopsList = stops().values(); QListIterator<QtGradientStop *> it(stopsList); while (it.hasNext()) removeStop(it.next()); }
void turnDeg(int deg, bool direction, int waitTime, int speed){ int distance = convertDegDist(deg); int clicks = convertDistClick(distance); int power = 0; int minimumPower = 40; int targetPower = speed; nMotorEncoder[motor_right] = 0; nMotorEncoder[motor_left] = 0; if(direction == TURN_RIGHT){ while(abs(nMotorEncoder[motor_left]) < abs(clicks) ){//&& abs(nMotorEncoder[motor_right]) < abs(clicks)){ if( abs(nMotorEncoder[motor_left]) < clicks / 2 && power < targetPower ){ power += 1; } if( abs(nMotorEncoder[motor_left]) >= clicks / 1.5 && power > minimumPower ){ power -= 1; } motor [motor_right] = -power; motor [motor_left] = power; } } else{ while(abs(nMotorEncoder[motor_right]) < abs(clicks) ){//&& abs(nMotorEncoder[motor_right]) < abs(clicks)){ if( abs(nMotorEncoder[motor_right]) < clicks / 2 && abs(power) < targetPower ){ power += 1; } if( abs(nMotorEncoder[motor_right]) > clicks / 2 && abs(power) > minimumPower ){ power -= 1; } motor [motor_right] = power; motor [motor_left] = -power; } } stops(); wait1Msec(waitTime); }
void QtGradientStopsModel::selectAll() { QList<QtGradientStop *> stopsList = stops().values(); QListIterator<QtGradientStop *> it(stopsList); while (it.hasNext()) selectStop(it.next(), true); }
void DisplayScreenTransferDestinationAddAction::_setFromParametersMap(const ParametersMap& map) { try { _screen = DisplayScreenTableSync::GetEditable(map.get<RegistryKeyType>(PARAMETER_DISPLAY_SCREEN_ID), *_env); _transferPlace = StopAreaTableSync::Get(map.get<RegistryKeyType>(PARAMETER_TRANSFER_PLACE_ID), *_env); } catch(ObjectNotFoundException<DisplayScreen>&) { throw ActionException("Display screen not found"); } catch(ObjectNotFoundException<StopArea>&) { throw ActionException("Transfer place not found"); } const string city(map.get<string>(PARAMETER_DESTINATION_PLACE_CITY_NAME)); GeographyModule::CityList cities(GeographyModule::GuessCity(city, 1)); if(cities.empty()) { throw ActionException("City not found"); } const string place(map.get<string>(PARAMETER_DESTINATION_PLACE_NAME)); vector<boost::shared_ptr<StopArea> > stops( cities.front()->search<StopArea>(place, 1) ); if(stops.empty()) { throw ActionException("Place not found"); } _destinationPlace = stops.front().get(); }
void locateIR () { //Locates IR Beacon int slowMovement = 25; while(HTIRS2readACDir(IR_SENSOR1) != 4 && HTIRS2readACDir(IR_SENSOR1) != 6){ //Moves until IR Sensor gets inbetween IR fields 4 and 6 motor [motor_left] = slowMovement; motor [motor_right] = slowMovement; } stops(); //Stops movement }
/* The function strange takes one argument p. This argument must be the textual representation of a C-function. */ int strange(const char* x) { int result; result = stops(x, x); if (result == 1) while (1) ++result; return result; }
QtGradientStop *QtGradientStopsModel::firstSelected() const { PositionStopMap stopList = stops(); PositionStopMap::ConstIterator itStop = stopList.constBegin(); while (itStop != stopList.constEnd()) { QtGradientStop *stop = itStop.value(); if (isSelected(stop)) return stop; ++itStop; }; return 0; }
void GradientStopsEditor::compositeStopDeleted( int stop ) { if( !handleSignals ) return; handleSignals = false; r.deleteStop( stop ); g.deleteStop( stop ); b.deleteStop( stop ); const QGradientStops &s = stops(); c.setCompositeGradientStops( s ); handleSignals = true; emit stopsChanged( s ); }
void turn(int speed, int time, bool direction) { //Makes robot turn in the specified direction if (direction == TURN_RIGHT) { //Turns left motor [motor_left] = speed; motor [motor_right] = -speed; wait1Msec (time); } else { //Turns Right motor [motor_left] = -speed; motor [motor_right] = speed; wait1Msec (time); } stops(); }
void GradientStopsEditor::compositeStopMoved( int stop, int value, qreal position, int newIndex ) { if( !handleSignals ) return; handleSignals = false; r.moveStop( stop, r.stopValue( stop ), position ); g.moveStop( stop, g.stopValue( stop ), position ); b.moveStop( stop, b.stopValue( stop ), position ); const QGradientStops &s = stops(); c.setCompositeGradientStops( s ); handleSignals = true; emit stopsChanged( s ); }
void shincapit(int time, int motorSpeed, int waitTime, bool dir) { //Moves the Flag and Flag Adjust if(dir == FORWARD){ servo[servoFlagAdjust] = 0; //Moves the servo } else{ servo[servoFlagAdjust] = 256; //moves the servo in } wait1Msec(2000); servo[servoFlagAdjust] = 127; //Stops the continous servo motor[motorFlag] = motorSpeed; wait1Msec(time); stops(); }
QtGradientStopsModel *QtGradientStopsModel::clone() const { QtGradientStopsModel *model = new QtGradientStopsModel(); QMap<qreal, QtGradientStop *> stopsToClone = stops(); QMapIterator<qreal, QtGradientStop *> it(stopsToClone); while (it.hasNext()) { it.next(); model->addStop(it.key(), it.value()->color()); } // clone selection and current also return model; }
void GradientStopsEditor::compositeStopAdded( int value, qreal position, int index ) { if( !handleSignals ) return; handleSignals = false; r.addStop( value, position ); g.addStop( value, position ); b.addStop( value, position ); const QGradientStops &s = stops(); c.setCompositeGradientStops( s ); handleSignals = true; emit stopsChanged( s ); }
void HikingTrailStopRemoveAction::run( Request& request ) { // stringstream text; // ::appendToLogIfChange(text, "Parameter ", _object->getAttribute(), _newValue); HikingTrail::Stops stops(_trail->getStops()); stops.erase(stops.begin() + _rank); _trail->setStops(stops); HikingTrailTableSync::Save(_trail.get()); // ::AddUpdateEntry(*_object, text.str(), request.getUser().get()); }
void DisplayScreenRemovePhysicalStopAction::run(Request& request) { // Preparation ArrivalDepartureTableGenerator::PhysicalStops stops(_screen->getPhysicalStops(false)); stops.erase(_stop->getKey()); _screen->setStops(stops); // Log ArrivalDepartureTableLog::addUpdateEntry( *_screen, "Retrait de l'arrêt de départ "+ _stop->getCodeBySources() +"/"+ _stop->getName(), *request.getUser() ); DisplayScreenTableSync::Save(_screen.get()); }
// set text and set a number of parameters for creating a layout (width, tabstops, strategy, // hyphenFrequency) static void nSetupParagraph(JNIEnv* env, jclass, jlong nativePtr, jcharArray text, jint length, jfloat firstWidth, jint firstWidthLineLimit, jfloat restWidth, jintArray variableTabStops, jint defaultTabStop, jint strategy, jint hyphenFrequency) { LineBreaker* b = reinterpret_cast<LineBreaker*>(nativePtr); b->resize(length); env->GetCharArrayRegion(text, 0, length, b->buffer()); b->setText(); b->setLineWidths(firstWidth, firstWidthLineLimit, restWidth); if (variableTabStops == nullptr) { b->setTabStops(nullptr, 0, defaultTabStop); } else { ScopedIntArrayRO stops(env, variableTabStops); b->setTabStops(stops.get(), stops.size(), defaultTabStop); } b->setStrategy(static_cast<BreakStrategy>(strategy)); b->setHyphenationFrequency(static_cast<HyphenationFrequency>(hyphenFrequency)); }
void drive2Encoder(int iEncoder, int power, bool direction) { if(direction == FORWARD){ while(abs(nMotorEncoder[motor_right]) < iEncoder && abs(nMotorEncoder[motor_left]) < iEncoder ){ motor [motor_left] = power; motor [motor_right] = power; wait1Msec(50); } } else{ while(abs(nMotorEncoder[motor_right]) > iEncoder && abs(nMotorEncoder[motor_left]) > iEncoder ){ motor [motor_left] = -power; motor [motor_right] = -power; wait1Msec(50); } } stops(); wait1Msec(500); }
static int pyATCAnim_setStops(pyATCAnim* self, PyObject* value, void*) { if (value == NULL) { self->fThis->setStops(std::vector<float>()); return 0; } else if (PyList_Check(value)) { std::vector<float> stops(PyList_Size(value)); for (size_t i=0; i<stops.size(); i++) { if (!PyFloat_Check(PyList_GetItem(value, i))) { PyErr_SetString(PyExc_TypeError, "stops should be a list of floats"); return -1; } stops[i] = PyFloat_AsDouble(PyList_GetItem(value, i)); } self->fThis->setStops(stops); return 0; } else { PyErr_SetString(PyExc_TypeError, "stops should be a list of floats"); return -1; } }
void PaletteEditor::closeEvent(QCloseEvent* event) { logInfo("PaletteEditor::closeEvent : saving settings"); QSettings settings; settings.beginGroup("paletteeditor"); settings.setValue("tabwidgetindex", m_tabWidget->currentIndex()); settings.setValue("lastdirectory", m_lastBrowseDir); // save the gradient to the settings GradientStops stops( m_gradientStops->getStops() ); settings.beginWriteArray("gradient"); for (int n = 0 ; n < stops.size() ; n++) { settings.setArrayIndex(n); settings.setValue("pos", stops[n].first); settings.setValue("color", stops[n].second); } settings.endArray(); event->accept(); }
void HikingTrailStopAddAction::run( Request& request ){ //stringstream text; //::appendToLogIfChange(text, "Parameter ", _object->getAttribute(), _newValue); HikingTrail::Stops stops(_trail->getStops()); if(_rank) { stops.insert(stops.begin() + *_rank, _stop.get()); } else { stops.push_back(_stop.get()); } _trail->setStops(stops); HikingTrailTableSync::Save(_trail.get()); //::AddUpdateEntry(*_object, text.str(), request.getUser().get()); }
void DisplayScreenAddDisplayedPlaceAction::_setFromParametersMap(const ParametersMap& map) { try { _screen = DisplayScreenTableSync::GetEditable( map.get<RegistryKeyType>(PARAMETER_SCREEN_ID), *_env ); RegistryKeyType id(map.getDefault<RegistryKeyType>(PARAMETER_PLACE, 0)); if(id > 0) { _place = StopAreaTableSync::Get(id, *_env); } else { const string city(map.get<string>(PARAMETER_CITY_NAME)); GeographyModule::CityList cities(GeographyModule::GuessCity(city, 1)); if(cities.empty()) { throw ActionException("City not found"); } const string place(map.get<string>(PARAMETER_PLACE_NAME)); vector<boost::shared_ptr<StopArea> > stops( cities.front()->search<StopArea>(place, 1) ); if(stops.empty()) { throw ActionException("Place not found"); } _place = stops.front(); } } catch (ObjectNotFoundException<DisplayScreen>&) { throw ActionException("Display screen not found"); } }
void moveDist(int dist, int waitTime, int speed){ int clicks = convertDistClick(dist); int power = 0; int targetPower = speed; int beginning = 200; int shortDist = 400; int slowMotion = 4; nMotorEncoder[motor_right] = 0; nMotorEncoder[motor_left] = 0; while(nMotorEncoder[motor_right] < clicks){ if(abs(clicks) > shortDist){ if(nMotorEncoder[motor_right] < beginning && power < targetPower){ power += 2; } if(clicks - nMotorEncoder[motor_right] < beginning && power > slowMotion){ power -= 2; } } if(clicks > 0 && clicks <= shortDist){ power = slowMotion; } if(abs(clicks) > shortDist && clicks < 0){ if(abs(nMotorEncoder[motor_right]) < abs(beginning) && abs(power) < abs(targetPower)){ power -= 2; } if(abs(clicks - nMotorEncoder[motor_right]) < abs(beginning) && power < slowMotion){ power += 2; } } if(clicks < 0 && abs(clicks) < abs(shortDist)){ power = -slowMotion; } motor[motor_right] = power; motor[motor_left] = power; } stops(); wait1Msec(waitTime); }
QColor QtGradientStopsModel::color(qreal pos) const { PositionStopMap gradStops = stops(); if (gradStops.isEmpty()) return QColor::fromRgbF(pos, pos, pos, 1.0); if (gradStops.contains(pos)) return gradStops[pos]->color(); gradStops[pos] = 0; PositionStopMap::ConstIterator itStop = gradStops.constFind(pos); if (itStop == gradStops.constBegin()) { ++itStop; return itStop.value()->color(); } if (itStop == --gradStops.constEnd()) { --itStop; return itStop.value()->color(); } PositionStopMap::ConstIterator itPrev = itStop; PositionStopMap::ConstIterator itNext = itStop; --itPrev; ++itNext; double prevX = itPrev.key(); double nextX = itNext.key(); double coefX = (pos - prevX) / (nextX - prevX); QColor prevCol = itPrev.value()->color(); QColor nextCol = itNext.value()->color(); QColor newColor; newColor.setRgbF((nextCol.redF() - prevCol.redF() ) * coefX + prevCol.redF(), (nextCol.greenF() - prevCol.greenF()) * coefX + prevCol.greenF(), (nextCol.blueF() - prevCol.blueF() ) * coefX + prevCol.blueF(), (nextCol.alphaF() - prevCol.alphaF()) * coefX + prevCol.alphaF()); return newColor; }
void QtGradientStopsModel::flipAll() { QMap<qreal, QtGradientStop *> stopsMap = stops(); QMapIterator<qreal, QtGradientStop *> itStop(stopsMap); itStop.toBack(); QMap<QtGradientStop *, bool> swappedList; while (itStop.hasPrevious()) { itStop.previous(); QtGradientStop *stop = itStop.value(); if (swappedList.contains(stop)) continue; const double newPos = 1.0 - itStop.key(); if (stopsMap.contains(newPos)) { QtGradientStop *swapped = stopsMap.value(newPos); swappedList[swapped] = true; swapStops(stop, swapped); } else { moveStop(stop, newPos); } } }
void move(int speed, int time) { //Makes robot move up or down in the specified direction motor[motor_right] = speed; motor[motor_left] = speed; wait1Msec (time); stops (); }
void PaletteEditor::stopsChangedAction() { static const int GradientBufferLastIdx = GradientBufferSize - 1; static const qreal dx = 1.0 / GradientBufferSize; QSize s( m_gradientLabel->maximumSize() ); QRect r( QPoint(0, 0), QSize(s.width(), (s.height() / 2.0 ) ) ); QImage palette_image(s, QImage::Format_RGB32); QPainter painter(&palette_image); GradientStops stops(m_gradientStops->getStops()); qStableSort(stops.begin(), stops.end(), GradientStop::lessThanGradientStopComparison); // now apply the ends and update the palette GradientStops ends( m_gradientEnds->getStops() ); QGradient::Spread spread((QGradient::Spread)m_gradientSpreadGroup->checkedId()); GradientStop n_stop(stops.first()); QRgb ccolor = n_stop.second.rgba(); for (int n = 0, fpos = n_stop.first * GradientBufferSize ; n < fpos ; n++) m_gradient[qMin(n, GradientBufferLastIdx)] = ccolor; int last_stop_idx = stops.size() - 1; for (int begin_idx = 0; begin_idx < last_stop_idx ; begin_idx++) { GradientStop a = stops.at(begin_idx); GradientStop b = stops.at(begin_idx + 1); QColor ac = a.second; QColor bc = b.second; qreal d = ( b.first - a.first ); qreal rdx, gdx, bdx, adx; if (b.colorspace == 0) { rdx = ( (bc.red() - ac.red() ) / d ) * dx; gdx = ( (bc.green() - ac.green() ) / d ) * dx; bdx = ( (bc.blue() - ac.blue() ) / d ) * dx; adx = ( (bc.alpha() - ac.alpha() ) / d ) * dx; } else { rdx = ( (bc.hue() - ac.hue() ) / d ) * dx; gdx = ( (bc.saturation() - ac.saturation() ) / d ) * dx; bdx = ( (bc.value() - ac.value() ) / d ) * dx; adx = ( (bc.alpha() - ac.alpha() ) / d ) * dx; if (b.colorspace == 1) { if (rdx == 0.0) rdx = 180.0 / d * dx; else if (rdx < 0) rdx *= -1; } else { if (rdx == 0.0) rdx = -180.0 / d * dx; else if (rdx > 0) rdx *= -1; } } int n = a.first * GradientBufferSize ; int nb = (int)(b.first * GradientBufferSize ); for (int i = 0 ; n < nb ; i++, n++) { if (b.colorspace == 0) { m_gradient[n] = qRgba( qBound(0, (int)( ac.red() + rdx * i + 0.5 ), 255), qBound(0, (int)( ac.green() + gdx * i + 0.5 ), 255), qBound(0, (int)( ac.blue() + bdx * i + 0.5 ), 255), qBound(0, (int)( ac.alpha() + adx * i + 0.5 ), 255)); } else { int h = (int)( ac.hue() + rdx * i + 0.5 ); if (h < 0) h += 360; m_gradient[n] = QColor::fromHsv(h % 360, qBound(0, (int)( ac.saturation() + gdx * i + 0.5 ), 255), qBound(0, (int)( ac.value() + bdx * i + 0.5 ), 255), qBound(0, (int)( ac.alpha() + adx * i + 0.5 ), 255)).rgba(); } } } n_stop = stops.last(); ccolor = n_stop.second.rgba(); for (int n = n_stop.first * GradientBufferSize ; n < GradientBufferSize ; n++) m_gradient[n] = ccolor; qreal start(ends.at(0).first); qreal end(ends.at(1).first); int begin_idx = start * 256 ; int end_idx = end * 256 ; int ibuf_size = end_idx - begin_idx; flam3_palette_entry* ibuf = new flam3_palette_entry[ibuf_size](); // a very acute filter qreal c2 = 0.01; qreal c3 = 1.0; qreal c4 = 0.01; qreal norm = c2 + c3 + c4; qreal k = 0.0; qreal skip( (GradientBufferSize / 256.0) / qMax(qreal(1.0/GradientBufferSize), end - start) ); for (int n = 0 ; n < ibuf_size ; n++, k += skip) { int j = k; QRgb a2( m_gradient[qBound(0, j + 0, GradientBufferLastIdx)] ); QRgb a3( m_gradient[qMin(j + 1, GradientBufferLastIdx)] ); QRgb a4( m_gradient[qMin(j + 2, GradientBufferLastIdx)] ); ibuf[n].color[0] = (qRed(a2)*c2 + qRed(a3)*c3 + qRed(a4)*c4 ) / (norm * 255.); ibuf[n].color[1] = (qGreen(a2)*c2 + qGreen(a3)*c3 + qGreen(a4)*c4 ) / (norm * 255.); ibuf[n].color[2] = (qBlue(a2)*c2 + qBlue(a3)*c3 + qBlue(a4)*c4 ) / (norm * 255.); ibuf[n].color[3] = (qAlpha(a2)*c2 + qAlpha(a3)*c3 + qAlpha(a4)*c4 ) / (norm * 255.); } // update the gradient editor label painter.fillRect(QRect(QPoint(0,0), s), checkers); if (ibuf_size == 256) { for (int n = 0, h = s.height() ; n < 256 ; n++) { painter.setPen(QColor::fromRgbF(ibuf[n].color[0], ibuf[n].color[1], ibuf[n].color[2], ibuf[n].color[3])); painter.drawLine(n, 0, n, h); } } else { for (int n = 0, h = s.height(), j = 0 ; n < 256 ; n++, j += 4) { QRgb a2( m_gradient[qBound(0, j + 0, GradientBufferLastIdx)] ); QRgb a3( m_gradient[qMin(j + 1, GradientBufferLastIdx)] ); QRgb a4( m_gradient[qMin(j + 2, GradientBufferLastIdx)] ); QRgb r((qRed(a2)*c2 + qRed(a3)*c3 + qRed(a4)*c4 ) / norm ); QRgb g((qGreen(a2)*c2 + qGreen(a3)*c3 + qGreen(a4)*c4 ) / norm ); QRgb b((qBlue(a2)*c2 + qBlue(a3)*c3 + qBlue(a4)*c4 ) / norm ); QRgb a((qAlpha(a2)*c2 + qAlpha(a3)*c3 + qAlpha(a4)*c4 ) / norm ); QColor c(r, g, b, a); painter.setPen(c); painter.drawLine(n, 0, n, h); } } m_gradientLabel->setPixmap(QPixmap::fromImage(palette_image)); // Rescale the gradient colors into the palette with a simple filter if (spread == QGradient::PadSpread) { QRgb fc(m_gradient[0]); flam3_palette_entry e = { 0., { qRed(fc)/255., qGreen(fc)/255., qBlue(fc)/255., qAlpha(fc)/255. }}; for (int n = 0 ; n < begin_idx ; n++) p[n] = e; for (int n = begin_idx, j = 0 ; n < end_idx ; n++, j++) p[n] = ibuf[j]; fc = m_gradient[GradientBufferLastIdx]; e = (flam3_palette_entry){ 1., { qRed(fc)/255., qGreen(fc)/ 255., qBlue(fc)/255., qAlpha(fc)/255. }}; for (int n = end_idx ; n < 256 ; n++) p[n] = e; } else if (spread == QGradient::RepeatSpread) { for (int n = begin_idx, j = 0 ; n < 256 ; n++, j++) p[n] = ibuf[j % ibuf_size]; for (int n = begin_idx - 1, j = ibuf_size * 4096 - 1 ; n >= 0 ; n--, j--) p[n] = ibuf[j % ibuf_size]; } else if (spread == QGradient::ReflectSpread) { for (int n = begin_idx, j = 0, h = 4096*ibuf_size -1 ; n < begin_idx + ibuf_size ; n++, j++, h--) { for (int k = n, q = n + ibuf_size ; k < 256 ; k += 2*ibuf_size, q += 2*ibuf_size ) { p[k] = ibuf[j % ibuf_size]; if (q < 256) p[q] = ibuf[h % ibuf_size]; } } for (int n = begin_idx - 1, j = ibuf_size * 4096 - 1, h = 0 ; n >= begin_idx - ibuf_size ; n--, j--, h++) { for (int k = n, q = n - ibuf_size ; k >= 0 ; k -= 2*ibuf_size, q -= 2*ibuf_size ) { p[k] = ibuf[h % ibuf_size]; if (q >= 0) p[q] = ibuf[j % ibuf_size]; } } } delete[] ibuf; setPaletteView(); emit paletteChanged(); }