⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.cpp

📁 rcssserver3d Robocup 3D比赛官方指定平台
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            // currently no update need, check again after full interval            mFPSTimer.Start(FPS_UPDATE_INTERVAL);            return;        }    shared_ptr<SimulationServer> sim = spark->GetSimulationServer();    if (sim.get() == 0)    {        return;    }    float now = sim->GetTime();    fps->UpdateStatic(std::max<float>(0, now - mLastFPSUpdate));    mLastFPSUpdate = now;    wxClientDC dc(this);    bool swapBuffers = true;    mCanvas->Render(dc, swapBuffers);    // recheck and update as soon as posssible    mFPSTimer.Start(1);}void mainframe::UpdateLogWindow(){    if (! SimSpark::HasLogContents())        {            return;        }    wxString buffer = SimSpark::GetLogBuffer();    SimSpark::ClearLogBuffer();    mCtrLog->AppendText(buffer);    mCtrLog->ShowPosition(mCtrLog->GetLastPosition() + 1);}void mainframe::PauseSimulation(){    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();    if (        (spark.get() == 0) ||        (spark->GetSimState() != S_RUNNING)        )        {            return;        }    shared_ptr<SimulationServer> sim = spark->GetSimulationServer();    if (sim.get() == 0)        {            return;        }    sim->Quit();    spark->SetSimState(S_PAUSED);    spark->GetLog()->Normal() << "(RsgEdit) pausing simulation\n";    PrintSimState();}void mainframe::ResetSimulation(){    PauseSimulation();    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();    if (        (spark.get() == 0) ||        (spark->GetSimState() != S_PAUSED)        )        {            assert(false);            return;        }    spark->ResetSimulation();    mCanvas->Reset();    spark->GetLog()->Normal() << "(RsgEdit) resetting simulation\n";}void mainframe::AdvanceSimulation(shared_ptr<SimulationServer>& sim, float tDeltaSec){    if (sim.get() == 0)        {            assert(false);            return;        }    // go through the next simulation cycle    sim->AdvanceTime(tDeltaSec);    shared_ptr<SimControlNode> inputCtr;    sim->Cycle(inputCtr);    // refresh the display    RefreshProperties();    wxClientDC dc(this);    bool swapBuffers = true;    mCanvas->Render(dc, swapBuffers);}void mainframe::InitSimulation(shared_ptr<SimulationServer>& sim){    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();    if (        (spark.get() == 0) ||        (sim.get() == 0)        )    {        assert(false);        return;    }    // tell the inputControl node the loaction of our camera    shared_ptr<InputControl> inputCtr = spark->GetInputControl();    if (inputCtr.get() != 0)        {            inputCtr->SetFPSController(std::string(MAINFRAME_FPS_CONTROLLER.fn_str()));            inputCtr->SetAdvanceTime(false);        }    sim->SetSimStep(SIM_SIMSTEP);    sim->Init(0,0);    sim->SetAutoTimeMode(false);    mLastFPSUpdate = 0.0;}void mainframe::DoneSimulation(shared_ptr<SimulationServer>& sim){    if (sim.get() == 0)        {            assert(false);            return;        }    sim->Done();    mLastFPSUpdate = sim->GetTime();    mFPSTimer.Start(FPS_UPDATE_INTERVAL);}void mainframe::StartSimulation(bool singleStep){    mFPSTimer.Stop();    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();    if (        (spark.get() == 0) ||        (spark->GetSimState() != S_PAUSED)        )        {            return;        }    shared_ptr<SimulationServer> sim = spark->GetSimulationServer();    if (sim.get() == 0)        {            return;        }    spark->SetSimState(S_RUNNING);    InitSimulation(sim);    spark->GetLog()->Normal() << "(RsgEdit) starting simulation\n";    wxLongLong tLast = wxGetLocalTimeMillis();    // force update of ui state    UpdateWindowUI(wxUPDATE_UI_RECURSE);    if (singleStep)        {            // leave simulation loop after first iteration            sim->Quit();        }    do {        if (SIM_SIMSTEP > 0.0f)            {                AdvanceSimulation(sim, SIM_SIMSTEP);            } else            {                wxLongLong tNow = wxGetLocalTimeMillis();                float tDeltaSec = (tNow - tLast).ToLong() / 1000.0;                tLast = tNow;                AdvanceSimulation(sim, tDeltaSec);            }        PrintSimState();        // pump the wxWidgets message loop        wxGetApp().Yield();    } while (! sim->WantsToQuit());    DoneSimulation(sim);    spark->SetSimState(S_PAUSED);    spark->GetLog()->Normal() << "(RsgEdit) simulation paused\n";    // force update of ui state    UpdateWindowUI(wxUPDATE_UI_RECURSE);}void mainframe::OnTreeItemExpanding(wxTreeEvent& event){    if (! mSparkTree.CreateChildren(event.GetItem()))        {            event.Veto();            return;        }}void mainframe::InitTreeNodeProperties(){    mPropList.Init(mSparkTree.GetLeaf(mCtrTree->GetSelection()), mCtrPropList);    RefreshProperties();}void mainframe::OnTreeSelChanged(wxTreeEvent& /*event*/){    InitTreeNodeProperties();}void mainframe::OnTreeItemRightClick(wxTreeEvent& event){    shared_ptr<Leaf> leaf = mSparkTree.GetLeaf(event.GetItem()).lock();    wxMenu* context = SparkContext::GetInstance().GetContextMenu(leaf);    if (context == 0)        {            return;        }    PopupMenu(context);}void mainframe::OnTreeItemActivated(wxTreeEvent& event){    shared_ptr<Leaf> leaf = mSparkTree.GetLeaf(event.GetItem()).lock();    if (leaf.get() == 0)        {            return;        }    SparkContext::GetInstance().SetSelection(leaf);}void mainframe::OnContextKinematic(wxCommandEvent& /*event*/){    weak_ptr<Leaf> leaf = SparkContext::GetInstance().GetContextNode();    if (leaf.expired())        {            assert(false);            return;        }    wxString location(leaf.lock()->GetFullPath().c_str(), wxConvUTF8);    kinematicFrame* frame(new kinematicFrame(this, wxID_ANY, location));    frame->SetParent(leaf);    frame->SetTitle(location);    frame->Show();}void mainframe::OnContextProperties(wxCommandEvent& /*event*/){    weak_ptr<Leaf> leaf = SparkContext::GetInstance().GetContextNode();    if (leaf.expired())        {            assert(false);            return;        }    wxString location(leaf.lock()->GetFullPath().c_str(), wxConvUTF8);    propertyframe* frame(new propertyframe(this, wxID_ANY, location));    frame->SetLeaf(leaf);    frame->SetTitle(location);    frame->Show();}void mainframe::OnContextEditSource(wxCommandEvent& /*event*/){    const SceneDict::FileRef* ref = GetContextFileRef();    if (ref == 0)    {        assert(false);        return;    }    EditFile(wxString::FromAscii(ref->fname.c_str()), ref->line);}void mainframe::OnContextCopyFileName(wxCommandEvent& /*event*/){    const SceneDict::FileRef* ref = GetContextFileRef();    if (ref == 0)    {        assert(false);        return;    }    wxFileName fn(wxString::FromAscii(ref->fname.c_str()));    fn.Normalize();    CopyToClipboard(fn.GetFullPath());}void mainframe::OnContextCopyPath(wxCommandEvent& /*event*/){    weak_ptr<Leaf> leaf = SparkContext::GetInstance().GetContextNode();    if (leaf.expired())        {            assert(false);            return;        }    CopyToClipboard(wxString::FromAscii(leaf.lock()->GetFullPath().c_str()));}const SceneDict::FileRef* mainframe::GetContextFileRef(){    weak_ptr<Leaf> leaf = SparkContext::GetInstance().GetContextNode();    if (leaf.expired())        {            assert(false);            return 0;        }    return SceneDict::GetInstance().Lookup(leaf);}void mainframe::CopyToClipboard(const wxString& str) const{    wxTheClipboard->Open();    wxTheClipboard->SetData(new wxTextDataObject(str));    wxTheClipboard->Close();}void mainframe::EditFile(const wxString& fname, int line){#if 0    wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromMimeType("text/plain");    if (ft == 0)        {            return;        }    wxFileName fn(fname);    fn.Normalize();    wxString cmd = ft->GetOpenCommand(fn.GetFullPath());    if (cmd.IsEmpty())        {            return;        }    wxExecute(cmd);#endif    bool select = true;    wxScintilla* edit = SparkEdit::GetInstance().GetEdit(fname,mCtrNotebook,select);    if (edit != 0)        {            edit->GotoLine(line);        }    if (edit == 0)    {        return;    }    edit->GotoLine(line);}void mainframe::RefreshProperties(){    mPropList.Refresh();    wxWindowList& children = GetChildren();    for (         wxWindowList::Node *node = children.GetFirst();         node != 0;         node = node->GetNext()         )        {            propertyframe* pf = dynamic_cast<propertyframe*>(node->GetData());            if (pf != 0)                {                    pf->RefreshProperties();                    continue;                }            kinematicFrame* kf = dynamic_cast<kinematicFrame*>(node->GetData());            if (kf != 0)                {                    kf->RefreshProperties();                    continue;                }        }}void mainframe::UpdateCached(){    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();    if (spark.get() == 0)        {            return;        }    spark->UpdateCached();    wxWindowList& children = GetChildren();    for (         wxWindowList::Node *node = children.GetFirst();         node != 0;         node = node->GetNext()         )        {            propertyframe* pf = dynamic_cast<propertyframe*>(node->GetData());            if (pf != 0)                {                    pf->UpdateCached();                    continue;                }            kinematicFrame* kf = dynamic_cast<kinematicFrame*>(node->GetData());            if (kf != 0)                {                    kf->UpdateCached();                    continue;                }        }}void mainframe::OnUpdateViewTree(wxUpdateUIEvent& event){    event.Check(mCtrVertSplitter->IsSplit());}void mainframe::OnViewTree(wxCommandEvent& /*event*/){    if (mCtrVertSplitter->IsSplit())        {            mLastVertSashPosition = mCtrVertSplitter->GetSashPosition();            mCtrVertSplitter->Unsplit(mLeftPane);        } else        {            SplitVert();        }}void mainframe::OnUpdateViewLog(wxUpdateUIEvent& event){    event.Check(mCtrHorSplitter->IsSplit());}void mainframe::OnViewLog(wxCommandEvent& /*event*/){    if (mCtrHorSplitter->IsSplit())        {            mLastHorSashPosition = mCtrHorSplitter->GetSashPosition();            mCtrHorSplitter->Unsplit(mBottomPane);        } else        {            SplitHor();        }}void mainframe::OnUpdateFileOpen(wxUpdateUIEvent& event){    event.Enable(GetSimState() == S_PAUSED);}bool mainframe::OpenSimulation(const wxString& fname){    ResetSimulation();    mSparkTree.Init(mCtrTree);    InitTreeNodeProperties();    shared_ptr<SimSpark> spark = wxGetApp().GetSpark();    if (spark.get() == 0)        {            assert(false);            return false;        }    spark->GetLog()->Normal() << "(RsgEdit) reading " << fname << "\n";    if (! spark->GetScriptServer()->Run(std::string(fname.fn_str())))    {        return false;    }    UpdateCached();    shared_ptr<SimulationServer> sim = spark->GetSimulationServer();    if (sim.get() == 0)        {            assert(false);            return false;        }    InitSimulation(sim);    if (SIM_SIMSTEP > 0.0)        {            AdvanceSimulation(sim, SIM_SIMSTEP);        } else        {            AdvanceSimulation(sim, 0.01f);        }    DoneSimulation(sim);    PrintSimState();    return true;}void mainframe::SaveModified(){    SparkEdit::GetInstance().SaveModified();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -