Commit 14adf2f7 authored by Unknown's avatar Unknown

Пошаговое выполнение сделано.

parent cf278222
......@@ -28,10 +28,8 @@
/// </summary>
private void InitializeComponent()
{
this.debug_log = new System.Windows.Forms.TextBox();
this.source_array_panel = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.support_array_panel = new System.Windows.Forms.Panel();
this.arrayCount = new System.Windows.Forms.TextBox();
......@@ -49,22 +47,10 @@
this.label8 = new System.Windows.Forms.Label();
this.queryR = new System.Windows.Forms.TextBox();
this.setQuery = new System.Windows.Forms.Button();
this.varDump = new System.Windows.Forms.Label();
this.stepsPanel.SuspendLayout();
this.SuspendLayout();
//
// debug_log
//
this.debug_log.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.debug_log.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.debug_log.Location = new System.Drawing.Point(12, 569);
this.debug_log.Multiline = true;
this.debug_log.Name = "debug_log";
this.debug_log.ReadOnly = true;
this.debug_log.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.debug_log.Size = new System.Drawing.Size(1240, 76);
this.debug_log.TabIndex = 0;
//
// source_array_panel
//
this.source_array_panel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
......@@ -85,16 +71,6 @@
this.label1.TabIndex = 2;
this.label1.Text = "ИСХОДНЫЙ МАССИВ";
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 553);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(63, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Debug Log:";
//
// label3
//
this.label3.AutoSize = true;
......@@ -186,7 +162,7 @@
this.stepDescription.Location = new System.Drawing.Point(0, 76);
this.stepDescription.Margin = new System.Windows.Forms.Padding(0);
this.stepDescription.Name = "stepDescription";
this.stepDescription.Size = new System.Drawing.Size(1236, 58);
this.stepDescription.Size = new System.Drawing.Size(1236, 83);
this.stepDescription.TabIndex = 13;
this.stepDescription.Text = "stepDescription";
this.stepDescription.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
......@@ -195,6 +171,7 @@
//
this.stepsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stepsPanel.Controls.Add(this.varDump);
this.stepsPanel.Controls.Add(this.label9);
this.stepsPanel.Controls.Add(this.nextStep);
this.stepsPanel.Controls.Add(this.stepCounter);
......@@ -202,7 +179,7 @@
this.stepsPanel.Controls.Add(this.stepDescription);
this.stepsPanel.Location = new System.Drawing.Point(12, 364);
this.stepsPanel.Name = "stepsPanel";
this.stepsPanel.Size = new System.Drawing.Size(1236, 179);
this.stepsPanel.Size = new System.Drawing.Size(1236, 271);
this.stepsPanel.TabIndex = 14;
//
// label9
......@@ -277,6 +254,19 @@
this.setQuery.UseVisualStyleBackColor = true;
this.setQuery.Click += new System.EventHandler(this.setQuery_Click);
//
// varDump
//
this.varDump.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.varDump.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.varDump.Location = new System.Drawing.Point(0, 169);
this.varDump.Margin = new System.Windows.Forms.Padding(0);
this.varDump.Name = "varDump";
this.varDump.Size = new System.Drawing.Size(1236, 83);
this.varDump.TabIndex = 19;
this.varDump.Text = "varDump";
this.varDump.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
......@@ -294,10 +284,8 @@
this.Controls.Add(this.arrayCount);
this.Controls.Add(this.label3);
this.Controls.Add(this.support_array_panel);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.source_array_panel);
this.Controls.Add(this.debug_log);
this.Name = "Form1";
this.Text = "Визуализатор SQRT-декомпозиции";
this.stepsPanel.ResumeLayout(false);
......@@ -308,11 +296,8 @@
}
#endregion
private System.Windows.Forms.TextBox debug_log;
private System.Windows.Forms.Panel source_array_panel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel support_array_panel;
private System.Windows.Forms.TextBox arrayCount;
......@@ -330,6 +315,7 @@
private System.Windows.Forms.TextBox queryR;
private System.Windows.Forms.Button setQuery;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label varDump;
}
}
......@@ -41,6 +41,7 @@ namespace SQRT_Decomposition_Visualizer
Step s = new Step();
s.description = "Вычислен размер сегмента. Размер сегмента = " + segment_length;
s.segment_size = segment_length;
steps.AddStep(s);
support = new List<int>(new int[(source.Count / segment_length) + 1]);
......@@ -122,6 +123,7 @@ namespace SQRT_Decomposition_Visualizer
s.support_state = new List<int>();
s.support_state.AddRange(support);
s.highlight_source = new List<int>();
s.sum = sum;
for (int i = l; i <= r; i++)
{
s.highlight_source.Add(i);
......@@ -130,12 +132,52 @@ namespace SQRT_Decomposition_Visualizer
}
else
{
s = new Step();
s.description = "Вычисление левого \"хвоста\".\r\nК общей сумме добавляются выделенные элементы.";
s.support_state = new List<int>();
s.support_state.AddRange(support);
s.highlight_source = new List<int>();
for (int i = l, end = (c_l + 1) * segment_length - 1; i <= end; ++i)
{
sum += source[i];
s.highlight_source.Add(i);
}
s.sum = sum;
steps.AddStep(s);
s = new Step();
s.description = "Вычисление основной части.\r\nК общей сумме добавляются сегменты, которые полностью попали в запрос.";
s.support_state = new List<int>();
s.support_state.AddRange(support);
s.highlight_support = new List<int>();
int c = 0;
for (int i = c_l + 1; i <= c_r - 1; ++i)
{
sum += support[i];
s.highlight_support.Add(i);
c++;
}
s.sum = sum;
if (c > 0)
steps.AddStep(s);
s = new Step();
s.description = "Вычисление правого \"хвоста\".\r\nК общей сумме добавляются выделенные элементы.";
s.support_state = new List<int>();
s.support_state.AddRange(support);
s.highlight_source = new List<int>();
for (int i = c_r * segment_length; i <= r; ++i)
{
sum += source[i];
s.highlight_source.Add(i);
}
s.sum = sum;
steps.AddStep(s);
}
s = new Step();
......@@ -158,6 +200,7 @@ namespace SQRT_Decomposition_Visualizer
public string description;
public List<int> highlight_source, highlight_support;
public List<int> support_state;
public int sum, segment_size;
}
class Steps
......@@ -166,6 +209,7 @@ namespace SQRT_Decomposition_Visualizer
Panel description;
List<Step> steps;
int currentStep;
int sum, segment_size;
public Steps(View source, View support, Panel description)
{
......@@ -211,6 +255,16 @@ namespace SQRT_Decomposition_Visualizer
(description.Controls["stepCounter"] as Label).Text = n + "/" + steps.Count;
(description.Controls["stepDescription"] as Label).Text = steps[n - 1].description;
if (steps[n-1].segment_size != 0)
{
segment_size = steps[n - 1].segment_size;
}
if (steps[n - 1].sum != 0)
{
sum = steps[n - 1].sum;
}
(description.Controls["varDump"] as Label).Text = "Размер сегмента: " + segment_size + "\r\nОбщая сумма: " + sum;
if (steps[n - 1].highlight_source != null)
{
source.UnhighlightElements();
......@@ -244,6 +298,16 @@ namespace SQRT_Decomposition_Visualizer
support.UnhighlightElements();
}
}
public int GetCurrentStep()
{
return currentStep;
}
public int GetStepsCount()
{
return steps.Count;
}
}
class View
......@@ -338,8 +402,14 @@ namespace SQRT_Decomposition_Visualizer
calculateSteps(Int32.Parse(arrayCount.Text));
}
private void label2_Click(object sender, EventArgs e)
{
}
void calculateSteps(int length, int min=0, int max= 100)
{
arraySize = length;
List<int> source_array = GenerateArray(length, min, max);
View source_array_view = new View(source_array_panel, "source");
source_array_view.DisplayArray(source_array);
......@@ -351,16 +421,40 @@ namespace SQRT_Decomposition_Visualizer
sqrtdsum = new SQRTDecompositionSum(source_array, ref steps);
sqrtdsum.GetRangeSum(qL,qR);
steps.Load();
StepButtonsControl();
StepButtonsControl();
}
void StepButtonsControl()
{
if (steps.GetCurrentStep() > 1)
{
prevStep.Enabled = true;
}
else
{
prevStep.Enabled = false;
}
if (steps.GetCurrentStep() < steps.GetStepsCount())
{
nextStep.Enabled = true;
}
else
{
nextStep.Enabled = false;
}
}
private void prevStep_Click(object sender, EventArgs e)
{
steps.PrevStep();
StepButtonsControl();
}
private void nextStep_Click(object sender, EventArgs e)
{
steps.NextStep();
StepButtonsControl();
}
private void setArraySize_Click(object sender, EventArgs e)
......
......@@ -31,6 +31,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
......@@ -78,5 +81,8 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment