Exemple #1
0
DatetimeList Stock::getDatetimeList(const KQuery& query) const {
    DatetimeList result;
    size_t start = 0, end = 0;
    if (getIndexRange(query, start, end)) {
        result = getDatetimeList(start, end, query.kType());
    }
    return result;
}
Exemple #2
0
KRecord Stock::
getKRecordByDate(const Datetime& datetime, KQuery::KType ktype) const {
    size_t startix = 0, endix = 0;
    KQuery query = KQueryByDate(datetime, Datetime(datetime.number() + 1), ktype);
    if (getIndexRange(query, startix, endix)) {
        return getKRecord(startix, ktype);
    }

    return Null<KRecord>();
}
Exemple #3
0
price_t Stock
::getMarketValue(const Datetime& datetime, KQuery::KType ktype) const{
    if (isNull()) {
        return 0.0;
    }

    if (!valid()) {
        if (datetime > lastDatetime()) {
            return 0.0;
        }
    }

    KQuery query = KQueryByDate(datetime, Null<Datetime>(), ktype);
    price_t price = 0.0;
    size_t out_start, out_end;
    KRecord k;
    if (getIndexRange(query, out_start, out_end)) {
        //找到的是>=datetime的记录
        k = getKRecord(out_start, ktype);
        if (k.datetime == datetime) {
            price = k.closePrice;
        } else {
            if (out_start != 0) {
                k = getKRecord(out_start - 1, ktype);
                price = k.closePrice;
            }
        }

    } else {
        //没有找到,则取最后一条记录
        size_t total = getCount(ktype);
        if (total > 0) {
            price = getKRecord(total - 1, ktype).closePrice;
        }
    }

    return price;
}
PhysicsFrameSplineEditor::PhysicsFrameSplineEditor(const GuiText& caption, GuiPane* dockPane, shared_ptr<GuiTheme> theme) : 
    GuiWindow(caption,
              theme,
              Rect2D::xywh(0,0,100,40), 
              GuiTheme::TOOL_WINDOW_STYLE,
              GuiWindow::HIDE_ON_CLOSE),
    m_selectedControlPointIndex(0),
    m_isDocked(dockPane != NULL)
    {

    m_cachedPhysicsFrameString = CFrame(m_cachedPhysicsFrameValue).toAny().unparse();
    m_spline.append(CFrame());

    m_surface.reset(new SplineSurface(this));
    m_nodeManipulator = ThirdPersonManipulator::create();
    m_nodeManipulator->setEnabled(false);

    GuiPane* p = dockPane;

    if (p == NULL) {
        // Place into the window
        p = pane();
    } else {
        // No need to show the window
        setVisible(false);
    }
    
    GuiPane* cpPane = p->addPane("Control Point", GuiTheme::ORNATE_PANE_STYLE);
    cpPane->moveBy(0, -15);

    Array<std::string> indexList;
    getIndexRange(1, indexList);
    m_selectedControlPointDropDown = cpPane->addDropDownList("Control point: ", indexList, &m_selectedControlPointIndex, 
                                        GuiControl::Callback(this, &PhysicsFrameSplineEditor::controlPointDropDownCallback));
    cpPane->addNumberBox("Time", Pointer<float>(this, &PhysicsFrameSplineEditor::selectedNodeTime, &PhysicsFrameSplineEditor::setSelectedNodeTime), "s");
    cpPane->addTextBox("", Pointer<std::string>(this, &PhysicsFrameSplineEditor::selectedNodePFrameAsString, &PhysicsFrameSplineEditor::setSelectedNodePFrameFromString));

    cpPane->beginRow(); {
        GuiButton* b = cpPane->addButton("Add new", this, &PhysicsFrameSplineEditor::addControlPoint);
        b->moveBy(-2, -7);
        m_removeSelectedButton = cpPane->addButton("Remove", this, &PhysicsFrameSplineEditor::removeSelectedControlPoint);
    } cpPane->endRow();
    cpPane->pack();
    GuiPane* exPane = p->addPane("Extrapolation Mode", GuiTheme::NO_PANE_STYLE);
    exPane->beginRow(); {
        GuiControl* linearButton  = exPane->addRadioButton("Linear", SplineExtrapolationMode::LINEAR, this, 
                                        &PhysicsFrameSplineEditor::extrapolationMode, &PhysicsFrameSplineEditor::setExtrapolationMode);
        GuiControl* clampedButton = exPane->addRadioButton("Clamped", SplineExtrapolationMode::CLAMP, this, 
                                        &PhysicsFrameSplineEditor::extrapolationMode, &PhysicsFrameSplineEditor::setExtrapolationMode);
        clampedButton->moveRightOf(linearButton);
        clampedButton->moveBy(-145, 0);
        GuiControl* cyclicButton  = exPane->addRadioButton("Cyclic", SplineExtrapolationMode::CYCLIC, this, 
                                        &PhysicsFrameSplineEditor::extrapolationMode, &PhysicsFrameSplineEditor::setExtrapolationMode);
        cyclicButton->moveRightOf(clampedButton);
        cyclicButton->moveBy(-140, 0);
    } exPane->endRow();
    exPane->pack();
    GuiPane* inPane = p->addPane("Interpolation Mode", GuiTheme::NO_PANE_STYLE);
    inPane->beginRow(); {
        GuiControl* linearButton = inPane->addRadioButton("Linear", SplineInterpolationMode::LINEAR, this, 
                                       &PhysicsFrameSplineEditor::interpolationMode, &PhysicsFrameSplineEditor::setInterpolationMode);
        GuiControl* cubicButton  = inPane->addRadioButton("Cubic", SplineInterpolationMode::CUBIC, this, 
                                       &PhysicsFrameSplineEditor::interpolationMode, &PhysicsFrameSplineEditor::setInterpolationMode); 
        cubicButton->moveRightOf(linearButton);
        cubicButton->moveBy(-145, 0);
    } inPane->endRow();
    inPane->pack();
    GuiPane* finalIntervalPane = p->addPane("Final Interval", GuiTheme::NO_PANE_STYLE);
    finalIntervalPane->moveRightOf(exPane);
    finalIntervalPane->moveBy(-100, -5);
    static int m_explicitFinalInterval = 0;
    m_finalIntervalChoice[0] = finalIntervalPane->addRadioButton("automatic", 0, &m_explicitFinalInterval);
    finalIntervalPane->beginRow(); {
        m_finalIntervalChoice[1] = finalIntervalPane->addRadioButton("", 1, &m_explicitFinalInterval);
        m_finalIntervalBox = finalIntervalPane->addNumberBox("", &m_spline.finalInterval, "s", GuiTheme::NO_SLIDER, -1.0f, 10000.0f, 0.001f);
        m_finalIntervalBox->setWidth(76);
        m_finalIntervalBox->moveBy(-2, 0);
    } finalIntervalPane->endRow();
    pack();

    setEnabled(false);
}
void PhysicsFrameSplineEditor::resizeControlPointDropDown(int i) {
    Array<std::string> indexList;
    getIndexRange(m_spline.control.size(), indexList);
    m_selectedControlPointDropDown->setList(indexList);
}