Beispiel #1
0
        /// <overloads>
        /// Validates the specified list of variable values.</overloads>
        /// <summary>
        /// Validates the specified <see cref="VariableModifierDictionary"/>.</summary>
        /// <param name="owner">
        /// The parent <see cref="Window"/> for any dialogs.</param>
        /// <param name="variables">
        /// A <see cref="VariableModifierDictionary"/> that maps <see cref="VariableClass.Id"/>
        /// string to the corresponding <see cref="VariableModifier"/> instance values.</param>
        /// <returns>
        /// <c>true</c> if the values of the specified <paramref name="variables"/> are valid;
        /// otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="variables"/> is a null reference.</exception>
        /// <remarks><para>
        /// <b>ValidateVariables</b> checks that every <see cref="ModifierTarget"/> value for each
        /// in the specified <paramref name="variables"/> collection is either an even multiple of
        /// the <see cref="VariableClass.Scale"/> of its <see cref="VariableClass"/>, or vice versa.
        /// </para><para>
        /// If this is not the case, <b>ValidateVariables</b> asks the user to confirm the value,
        /// and returns <c>false</c> if the user declines. <b>ValidateVariables</b> returns
        /// <c>true</c> if all <paramref name="variables"/> pass this test.</para></remarks>

        public static bool ValidateVariables(Window owner, VariableModifierDictionary variables)
        {
            if (variables == null)
            {
                ThrowHelper.ThrowArgumentNullException("variables");
            }

            VariableSection variableSection = MasterSection.Instance.Variables;

            foreach (var pair in variables)
            {
                // get variable, display scale, and new value
                VariableClass variable = variableSection.GetVariable(pair.Key);
                if (variable == null)
                {
                    continue;
                }

                int scale = variable.Scale;
                if (scale == 1)
                {
                    continue;
                }

                foreach (ModifierTarget target in VariableModifier.AllModifierTargets)
                {
                    int value = Math.Abs(pair.Value.GetByTarget(target).GetValueOrDefault());
                    if (value == 0)
                    {
                        continue;
                    }

                    // check that new value conforms to scale
                    if ((value > scale && value % scale != 0) ||
                        (value < scale && scale % value != 0))
                    {
                        string message = String.Format(ApplicationInfo.Culture,
                                                       Global.Strings.DialogVariableScaleMismatch, pair.Key);

                        MessageBoxResult result = MessageBox.Show(owner,
                                                                  message, Global.Strings.TitleVariableScaleMismatch,
                                                                  MessageBoxButton.OKCancel, MessageBoxImage.Warning);

                        if (result == MessageBoxResult.Cancel)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double        b   = 0;
            double        h   = 0;
            List <double> VPx = new List <double>();
            List <double> VPy = new List <double>();

            if (!DA.GetData(0, ref b))
            {
                return;
            }
            if (!DA.GetData(1, ref h))
            {
                return;
            }
            if (!DA.GetDataList(2, VPx))
            {
                return;
            }
            if (!DA.GetDataList(3, VPy))
            {
                return;
            }

            if (VPx.Count == 1)
            {
                VPx.Add(1);
            }
            if (VPy.Count == 1)
            {
                VPy.Add(1);
            }

            Transform mirrorYZ = Transform.Mirror(Plane.WorldYZ);
            Transform mirrorXZ = Transform.Mirror(Plane.WorldZX);

            List <Point3d> sctPts  = new List <Point3d>();
            List <Point3d> sctPts1 = new List <Point3d>();
            List <Point3d> sctPts2 = new List <Point3d>();

            Plane pln = Plane.WorldYZ;

            //Point3d ptA = pln.PointAt(-b * 0.5, 0); sctPts.Add(ptA);
            //Point3d ptB = pln.PointAt(-b * 0.5, -h); sctPts.Add(ptB);
            //Point3d ptC = ptB; ptC.Transform(mirrorXZ); sctPts.Add(ptC);
            //Point3d ptD = ptA; ptD.Transform(mirrorXZ); sctPts.Add(ptD);
            //sctPts.Add(ptA);

            if (VPx.Count < VPy.Count)
            {
                for (int i = VPx.Count; i < VPy.Count; i++)
                {
                    VPx.Add(VPx[VPx.Count - 1]);
                }
            }
            if (VPx.Count > VPy.Count)
            {
                for (int i = VPy.Count; i < VPx.Count; i++)
                {
                    VPy.Add(VPy[VPy.Count - 1]);
                }
            }

            b *= 0.5;

            double a1 = VPy[0]; double ptX = -VPx[0] * b; double ptY = -a1 * h;

            //Point3d ptT = pln.PointAt(-b, 0); sctPts1.Add(ptT); //fix to allow for variable width at top

            Point3d ptM = pln.PointAt(ptX, ptY);

            sctPts1.Add(ptM);

            for (int i = 1; i < VPx.Count; i++)
            {
                double a2 = VPy[i];
                double a  = (1 - a1) * a2 + a1;
                ptX = -b * VPx[i];
                ptY = -h * a;
                ptM = pln.PointAt(ptX, ptY);
                sctPts1.Add(ptM);
                a1 = a;
            }

            sctPts2.AddRange(sctPts1);
            for (int i = 0; i < sctPts2.Count; i++)
            {
                Point3d pt = sctPts2[i];
                pt.Transform(mirrorXZ);
                sctPts2[i] = pt;
            }
            sctPts2.Reverse();

            //foreach (Point3d pt in sctPts2) { pt.Transform(mirrorXZ); }
            //Point3d ptB = pln.PointAt(ptX, -h); sctPts1.Add(ptB);

            sctPts.AddRange(sctPts1);
            sctPts.AddRange(sctPts2);
            sctPts.Add(sctPts1[0]);
            Curve sctCrv = Curve.CreateInterpolatedCurve(sctPts, 1);

            VariableSection vSct = new VariableSection(pln, sctPts1);

            DA.SetDataList(0, sctPts1);
            DA.SetData(1, sctCrv);
            DA.SetData(2, vSct);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowVariable"/> class with the specified
        /// initially selected <see cref="VariableClass"/> and <see cref="VariableDisplay"/> flags.
        /// </summary>
        /// <param name="variable"><para>
        /// The <see cref="VariableClass"/> to select initially.
        /// </para><para>-or-</para><para>
        /// A null reference to select the first <see cref="AttributeClass"/>, <see
        /// cref="ResourceClass"/>, or <see cref="CounterClass"/>, in that order.</para></param>
        /// <param name="flags">
        /// A <see cref="VariableDisplay"/> value indicating which display flags to select
        /// initially.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="variable"/> is neither a null reference nor an element of the <see
        /// cref="VariableSection"/> collection that matches its <see
        /// cref="VariableClass.Category"/>.</exception>
        /// <exception cref="InvalidEnumArgumentException">
        /// <paramref name="variable"/> specifies an invalid <see cref="VariableClass.Category"/>.
        /// </exception>

        public ShowVariable(VariableClass variable, VariableDisplay flags)
        {
            InitializeComponent();

            if (variable != null)
            {
                VariableSection variables  = MasterSection.Instance.Variables;
                var             dictionary = variables.GetVariables(variable.Category);

                // specified variable must be part of its collection
                if (!dictionary.ContainsKey(variable.Id))
                {
                    ThrowHelper.ThrowArgumentException(
                        "variable", Global.Strings.ArgumentNotNullOrVariable);
                }
            }

            Variable      = variable;
            VariableFlags = flags;

            // read specified display flags into check boxes
            if ((flags & VariableDisplay.Basic) != 0)
            {
                BasicToggle.IsChecked = true;
            }
            if ((flags & VariableDisplay.Modifier) != 0)
            {
                ModifierToggle.IsChecked = true;
            }
            if ((flags & VariableDisplay.Numbers) != 0)
            {
                NumbersToggle.IsChecked = true;
            }
            if ((flags & VariableDisplay.Shades) != 0)
            {
                ShadesToggle.IsChecked = true;
            }

            // adjust column width of Variable list view
            DependencyPropertyDescriptor.FromProperty(
                ListView.ActualWidthProperty, typeof(ListView))
            .AddValueChanged(VariableList, OnVariableWidthChanged);

            if (variable != null)
            {
                // select specified variable, if any
                switch (variable.Category)
                {
                case VariableCategory.Attribute:
                    AttributeToggle.IsChecked = true;
                    break;

                case VariableCategory.Counter:
                    CounterToggle.IsChecked = true;
                    break;

                case VariableCategory.Resource:
                    ResourceToggle.IsChecked = true;
                    break;

                default:
                    ThrowHelper.ThrowInvalidEnumArgumentException("variable.Category",
                                                                  (int)variable.Category, typeof(VariableCategory));
                    break;
                }

                VariableList.SelectAndShow(variable);
            }
            else
            {
                // select category with defined variables
                if (MasterSection.Instance.Variables.Attributes.Count > 0)
                {
                    AttributeToggle.IsChecked = true;
                }
                else if (MasterSection.Instance.Variables.Resources.Count > 0)
                {
                    ResourceToggle.IsChecked = true;
                }
                else if (MasterSection.Instance.Variables.Counters.Count > 0)
                {
                    CounterToggle.IsChecked = true;
                }
                else
                {
                    AttributeToggle.IsChecked = true;
                }
            }
        }