//input1 is whether go is coming in as an input1 or input2 private void RepositionInputs(GraphicOperator go, List<GraphicOperator> list, int upward, bool input1, int Xseparator) { if (go != null && list != null && (go.Input_1 != null || go.Input_2 != null)) { #region level direction if (upward == 0) { if (go.isUnaryOp() && go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 0, true, Xseparator); } else { if (go.has_Input1() && go.has_Input2()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 60); go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 60); RemoveFromList(go.Input_1, list); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); RepositionInputs(go.Input_2, list, 2, false, Xseparator); } else if (go.has_Input1()) { RemoveFromList(go.Input_1, list); go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RepositionInputs(go.Input_1, list, 0, true, Xseparator); } else if (go.has_Input2()) { RemoveFromList(go.Input_2, list); go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RepositionInputs(go.Input_2, list, 0, false, Xseparator); } } } #endregion #region upward else if (upward == 1) { if (input1) { if (go.isUnaryOp() && go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 60); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); } else { if (go.has_Input1() && go.has_Input2()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 120); go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 60); RemoveFromList(go.Input_1, list); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); RepositionInputs(go.Input_2, list, 1, false, Xseparator); } else if (go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 60); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); } else if (go.has_Input2()) { go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 60); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_2, list, 1, false, Xseparator); } } } else //input2 { if (go.isUnaryOp() && go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); } else { if (go.has_Input1() && go.has_Input2()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y - 60); go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_1, list); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); RepositionInputs(go.Input_2, list, 1, false, Xseparator); } else if (go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 1, true, Xseparator); } else if (go.has_Input2()) { go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_2, list, 1, false, Xseparator); } } } } #endregion #region downward else //downward { if (input1) { if (go.isUnaryOp() && go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 2, true, Xseparator); } else { if (go.has_Input1() && go.has_Input2()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 60); RemoveFromList(go.Input_1, list); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_1, list, 2, true, Xseparator); RepositionInputs(go.Input_2, list, 2, false, Xseparator); } else if (go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 2, true, Xseparator); } else if (go.has_Input2()) { go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_2, list, 2, false, Xseparator); } } } else //input2 { if (go.isUnaryOp() && go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 60); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 2, true, Xseparator); } else { if (go.has_Input1() && go.has_Input2()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 60); go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 120); RemoveFromList(go.Input_1, list); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_1, list, 2, true, Xseparator); RepositionInputs(go.Input_2, list, 2, false, Xseparator); } else if (go.has_Input1()) { go.Input_1.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 60); RemoveFromList(go.Input_1, list); RepositionInputs(go.Input_1, list, 2, true, Xseparator); } else if (go.has_Input2()) { go.Input_2.PicBox.Location = new Point(go.PicBox.Location.X - 50 - Xseparator, go.PicBox.Location.Y + 60); RemoveFromList(go.Input_2, list); RepositionInputs(go.Input_2, list, 2, false, Xseparator); } } } } #endregion } }
private void OrganizeAlgorithm(GraphicOperator go, List<GraphicOperator> list, bool upwards, bool passedBinary) { // // TODO: double check that this code actually gets used, may be old code // GraphicOperator temp1 = new GraphicOperator(); GraphicOperator temp2 = new GraphicOperator(); temp1 = go.Input_1; temp2 = go.Input_2; if (temp1 != null) { if (temp1.isUnaryOp() && temp1.has_Input1()) { UnaryReposition(temp1.Input_1, temp1, upwards, passedBinary); OrganizeAlgorithm(temp1, list, upwards, passedBinary); //also try !passedBinary } else if (temp1.isBinaryOp() && (temp1.has_Input1() || temp1.has_Input2())) { if (temp1.has_Input1() && temp1.has_Input2()) { BinaryReposition(temp1.Input_1, temp1.Input_2, temp1, upwards, passedBinary); OrganizeAlgorithm(temp1, list, true, true); } else if (temp1.has_Input1() && !temp1.has_Input2()) { UnaryReposition(temp1, temp1, upwards, passedBinary); OrganizeAlgorithm(temp1, list, upwards, passedBinary); } else if (!temp1.has_Input1() && temp1.has_Input2()) { UnaryReposition(temp1.Input_2, temp1, upwards, passedBinary); OrganizeAlgorithm(temp1, list, upwards, passedBinary); } } RemoveFromList(temp1, list); } if (temp2 != null) { if (temp2.isUnaryOp() && temp2.has_Input1()) { UnaryReposition(temp2.Input_1, temp2, upwards, passedBinary); OrganizeAlgorithm(temp2, list, upwards, passedBinary); } else if (temp2.isBinaryOp() && (temp2.has_Input1() || temp2.has_Input2())) { if (temp2.has_Input1() && temp2.has_Input2()) { BinaryReposition(temp2.Input_1, temp2.Input_2, temp2, upwards, passedBinary); OrganizeAlgorithm(temp2, list, false, true); } else if (temp2.has_Input1() && !temp2.has_Input2()) { UnaryReposition(temp2.Input_1, temp2, upwards, passedBinary); OrganizeAlgorithm(temp2, list, upwards, passedBinary); } else if (!temp2.has_Input1() && temp2.has_Input2()) { UnaryReposition(temp2.Input_2, temp2, upwards, passedBinary); OrganizeAlgorithm(temp2, list, upwards, passedBinary); } } RemoveFromList(temp2, list); } }