private string ObjectName(bool canheader) { if (d_wrapper != null) { return(d_wrapper.Id); } else if (d_object != null) { Cdn.Variable prop = d_object as Cdn.Variable; if (prop != null) { return(prop.Name); } Cdn.EdgeAction action = d_object as Cdn.EdgeAction; if (action != null) { return(action.Target); } } if (canheader) { return(HeaderName); } else { return(null); } }
public Cdn.Object GetVariableTemplate(Cdn.Variable variable, bool match_full) { IntPtr raw_ret = cdn_object_get_variable_template(Handle, variable == null ? IntPtr.Zero : variable.Handle, match_full); Cdn.Object ret = GLib.Object.GetObject(raw_ret) as Cdn.Object; return(ret); }
public static string Translate(Cdn.Variable property, Context context) { Instruction[] instructions = property.Expression.Instructions; if (instructions.Length == 1 && instructions[0] is InstructionNumber) { string val = ((InstructionNumber)instructions[0]).Representation; if (val.ToLower() == "pi") { return("Math.PI"); } else if (val.ToLower() == "e") { return("Math.E"); } int pos = val.IndexOf('.'); if (pos == -1) { return(Translate(property.Value, context)); } else { return(Translate(property.Value, val.Length - pos - 1, context)); } } return(Translate(property.Value, context)); }
public ModifyVariable(Wrappers.Wrapper wrapped, Cdn.Variable property, Cdn.VariableFlags flags) : base(wrapped, property) { d_expression = null; d_flags = flags; d_previousFlags = property.Flags; }
public Cdn.ExpressionTreeIter Substitute(Cdn.Variable property, Cdn.ExpressionTreeIter subst) { IntPtr raw_ret = cdn_expression_tree_iter_substitute(Handle, property == null ? IntPtr.Zero : property.Handle, subst == null ? IntPtr.Zero : subst.Handle); Cdn.ExpressionTreeIter ret = raw_ret == IntPtr.Zero ? null : (Cdn.ExpressionTreeIter)GLib.Opaque.GetOpaque(raw_ret, typeof(Cdn.ExpressionTreeIter), false); return(ret); }
public bool Equal(Cdn.Variable other, bool asstring) { bool raw_ret = cdn_variable_equal(Handle, other == null ? IntPtr.Zero : other.Handle, asstring); bool ret = raw_ret; return(ret); }
private void FillFlagsStore(Cdn.Variable property) { d_flagsStore.Clear(); Cdn.VariableFlags flags = property.Flags; Cdn.VariableFlags building = Cdn.VariableFlags.None; List <string> items = new List <string>(); List <KeyValuePair <string, Cdn.VariableFlags> > copy = new List <KeyValuePair <string, Cdn.VariableFlags> >(d_flaglist); copy.Reverse(); foreach (KeyValuePair <string, Cdn.VariableFlags> pair in copy) { string name = pair.Key; if ((flags & pair.Value) == pair.Value && (building & pair.Value) == 0) { building |= pair.Value; name = "• " + name; } items.Add(name); } items.Reverse(); foreach (string s in items) { d_flagsStore.AppendValues(s); } }
public EnumItem(Cdn.Variable property, string shortname, string cname, string comment, string v) { Variable = property; ShortName = shortname; CName = cname; Comment = comment; Value = v; }
public InstructionVariable(Cdn.Variable property, Cdn.InstructionVariableBinding binding) : base(IntPtr.Zero) { if (GetType() != typeof(InstructionVariable)) { throw new InvalidOperationException("Can't override this constructor."); } Raw = cdn_instruction_variable_new_with_binding(property == null ? IntPtr.Zero : property.Handle, (int)binding); }
public Cdn.Variable LookupVariableLast(string name) { IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name); IntPtr raw_ret = cdn_compile_context_lookup_variable_last(Handle, native_name); Cdn.Variable ret = GLib.Object.GetObject(raw_ret) as Cdn.Variable; GLib.Marshaller.Free(native_name); return(ret); }
public Cdn.Variable Variable(string name) { IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name); IntPtr raw_ret = cdn_object_get_variable(Handle, native_name); Cdn.Variable ret = GLib.Object.GetObject(raw_ret) as Cdn.Variable; GLib.Marshaller.Free(native_name); return(ret); }
public Cdn.Variable FindVariable(string selector) { IntPtr native_selector = GLib.Marshaller.StringToPtrGStrdup(selector); IntPtr raw_ret = cdn_node_find_variable(Handle, native_selector); Cdn.Variable ret = GLib.Object.GetObject(raw_ret) as Cdn.Variable; GLib.Marshaller.Free(native_selector); return(ret); }
private string PrettyFullName(Cdn.Variable v) { if (v.Object == d_program.Options.Network || v.Object == d_program.Options.Network.Integrator) { return(v.Name); } else { return(v.FullName); } }
public Cdn.Variable Copy() { IntPtr raw_ret = cdn_variable_copy(Handle); if (raw_ret != IntPtr.Zero) { g_object_ref_sink(Raw); } Cdn.Variable ret = GLib.Object.GetObject(raw_ret, true) as Cdn.Variable; return(ret); }
public unsafe Cdn.ExpressionTreeIter SolveFor(Cdn.Variable prop) { IntPtr error = IntPtr.Zero; IntPtr raw_ret = cdn_expression_tree_iter_solve_for(Handle, prop == null ? IntPtr.Zero : prop.Handle, out error); Cdn.ExpressionTreeIter ret = raw_ret == IntPtr.Zero ? null : (Cdn.ExpressionTreeIter)GLib.Opaque.GetOpaque(raw_ret, typeof(Cdn.ExpressionTreeIter), false); if (error != IntPtr.Zero) { throw new GLib.GException(error); } return(ret); }
public unsafe bool AddVariable(Cdn.Variable variable) { IntPtr error = IntPtr.Zero; bool raw_ret = cdn_object_add_variable(Handle, variable == null ? IntPtr.Zero : variable.Handle, out error); bool ret = raw_ret; if (error != IntPtr.Zero) { throw new GLib.GException(error); } return(ret); }
private void OnVariableRemoved(Wrappers.Wrapper wrapper, Cdn.Variable property) { foreach (WrapperNode node in AllChildren) { if (node.d_object == property) { Remove(node); break; } } }
private void PrintSparsity(State s, Cdn.Variable v) { SparsityInfo info; if (!d_stateSparsity.TryGetValue(s, out info)) { Console.Error.WriteLine("Did not compute sparsity for state `{0}'", v.FullNameForDisplay); return; } Console.WriteLine("{0}:", v.FullNameForDisplay); Console.Write(info.LogicalString); }
public Cdn.Variable AddVariable(string name, string val, Cdn.VariableFlags flags) { Cdn.Variable prop = new Cdn.Variable(name, new Cdn.Expression(val), flags); if (AddVariable(prop)) { return(prop); } else { return(null); } }
private Cdn.Variable PromoteConstraint(Cdn.Variable variable) { var c = variable.Constraint; if (c == null) { return(null); } // Create a separate variable for the actual expression of // 'variable' and set the new expression of 'variable' to the // constraint expression. var nv = new Cdn.Variable(String.Format("_{0}_unc", variable.Name), variable.Expression.Copy(), VariableFlags.None); variable.Object.AddVariable(nv); var instrs = variable.Constraint.Instructions; for (int i = 0; i < instrs.Length; ++i) { Cdn.InstructionVariable vinstr; vinstr = instrs[i] as InstructionVariable; if (vinstr != null && vinstr.Variable == variable) { instrs[i] = (Cdn.Instruction)vinstr.Copy(); ((InstructionVariable)instrs[i]).Variable = nv; } } var expr = variable.Constraint.Copy(); expr.Instructions = instrs; variable.Expression = expr; Cdn.EdgeAction[] actions; if (!variable.HasFlag(VariableFlags.Integrated) && d_actionedVariables.TryGetValue(variable, out actions)) { foreach (var action in actions) { // Redirect edge to the unconstraint variable for direct edges action.Target = nv.Name; } } return(nv); }
protected virtual void OnVariableAdded(Cdn.Variable variable) { GLib.Value ret = GLib.Value.Empty; GLib.ValueArray inst_and_params = new GLib.ValueArray(2); GLib.Value[] vals = new GLib.Value [2]; vals [0] = new GLib.Value(this); inst_and_params.Append(vals [0]); vals [1] = new GLib.Value(variable); inst_and_params.Append(vals [1]); g_signal_chain_from_overridden(inst_and_params.ArrayPtr, ref ret); foreach (GLib.Value v in vals) { v.Dispose(); } }
private void DoVariableAdded(Wrappers.Wrapper obj, Cdn.Variable prop) { Node node = new Node(prop); d_treeview.NodeStore.Remove(d_dummy); d_treeview.NodeStore.Add(node); d_treeview.NodeStore.Add(d_dummy); if (d_selectProperty) { d_treeview.Selection.UnselectAll(); d_treeview.Selection.SelectPath(node.Path); d_treeview.SetCursor(node.Path, d_treeview.GetColumn(0), true); } }
private void Resolve(Node node, Cdn.Variable variable, HashSet <Cdn.Expression> seen, Dictionary <object, State> mapping) { State mapped = null; DataTable.DataItem item; if ((mapping != null && mapping.TryGetValue(variable, out mapped)) || d_states.TryGetValue(variable, out item)) { seen.Add(variable.Expression); AddDependency(node, variable, mapped); } else { Resolve(node, variable.Expression, seen, mapping); } }
private void AddFlaggedVariable(Cdn.Variable property) { foreach (Cdn.VariableFlags flags in Enum.GetValues(typeof(Cdn.VariableFlags))) { if ((property.Flags & flags) != 0) { List <Cdn.Variable> lst; if (!d_flaggedVariables.TryGetValue(flags, out lst)) { lst = new List <Variable>(); d_flaggedVariables[flags] = lst; } lst.Add(property); } } }
private void AddAux(State s, HashSet <object> unique) { if (unique != null && unique.Contains(s.Object)) { return; } Cdn.Variable v = (Cdn.Variable)s.Object; if ((v.Flags & (VariableFlags.In | VariableFlags.Once)) == 0) { d_auxStates.Add(s); if (unique != null) { unique.Add(s.Object); } } }
public Monitor(Cdn.Network network, Cdn.Variable property) : base(IntPtr.Zero) { if (GetType() != typeof(Monitor)) { ArrayList vals = new ArrayList(); ArrayList names = new ArrayList(); if (network != null) { names.Add("network"); vals.Add(new GLib.Value(network)); } if (property != null) { names.Add("property"); vals.Add(new GLib.Value(property)); } CreateNativeObject((string[])names.ToArray(typeof(string)), (GLib.Value[])vals.ToArray(typeof(GLib.Value))); return; } Raw = cdn_monitor_new(network == null ? IntPtr.Zero : network.Handle, property == null ? IntPtr.Zero : property.Handle); }
private Cdn.Variable FindSame(Cdn.Network nout, Cdn.Variable v) { var parent = v.Object; Stack <Cdn.Object> parents = new Stack <Object>(); while (parent != null && parent.Parent != null) { parents.Push(parent); parent = parent.Parent; } Cdn.Object outParent = nout; while (outParent != null && parents.Count > 0) { parent = parents.Pop(); var node = outParent as Cdn.Node; if (node != null) { outParent = node.GetChild(parent.Id); } else { outParent = null; } } if (outParent != null) { return(outParent.Variable(v.Name)); } else { return(null); } }
private void DoRemoveProperty() { List <Undo.IAction> actions = new List <Undo.IAction>(); foreach (TreePath path in d_treeview.Selection.GetSelectedRows()) { Node node = d_treeview.NodeStore.FindPath(path); if (node == d_dummy) { continue; } Wrappers.Wrapper temp = d_wrapper.GetVariableTemplate(node.Variable, false); if (temp != null) { Cdn.Variable tempProp = temp.Variable(node.Variable.Name); actions.Add(new Undo.ModifyVariable(d_wrapper, node.Variable, tempProp.Expression.AsString)); actions.Add(new Undo.ModifyVariable(d_wrapper, node.Variable, tempProp.Flags)); } else { actions.Add(new Undo.RemoveVariable(d_wrapper, node.Variable)); } } try { d_actions.Do(new Undo.Group(actions)); } catch (GLib.GException err) { // Display could not remove, or something Error(this, err); } }
protected virtual string Translate(InstructionVariable instruction, Context context) { Cdn.Variable prop = instruction.Variable; if (!context.Program.StateTable.Contains(prop)) { throw new NotImplementedException(String.Format("The variable `{0}' is not implemented", prop.FullName)); } DataTable.DataItem item = context.Program.StateTable[prop]; if (instruction.HasSlice) { Cdn.Dimension dim; int[] slice = instruction.GetSlice(out dim); if (context.SupportsFirstClassArrays) { return(String.Format("{0}[{1}][{2}]", context.This(context.Program.StateTable), item.AliasOrIndex, slice[0])); } else { return(String.Format("{0}[{1}]", context.This(context.Program.StateTable), context.AddedIndex(item, slice[0]))); } } else { return(String.Format("{0}[{1}]", context.This(context.Program.StateTable), item.AliasOrIndex)); } }
public EventActionState(Cdn.EdgeAction action, Cdn.Variable v) : base(v, action.Equation, State.Flags.EventAction | (action.TargetVariable.HasFlag(VariableFlags.Integrated) ? State.Flags.Derivative : 0)) { d_action = action; d_variable = v; }