public override void Execute() { ICanvasViewer viewer = _smartSession.SmartWindowManager.ActiveCanvasViewer; if (viewer == null) { return; } IRasterDrawing drawing = viewer.ActiveObject as IRasterDrawing; if (drawing == null) { return; } using (frmSelectExpression frm = new frmSelectExpression()) { frm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string expression = frm.Expression; // using (frmBandVarMapper frm1 = new frmBandVarMapper()) { frm1.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; frm1.SetExpression(expression); UCBandVarSetter.FileBandNames file = new UCBandVarSetter.FileBandNames(); file.FileName = drawing.FileName; file.BandNames = new UCBandVarSetter.BandName[drawing.BandCount]; for (int b = 0; b < drawing.BandCount; b++) { file.BandNames[b] = new UCBandVarSetter.BandName(b + 1); } frm1.SetFiles(new UCBandVarSetter.FileBandNames[] { file }); frm1.OutFileName = _smartSession.TemporalFileManager.NextTemporalFilename(".LDF", new string[] { ".HDR" }); if (frm1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Dictionary <string, int> mappedBandNos = frm1.MappedBandNos; string[] keys = mappedBandNos.Keys.ToArray().Reverse().ToArray(); foreach (string var in keys) { expression = expression.Replace(var, "band" + mappedBandNos[var]); } expression = expression.Replace("band", "b"); DoBandMath(drawing, frm1.OutFileName, expression); } } } } }
private void button1_Click_1(object sender, EventArgs e) { using (frmSelectExpression frm = new frmSelectExpression()) { if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtExpression.Text = frm.Expression; // using (frmBandVarMapper frm1 = new frmBandVarMapper()) { frm1.SetExpression(txtExpression.Text); UCBandVarSetter.FileBandNames file = new UCBandVarSetter.FileBandNames(); file.FileName = @"F:\FY3A\1.LDF"; file.BandNames = new UCBandVarSetter.BandName[] { new UCBandVarSetter.BandName(1), new UCBandVarSetter.BandName(2), new UCBandVarSetter.BandName(13), new UCBandVarSetter.BandName(14), }; frm1.SetFiles(new UCBandVarSetter.FileBandNames[] { file }); if (frm1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Dictionary <string, int> mappedBandNos = frm1.MappedBandNos; string exp = txtExpression.Text; string[] keys = mappedBandNos.Keys.ToArray().Reverse().ToArray(); foreach (string var in keys) { exp = exp.Replace(var, "b" + mappedBandNos[var]); } txtExpression.Text = exp; } } } } }