簡體   English   中英

IL數字隱藏PlotCube

[英]ILNumerics hide PlotCube

我有一個場景,其中包含兩個不同的PlotCube,必須分別顯示。 隱藏和顯示PlotCube的最佳過程是什么。 我嘗試使用remove,但這似乎改變了PlotCube對象。 代碼行是:

IlPanel1.Scene.add(PlotCube1)  
IlPanel1.Scene.add(PlotCube2)  

現在兩個立方體都可見。 現在我只想顯示PlotCube2

IlPanel1.Scene.Remove(PlotCube1)  
IlPanel1.Scene.add(PlotCube2)

要切換回PlotCube1:

IlPanel1.Scene.Remove(PlotCube2)  
IlPanel1.Scene.add(PlotCube1)  

但這是行不通的。 remove語句似乎刪除了整個對象。 有沒有一種方法可以在不影響原始對象的情況下添加/刪除元素,如LinePlots,SurfacePlots,PlotCubes?

使用繪圖多維數據集的“ 可見性”屬性來設置其可見性:

// stores the current state. (You may even use one of the ILPlotCube.Visible flags directly)
bool m_panelState = false;

// give the plot cubes unique tags so we can find them later.
private void ilPanel1_Load(object sender, EventArgs e) {
    ilPanel1.Scene.Add(new ILPlotCube("plotcube1") {
        Plots = {
            Shapes.Circle100, // just some arbitrary content
            new ILLabel("Plot Cube 1")
        },
        // first plot cube starts invisible
        Visible = false
    });
    ilPanel1.Scene.Add(new ILPlotCube("plotcube2") {
        Plots = {
            Shapes.Hemisphere, // just some content
            new ILLabel("Plot Cube 2")
        }
    });
}
// a button is used to switch between the plot cubes
private void button1_Click(object sender, EventArgs e) {
    m_panelState = !m_panelState;
    SetState(); 
}
// both plot cubes are made (un)visible depending on the value of the state variable
private void SetState() {
    ilPanel1.Scene.First<ILPlotCube>("plotcube1").Visible = m_panelState;
    ilPanel1.Scene.First<ILPlotCube>("plotcube2").Visible = !m_panelState;
    ilPanel1.Refresh(); 
}

重要的部分是在面板上調用Refresh()以便立即顯示修改。

請注意,通常最好保留周圍的繪圖對象,以備日后再次使用它們時使用。 與其將它們從場景圖中刪除而不是稍后再創建類似的對象,將對象設置為Visible = false會更快,並且不會招致(重新)創建圖形對象的巨大開銷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM