Ejemplo n.º 1
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        private static void SetEntityRepresentation(this IBHoMObject obj, int seqNumber, Boxes component, double xSpace, double ySpace)
        {
            double x     = 0;
            double y     = 0;
            double cellX = xSpace - 2 * component.Padding;
            double cellY = ySpace - 2 * component.Padding;

            if (component.IsHorizontal)
            {
                x = System.Convert.ToDouble(m_Xscale.IScale(seqNumber));
                y = System.Convert.ToDouble(m_Yscale.IScale(obj.PropertyValue(component.Group)));
            }
            else
            {
                x = System.Convert.ToDouble(m_Xscale.IScale(obj.PropertyValue(component.Group)));
                y = System.Convert.ToDouble(m_Yscale.IScale(seqNumber));
            }

            EntityRepresentation representation = new EntityRepresentation();

            Point basePt = SetAnchorPoint(Geometry.Create.Point(x, y, 0), component.Padding, component.Padding, 0);

            representation.Boundary              = Box(basePt, cellX, cellY);
            representation.Text                  = obj.PropertyValue(component.Text).ToString();
            representation.TextPosition          = SetAnchorPoint(basePt, component.Padding, component.Padding, 0);
            representation.OutgoingRelationPoint = SetAnchorPoint(basePt, cellX, cellY / 2, 0);
            representation.IncomingRelationPoint = SetAnchorPoint(basePt, 0, cellY / 2, 0);
            representation.Colour                = Convert.ColourFromObject(m_Colourscale.IScale(obj.PropertyValue(component.Colour)));
            obj.Fragments.AddOrReplace(representation);
        }
Ejemplo n.º 2
0
        private static void RepresentationFragment(this Links component, Dataset dataset, ViewConfig viewConfig)
        {
            BHoMGroup <IBHoMObject> entityGroup = (BHoMGroup <IBHoMObject>)dataset.Data.Find(x => x.Name == "Entities");
            List <IBHoMObject>      entities    = entityGroup.Elements;

            BHoMGroup <IBHoMObject> relationGroup = (BHoMGroup <IBHoMObject>)dataset.Data.Find(x => x.Name == "Relations");
            List <IBHoMObject>      relations     = relationGroup.Elements;

            Gradient gradient = Create.Gradient();

            List <object> colourNames = new List <object>();

            if (component.Colour.Contains("Source."))
            {
                colourNames = Convert.ToDataList(entities.PropertyValue(component.Colour.Replace("Source.", "")));
            }
            if (component.Colour.Contains("Target."))
            {
                colourNames = Convert.ToDataList(entities.PropertyValue(component.Colour.Replace("Target.", "")));
            }
            else
            {
                colourNames = Convert.ToDataList(relations.PropertyValue(component.Colour));
            }

            IScale colourScale = Create.IScale(colourNames, gradient.Markers.Values.Cast <object>().ToList());

            foreach (IBHoMObject obj in relations)
            {
                IBHoMObject start = entities.Find(ent => ent.BHoM_Guid.Equals(obj.PropertyValue(component.Start)));
                IBHoMObject end   = entities.Find(ent => ent.BHoM_Guid.Equals(obj.PropertyValue(component.End)));

                EntityRepresentation startFrag = start.FindFragment <EntityRepresentation>();
                EntityRepresentation endFrag   = end.FindFragment <EntityRepresentation>();

                RelationRepresentation representation = new RelationRepresentation();
                Line line = Geometry.Create.Line(startFrag.OutgoingRelationPoint, endFrag.IncomingRelationPoint);

                representation.Curves.Add(line);

                representation.Curves.AddRange(component.Marker.IMarker(line.End, line.Direction()));
                representation.TextDirection = line.Direction();
                representation.TextPosition  = line.IPointAtLength(line.Length() / 3);

                if (component.Text.Contains("Source."))
                {
                    representation.Text = start.PropertyValue(component.Text.Replace("Source.", "")).ToString();
                }
                else if (component.Text.Contains("Target."))
                {
                    representation.Text = end.PropertyValue(component.Text.Replace("Target.", "")).ToString();
                }
                else
                {
                    representation.Text = obj.PropertyValue(component.Text).ToString();
                }


                if (component.Colour.Contains("Source."))
                {
                    representation.Colour = Convert.ColourFromObject(colourScale.IScale(start.PropertyValue(component.Colour.Replace("Source.", ""))));
                }
                else if (component.Colour.Contains("Target."))
                {
                    representation.Colour = Convert.ColourFromObject(colourScale.IScale(end.PropertyValue(component.Colour.Replace("Target.", ""))));
                }
                else
                {
                    representation.Colour = Convert.ColourFromObject(colourScale.IScale(obj.PropertyValue(component.Colour)));
                }

                obj.Fragments.AddOrReplace(representation);
            }
        }