Exemple #1
0
        public void Generic_Converter_Throws_When_Given_Incompatible_Value()
        {
            IStringTemplateValueConverter converter = new StringCollectionConverter();

            var shouldWork = converter.Convert(StringCollectionValues);

            Assert.Equal(ExpectedStringCollectionConcatenation, shouldWork); // sanity check

            Assert.Throws <NotSupportedException>(() => converter.Convert("whatever"));
        }
        public graphWindow(designGraph dg, CanvasProperty canvasProperties,
                           string filename, string title)
        {
            /* the following is common to all GS window types. */
            InitializeComponent();
            Owner         = main;
            ShowInTaskbar = false;
            foreach (CommandBinding cb in main.CommandBindings)
            {
                CommandBindings.Add(cb);
                graphGUI.CommandBindings.Add(cb);
            }
            foreach (InputBinding ib in main.InputBindings)
            {
                InputBindings.Add(ib);
                graphGUI.InputBindings.Add(ib);
            }
            /***************************************************/

            graph = graphGUI.graph = dg;
            graphGUI.ScrollOwner = scrollViewer1;

            canvasProps = canvasProperties ?? new CanvasProperty();
            canvasProps.AddGUIToControl(graphGUI);
            AdoptWindowWideCanvasProperties();

            this.filename = !string.IsNullOrEmpty(filename) ? filename : "Untitled";
            Title         = !string.IsNullOrEmpty(title) ? title : Path.GetFileNameWithoutExtension(this.filename);

            graphGUI.InitDrawGraph();

            txtGlobalVariables.Text = DoubleCollectionConverter.Convert(graph.globalVariables);
            txtGlobalLabels.Text    = StringCollectionConverter.Convert(graph.globalLabels);
        }
Exemple #3
0
        /* K Changes to Labels and Variables */

        private void txtKGlobalLabels_LostFocus(object sender, RoutedEventArgs e)
        {
            var labels         = StringCollectionConverter.Convert(txtKGlobalLabels.Text);
            var removedKLabels = KLabels.Where(a => !labels.Contains(a)).ToList();

            foreach (string a in removedKLabels)
            {
                rule.L.globalLabels.Remove(a);
                rule.R.globalLabels.Remove(a);
            }
            KLabels = labels;
            var union = KLabels.Union(rule.L.globalLabels);

            main.property.RulePrpt.txtLGlobalLabels_LostFocus(new TextBox
            {
                Text =
                    StringCollectionConverter.Convert(
                        new List <string>(union))
            }, null);

            union = KLabels.Union(rule.R.globalLabels);
            main.property.RulePrpt.txtRGlobalLabels_LostFocus(new TextBox
            {
                Text =
                    StringCollectionConverter.Convert(
                        new List <string>(union))
            }, null);
        }
Exemple #4
0
        internal void Update(ruleSet RuleSet, ruleSetWindow rsW)
        {
            SelectedRuleSet = RuleSet;
            txtName.Text    = rsW.Title;
            for (int i = 0; i < GSApp.settings.rulesets.GetLength(0); i++)
            {
                if (SelectedRuleSet.Equals(GSApp.settings.rulesets[i]))
                {
                    txtName.Text += " (set to RuleSet #" + i + ")";
                    break;
                }
            }

            txtTriggerRuleNo.Text = SelectedRuleSet.TriggerRuleNum.ToString();

            cmdChoiceMethod.SelectedIndex = cmdChoiceMethod.Items.IndexOf(SelectedRuleSet.choiceMethod);

            cmdInterimCandidates.SelectedIndex = cmdInterimCandidates.Items.IndexOf(SelectedRuleSet.interimCandidates);
            cmdFinalCandidates.SelectedIndex   = cmdFinalCandidates.Items.IndexOf(SelectedRuleSet.finalCandidates);

            cmdAfterNormalCycle.SelectedIndex = cmdAfterNormalCycle.Items.IndexOf(SelectedRuleSet.generationAfterNormal);
            cmdChoiceSendsStop.SelectedIndex  = cmdChoiceSendsStop.Items.IndexOf(SelectedRuleSet.generationAfterChoice);
            cmdNoOfCallsReached.SelectedIndex =
                cmdNoOfCallsReached.Items.IndexOf(SelectedRuleSet.generationAfterCycleLimit);
            cmdNoRulesRecognized.SelectedIndex =
                cmdNoRulesRecognized.Items.IndexOf(SelectedRuleSet.generationAfterNoRules);
            cmdTriggerRuleInvoked.SelectedIndex =
                cmdTriggerRuleInvoked.Items.IndexOf(SelectedRuleSet.generationAfterTriggerRule);
            txtRecognizeSourceFiles.Text = StringCollectionConverter.Convert(SelectedRuleSet.recognizeSourceFiles);
            txtApplySourceFiles.Text     = StringCollectionConverter.Convert(SelectedRuleSet.applySourceFiles);
        }
        private void Update()
        {
            txtFilename.Text = (string.IsNullOrWhiteSpace(ruleWin.filename))
                ? ruleWin.Title : ruleWin.filename;
            txtFilename.PageRight();
            /* updating L, K, and R global variables. */
            ruleWin.txtLGlobalVariables.Text             = txtLVariables.Text
                                                         = DoubleCollectionConverter.Convert(rule.L.globalVariables);
            ruleWin.txtRGlobalVariables.Text             = txtRVariables.Text
                                                         = DoubleCollectionConverter.Convert(rule.R.globalVariables);
            var KVars     = rule.R.globalVariables.Intersect(rule.L.globalVariables);
            var listKVars = new List <double>();

            foreach (double x in KVars)
            {
                listKVars.Add(x);
            }
            ruleWin.txtKGlobalVariables.Text = DoubleCollectionConverter.Convert(listKVars);

            /* updating L, K, and R global labels. This involves an additional need to consider both order labels and
             * negating labels. */
            ruleWin.txtLGlobalLabels.Text             = txtLGlobalLabels.Text
                                                      = StringCollectionConverter.Convert(rule.L.globalLabels);
            ruleWin.txtRGlobalLabels.Text             = txtRGlobalLabels.Text
                                                      = StringCollectionConverter.Convert(rule.R.globalLabels);

            /* the idea below was to change the way orderLabels appear but it lead to problems when switching
             * back and forth between ordered and unordered. It is repairable but truthfully, most rules do not have
             * a lot of labels. The host may build up a substantial amount, so this concept may be more appropriate
             * to graphDisplay and graph properties than rules. */
            //if (rule.OrderedGlobalLabels)
            //{
            //    ruleWin.txtLGlobalLabels.Text = txtLGlobalLabels.Text
            //        = txtLGlobalLabels.Text.Replace(", ", "-");
            //    ruleWin.txtRGlobalLabels.Text = txtRGlobalLabels.Text
            //        = txtRGlobalLabels.Text.Replace(", ", "-");
            //    ruleWin.txtKGlobalLabels.Text = "";
            //}
            //else
            //{
            var listKLabels = new List <string>(rule.R.globalLabels.Intersect(rule.L.globalLabels));

            ruleWin.txtKGlobalLabels.Text = StringCollectionConverter.Convert(listKLabels);
            //}
            txtLNegatingLabels.Text = StringCollectionConverter.Convert(rule.negateLabels);
            if (txtLNegatingLabels.Text.Length > 0)
            {
                ruleWin.txtLGlobalLabels.Text += " ~(" + txtLNegatingLabels.Text + ")";
            }
            txtApplyFunctions.Text               = StringCollectionConverter.Convert(rule.applyFunctions);
            txtRecognizeFunctions.Text           = StringCollectionConverter.Convert(rule.recognizeFunctions);
            chkContainsAllGlobalLabels.IsChecked = rule.containsAllGlobalLabels;
            chkInduced.IsChecked             = rule.induced;
            chkOrderedGlobalLabels.IsChecked = rule.OrderedGlobalLabels;
            chkSpanning.IsChecked            = rule.spanning;
            chkTerminationRule.IsChecked     = rule.termination;
        }
Exemple #6
0
        private void txtNeighborNegabels_LostFocus(object sender, RoutedEventArgs e)
        {
            var lststr = StringCollectionConverter.Convert(txtNeighborNegabels.Text.Replace("<none>", ""));

            selectedEmbeddingRule.neighborNodeNegabels.Clear();
            foreach (string str in lststr)
            {
                selectedEmbeddingRule.neighborNodeNegabels.Add(str);
            }
            Update();
        }
        private void txtNegLabels_LostFocus(object sender, RoutedEventArgs e)
        {
            var lststr = StringCollectionConverter.Convert(txtNegLabels.Text);

            ((ruleHyperarc)firstHyperArc).negateLabels.Clear();
            foreach (string str in lststr)
            {
                ((ruleHyperarc)firstHyperArc).negateLabels.Add(str);
            }
            Update();
        }
Exemple #8
0
        private void txtFreeArcLabels_LostFocus(object sender, RoutedEventArgs e)
        {
            var lststr = StringCollectionConverter.Convert(txtFreeArcLabels.Text.Replace("<any>", ""));

            selectedEmbeddingRule.freeArcLabels.Clear();
            foreach (string str in lststr)
            {
                selectedEmbeddingRule.freeArcLabels.Add(str);
            }
            Update();
        }
Exemple #9
0
 private void btnSaveToFile_Click(object sender, RoutedEventArgs e)
 {
     if (newSettings.numOfRuleSets < newSettings.defaultRSFileNames.Count)
     {
         newSettings.defaultRSFileNames.RemoveRange(newSettings.numOfRuleSets, newSettings.defaultRSFileNames.Count
                                                    - newSettings.numOfRuleSets);
     }
     newSettings.DefaultRuleSets
         = StringCollectionConverter.Convert(newSettings.defaultRSFileNames);
     newSettings.saveNewSettings();
     btnApplyInThisProcess.IsDefault = true;
 }
Exemple #10
0
        private void txtRecognizeSourceFiles_LostFocus(object sender, RoutedEventArgs e)
        {
            var lststr = StringCollectionConverter.Convert(txtRecognizeSourceFiles.Text);

            SelectedRuleSet.recognizeSourceFiles.Clear();
            foreach (string s in lststr)
            {
                RuleParamCodeFiler.checkForRuleFile(SelectedRuleSet,
                                                    SelectedRuleSet.recognizeSourceFiles, s);
            }
            txtRecognizeSourceFiles.Text = StringCollectionConverter.Convert(SelectedRuleSet.recognizeSourceFiles);
        }
        /// <summary>
        ///   Gets the save filename.
        /// </summary>
        /// <param name = "filter">The filter of file types.</param>
        /// <param name = "name">a starting name.</param>
        /// <param name = "dir">The directory</param>
        /// <returns></returns>
        public string GetSaveFilename(string filter, string name, string dir)
        {
            var fileChooser = new SaveFileDialog();

            fileChooser.Title            = "Save Active " + StringCollectionConverter.Convert(filter)[0] + " as ...";
            fileChooser.InitialDirectory = dir;
            fileChooser.Filter           = filter;
            fileChooser.FileName         = name;
            fileChooser.CheckFileExists  = false;
            string filename;

            try
            {
                if ((Boolean)fileChooser.ShowDialog(this))
                {
                    filename = fileChooser.FileName;
                    if (string.IsNullOrWhiteSpace(filename))
                    {
                        MessageBox.Show("Invalid file name", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    return(filename);
                }
                return("");
            }
            catch (Exception exc)
            {
                try
                {
                    /* this is wonky and strange, but the reason is that the SaveFileDialog
                     * will crash if the FileName does not pass the filter. There is a bunch
                     * of code that could be written to avoid this, such as parsing the filter,
                     * but it seemed fine to just reset the FileName and try once more. */
                    fileChooser.FileName = "";
                    if ((Boolean)fileChooser.ShowDialog(this))
                    {
                        filename = fileChooser.FileName;
                        if (string.IsNullOrWhiteSpace(filename))
                        {
                            MessageBox.Show("Invalid file name", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        return(filename);
                    }
                    return("");
                }

                catch
                {
                    ErrorLogger.Catch(exc);
                    return("");
                }
            }
        }
Exemple #12
0
 private void btnSaveAS_Click(object sender, RoutedEventArgs e)
 {
     if (newSettings.numOfRuleSets < newSettings.defaultRSFileNames.Count)
     {
         newSettings.defaultRSFileNames.RemoveRange(newSettings.numOfRuleSets, newSettings.defaultRSFileNames.Count
                                                    - newSettings.numOfRuleSets);
     }
     newSettings.DefaultRuleSets
         = StringCollectionConverter.Convert(newSettings.defaultRSFileNames);
     newSettings.saveNewSettings(main.GetSaveFilename("GraphSynth config file (*.gsconfig)|*.gsconfig",
                                                      "", GSApp.settings.WorkingDirAbsolute));
     btnApplyInThisProcess.IsDefault = true;
 }
Exemple #13
0
        private void txtNegLabels_LostFocus(object sender, RoutedEventArgs e)
        {
            var caretIndex = txtNegLabels.CaretIndex;
            var origLength = txtNegLabels.Text.Length;
            var lststr     = StringCollectionConverter.Convert(txtNegLabels.Text);

            ((ruleNode)firstNode).negateLabels.Clear();
            foreach (string str in lststr)
            {
                ((ruleNode)firstNode).negateLabels.Add(str);
            }
            Update();
            TextBoxHelper.SetCaret(txtNegLabels, caretIndex, origLength);
        }
        public void txtLNegatingLabels_LostFocus(object sender, RoutedEventArgs e)
        {
            var senderTextBox = (TextBox)sender;
            var caretIndex    = senderTextBox.CaretIndex;
            var origLength    = senderTextBox.Text.Length;
            var lststr        = StringCollectionConverter.Convert(senderTextBox.Text);

            rule.negateLabels.Clear();
            foreach (string str in lststr)
            {
                rule.negateLabels.Add(str);
            }
            Update();
            TextBoxHelper.SetCaret(senderTextBox, caretIndex, origLength);
        }
        private void txtApplyFunctions_LostFocus(object sender, RoutedEventArgs e)
        {
            var senderTextBox = (TextBox)sender;
            var caretIndex    = senderTextBox.CaretIndex;
            var origLength    = senderTextBox.Text.Length;
            var lststr        = StringCollectionConverter.Convert(senderTextBox.Text);

            rule.applyFunctions.Clear();
            foreach (string str in lststr)
            {
                rule.applyFunctions.Add(str);
            }
            Update();
            senderTextBox.Text += " ";
            TextBoxHelper.SetCaret(senderTextBox, caretIndex, origLength);
            RuleParamCodeFiler.checkForFunctions(false, rule, rule.applyFunctions);
        }
Exemple #16
0
        private void btnApplyInThisProcess_Click(object sender, RoutedEventArgs e)
        {
            if (newSettings.numOfRuleSets < newSettings.defaultRSFileNames.Count)
            {
                newSettings.defaultRSFileNames.RemoveRange(newSettings.numOfRuleSets, newSettings.defaultRSFileNames.Count
                                                           - newSettings.numOfRuleSets);
            }
            newSettings.DefaultRuleSets
                = StringCollectionConverter.Convert(newSettings.defaultRSFileNames);
            var tempSettings = GSApp.settings;

            GSApp.settings            = newSettings;
            SearchIO.defaultVerbosity = newSettings.DefaultVerbosity;
            try
            {
                newSettings.filer = new WPFFiler(newSettings.InputDirAbs, newSettings.OutputDirAbs, newSettings.RulesDirAbs);
                newSettings.LoadDefaultSeedAndRuleSets();
                for (int i = 0; i < newSettings.numOfRuleSets; i++)
                {
                    if (newSettings.rulesets[i] != null)
                    {
                        ((ruleSet)newSettings.rulesets[i]).RuleSetIndex = i;
                    }
                }
                /* The following three command are a repeat from MainWindow.Startup.cs. */
                main.setUpGraphElementAddButtons();
                main.setUpGraphLayoutMenu();
                main.setUpSearchProcessMenu();
            }
            catch (Exception ee)
            {
                var msgResult = MessageBox.Show("Settings did not work because of the following error: " + ee +
                                                " Revert to Previous Settings?", "Error in Settings. Revert back?",
                                                MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (msgResult == MessageBoxResult.Yes || msgResult == MessageBoxResult.OK)
                {
                    GSApp.settings = tempSettings;
                }
                return;
            }
            Close();
        }
Exemple #17
0
        private void Update()
        {
            txtFilename.Text = (string.IsNullOrWhiteSpace(graphWin.filename))
                ?  graphWin.Title: graphWin.filename;
            txtFilename.PageRight();

            if (GSApp.settings.seed == selectedGraph)
            {
                txtSeed.Text   = "This is the current seed.";
                txtSeed.Height = double.NaN;
            }
            else
            {
                txtSeed.Text   = "";
                txtSeed.Height = 0.0;
            }
            graphWin.txtGlobalVariables.Text             = txtVariables.Text
                                                         = DoubleCollectionConverter.Convert(selectedGraph.globalVariables);
            graphWin.txtGlobalLabels.Text                = txtGlobalLabels.Text
                                                         = StringCollectionConverter.Convert(selectedGraph.globalLabels);
        }
        private void txtLabels_LostFocus(object sender, RoutedEventArgs e)
        {
            if (hyperarcs.Count == 0)
            {
                return;
            }
            MultiBindingExpression mbe;
            var caretIndex = txtLabels.CaretIndex;
            var origLength = txtLabels.Text.Length;
            var oldLabels  = firstHyperArc.localLabels;
            var newLabels  = StringCollectionConverter.Convert(txtLabels.Text);

            if ((gui is RuleDisplay) &&
                (gui == ((RuleDisplay)gui).rW.graphGUIK))
            {
                var rW   = ((RuleDisplay)gui).rW;
                var Larc = rW.rule.L.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name));
                var Rarc = rW.rule.R.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name));

                var removedKLabels = oldLabels.Where(a => !newLabels.Contains(a)).ToList();
                foreach (string a in removedKLabels)
                {
                    Larc.localLabels.Remove(a);
                    Rarc.localLabels.Remove(a);
                }
                var newLLabels = new List <string>(Larc.localLabels.Union(newLabels));
                Larc.localLabels.Clear();
                foreach (string a in newLLabels)
                {
                    Larc.localLabels.Add(a);
                }
                var nI = ((HyperArcShape)Larc.DisplayShape.Shape).icon;
                mbe = BindingOperations.GetMultiBindingExpression(nI, IconShape.DisplayTextProperty);
                mbe.UpdateTarget();

                var newRLabels = new List <string>(Rarc.localLabels.Union(newLabels));
                Rarc.localLabels.Clear();
                foreach (string a in newRLabels)
                {
                    Rarc.localLabels.Add(a);
                }
                nI  = ((HyperArcShape)Rarc.DisplayShape.Shape).icon;
                mbe = BindingOperations.GetMultiBindingExpression(nI, IconShape.DisplayTextProperty);
                mbe.UpdateTarget();
            }
            else if (gui is RuleDisplay)
            {
                // this is a rule LHS or RHS
                var      rW            = ((RuleDisplay)gui).rW;
                hyperarc otherHyperArc = null;
                otherHyperArc = gui == rW.graphGUIL
                    ? rW.rule.R.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name))
                    : rW.rule.L.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name));
                if (otherHyperArc != null)
                {
                    var Klabels = new List <string>(otherHyperArc.localLabels.Intersect(newLabels));
                    otherHyperArc =
                        rW.graphGUIK.graph.hyperarcs.Find(b => string.Equals(b.name, firstHyperArc.name));
                    otherHyperArc.localLabels.Clear();
                    foreach (string a in Klabels)
                    {
                        otherHyperArc.localLabels.Add(a);
                    }
                    var nI = ((HyperArcShape)otherHyperArc.DisplayShape.Shape).icon;
                    mbe = BindingOperations.GetMultiBindingExpression(nI, IconShape.DisplayTextProperty);
                    mbe.UpdateTarget();
                }
            }
            firstHyperArc.localLabels.Clear();
            foreach (string a in newLabels)
            {
                firstHyperArc.localLabels.Add(a);
            }
            mbe = BindingOperations.GetMultiBindingExpression(hyperArcIcon, IconShape.DisplayTextProperty);
            mbe.UpdateTarget();
            Update();
            TextBoxHelper.SetCaret(txtLabels, caretIndex, origLength);
        }
Exemple #19
0
        private static void createRecognizeFunctionTemplate(string path, grammarRule rule, string funcName)
        {
            var r          = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read), Encoding.Default);
            var fileString = r.ReadToEnd();
            /** find place to insert new function **/
            var startOfApplyFuncsIndex = fileString.IndexOf("#region Parametric Application Rules", 0, StringComparison.Ordinal);
            var startBackABitIndex     = startOfApplyFuncsIndex;
            var position = -1;

            do
            {
                startBackABitIndex -= 10;
                position            = fileString.IndexOf("#endregion", startBackABitIndex, StringComparison.Ordinal);
            } while (position > startOfApplyFuncsIndex);
            /***************************************/
            var sb = new StringBuilder("");

            r.Close();

            sb.Append("\n/* This is RECOGNIZE for the rule entitled: ");
            sb.Append(rule.name);
            sb.Append(" */");
            sb.Append("\npublic double ");
            sb.Append(funcName);
            sb.Append("(option opt, designGraph host)\n{\n");
            sb.Append("#region Define Mapped Elements\n");
            sb.Append("/* the following variables are declared for your convenience. They are the mapped elements" +
                      " of the LHS in the host graph. */\n");
            for (int i = 0; i < rule.L.nodes.Count; i++)
            {
                var n = (ruleNode)rule.L.nodes[i];
                if (n.NotExist)
                {
                    continue;
                }
                if (n.localLabels.Count > 0)
                {
                    sb.Append("/* " + n.name + " is the node in L that has labels: " +
                              StringCollectionConverter.Convert(n.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + n.name + " is the node in L that has no labels;");
                }
                if (n.negateLabels.Count > 0)
                {
                    sb.Append(" has the negating labels: " +
                              StringCollectionConverter.Convert(n.negateLabels) + ";");
                }
                sb.Append("\n * is connected to: " + StringCollectionConverter.Convert(n.arcs.Select(a => a.name)) +
                          ";");
                sb.Append(" and is located at [" + n.X + ", " + n.Y + ", " + n.Z + "]. */\n");
                sb.Append("var " + n.name + " = opt.nodes[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.L.arcs.Count; i++)
            {
                var a = (ruleArc)rule.L.arcs[i];
                if (a.NotExist)
                {
                    continue;
                }
                if (a.localLabels.Count > 0)
                {
                    sb.Append("/* " + a.name + " is the arc in L that has labels: " +
                              StringCollectionConverter.Convert(a.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + a.name + " is the arc in L that has no labels;");
                }
                if (a.negateLabels.Count > 0)
                {
                    sb.Append(" has the negating labels: " + StringCollectionConverter.Convert(a.negateLabels) + ";");
                }
                sb.Append("\n * and is connected from " + a.From.name + " to " + a.To.name + ". */\n");
                sb.Append("var " + a.name + " = opt.arcs[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.L.hyperarcs.Count; i++)
            {
                var ha = (ruleHyperarc)rule.L.hyperarcs[i];
                if (ha.NotExist)
                {
                    continue;
                }
                if (ha.localLabels.Count > 0)
                {
                    sb.Append("/* " + ha.name + " is the hypearc in L that has labels: " +
                              StringCollectionConverter.Convert(ha.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + ha.name + " is the hyperarc in L that no labels;");
                }
                if (ha.negateLabels.Count > 0)
                {
                    sb.Append(" has the negating labels: " +
                              StringCollectionConverter.Convert(ha.negateLabels) + ";\n");
                }
                sb.Append("\n * and is connected to: " + StringCollectionConverter.Convert(ha.nodes.Select(n => n.name)) +
                          ". */\n");
                sb.Append("var " + ha.name + " = opt.hyperarcs[" + i + "];\n\n");
            }
            sb.Append("#endregion\n\n\n");
            sb.Append("\n\n/* here is where the code for the RECOGNIZE function is to be located.\n");
            sb.Append(" * please remember that returning a positive real (double) is equivalent to\n");
            sb.Append(" * a constraint violation. Zero and negative numbers are feasible. */\n");
            sb.Append("return 0.0;\n}\n");
            fileString = fileString.Insert(position, sb.ToString());

            var w = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write), Encoding.Default);

            w.Write(fileString);
            w.Flush();
            w.Close();
        }
Exemple #20
0
        private static void createApplyFunctionTemplate(string path, grammarRule rule, string funcName)
        {
            var r          = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read), Encoding.Default);
            var fileString = r.ReadToEnd();
            /** find place to insert new function **/
            var position = fileString.IndexOf("#region Parametric Application Rules", 0, StringComparison.Ordinal);

            while (fileString.IndexOf("#endregion", position + 1, StringComparison.Ordinal) > 0)
            {
                position = fileString.IndexOf("#endregion", position + 1, StringComparison.Ordinal);
            }
            /***************************************/
            var sb = new StringBuilder("");

            r.Close();

            sb.Append("\n/* This is APPLY for the rule entitled: ");
            sb.Append(rule.name);
            sb.Append(" */");
            sb.Append("\npublic void ");
            sb.Append(funcName);
            sb.Append(
                "(option opt, designGraph host, designGraph Rmapping, double[] parameters)\n{\n");


            sb.Append("#region Define Mapped Elements\n");
            sb.Append("/* the following variables are declared for your convenience. They are the mapped elements" +
                      " of the L, K, and R elements\n" +
                      " * in the host graph. The convention that is used is when the element is only in L, then the\n" +
                      " * variable name is followed by \"_deleted\", when the element is only in R, then it is appended\n" +
                      " * with \"_added\". If it is in both (in K), then no post-script is added. */\n");
            for (int i = 0; i < rule.L.nodes.Count; i++)
            {
                var n = (ruleNode)rule.L.nodes[i];
                if (n.NotExist)
                {
                    continue;
                }
                var name = (rule.R.nodes.Any(rn => rn.name.Equals(n.name))) ? n.name : n.name + "_deleted";
                var where = (rule.R.nodes.Any(rn => rn.name.Equals(n.name))) ? "K" : "L";
                if (n.localLabels.Count > 0)
                {
                    sb.Append("/* " + name + " is the node in " + where + " that has labels: " +
                              StringCollectionConverter.Convert(n.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + name + " is the node in " + where + " that has no labels;");
                }
                if (n.negateLabels.Count > 0)
                {
                    sb.Append(" has the negating labels: " +
                              StringCollectionConverter.Convert(n.negateLabels) + ";");
                }
                sb.Append("\n * is connected to: " + StringCollectionConverter.Convert(n.arcs.Select(a => a.name)) +
                          ";");
                sb.Append(" and is located at [" + n.X + ", " + n.Y + ", " + n.Z + "]. */\n");
                sb.Append("var " + name + " = opt.nodes[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.R.nodes.Count; i++)
            {
                var n = (ruleNode)rule.R.nodes[i];
                if (rule.L.nodes.Any(ln => ln.name.Equals(n.name)))
                {
                    continue;
                }
                if (n.localLabels.Count > 0)
                {
                    sb.Append("/* " + n.name + "_added is the node in R that has labels: " +
                              StringCollectionConverter.Convert(n.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + n.name + "_added is the node in R that has no labels;");
                }
                sb.Append("\n * is connected to: " + StringCollectionConverter.Convert(n.arcs.Select(a => a.name)) +
                          ";");
                sb.Append(" and is located at [" + n.X + ", " + n.Y + ", " + n.Z + "]. */\n");
                sb.Append("var " + n.name + "_added = Rmapping.nodes[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.L.arcs.Count; i++)
            {
                var a = (ruleArc)rule.L.arcs[i];
                if (a.NotExist)
                {
                    continue;
                }
                var name = (rule.R.arcs.Any(ra => ra.name.Equals(a.name))) ? a.name : a.name + "_deleted";
                var where = (rule.R.arcs.Any(ra => ra.name.Equals(a.name))) ? "K" : "L";
                if (a.localLabels.Count > 0)
                {
                    sb.Append("/* " + name + " is the arc in " + where + " that has labels: " +
                              StringCollectionConverter.Convert(a.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + name + " is the arc in " + where + " that has no labels;");
                }
                if (a.negateLabels.Count > 0)
                {
                    sb.Append(" has the negating labels: " + StringCollectionConverter.Convert(a.negateLabels) + ";");
                }
                var fromName = a.From == null ? "nothing" : a.From.name;
                var toName   = a.To == null ? "nothing" : a.To.name;
                sb.Append("\n * and is connected from " + fromName + " to " + toName + ". */\n");
                sb.Append("var " + name + " = opt.arcs[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.R.arcs.Count; i++)
            {
                var a = (ruleArc)rule.R.arcs[i];
                if (rule.L.arcs.Any(ln => ln.name.Equals(a.name)))
                {
                    continue;
                }
                if (a.localLabels.Count > 0)
                {
                    sb.Append("/* " + a.name + "_added is the arc in R that has labels: " +
                              StringCollectionConverter.Convert(a.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + a.name + "_added is the arc in R that has no labels;");
                }
                var fromName = a.From == null ? "nothing" : a.From.name;
                var toName   = a.To == null ? "nothing" : a.To.name;
                sb.Append("\n * and is connected from " + fromName + " to " + toName + ". */\n");
                sb.Append("var " + a.name + "_added = Rmapping.arcs[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.L.hyperarcs.Count; i++)
            {
                var ha = (ruleHyperarc)rule.L.hyperarcs[i];
                if (ha.NotExist)
                {
                    continue;
                }
                var name = (rule.R.hyperarcs.Any(ra => ra.name.Equals(ha.name))) ? ha.name : ha.name + "_deleted";
                var where = (rule.R.hyperarcs.Any(ra => ra.name.Equals(ha.name))) ? "K" : "L";
                if (ha.localLabels.Count > 0)
                {
                    sb.Append("/* " + name + " is the hypearc in " + where + " that has labels: " +
                              StringCollectionConverter.Convert(ha.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + name + " is the hyperarc in " + where + " that no labels;");
                }
                if (ha.negateLabels.Count > 0)
                {
                    sb.Append(" has the negating labels: " +
                              StringCollectionConverter.Convert(ha.negateLabels) + ";\n");
                }
                sb.Append("\n * and is connected to: " + StringCollectionConverter.Convert(ha.nodes.Select(n => n.name)) +
                          ". */\n");
                sb.Append("var " + name + " = opt.hyperarcs[" + i + "];\n\n");
            }
            for (int i = 0; i < rule.R.hyperarcs.Count; i++)
            {
                var a = (ruleHyperarc)rule.R.hyperarcs[i];
                if (rule.L.hyperarcs.Any(ln => ln.name.Equals(a.name)))
                {
                    continue;
                }
                if (a.localLabels.Count > 0)
                {
                    sb.Append("/* " + a.name + "_added is the hyperarc in R that has labels: " +
                              StringCollectionConverter.Convert(a.localLabels) + ";");
                }
                else
                {
                    sb.Append("/* " + a.name + "_added is the hyperarc in R that has no labels;");
                }
                sb.Append("\n * and is connected to: " + StringCollectionConverter.Convert(a.nodes.Select(n => n.name)) +
                          ". */\n");
                sb.Append("var " + a.name + "_added = Rmapping.hyperarcs[" + i + "];\n\n");
            }
            sb.Append("#endregion\n\n\n");

            sb.Append("\n\n/* here is where the code for the APPLY function is to be located.\n");
            sb.Append("* please modify host (or located nodes) with the input from parameters. */\n");
            sb.Append("\n}\n");

            fileString = fileString.Insert(position, sb.ToString());

            var w = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write), Encoding.Default);

            w.Write(fileString);
            w.Flush();
            w.Close();
        }
Exemple #21
0
        private void Update()
        {
            if (nodes.Count == 1)
            {
                txtName.IsEnabled     = txtLabels.IsEnabled = txtVariables.IsEnabled = true;
                txtName.Text          = firstNode.name;
                btnConfirm.Visibility = firstNode is ruleNode
                    ? Visibility.Visible : Visibility.Hidden;
                txtLabels.Text    = StringCollectionConverter.Convert(firstNode.localLabels);
                txtVariables.Text = DoubleCollectionConverter.Convert(firstNode.localVariables);

                txtNodeType.IsEnabled = true;
                if (gui is RuleDisplay)
                {
                    txtNodeType.Text = ((ruleNode)firstNode).TargetType;
                }
                else
                {
                    txtNodeType.Text = firstNode.GetType().ToString();
                }

                txtBxPosX.Foreground = txtBxPosY.Foreground = txtBxPosZ.Foreground = Brushes.Black;
                txtBxPosX.Text       = firstNode.X.ToString();
                txtBxPosY.Text       = firstNode.Y.ToString();
                txtBxPosZ.Text       = firstNode.Z.ToString();

                if ((gui is RuleDisplay) &&
                    (gui == ((RuleDisplay)gui).rW.graphGUIL))
                {
                    chkContainsLocalLabels.IsChecked = ((ruleNode)firstNode).containsAllLocalLabels;
                    chkStrictDegreeMatch.IsChecked   = ((ruleNode)firstNode).strictDegreeMatch;
                    chkNotExist.IsChecked            = ((ruleNode)firstNode).NotExist;

                    txtNegLabels.IsEnabled = true;
                    txtNegLabels.Text
                        = StringCollectionConverter.Convert(((ruleNode)firstNode).negateLabels);
                    if (!stackNodeProps.Children.Contains(wrapRuleBools))
                    {
                        stackNodeProps.Children.Add(wrapRuleBools);
                    }
                    if (!stackNodeProps.Children.Contains(gridRuleNegLabels))
                    {
                        stackNodeProps.Children.Add(gridRuleNegLabels);
                    }
                }
                else
                {
                    stackNodeProps.Children.Remove(wrapRuleBools);
                    stackNodeProps.Children.Remove(gridRuleNegLabels);
                }
            }
            else if (nodes.Count > 1)
            {
                txtName.Text      = "<multiple nodes>";
                txtLabels.Text    = "<multiple nodes>";
                txtVariables.Text = "<multiple nodes>";
                txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = false;
                //                expLocation.IsEnabled = false;

                var allSame = true;
                /*****************  Node Type *************/
                if (gui is RuleDisplay)
                {
                    var aType = ((ruleNode)firstNode).TargetType;
                    for (var i = 1; i < nodes.Count; i++)
                    {
                        if (aType != ((ruleNode)nodes[i]).TargetType)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        txtNodeType.IsEnabled = true;
                        txtNodeType.Text      = aType;
                    }
                    else
                    {
                        txtNodeType.IsEnabled = false;
                        txtNodeType.Text      = "<multiple types>";
                    }
                }
                else
                {
                    var aType = firstNode.GetType();
                    for (var i = 1; i < nodes.Count; i++)
                    {
                        if (aType != nodes[i].GetType())
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        txtNodeType.IsEnabled = true;
                        txtNodeType.Text      = aType.ToString();
                    }
                    else
                    {
                        txtNodeType.IsEnabled = false;
                        txtNodeType.Text      = "<multiple types>";
                    }
                }

                /*****************  X-Position *************/
                allSame = true;
                var pos = firstNode.X;
                for (var i = 1; i < nodes.Count; i++)
                {
                    if (!pos.Equals(nodes[i].X))
                    {
                        allSame = false;
                        break;
                    }
                }
                if (allSame)
                {
                    txtBxPosX.Foreground = Brushes.Black;
                    txtBxPosX.Text       = pos.ToString();
                }
                else
                {
                    txtBxPosX.Foreground = Brushes.Gray;
                    txtBxPosX.Text       = "diff";
                }
                /*****************  Y-Position *************/
                allSame = true;
                pos     = firstNode.Y;
                for (var i = 1; i < nodes.Count; i++)
                {
                    if (!pos.Equals(nodes[i].Y))
                    {
                        allSame = false;
                        break;
                    }
                }
                if (allSame)
                {
                    txtBxPosY.Foreground = Brushes.Black;
                    txtBxPosY.Text       = pos.ToString();
                }
                else
                {
                    txtBxPosY.Foreground = Brushes.Gray;
                    txtBxPosY.Text       = "diff";
                }
                /*****************  Z-Position *************/
                allSame = true;
                pos     = firstNode.Z;
                for (var i = 1; i < nodes.Count; i++)
                {
                    if (!pos.Equals(nodes[i].Z))
                    {
                        allSame = false;
                        break;
                    }
                }
                if (allSame)
                {
                    txtBxPosZ.Foreground = Brushes.Black;
                    txtBxPosZ.Text       = pos.ToString();
                }
                else
                {
                    txtBxPosZ.Foreground = Brushes.Gray;
                    txtBxPosZ.Text       = "diff";
                }

                if ((gui is RuleDisplay) &&
                    (gui == ((RuleDisplay)gui).rW.graphGUIL))
                {
                    allSame = true;
                    var nBool = ((ruleNode)firstNode).containsAllLocalLabels;
                    for (var i = 1; i < nodes.Count; i++)
                    {
                        if (nBool != ((ruleNode)nodes[i]).containsAllLocalLabels)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        chkContainsLocalLabels.IsChecked = nBool;
                    }
                    else
                    {
                        chkContainsLocalLabels.IsChecked = null;
                    }

                    allSame = true;
                    nBool   = ((ruleNode)firstNode).strictDegreeMatch;
                    for (var i = 1; i < nodes.Count; i++)
                    {
                        if (nBool != ((ruleNode)nodes[i]).strictDegreeMatch)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        chkStrictDegreeMatch.IsChecked = nBool;
                    }
                    else
                    {
                        chkStrictDegreeMatch.IsChecked = null;
                    }

                    allSame = true;
                    nBool   = ((ruleNode)firstNode).NotExist;
                    for (var i = 1; i < nodes.Count; i++)
                    {
                        if (nBool != ((ruleNode)nodes[i]).NotExist)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        chkNotExist.IsChecked = nBool;
                    }
                    else
                    {
                        chkNotExist.IsChecked = null;
                    }

                    txtNegLabels.IsEnabled = false;
                    txtNegLabels.Text      = "<multiple nodes>";
                    if (!stackNodeProps.Children.Contains(wrapRuleBools))
                    {
                        stackNodeProps.Children.Add(wrapRuleBools);
                    }
                    if (!stackNodeProps.Children.Contains(gridRuleNegLabels))
                    {
                        stackNodeProps.Children.Add(gridRuleNegLabels);
                    }
                }
                else
                {
                    stackNodeProps.Children.Remove(wrapRuleBools);
                    stackNodeProps.Children.Remove(gridRuleNegLabels);
                }
            }
        }
        private void Update()
        {
            if (hyperarcs.Count == 1)
            {
                txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = true;
                txtName.Text      = firstHyperArc.name;
                if (firstHyperArc is ruleHyperarc)
                {
                    btnConfirm.Visibility = Visibility.Visible;
                }
                else
                {
                    btnConfirm.Visibility = Visibility.Hidden;
                }
                txtLabels.Text    = StringCollectionConverter.Convert(firstHyperArc.localLabels);
                txtVariables.Text = DoubleCollectionConverter.Convert(firstHyperArc.localVariables);

                txtHyperArcType.IsEnabled = true;
                if (gui is RuleDisplay)
                {
                    txtHyperArcType.Text = ((ruleHyperarc)firstHyperArc).TargetType;
                }
                else
                {
                    txtHyperArcType.Text = firstHyperArc.GetType().ToString();
                }

                if ((gui is RuleDisplay) &&
                    (gui == ((RuleDisplay)gui).rW.graphGUIL))
                {
                    chkContainsLocalLabels.IsChecked = ((ruleHyperarc)firstHyperArc).containsAllLocalLabels;
                    chkStrictNodeCount.IsChecked     = ((ruleHyperarc)firstHyperArc).strictNodeCountMatch;
                    chkNotExist.IsChecked            = ((ruleHyperarc)firstHyperArc).NotExist;
                    txtNegLabels.IsEnabled           = true;
                    txtNegLabels.Text
                        = StringCollectionConverter.Convert(((ruleHyperarc)firstHyperArc).negateLabels);
                    if (!stackHyperArcProps.Children.Contains(wrapRuleBools))
                    {
                        stackHyperArcProps.Children.Add(wrapRuleBools);
                    }
                    if (!stackHyperArcProps.Children.Contains(gridRuleNegLabels))
                    {
                        stackHyperArcProps.Children.Add(gridRuleNegLabels);
                    }
                }
                else
                {
                    stackHyperArcProps.Children.Remove(wrapRuleBools);
                    stackHyperArcProps.Children.Remove(gridRuleNegLabels);
                }
            }
            else
            {
                txtName.Text      = "<multiple hyperarcs>";
                txtLabels.Text    = "<multiple hyperarcs>";
                txtVariables.Text = "<multiple hyperarcs>";
                txtName.IsEnabled = txtLabels.IsEnabled = txtVariables.IsEnabled = false;

                var allSame = true;
                if (gui is RuleDisplay)
                {
                    var aType = ((ruleHyperarc)firstHyperArc).TargetType;
                    for (var i = 1; i < hyperarcs.Count; i++)
                    {
                        if (aType != ((ruleHyperarc)hyperarcs[i]).TargetType)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        txtHyperArcType.IsEnabled = true;
                        txtHyperArcType.Text      = aType;
                    }
                    else
                    {
                        txtHyperArcType.IsEnabled = false;
                        txtHyperArcType.Text      = "<multiple types>";
                    }
                }
                else
                {
                    var aType = firstHyperArc.GetType();
                    for (var i = 1; i < hyperarcs.Count; i++)
                    {
                        if (aType != hyperarcs[i].GetType())
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        txtHyperArcType.IsEnabled = true;
                        txtHyperArcType.Text      = aType.ToString();
                    }
                    else
                    {
                        txtHyperArcType.IsEnabled = false;
                        txtHyperArcType.Text      = "<multiple types>";
                    }
                }

                if ((gui is RuleDisplay) &&
                    (gui == ((RuleDisplay)gui).rW.graphGUIL))
                {
                    allSame = true;
                    var aBool = ((ruleHyperarc)firstHyperArc).containsAllLocalLabels;
                    for (var i = 1; i < hyperarcs.Count; i++)
                    {
                        if (aBool != ((ruleHyperarc)hyperarcs[i]).containsAllLocalLabels)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        chkContainsLocalLabels.IsChecked = aBool;
                    }
                    else
                    {
                        chkContainsLocalLabels.IsChecked = null;
                    }

                    allSame = true;
                    aBool   = ((ruleHyperarc)firstHyperArc).strictNodeCountMatch;
                    for (var i = 1; i < hyperarcs.Count; i++)
                    {
                        if (aBool != ((ruleHyperarc)hyperarcs[i]).strictNodeCountMatch)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        chkStrictNodeCount.IsChecked = aBool;
                    }
                    else
                    {
                        chkStrictNodeCount.IsChecked = null;
                    }

                    allSame = true;
                    aBool   = ((ruleHyperarc)firstHyperArc).NotExist;
                    for (var i = 1; i < hyperarcs.Count; i++)
                    {
                        if (aBool != ((ruleHyperarc)hyperarcs[i]).NotExist)
                        {
                            allSame = false;
                            break;
                        }
                    }
                    if (allSame)
                    {
                        chkNotExist.IsChecked = aBool;
                    }
                    else
                    {
                        chkNotExist.IsChecked = null;
                    }


                    txtNegLabels.IsEnabled = false;
                    txtNegLabels.Text      = "<multiple hyperarcs>";
                    if (!stackHyperArcProps.Children.Contains(wrapRuleBools))
                    {
                        stackHyperArcProps.Children.Add(wrapRuleBools);
                    }
                    if (!stackHyperArcProps.Children.Contains(gridRuleNegLabels))
                    {
                        stackHyperArcProps.Children.Add(gridRuleNegLabels);
                    }
                }
                else
                {
                    stackHyperArcProps.Children.Remove(wrapRuleBools);
                    stackHyperArcProps.Children.Remove(gridRuleNegLabels);
                }
            }
        }
Exemple #23
0
        private void Update()
        {
            if (noRecursion)
            {
                return;
            }
            noRecursion = true;
            EnableProperties();
            //free arc labels text
            if (selectedEmbeddingRule.freeArcLabels.Count == 0)
            {
                txtFreeArcLabels.Text = "<any>";
            }
            else
            {
                txtFreeArcLabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.freeArcLabels);
            }

            //free arc neg labels
            if (selectedEmbeddingRule.freeArcNegabels.Count == 0)
            {
                txtFreeArcNegabels.Text = "<none>";
            }
            else
            {
                txtFreeArcNegabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.freeArcNegabels);
            }

            //L node name
            if ((string.IsNullOrWhiteSpace(selectedEmbeddingRule.LNodeName)) ||
                (!cmdLNodeName.Items.Contains(selectedEmbeddingRule.LNodeName)))
            {
                cmdLNodeName.SelectedItem = "<any>";
            }
            else if (!selectedEmbeddingRule.LNodeName.Equals(cmdLNodeName.SelectedItem))
            {
                cmdLNodeName.SelectedItem = selectedEmbeddingRule.LNodeName;
            }

            // neighbor node labels
            if (selectedEmbeddingRule.neighborNodeLabels.Count == 0)
            {
                txtNeighborLabels.Text = "<any>";
            }
            else
            {
                txtNeighborLabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.neighborNodeLabels);
            }

            // neighbor node negabels
            if (selectedEmbeddingRule.neighborNodeNegabels.Count == 0)
            {
                txtNeighborNegabels.Text = "<none>";
            }
            else
            {
                txtNeighborNegabels.Text = StringCollectionConverter.Convert(selectedEmbeddingRule.neighborNodeNegabels);
            }

            // orginal direction
            if (cmdOriginalDirection.SelectedIndex != selectedEmbeddingRule.originalDirection + 1)
            {
                cmdOriginalDirection.SelectedIndex = selectedEmbeddingRule.originalDirection + 1;
            }

            //R node Name
            if ((string.IsNullOrWhiteSpace(selectedEmbeddingRule.RNodeName)) ||
                (!cmdRNodeName.Items.Contains(selectedEmbeddingRule.RNodeName)))
            {
                cmdRNodeName.SelectedItem = "<null> (leave dangling)";
            }
            else if (!selectedEmbeddingRule.RNodeName.Equals(cmdRNodeName.SelectedItem))
            {
                cmdRNodeName.SelectedItem = selectedEmbeddingRule.RNodeName;
            }


            // allow duplication
            if (chkAllowDup.IsChecked != selectedEmbeddingRule.allowArcDuplication)
            {
                chkAllowDup.IsChecked = selectedEmbeddingRule.allowArcDuplication;
            }

            //new direction
            if (cmdNewDirection.SelectedIndex != selectedEmbeddingRule.newDirection + 1)
            {
                cmdNewDirection.SelectedIndex = selectedEmbeddingRule.newDirection + 1;
            }
            var s = eRulesListBox.SelectedIndex;

            listBoxBE.UpdateTarget();
            eRulesListBox.SelectedIndex = s;
            noRecursion = false;
        }
Exemple #24
0
        protected IconShape(graphElement e, GraphGUI gd, object textDisplayData,
                            double maxOpacity, double radiusMultiplier, double radiusAddition, object arcController)
        {
            GraphElement = e;
            if (textDisplayData == null)
            {
                textDisplayData = "";
            }
            else
            {
                textDisplayData = textDisplayData.ToString().Split(new[] { ':' })[0];
            }
            var    tDDataList = StringCollectionConverter.Convert(textDisplayData.ToString());
            double result;

            if ((tDDataList.Count > 1) && (double.TryParse(tDDataList[1], out result)))
            {
                DisplayTextDistance = result;
            }
            else
            {
                DisplayTextDistance = double.NaN;
            }
            if ((tDDataList.Count > 2) && (double.TryParse(tDDataList[2], out result)))
            {
                DisplayTextPosition = result;
            }
            else
            {
                DisplayTextPosition = double.NaN;
            }
            if ((tDDataList.Count > 3) && (double.TryParse(tDDataList[3], out result)))
            {
                FontSize = result;
            }
            else
            {
                FontSize = double.NaN;
            }

            var binding = new Binding
            {
                Source = gd,
                Mode   = BindingMode.OneWay,
                Path   = new PropertyPath(GraphGUI.ScaleFactorProperty)
            };

            SetBinding(ScaleFactorProperty, binding);
            binding = new Binding
            {
                Converter = new IconOpacityConverter(this, maxOpacity, radiusMultiplier, radiusAddition),
                Source    = gd,
                Mode      = BindingMode.OneWay,
                Path      = new PropertyPath(GraphGUI.MouseLocationProperty)
            };
            SetBinding(StrokeOpacityProperty, binding);

            /* whether or not to show the text depends on various parameters */
            var multiBinding = new MultiBinding
            {
                Converter          = new DisplayTextConverter(),
                Mode               = BindingMode.OneWay,
                ConverterParameter = GraphElement
            };

            {
                binding = new Binding {
                    Source = this, Path = new PropertyPath(ShowNameProperty)
                };
                multiBinding.Bindings.Add(binding);

                binding = new Binding {
                    Source = this, Path = new PropertyPath(ShowLabelsProperty)
                };
                multiBinding.Bindings.Add(binding);

                binding = new Binding {
                    Source = this, Path = new PropertyPath(FontSizeProperty)
                };
                multiBinding.Bindings.Add(binding);
            }
            SetBinding(DisplayTextProperty, multiBinding);

            /* where is text to be shown? */
            multiBinding = new MultiBinding
            {
                Converter          = new PositionTextConverter(),
                ConverterParameter = arcController,
                Mode = BindingMode.OneWay
            };
            {
                binding = new Binding {
                    Source = this, Path = new PropertyPath(DisplayTextDistanceProperty)
                };
                multiBinding.Bindings.Add(binding);

                binding = new Binding {
                    Source = this, Path = new PropertyPath(DisplayTextPositionProperty)
                };
                multiBinding.Bindings.Add(binding);

                binding = new Binding {
                    Source = this, Path = new PropertyPath(DisplayTextProperty)
                };
                multiBinding.Bindings.Add(binding);
            }
            SetBinding(TextPointProperty, multiBinding);
        }