예제 #1
0
    protected override void OnUpdate()
    {
        if (!initialize)
        {
            List <SpriteSheetMaterial> materials = new List <SpriteSheetMaterial>();
            EntityManager.GetAllUniqueSharedComponentData(materials);
            for (int i = 0; i < materials.Count; i++)
            {
                if (!materials[i].material)
                {
                    materials.Remove(materials[i]);
                }
            }

            renderInfos = new RenderInformation[materials.Count];
            for (int i = 0; i < renderInfos.Length; i++)
            {
                renderInfos[i] = new RenderInformation(materials[i].material);
            }

            mesh       = MeshExtension.Quad();
            initialize = true;
        }

        for (int i = 0; i < renderInfos.Length; i++)
        {
            if (UpdateBuffers(i) > 0)
            {
                Graphics.DrawMeshInstancedIndirect(mesh, 0, renderInfos[i].material, new Bounds(Vector2.zero, Vector3.one), renderInfos[i].argsBuffer);
            }
        }
    }
    int UpdateBuffers(int renderIndex)
    {
        SpriteSheetManager.ReleaseBuffer(renderIndex);

        RenderInformation renderInformation = SpriteSheetManager.renderInformation[renderIndex];
        int instanceCount = EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Length;

        if (instanceCount > 0)
        {
            //TODO: deve moltiplicare il numero di sprites per questa animazione

            int stride = instanceCount >= 16 ? 16 : 16 * SpriteSheetCache.GetLenght(renderInformation.material);
            renderInformation.uvBuffer = new ComputeBuffer(instanceCount, stride);
            renderInformation.uvBuffer.SetData(EntityManager.GetBuffer <UvBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("uvBuffer", renderInformation.uvBuffer);


            renderInformation.indexBuffer = new ComputeBuffer(instanceCount, sizeof(int));
            renderInformation.indexBuffer.SetData(EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
            renderInformation.material.SetBuffer("indexBuffer", renderInformation.indexBuffer);

            renderInformation.matrixBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.matrixBuffer.SetData(EntityManager.GetBuffer <MatrixBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("matrixBuffer", renderInformation.matrixBuffer);

            renderInformation.args[1] = (uint)instanceCount;
            renderInformation.argsBuffer.SetData(renderInformation.args);

            renderInformation.colorsBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.colorsBuffer.SetData(EntityManager.GetBuffer <SpriteColorBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("colorsBuffer", renderInformation.colorsBuffer);
        }
        return(instanceCount);
    }
예제 #3
0
 public BuildingDescription(VerbalStructureDescription verbalStructureDescription, Knowledge unlockCost, ConstructionInformation constructionInformation, ProductionInformation productionInformation, RenderInformation renderInformation, bool canExtractWater)
 {
     ConstructionInformation    = constructionInformation;
     ProductionInformation      = productionInformation;
     RenderInformation          = renderInformation;
     CanExtractWater            = canExtractWater;
     VerbalStructureDescription = verbalStructureDescription;
     UnlockCost = unlockCost;
 }
예제 #4
0
 public override void DrawSubObjekt(RenderInformation RI, MeshPart M, GraphicNode GN)
 {
     Device.Context.VertexShader.SetConstantBuffer(cBuf, 0);
     Device.Context.PixelShader.SetConstantBuffer(cBuf2, 1);
     if (M == null || M.Buffer == null || M.Buffer.VertexCount == 0) return;
     Device.InputAssembler.SetVertexBuffer(0, M.Buffer.Bindings[0]);
     if(M.Material.DiffuseTexture != null)
         Device.Context.PixelShader.SetShaderResource(M.Material.DiffuseTexture.ShaderResourceView, 0);
     else Device.Context.PixelShader.SetShaderResource(ShaderResourceTexture.WhiteTexture.ShaderResourceView, 0);
     Device.Context.Draw(M.Buffer.VertexCount, 0);
 }
예제 #5
0
파일: Form1.cs 프로젝트: caoweisir/GerberVS
 private void Form1_Load(object sender, EventArgs e)
 {
     gerberLib     = new LibGerberVS();
     project       = gerberLib.CreateNewProject();
     renderInfo    = new RenderInformation();
     selectionInfo = new SelectionInformation();
     RenderModeComboBox.SelectedIndex = 0;
     renderMode = GerberRenderMode.TranslateToCentre;
     pcbImagePanel.BackColor = Color.Black;
     project.BackgroundColor = pcbImagePanel.BackColor;
     fullScreen = false;
     UpdateMenus();
 }
예제 #6
0
 public static string getColorRef(GraphicalPrimitive2D graphItem, RenderInformation rendinfo, Group refgroup)
 {
     if (FillColor.isColorID(graphItem.Fill, rendinfo.ColorDefinitions))
     {
         return(graphItem.Fill);
     }
     else if (FillColor.isColorID(refgroup.Fill, rendinfo.ColorDefinitions))
     {
         return(refgroup.Fill);
     }
     else
     {
         return(null);
     }
 }
예제 #7
0
        private void Loop()
        {
            int sleep = 15;

            while (console.IsOpen)
            {
                cmdManager.Update(15f);
                lock (keys)
                {
                    if (keys.Count > 0)
                    {
                        for (int i = 0; i < keys.Count; i++)
                        {
                            if (keys[i] < 0)
                            {
                                console.Update(sleep + 2, keys[i] == -2, keys[i] == -1);
                            }
                            else
                            {
                                console.Update(sleep + 2, (char)keys[i], false, false);
                            }

                            keys.RemoveAt(0);
                            i--;
                        }
                    }
                    else
                    {
                        console.Update(sleep + 2, false, false);
                    }
                }

                lastr = r;
                r     = console.RenderingInfo;


                if (this.InvokeRequired)
                {
                    this.Invoke((MethodInvoker)UpdateControls);
                }
                else
                {
                    UpdateControls();
                }
                Thread.Sleep(sleep);
            }
        }
예제 #8
0
                    public static RenderInformation FromBaseObject(BaseObject baseObj)
                    {
                        if (baseObj == null || baseObj.NativeObject == IntPtr.Zero)
                        {
                            return(null);
                        }
                        RenderInformation obj = baseObj as  RenderInformation;

                        if (object.Equals(obj, null))
                        {
                            obj = new RenderInformation(CreatedWhenConstruct.CWC_NotToCreate);
                            obj.BindNativeObject(baseObj.NativeObject, "CRenderInformation");
                            obj.IncreaseCast();
                        }

                        return(obj);
                    }
    //we should only update the index of the changed datas for index buffer,matrixbuffer and color buffer inside a burst job to avoid overhead
    int UpdateBuffers(int renderIndex)
    {
        SpriteSheetManager.ReleaseBuffer(renderIndex);

        RenderInformation renderInformation = SpriteSheetManager.renderInformation[renderIndex];
        int instanceCount = EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Length;

        if (instanceCount > 0)
        {
            int stride = instanceCount >= 16 ? 16 : 16 * SpriteSheetCache.GetLenght(renderInformation.material);
            if (renderInformation.updateUvs)
            {
                SpriteSheetManager.ReleaseUvBuffer(renderIndex);
                renderInformation.uvBuffer = new ComputeBuffer(instanceCount, stride);
                renderInformation.uvBuffer.SetData(EntityManager.GetBuffer <UvBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
                renderInformation.material.SetBuffer("uvBuffer", renderInformation.uvBuffer);
                renderInformation.updateUvs = false;
            }

            renderInformation.indexBuffer = new ComputeBuffer(instanceCount, sizeof(int));
            renderInformation.indexBuffer.SetData(EntityManager.GetBuffer <SpriteIndexBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
            renderInformation.material.SetBuffer("indexBuffer", renderInformation.indexBuffer);

            renderInformation.layerBuffer = new ComputeBuffer(instanceCount, sizeof(int));
            renderInformation.layerBuffer.SetData(EntityManager.GetBuffer <SpriteLayerBuffer>(renderInformation.bufferEntity).Reinterpret <int>().AsNativeArray());
            renderInformation.material.SetBuffer("layerBuffer", renderInformation.layerBuffer);

            renderInformation.matrixBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.matrixBuffer.SetData(EntityManager.GetBuffer <MatrixBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("matrixBuffer", renderInformation.matrixBuffer);

            renderInformation.args[1] = (uint)instanceCount;
            renderInformation.argsBuffer.SetData(renderInformation.args);

            renderInformation.colorsBuffer = new ComputeBuffer(instanceCount, 16);
            renderInformation.colorsBuffer.SetData(EntityManager.GetBuffer <SpriteColorBuffer>(renderInformation.bufferEntity).Reinterpret <float4>().AsNativeArray());
            renderInformation.material.SetBuffer("colorsBuffer", renderInformation.colorsBuffer);
        }
        return(instanceCount);
    }
예제 #10
0
        // Adapted from Group.RenderText
        public static void TextTex(this Group group, TextGlyph glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            writer.WriteLine("{");
            writer.Indent += 1;
            CommentTex(glyph, group, writer);
            string text = glyph.GetTextToDraw();
            RectangleF bound_rectangle = glyph.Bounds.toRect();

            Font font = group.GetScaledFont(scale, refgroup);
            SizeF string_size = g.MeasureString(text, font);
            PointF text_coord = group.GetPoint(group, bound_rectangle);

            Color text_color = group.GetStrokeColor(rendinfo, refgroup);
            if (!text_color.Equals(Color.Empty))
            {
                // refer stroke information to a ColorDefinition ID or assign a new colordefinition to "curLineColor"
                string strokeRef = FillColor.getStrokeRef(group, rendinfo, refgroup);
                if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
                {
                    strokeRef = "curLineColor";
                    FillColor.AssignColorRGBTex(text_color, "curLineColor", writer);
                }

                //adapted from Group.CorrectPosition
                switch (group.GetTextAnchor(group))
                {
                    // TikZ text is automatically centered at the drawing point
                    case Text.TextAnchors.start:
                        text_coord.X += string_size.Width / 2f;
                        break;
                    case Text.TextAnchors.end:
                        text_coord.X -= string_size.Width / 2f;
                        break;
                }

                writer.WriteLine("\\draw ({0}pt, {1}pt) node[text = {7}{2}, font = \\fontsize{{ {3} }} {{ {4} }}\\fontfamily{6}\\selectfont] {{ {5} }};",
                    (text_coord.X).ToString(),
                    (text_coord.Y).ToString(),
                    FillColor.AlphaValTex(text_color),
                    font.SizeInPoints,
                    font.SizeInPoints,
                    correctText(text),
                    FontTex(font, fontTexTable),
                    strokeRef);
            }
            writer.Indent -= 1;
            writer.WriteLine("}");
        }
예제 #11
0
        // adapted from EmlRenderExtension.Rectangle.draw
        public static void RectangleTex(this SBMLExtension.EmlRenderExtension.Rectangle rectangle, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, RectangleF refbounds, double scale)
        {
            writer.WriteLine("{");
            writer.Indent += 1;
            CommentTex(glyph, rectangle, writer);
            // Check what kind of filling
            RectangleF bound_rectangle = glyph.Bounds.toRect();
            if (!refbounds.IsEmpty)
                bound_rectangle = refbounds;
            FillColor fill = rectangle.GetFillColor(rendinfo, bound_rectangle, refgroup);

            RotateAndShift(rectangle, bound_rectangle, writer);

            if (fill == null)
            {
                fill = new FillColor(Color.Empty);
            }
            if (fill.gradient && !fill.radial && fill.colorList.Count > 1)
            {
                rectangle.LinearGradTex(bound_rectangle, fill, writer, rendinfo, refgroup, scale);
            }
            else if (fill.gradient && fill.colorList.Count > 1)
            {
                rectangle.RadialGradTex(bound_rectangle, fill, writer, rendinfo, refgroup, scale);
            }
            else
            {
                rectangle.SolidColorTex(bound_rectangle, fill, writer, rendinfo, refgroup, scale);
            }

            writer.Indent -= 1;
            writer.WriteLine("}");
        }
예제 #12
0
        public static void ReactionLineStartTex(this Group group, CurveSegment segment, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            if (!string.IsNullOrEmpty(refgroup.StartHead))
            {
                PointF p1 = segment.Start.ToPointF();
                PointF p2 = segment.End.ToPointF();
                if (segment.Type != "LineSegment")
                {
                    p2 = segment.BasePoint2.ToPointF();
                }
                LineEnding ending = rendinfo.GetLineEnding(refgroup.StartHead);
                writer.WriteLine("{");
                writer.Indent += 1;

                writer.WriteLine("\\pgftransformshift{{\\pgfpoint{{ {0}pt }}{{ {1}pt }} }}",
                       p1.X.ToString(),
                       (p1.Y).ToString());

                RotationalMappingLineEndTex(ending, p1, p2, writer, refgroup);

                ending.LineEndingTex(glyph, writer, g, rendinfo, refgroup, scale, false, fontTexTable); // pass false as we have already done rotation
                writer.Indent -= 1;
                writer.WriteLine("}");
            }
        }
예제 #13
0
 public static void LineEndingTex(this LineEnding ending, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Boolean notInReactionGlyph, Hashtable fontTexTable)
 {
     writer.WriteLine("{");
     writer.Indent += 1;
     CommentTex(glyph, ending, writer);
     RectangleF bound_rectangle = ending.BoundingBox.toRect();
     if (notInReactionGlyph)
     {
         bound_rectangle = glyph.Bounds.toRect();
         RotateAndShift(ending, bound_rectangle, writer);
     }
     ending.Group.ToTex(glyph, writer, g, rendinfo, refgroup, bound_rectangle, scale, fontTexTable);
     writer.Indent -= 1;
     writer.WriteLine("}");
 }
예제 #14
0
        // adapted from RadialGradient.GetBrush
        public static FillColor GetRadialFillColor(this RadialGradient radialGrad, RenderInformation rendinfo)
        {
            GradientDefinition gradBase = (GradientDefinition)radialGrad;
            ColorBlend interpolationColors = gradBase.GetInterpolationColors(rendinfo);
            List<Color> colors = new List<Color>();
            List<float> positions = new List<float>();
            for (int ii = 0; ii < interpolationColors.Colors.Length; ii++)
            {
                colors.Add(interpolationColors.Colors[ii]);
                positions.Add(interpolationColors.Positions[ii]*100f); // convert to percent
            }

            float focalX;
            float focalY;
            if (!string.IsNullOrEmpty(radialGrad.FX))
            {
                //focalX = radialGrad.FX.Contains("%") ? SBMLExtension.Util.readSingle(radialGrad.FX) : SBMLExtension.Util.readSingle(radialGrad.FX)/bound_rectangle.Width * 100f;
                focalX = SBMLExtension.Util.readSingle(radialGrad.FX);
            }
            else
            {
                //focalX = radialGrad.CX.Contains("%") ? SBMLExtension.Util.readSingle(radialGrad.CX) : SBMLExtension.Util.readSingle(radialGrad.CX)/ bound_rectangle.Width * 100f;
                focalX = SBMLExtension.Util.readSingle(radialGrad.CX);
            }
            if (!string.IsNullOrEmpty(radialGrad.FY))
            {
                //focalY = radialGrad.FY.Contains("%") ? SBMLExtension.Util.readSingle(radialGrad.FY) : SBMLExtension.Util.readSingle(radialGrad.FY)/ bound_rectangle.Height * 100f;
                focalY = SBMLExtension.Util.readSingle(radialGrad.FY);
            }
            else
            {
                //focalY = radialGrad.CY.Contains("%") ? SBMLExtension.Util.readSingle(radialGrad.CY) : SBMLExtension.Util.readSingle(radialGrad.CY)/ bound_rectangle.Height * 100f;
                focalY = SBMLExtension.Util.readSingle(radialGrad.CY);
            }

            PointF focal = new PointF(focalX, focalY);
            return new FillColor(colors, positions, focal, gradBase.SpreadMethod, radialGrad.ID);
        }
예제 #15
0
        // adapted from LinearGradient.GetBrush
        public static FillColor GetLinearGradFillColor(this LinearGradient linearGrad, RenderInformation rendinfo)
        {
            List<Color> colors = new List<Color>();
            List<float> positions = new List<float>();
            foreach (GradientStop stop in linearGrad.Stop)
            {
                colors.Add(rendinfo.GetColor(stop.StopColor));
                positions.Add(SBMLExtension.Util.readSingle(stop.Offset));
            }
            PointF startP = new PointF(SBMLExtension.Util.readSingle(linearGrad.X1), SBMLExtension.Util.readSingle(linearGrad.Y1));
            PointF endP = new PointF(SBMLExtension.Util.readSingle(linearGrad.X2), SBMLExtension.Util.readSingle(linearGrad.Y2));

            if (startP.X != endP.X || startP.Y != endP.Y)
            {
                double gradient_rotation = FillColor.GetGradientRotation(startP, endP);
                return new FillColor(colors, positions, gradient_rotation, linearGrad.SpreadMethod, linearGrad.ID);
            }

            return null; //the two points are on the same spot; this is not a gradient
        }
예제 #16
0
        private static void SolidColorPolygon(this Polygon polygon, RectangleF bound_rectangle, FillColor fillColor, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            string strokewidth = polygon.GetStrokeWidth(rendinfo, refgroup, scale);
            string dashed = "";
            if (!string.IsNullOrEmpty(polygon.GetDashType(refgroup)))
            {
                dashed = ", " + polygon.DashTex(polygon.GetDashType(refgroup));
            }
            // obtain stroke color and filling color
            Color linecolor = polygon.GetStrokeColor(rendinfo, refgroup);
            Color curSolidColor = fillColor.colorList[0];

            // refer stroke information to a ColorDefinition ID or assign a new colordefinition to "curLineColor"
            string strokeRef = FillColor.getStrokeRef(polygon, rendinfo, refgroup);
            if (linecolor.Equals(Color.Empty))
            {
                strokeRef = "none";
            }
            else if (!FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curSolidColor";
                FillColor.AssignColorRGBTex(curSolidColor, "curSolidColor", writer);
            }

            // refer solidfill information to a ColorDefinition ID or assign a new colordefinition to "curSolidColor"
            string solidRef = FillColor.getColorRef(polygon, rendinfo, refgroup);
            if (curSolidColor.Equals(Color.Empty))
            {
                solidRef = "none";
            }
            else if (!FillColor.isColorID(solidRef, rendinfo.ColorDefinitions))
            {
                solidRef = "curSolidColor";
                FillColor.AssignColorRGBTex(curSolidColor, "curSolidColor", writer);
            }

            writer.WriteLine("\\draw [line width = {0}pt, color = {4}{1}, fill = {5}{2} {3}] ",
                strokewidth,
                FillColor.AlphaValTex(linecolor),
                FillColor.AlphaValTex(curSolidColor),
                dashed,
                strokeRef,
                solidRef);

            PolygonSegmentsTex(polygon.CurveSegments, bound_rectangle, writer, false);
            PolygonElementsTex(polygon.ListOfElements, writer, bound_rectangle,false);
        }
예제 #17
0
        private static void RadialGradTex(this SBMLExtension.EmlRenderExtension.Rectangle rectangle, RectangleF bound_rectangle, FillColor fillcolor, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            // define the overall shape
            rectangle.DefineTex(bound_rectangle, writer);

            // draw the filling
            if (fillcolor.colorList.Count == fillcolor.positionList.Count)
            {
                if (!FillColor.isGradientID(fillcolor.ID, rendinfo.GradientDefinitions))
                {
                    FillColor.AssignGradientTex(fillcolor, fillcolor.ID, writer);
                }

                if (string.IsNullOrEmpty(rectangle.RX) || (SBMLExtension.Util.readSingle(rectangle.RX) == 0f))
                {
                    writer.WriteLine("\\fill[shading = {0}] \\wholeShape;", fillcolor.ID);
                }

                else
                {
                    float fRadiusX = rectangle.RX.Contains("%") ? ((bound_rectangle.Width * SBMLExtension.Util.readSingle(rectangle.RX)) / 100f) : SBMLExtension.Util.readSingle(rectangle.RX);
                    float fRadiusY = rectangle.RY.Contains("%") ? ((bound_rectangle.Height * SBMLExtension.Util.readSingle(rectangle.RY)) / 100f) : SBMLExtension.Util.readSingle(rectangle.RY);
                    // In actuality PGF/TikZ does not round with x and y parameters, so we need to fudge
                    // Also note that PGF/TikZ does not scale rounding

                    float fRadius = (fRadiusX + fRadiusY) / (2f * (float)scale);
                    writer.WriteLine("\\fill[rounded corners = {0}pt, shading = {1}] \\wholeShape;",
                            fRadius, fillcolor.ID);
                }
            }
            // draw the outline
            rectangle.OutlineTex(bound_rectangle, "wholeShape", writer, rendinfo, refgroup, scale);
        }
예제 #18
0
 public BuildingDescription(VerbalStructureDescription verbalStructureDescription, Knowledge unlockCost, ConstructionInformation constructionInformation, RenderInformation renderInformation, bool canExtractWater) : this(verbalStructureDescription, unlockCost, constructionInformation, null, renderInformation, canExtractWater)
 {
 }
예제 #19
0
        //private void DefineLineEndings(System.Collections.Generic.List<LineEnding> lineEndingDefs, RenderInformation rendinfo, IndentedTextWriter writer, Graphics g, double scale, Hashtable fontTeXTable)
        //{
        //    if (lineEndingDefs.Count > 0)
        //    {
        //        writer.WriteLine("% List of LineEndings used: ");
        //        for (int ii = 0; ii < lineEndingDefs.Count; ii++)
        //        {
        //            LineEnding ending = lineEndingDefs[ii];
        //            writer.WriteLine("\\def \\{0} {{", ending.ID);
        //            writer.Indent += 1;
        //            SBMLExtension.LayoutExtension.GraphicalObject glyph = new SBMLExtension.LayoutExtension.GraphicalObject();
        //            RectangleF refbounds = new RectangleF();
        //            ending.Group.ToTex(glyph, writer, g, rendinfo, ending.Group, refbounds, scale, fontTeXTable);
        //            writer.Indent -= 1;
        //            writer.WriteLine("}");
        //        }
        //    }
        //}

        private void DefineColorsAndGradients(List <ColorDefinition> ColorDefinitions,
                                              List <GradientDefinition> GradientDefinitions, RenderInformation rendinfo,
                                              IndentedTextWriter writer)
        {
            if (ColorDefinitions.Count > 0)
            {
                writer.WriteLine("% List of colors used: ");
                for (var ii = 0; ii < ColorDefinitions.Count; ii++)
                {
                    var def   = ColorDefinitions[ii];
                    var color = rendinfo.GetColor(def.ID);
                    FillColor.AssignColorRGBTex(color, def.ID, writer);
                }
                writer.WriteLine();
            }
            if (GradientDefinitions.Count > 0)
            {
                writer.WriteLine("% List of gradients used: ");
                for (var ii = 0; ii < GradientDefinitions.Count; ii++)
                {
                    var       def = GradientDefinitions[ii];
                    FillColor fill;
                    if (def is LinearGradient)
                    {
                        var lindef = (LinearGradient)def;
                        fill = lindef.GetLinearGradFillColor(rendinfo);
                        FillColor.AssignGradientTex(fill, lindef.ID, writer);
                    }
                    else
                    {
                        var raddef = (RadialGradient)def;
                        fill = raddef.GetRadialFillColor(rendinfo);
                        FillColor.AssignGradientTex(fill, raddef.ID, writer);
                    }
                    writer.WriteLine();
                }
            }
        }
예제 #20
0
        // Adapted from EmlRenderExtension.Group.Draw()
        public static void ToTex(this Group group, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, RectangleF refbounds, double scale, Hashtable fontTexTable)
        {
            if (group.Children.Count == 0)
            {
                if (glyph is TextGlyph)
                {
                    group.TextTex((TextGlyph)glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
                }
                else if (glyph is ReactionGlyph)
                {
                    group.ReactionTex((ReactionGlyph)glyph, writer, g, rendinfo, refgroup, refbounds, scale, fontTexTable);
                }
                else if (glyph is SpeciesReference)
                {
                    SpeciesReference graphElement = (SpeciesReference)glyph;
                    Style styleForObjectID = rendinfo.GetStyleForObjectId(graphElement);

                    if (styleForObjectID == null)
                        styleForObjectID = rendinfo.GetStyleForObjectRole(graphElement);

                    if (styleForObjectID == null)
                        styleForObjectID = rendinfo.GetStyleForObjectType(graphElement);

                    if (styleForObjectID == null && string.IsNullOrEmpty(graphElement.ObjectRole))
                    {
                        graphElement.ObjectRole = graphElement.Role;
                        styleForObjectID = rendinfo.GetStyleForObjectRole(graphElement);
                    }
                    if (styleForObjectID == null)
                    {
                        group.SpeciesReferenceTex((SpeciesReference)glyph, writer, g, rendinfo, group, scale, fontTexTable);
                    }
                    else
                    {
                        group.SpeciesReferenceTex((SpeciesReference)glyph, writer, g, rendinfo, styleForObjectID.Group, scale, fontTexTable);
                    }
                }
                else
                {
                    Style styleForObjectRole = rendinfo.GetStyleForObjectId(glyph);
                    if (styleForObjectRole == null)
                        styleForObjectRole = rendinfo.GetStyleForObjectRole(glyph);
                    if (styleForObjectRole == null)
                        styleForObjectRole = rendinfo.GetStyleForObjectType(glyph);
                    if ((styleForObjectRole != null) && ((styleForObjectRole.Group != null) && (styleForObjectRole.Group.Children.Count != 0)))
                    {
                        styleForObjectRole.Group.ToTex(glyph, writer, g, rendinfo, styleForObjectRole.Group, refbounds, scale, fontTexTable);
                    }
                }
            }
            else{
                foreach (SBMLExtension.EmlRenderExtension.GraphicalObject childObj in group.Children)
                {
                    // Determine what type is the childObj and find the style accordingly
                    if (childObj is SBMLExtension.EmlRenderExtension.Image)
                    {
                        SBMLExtension.EmlRenderExtension.Image childImage = (SBMLExtension.EmlRenderExtension.Image)childObj;
                        childImage.ImageTex(glyph, writer, rendinfo, refgroup, scale);
                    }
                    else
                    {
                        // childObj is a GraphicalPrimitve1D
                        if (childObj is Text)
                        {
                            Text childText = (Text)childObj;
                            childText.TextTex(glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
                        }
                        else if (childObj is Group)
                        {
                            writer.WriteLine("{");
                            writer.Indent += 1;
                            CommentTex(glyph, childObj, writer);
                            Group childgrp = (Group)childObj;
                            childgrp.ToTex(glyph, writer, g, rendinfo, refgroup, refbounds, scale, fontTexTable);
                            writer.Indent -= 1;
                            writer.WriteLine("}");
                        }
                        else
                        {
                            // childObj is a GraphicalPrimitve2D
                            if (childObj is SBMLExtension.EmlRenderExtension.Rectangle)
                            {
                                SBMLExtension.EmlRenderExtension.Rectangle childRect = (SBMLExtension.EmlRenderExtension.Rectangle)childObj;
                                childRect.RectangleTex(glyph, writer, rendinfo, refgroup, refbounds, scale);
                            }
                            if (childObj is SBMLExtension.EmlRenderExtension.Polygon)
                            {
                                Polygon childPoly = (Polygon)childObj;
                                childPoly.PolygonTex(glyph, writer, rendinfo, refgroup, refbounds, scale);
                            }
                            if (childObj is SBMLExtension.EmlRenderExtension.LineEnding)
                            {
                                LineEnding childEnd = (LineEnding)childObj;
                                childEnd.LineEndingTex(glyph, writer, g, rendinfo, refgroup, scale, true, fontTexTable);
                            }
                            if (childObj is SBMLExtension.EmlRenderExtension.Ellipses)
                            {
                                Ellipses childEllipse = (Ellipses)childObj;
                                childEllipse.EllipseTex(glyph, rendinfo, writer, refgroup, refbounds, scale);
                            }
                            if (childObj is SBMLExtension.EmlRenderExtension.Curve)
                            {
                                SBMLExtension.EmlRenderExtension.Curve childCurve = (SBMLExtension.EmlRenderExtension.Curve)childObj;
                                childCurve.CurveTex(glyph, rendinfo, writer, refgroup, refbounds, scale);
                            }
                        }
                    }
                }
                //if (glyph is ReactionGlyph)
                //{
                //    //ReactionGlyph rGlyph = (ReactionGlyph)glyph;
                //    //foreach (SpeciesReference reference in rGlyph.SpeciesReferences)
                //    //{
                //    //    Style styleForObjectType = rendinfo.GetStyleForObjectId(reference);
                //    //    if (styleForObjectType == null)
                //    //        styleForObjectType = rendinfo.GetStyleForObjectRole(reference);
                //    //    if (styleForObjectType == null)
                //    //        styleForObjectType = rendinfo.GetStyleForObjectType(reference);
                //    //    if (styleForObjectType == null)
                //    //        group.SpeciesReferenceTex(reference, writer, g, rendinfo, group, scale, fontTexTable);
                //    //    else
                //    //        group.SpeciesReferenceTex(reference, writer, g, rendinfo, styleForObjectType.Group, scale, fontTexTable);
                //    //}
                //}
            }

            //if (!string.IsNullOrEmpty(group.EndHead))
            //{
            //    LineEnding endhead = rendinfo.GetLineEnding(group.EndHead);
            //    endhead.LineEndingTex(glyph, writer, g, rendinfo, group, scale, false, fontTexTable);
            //}
            //if (!string.IsNullOrEmpty(group.StartHead))
            //{
            //    LineEnding starthead = rendinfo.GetLineEnding(group.StartHead);
            //    starthead.LineEndingTex(glyph, writer, g, rendinfo, group, scale, false, fontTexTable);
            //}
        }
예제 #21
0
        private static void SolidColorTex(this Ellipses ellipse, RectangleF bound_rectangle, FillColor fillcolor, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            PointF position = EllipsePositionInBounds(ellipse, bound_rectangle);
            PointF radii = CorrectEllipseRadii(ellipse, bound_rectangle); ;

            //define the overall shape
            ellipse.DefineTex(position, radii, writer);

            // obtain fill color information
            Color curSolidColor = fillcolor.colorList[0];

            // refer solidfill information to a ColorDefinition ID or assign a new colordefinition to "curSolidColor"
            string solidRef = FillColor.getColorRef(ellipse, rendinfo, refgroup);
            if (fillcolor.colorList[0].Equals(Color.Empty))
            {
                solidRef = "none";
            }
            else if (!FillColor.isColorID(solidRef, rendinfo.ColorDefinitions))
            {
                solidRef = "curSolidColor";
                FillColor.AssignColorRGBTex(curSolidColor, "curSolidColor", writer);
            }

            writer.WriteLine("\\fill[color = {1}{0}] \\wholeShape;",
                FillColor.AlphaValTex(curSolidColor),
                solidRef);

            //draw the outline
            ellipse.OutlineTex(bound_rectangle, "wholeShape", writer, rendinfo, refgroup, scale);
        }
예제 #22
0
                    public BaseObject Create()
                    {
                        RenderInformation emptyInstance = new RenderInformation(CreatedWhenConstruct.CWC_NotToCreate);

                        return(emptyInstance);
                    }
예제 #23
0
        private static void RadialGradTex(this Ellipses ellipse, RectangleF bound_rectangle, FillColor fillcolor, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            PointF position = EllipsePositionInBounds(ellipse, bound_rectangle);
            PointF radii = CorrectEllipseRadii(ellipse, bound_rectangle); ;

            //define the overall shape
            ellipse.DefineTex(position, radii, writer);

            if (fillcolor.colorList.Count == fillcolor.positionList.Count)
            {
                if (!FillColor.isGradientID(fillcolor.ID, rendinfo.GradientDefinitions))
                {
                    FillColor.AssignGradientTex(fillcolor, fillcolor.ID, writer);
                }

                writer.WriteLine("\\fill[shading = {0}, shading angle = {1}] \\wholeShape;",
                fillcolor.ID,
                -180 + fillcolor.gradient_rotation);
            }

            //draw the outline
            ellipse.OutlineTex(bound_rectangle, "wholeShape", writer, rendinfo, refgroup, scale);
        }
예제 #24
0
        public override void PrepareForNode(RenderInformation RI, GraphicNode GN)
        {
            dS.Position = 0L;
            dS.Write<Matrix>(Matrix.Transpose(RI.WorldMatrix * M));
            dS.Write<Matrix>(Matrix.Transpose(RI.WorldMatrix));
            dS.Position = 0L;
            Device.Context.UpdateSubresource(new DataBox(0, 0, dS), cBuf, 0);

            dS2.Position = 0L;
            dS2.Write<Vector3>(RI.CameraPosition);
            dS2.Position = 0L;
            Device.Context.UpdateSubresource(new DataBox(0, 0, dS2), cBuf2, 0);
        }
예제 #25
0
        //draws a solid color rectangle
        private static void SolidColorTex(this SBMLExtension.EmlRenderExtension.Rectangle rectangle, RectangleF bound_rectangle, FillColor fillcolor, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            //define the overall shape
            rectangle.DefineTex(bound_rectangle, writer);

            // draw the filling
            Color curSolidColor = fillcolor.colorList[0];

            // refer solidfill information to a ColorDefinition ID or assign a new colordefinition to "curSolidColor"
            string solidRef = FillColor.getColorRef(rectangle, rendinfo, refgroup);
            if (fillcolor.colorList[0].Equals(Color.Empty))
            {
                solidRef = "none";
            }
            else if (!FillColor.isColorID(solidRef, rendinfo.ColorDefinitions))
            {
                solidRef = "curSolidColor";
                FillColor.AssignColorRGBTex(curSolidColor, "curSolidColor", writer);
            }

            if (string.IsNullOrEmpty(rectangle.RX) || (SBMLExtension.Util.readSingle(rectangle.RX) == 0f))
            {
                writer.WriteLine("\\fill[fill = {1}{0}] \\wholeShape;",
                    FillColor.AlphaValTex(curSolidColor),
                    solidRef);
            }

            else
            {
                float fRadiusX = rectangle.RX.Contains("%") ? ((bound_rectangle.Width * SBMLExtension.Util.readSingle(rectangle.RX)) / 100f) : SBMLExtension.Util.readSingle(rectangle.RX);
                float fRadiusY = rectangle.RY.Contains("%") ? ((bound_rectangle.Height * SBMLExtension.Util.readSingle(rectangle.RY)) / 100f) : SBMLExtension.Util.readSingle(rectangle.RY);
                // In actuality PGF/TikZ does not round with x and y parameters, so we need to fudge
                // Also note that PGF/TikZ does not scale rounding

                float fRadius = (fRadiusX + fRadiusY) / (2f * (float)scale);
                writer.WriteLine("\\draw[rounded corners = {0}pt, fill = {2}{1}] \\wholeShape;",
                        fRadius,
                        FillColor.AlphaValTex(curSolidColor),
                        solidRef);
            }
            // draw the outline
            rectangle.OutlineTex(bound_rectangle, "wholeShape", writer, rendinfo, refgroup, scale);
        }
예제 #26
0
        private RenderInformation DetermineRenderInformation(Dataset dataset)
        {
            bool       hasAlpha    = false;
            bool       isIndexed   = false;
            int        channelSize = -1;
            ColorTable colorTable  = null;

            RenderInformation info = new RenderInformation
            {
                BandMap      = new[] { 1, 1, 1, 1 },
                ChannelCount = dataset.RasterCount
            };

            foreach (int i in Enumerable.Range(0, info.ChannelCount))
            {
                int bandNumber = i + 1;

                using (Band band = dataset.GetRasterBand(bandNumber))
                {
                    channelSize = Gdal.GetDataTypeSize(band.DataType);

                    switch (band.GetRasterColorInterpretation())
                    {
                    case ColorInterp.GCI_RedBand:
                        info.BandMap[2] = bandNumber;
                        break;

                    case ColorInterp.GCI_GreenBand:
                        info.BandMap[1] = bandNumber;
                        break;

                    case ColorInterp.GCI_BlueBand:
                        info.BandMap[0] = bandNumber;
                        break;

                    case ColorInterp.GCI_AlphaBand:
                        hasAlpha        = true;
                        info.BandMap[3] = bandNumber;
                        break;

                    case ColorInterp.GCI_PaletteIndex:
                        colorTable      = band.GetRasterColorTable();
                        isIndexed       = true;
                        info.BandMap[0] = bandNumber;
                        break;

                    case ColorInterp.GCI_GrayIndex:
                        isIndexed       = true;
                        info.BandMap[0] = bandNumber;
                        break;

                    default:
                        if (i < 4 && info.BandMap[i] == 0)
                        {
                            info.ChannelCount = Math.Min(info.ChannelCount, bandNumber - 1);
                            info.BandMap[i]   = bandNumber;
                        }

                        break;
                    }
                }
            }

            if (isIndexed)
            {
                info.PixelFormat = PixelFormats.Indexed8;
                info.PixelSpace  = 1;

                if (colorTable == null)
                {
                    info.Colors = BitmapPalettes.Gray256Transparent;
                }
                else
                {
                    var colors = new List <Color>();

                    for (var i = 0; i < colorTable.GetCount(); i++)
                    {
                        var color = colorTable.GetColorEntry(i);

                        colors.Add(Color.FromArgb((byte)color.c4, (byte)color.c1, (byte)color.c2, (byte)color.c3));
                    }

                    info.Colors = new BitmapPalette(colors);
                }
            }
            else
            {
                int multiplier = channelSize / 8;
                if (info.ChannelCount == 1)
                {
                    info.PixelFormat = channelSize > 8 ? PixelFormats.Gray16 : PixelFormats.Gray8;
                    info.PixelSpace  = multiplier;
                }
                else
                {
                    if (hasAlpha)
                    {
                        info.PixelFormat = channelSize > 8 ? PixelFormats.Rgba64 : PixelFormats.Bgra32;
                    }
                    else
                    {
                        info.PixelFormat = channelSize > 8 ? PixelFormats.Rgb48 : PixelFormats.Bgr24;
                    }

                    info.PixelSpace = multiplier * info.ChannelCount;
                }
            }

            return(info);
        }
예제 #27
0
        // adapted from RenderSpeciesReference
        private static void SpeciesReferenceTex(this Group group, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            SpeciesReference reference = (SpeciesReference) glyph;
            RectangleF bound_rectangle = glyph.Bounds.toRect();

            SolidBrush brush = (SolidBrush)group.GetBrush(rendinfo, bound_rectangle, refgroup);
            Color fillcolor = brush.Color;

            if (reference.Curve.CurveSegments.Count != 0)
            {
                group.ReactionLineStartTex(reference.Curve.CurveSegments[0], glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
                //group.ReactionLineEndingTex(reference.Curve.CurveSegments[0], glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
            }

            for (int i = 0; i < reference.Curve.CurveSegments.Count; i++)
            {
                bool endOfLine = i == (reference.Curve.CurveSegments.Count - 1);
                group.SingleSegmentTex(reference.Curve.CurveSegments[i], glyph, endOfLine, writer, g, rendinfo, refgroup, scale, fontTexTable);
            }
        }
예제 #28
0
 public override void DrawSubObjekt(RenderInformation RI, MeshPart GSO, GraphicNode GN)
 {
 }
예제 #29
0
        public static void CurveTex(this SBMLExtension.EmlRenderExtension.Curve curve, SBMLExtension.LayoutExtension.GraphicalObject glyph, RenderInformation rendinfo, IndentedTextWriter writer, Group refgroup, RectangleF refbounds, double scale)
        {
            writer.WriteLine("{");
            writer.Indent += 1;
            CommentTex(glyph, curve, writer);
            RectangleF bound_rectangle = glyph.Bounds.toRect();
            if (!refbounds.IsEmpty)
                bound_rectangle = refbounds;
            RotateAndShift(curve, bound_rectangle, writer);

            // obtain fill and stroke information
            Color linecolor = curve.GetStrokeColor(rendinfo, refgroup);
            string strokewidth = curve.GetStrokeWidth(rendinfo, refgroup, scale);
            FillColor fill = curve.GetFillColor(rendinfo, bound_rectangle, refgroup);
            string dashed = "";
            if (!string.IsNullOrEmpty(curve.GetDashType(refgroup)))
            {
                dashed = ", " + curve.DashTex(curve.GetDashType(refgroup));
            }

            // refer stroke information to a ColorDefinition or assign a new colordefinition to "curLineColor"
            string strokeRef = FillColor.getStrokeRef(curve, rendinfo, refgroup);
            if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curLineColor";
                FillColor.AssignColorRGBTex(linecolor, "curLineColor", writer);
            }

            // now either draw the outline if fill is null, or draw and fill otherwise
            if (fill == null || fill.colorList[0].Equals(Color.Empty))
            {
                if (curve.CurveSegments.Count != 0)
                {
                    // draw all curveSegments
                    writer.WriteLine("\\draw [line width = {0}pt, color = {3}{1} {2}] ",
                        strokewidth,
                        FillColor.AlphaValTex(linecolor),
                        dashed,
                        strokeRef);
                    SegmentsTex(curve.CurveSegments, bound_rectangle, writer, false);
                }

                if (curve.ListOfElements.Count != 0)
                {
                    // draw all listOfElements
                    writer.Write("\\draw [line width = {0}pt, color = {3}{1} {2}] ",
                        strokewidth,
                        FillColor.AlphaValTex(linecolor),
                        dashed,
                        strokeRef);
                    ElementsTex(curve.ListOfElements, writer, bound_rectangle, false, false);
                }
            }
            else if (fill.gradient)
            {
                if (!FillColor.isGradientID(fill.ID, rendinfo.GradientDefinitions))
                {
                    FillColor.AssignGradientTex(fill, fill.ID, writer);
                }
                if (curve.CurveSegments.Count != 0)
                {
                    // draw all curveSegments
                    writer.WriteLine("\\draw [line width = {0}pt, color = {5}{1},shading = {4}, shading angle = {2} {3}] ",
                        strokewidth,
                        FillColor.AlphaValTex(linecolor),
                        fill.gradient_rotation,
                        dashed,
                        fill.ID,
                        strokeRef);
                    PolygonSegmentsTex(curve.CurveSegments, bound_rectangle, writer, false);
                }

                if (curve.ListOfElements.Count != 0)
                {
                    // draw all listOfElements
                    writer.WriteLine("\\draw [line width = {0}pt, color = {5}{1}, shading = {4}, shading angle = {2} {3}] ",
                        strokewidth,
                        FillColor.AlphaValTex(linecolor),
                        fill.gradient_rotation,
                        dashed,
                        fill.ID,
                        strokeRef);
                    ElementsTex(curve.ListOfElements, writer, bound_rectangle, false, true);
                }
            }

            else //solid fill
            {
                Color curSolidColor = fill.colorList[0];
                string solidRef = FillColor.getColorRef(curve, rendinfo, refgroup);
                if (String.IsNullOrEmpty(solidRef) || !FillColor.isColorID(solidRef, rendinfo.ColorDefinitions))
                {
                    solidRef = "curSolidColor";
                    FillColor.AssignColorRGBTex(curSolidColor, "curSolidColor", writer);
                }
                if (curve.CurveSegments.Count != 0)
                {
                    // draw all curveSegments
                    writer.WriteLine("\\draw [line width = {0}pt, {4}{1}, fill = {5}{2} {3}] ",
                        strokewidth,
                        FillColor.AlphaValTex(linecolor),
                        FillColor.AlphaValTex(curSolidColor),
                        dashed,
                        strokeRef,
                        solidRef);
                    PolygonSegmentsTex(curve.CurveSegments, bound_rectangle, writer, false);
                }

                if (curve.ListOfElements.Count != 0)
                {
                    // draw all listOfElements
                    writer.WriteLine("\\draw [line width = {0}pt, color = {4}{1}, fill = {5}{2} {3}] ",
                        strokewidth,
                        FillColor.AlphaValTex(linecolor),
                        FillColor.AlphaValTex(curSolidColor),
                        dashed,
                        strokeRef,
                        solidRef);
                    ElementsTex(curve.ListOfElements, writer, bound_rectangle, false, true);
                }
            }
            writer.Indent -= 1;
            writer.WriteLine("}");
        }
예제 #30
0
 public override void PrepareForNode(RenderInformation RI, GraphicNode N)
 {
 }
예제 #31
0
        public static void ImageTex(this SBMLExtension.EmlRenderExtension.Image image, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            if (string.IsNullOrEmpty(image.FullPath))
            {
                image.FullPath = image.HRef;
                if (!File.Exists(image.FullPath))
                {
                    string dir = (string) SBMLExtension.Util.CurrentDirectory;
                    image.FullPath = dir + "\\" + image.FullPath;
                }
            }
            if (!string.IsNullOrEmpty(image.FullPath) && File.Exists(image.FullPath))
            {
                writer.WriteLine("{");
                writer.Indent += 1;
                CommentTex(glyph, image, writer);
                RectangleF bound_rectangle = glyph.Bounds.toRect();
                PointF location = new PointF(image.X.Contains("%") ? (bound_rectangle.X + ((bound_rectangle.Width * SBMLExtension.Util.readSingle(image.X)) / 100f)) : (bound_rectangle.X + SBMLExtension.Util.readSingle(image.X)),
                                             image.Y.Contains("%") ? (bound_rectangle.Y + ((bound_rectangle.Height * SBMLExtension.Util.readSingle(image.Y)) / 100f)) : (bound_rectangle.Y + SBMLExtension.Util.readSingle(image.Y)));

                SizeF size = new SizeF(image.Width.Contains("%") ? ((bound_rectangle.Width * SBMLExtension.Util.readSingle(image.Width)) / 100f) : SBMLExtension.Util.readSingle(image.Width),
                                       image.Height.Contains("%") ? ((bound_rectangle.Height * SBMLExtension.Util.readSingle(image.Height)) / 100f) : SBMLExtension.Util.readSingle(image.Height));
                size.Height = size.Height * (float)scale;
                size.Width = size.Width * (float)scale;
                //note that pgftransformcm does not rotate imported images
                double rotate = 0;
                if (!string.IsNullOrEmpty(image.Transform))
                {
                    Matrix matrix = image.GetMatrix(bound_rectangle.X, bound_rectangle.Y);
                    if (Math.Abs(matrix.Elements[0]) <= 1)
                    {
                        rotate = Math.Asin(matrix.Elements[0]);
                    }
                }

                writer.WriteLine("\\draw ({1}pt, {2}pt) node []{{ \\includegraphics[height = {3}pt, width = {4}pt, angle = {5}]{{{0}}} }};",
                    Path.GetFileName(image.FullPath),
                    location.X,
                    location.Y,
                    size.Height,
                    size.Width,
                    rotate
                    );
                writer.Indent -= 1;
                writer.WriteLine("}");
            }
        }
예제 #32
0
 public static string getStrokeRef(GraphicalPrimitive1D graphItem, RenderInformation rendinfo, Group refgroup)
 {
     if (FillColor.isColorID(graphItem.Stroke, rendinfo.ColorDefinitions))
     {
         return graphItem.Stroke;
     }
     else if (FillColor.isColorID(refgroup.Stroke, rendinfo.ColorDefinitions))
     {
         return refgroup.Stroke;
     }
     else if (FillColor.isColorID(refgroup.Fill, rendinfo.ColorDefinitions))
     {
         return refgroup.Fill;
     }
     else
     {
         return null;
     }
 }
예제 #33
0
        public static void PolygonTex(this Polygon polygon, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, RectangleF refbounds, double scale)
        {
            writer.WriteLine("{");
            writer.Indent += 1;
            CommentTex(glyph, polygon, writer);
            RectangleF bound_rectangle = glyph.Bounds.toRect();
            if (!refbounds.IsEmpty)
                bound_rectangle = refbounds;
            FillColor fill = polygon.GetFillColor(rendinfo, bound_rectangle, refgroup);

            RotateAndShift(polygon, bound_rectangle, writer);

            if (fill == null)
            {
                fill = new FillColor(Color.Empty);
            }

            if (fill.gradient && !fill.radial && fill.colorList.Count > 1)
            {
                polygon.LinearGradientPolygon(bound_rectangle, fill, writer, rendinfo, refgroup, scale);
            }
            else if (fill.gradient && fill.colorList.Count > 1)
            {
                polygon.PathGradientPolygon(bound_rectangle, fill, writer, rendinfo, refgroup, scale);
            }
            else
            {
                polygon.SolidColorPolygon(bound_rectangle, fill, writer, rendinfo, refgroup, scale);
            }

            writer.Indent -= 1;
            writer.WriteLine("}");
        }
예제 #34
0
        private static Color GetStrokeColor(this GraphicalPrimitive1D graphItem, RenderInformation rendinfo, Group refgroup)
        {
            Color strokeColor = Color.Empty;
            if (string.IsNullOrEmpty(graphItem.Stroke) || graphItem.Stroke == "none")
                strokeColor = rendinfo.GetColor(refgroup.Stroke);
            else
                strokeColor = rendinfo.GetColor(graphItem.Stroke);

            if (strokeColor.IsEmpty)
                strokeColor = rendinfo.GetColor(refgroup.Fill);

            return strokeColor;
        }
예제 #35
0
        // Adapted from Group.RenderReaction
        public static void ReactionTex(this Group group, ReactionGlyph glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, RectangleF refbounds, double scale, Hashtable fontTexTable)
        {
            writer.WriteLine("{");
            writer.Indent += 1;
            CommentTex(glyph, group, writer);
            RectangleF bound_rectangle = glyph.Bounds.toRect();

            foreach (SpeciesReference reference in glyph.SpeciesReferences)
            {
                Style styleForReference = rendinfo.GetStyleForObject(reference);
                if (styleForReference != null)
                {
                    group.ToTex(reference, writer, g, rendinfo, styleForReference.Group, refbounds, scale, fontTexTable);
                }
                else
                {
                    group.ToTex(reference, writer, g, rendinfo, refgroup, refbounds, scale, fontTexTable);
                }
            }
            if (glyph.Curve.CurveSegments.Count != 0)
            {
                group.ReactionLineStartTex(glyph.Curve.CurveSegments[0], glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
                //group.ReactionLineEndingTex(glyph.Curve.CurveSegments[0], glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
            }

            foreach (CurveSegment segment in glyph.Curve.CurveSegments)
            {
                group.SingleSegmentTex(segment, glyph, glyph.Curve.CurveSegments.Count == 1, writer, g, rendinfo, group, scale, fontTexTable);
            }
            writer.Indent -= 1;
            writer.WriteLine("}");
        }
예제 #36
0
        private static string GetStrokeWidth(this GraphicalPrimitive1D graphItem, RenderInformation rendinfo, Group refgroup, double scale)
        {
            string strokeW = graphItem.StrokeWidth;
            if (string.IsNullOrEmpty(strokeW))
                strokeW = refgroup.StrokeWidth;

            if (string.IsNullOrEmpty(strokeW))
                strokeW = "1.0";

            double strokeWidth = double.Parse(strokeW);
            strokeWidth = strokeWidth * scale;
            return strokeWidth.ToString();
        }
예제 #37
0
        // works like group.DrawSegment for TeX
        public static void SingleSegmentTex(this Group group, CurveSegment segment, SBMLExtension.LayoutExtension.GraphicalObject glyph, Boolean endOfLine, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            string strokewidth = group.GetStrokeWidth(rendinfo, refgroup, scale);
            Color linecolor = group.GetStrokeColor(rendinfo, refgroup);

            string strokeRef = FillColor.getStrokeRef(group, rendinfo, refgroup);
            if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curLineColor";
                FillColor.AssignColorRGBTex(linecolor, "curLineColor", writer);
            }

            string dashed = ", " + group.DashTex(group.GetDashType(refgroup));
            string segmentHead = "[line width = " + strokewidth + "pt, color = " + strokeRef + FillColor.AlphaValTex(linecolor) + dashed + "]";

                if (segment.Type == "CubicBezier")
                {
                    writer.WriteLine("\\draw{8} ({0}pt, {1}pt) .. controls ({2}pt, {3}pt) and ({4}pt, {5}pt) .. ({6}pt, {7}pt);",
                    segment.Start.X, segment.Start.Y,
                    segment.BasePoint1.X, segment.BasePoint1.Y,
                    segment.BasePoint2.X, segment.BasePoint2.Y,
                    segment.End.X, segment.End.Y,
                    segmentHead);
                }
                else if (segment.Type == "LineSegment")
                {
                    writer.WriteLine("\\draw{4} ({0}pt, {1}pt) -- ({2}pt, {3}pt);",
                    segment.Start.X, segment.Start.Y,
                    segment.End.X, segment.End.Y,
                    segmentHead);
                }

                if (endOfLine)
                {
                    group.ReactionLineEndingTex(segment, glyph, writer, g, rendinfo, refgroup, scale, fontTexTable);
                }
        }
예제 #38
0
        private static void OutlineTex(this SBMLExtension.EmlRenderExtension.Rectangle rectangle, RectangleF bound_rectangle, string shapename, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            string strokewidth = rectangle.GetStrokeWidth(rendinfo, refgroup, scale);
            string dashed = "";
            if (!string.IsNullOrEmpty(rectangle.GetDashType(refgroup)))
            {
                dashed = ", " + rectangle.DashTex(rectangle.GetDashType(refgroup));
            }
            Color linecolor = rectangle.GetStrokeColor(rendinfo, refgroup);

            // refer stroke information to a ColorDefinition ID or assign a new colordefinition to "curLineColor"
            string strokeRef = FillColor.getStrokeRef(rectangle, rendinfo, refgroup);
            if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curLineColor";
                FillColor.AssignColorRGBTex(linecolor, "curLineColor", writer);
            }

            if (string.IsNullOrEmpty(rectangle.RX) || (SBMLExtension.Util.readSingle(rectangle.RX) == 0f))
            {
                writer.WriteLine("\\draw[line width = {0}pt, color = {4}{1} {2}] \\{3};",
                    strokewidth,
                    FillColor.AlphaValTex(linecolor),
                    dashed,
                    shapename,
                    strokeRef);
            }

            else
            {
                float fRadiusX = rectangle.RX.Contains("%") ? ((bound_rectangle.Width * SBMLExtension.Util.readSingle(rectangle.RX)) / 100f) : SBMLExtension.Util.readSingle(rectangle.RX);
                float fRadiusY = rectangle.RY.Contains("%") ? ((bound_rectangle.Height * SBMLExtension.Util.readSingle(rectangle.RY)) / 100f) : SBMLExtension.Util.readSingle(rectangle.RY);
                // In actuality PGF/TikZ does not round with x and y parameters, so we need to fudge
                // Also note that PGF/TikZ does not scale rounding

                float fRadius = (fRadiusX + fRadiusY) / (2f * (float)scale);
                writer.WriteLine("\\draw[line width = {0}pt, color = {5}{1}, rounded corners = {2}pt {3}] \\{4};",
                    strokewidth,
                    FillColor.AlphaValTex(linecolor),
                    fRadius,
                    dashed,
                    shapename,
                    strokeRef);
            }
        }
예제 #39
0
        public static void TextTex(this Text text, SBMLExtension.LayoutExtension.GraphicalObject glyph, IndentedTextWriter writer, Graphics g, RenderInformation rendinfo, Group refgroup, double scale, Hashtable fontTexTable)
        {
            writer.WriteLine("{");
            writer.Indent += 1;
            CommentTex(glyph, text, writer);
            RectangleF bound_rectangle = glyph.Bounds.toRect();

            Text.TextAnchors horizontalAnchor = text.GetHorizontalAnchor(refgroup);
            Text.VerticalTextAnchors verticalAnchor = text.GetVerticalAnchor(refgroup);
            Font font = text.GetScaledFont(scale, refgroup);

            SizeF string_size = g.MeasureString(text.TheText, font);
            PointF text_coord = text.GetPoint(bound_rectangle);

            Color text_color = text.GetStrokeColor(rendinfo, refgroup);
            if (!text_color.Equals(Color.Empty))
            {
                // refer stroke information to a ColorDefinition ID or assign a new colordefinition to "curLineColor"
                string strokeRef = FillColor.getStrokeRef(text, rendinfo, refgroup);
                if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
                {
                    strokeRef = "curLineColor";
                    FillColor.AssignColorRGBTex(text_color, "curLineColor", writer);
                }

                switch (horizontalAnchor)
                {
                    case Text.TextAnchors.start:
                        text_coord.X += string_size.Width / 2f;
                        break;

                    case Text.TextAnchors.middle:
                        text_coord.X += bound_rectangle.Width / 2f;
                        break;

                    case Text.TextAnchors.end:
                        text_coord.X += bound_rectangle.Width - string_size.Width / 2f;
                        break;
                }
                switch (verticalAnchor)
                {
                    case Text.VerticalTextAnchors.top:
                        text_coord.Y += string_size.Height / 2f;
                        break;

                    case Text.VerticalTextAnchors.middle:
                        text_coord.Y += (bound_rectangle.Height / 2f);
                        break;

                    case Text.VerticalTextAnchors.bottom:
                        text_coord.Y += bound_rectangle.Height - string_size.Height / 2f;
                        break;
                }

                writer.WriteLine("\\draw ({0}pt, {1}pt) node[text = {7}{2}, font = \\fontsize{{ {3} }} {{ {4} }}\\fontfamily{6}\\selectfont] {{ {5} }};",
                   (text_coord.X).ToString(),
                   (text_coord.Y).ToString(),
                   FillColor.AlphaValTex(text_color),
                   font.SizeInPoints,
                   font.SizeInPoints,
                   correctText(text.TheText),
                   FontTex(font, fontTexTable),
                   strokeRef);
            }
            writer.Indent -= 1;
            writer.WriteLine("}");
        }
예제 #40
0
        private static void OutlineTex(this Ellipses ellipse, RectangleF bound_rectangle, string shapename, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            string strokewidth = ellipse.GetStrokeWidth(rendinfo, refgroup, scale);
            string dashed = "";
            if (!string.IsNullOrEmpty(ellipse.GetDashType(refgroup)))
            {
                dashed = ", " + ellipse.DashTex(ellipse.GetDashType(refgroup));
            }
            Color linecolor = ellipse.GetStrokeColor(rendinfo, refgroup);

            // refer stroke information to a ColorDefinition ID or assign a new colordefinition to "curLineColor"
            string strokeRef = FillColor.getStrokeRef(ellipse, rendinfo, refgroup);
            if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curLineColor";
                FillColor.AssignColorRGBTex(linecolor, "curLineColor", writer);
            }

            writer.WriteLine("\\draw[line width = {0}pt, color = {4}{1} {2}] \\{3};",
                    strokewidth,
                    FillColor.AlphaValTex(linecolor),
                    dashed,
                    shapename,
                    strokeRef);
        }
예제 #41
0
        // adapted from GraphicalPrimitve2D.GetBrush()
        private static FillColor GetFillColor(this GraphicalPrimitive2D graphItem, RenderInformation rendinfo, RectangleF bound_rectangle, Group refgroup)
        {
            try
            {
                if (string.IsNullOrEmpty(graphItem.Fill) || (graphItem.Fill == "none"))
                    return rendinfo.GetFillColor(refgroup.Fill, bound_rectangle);

                return rendinfo.GetFillColor(graphItem.Fill, bound_rectangle);
            }
            catch (Exception)
            {
                GraphicalPrimitive1D graphBase = (GraphicalPrimitive1D) graphItem;
                return rendinfo.GetFillColor(graphBase.Stroke, bound_rectangle);
            }
        }
예제 #42
0
        private static void PathGradientPolygon(this Polygon polygon, RectangleF bound_rectangle, FillColor fillcolor, IndentedTextWriter writer, RenderInformation rendinfo, Group refgroup, double scale)
        {
            string strokewidth = polygon.GetStrokeWidth(rendinfo, refgroup, scale);
            string dashed = "";
            if (!string.IsNullOrEmpty(polygon.GetDashType(refgroup)))
            {
                dashed = ", " + polygon.DashTex(polygon.GetDashType(refgroup));
            }
            Color linecolor = polygon.GetStrokeColor(rendinfo, refgroup);

            // refer stroke information to a ColorDefinition or assign a new colordefinition to "curLineColor"
            string strokeRef = FillColor.getStrokeRef(polygon, rendinfo, refgroup);
            if (String.IsNullOrEmpty(strokeRef) || !FillColor.isColorID(strokeRef, rendinfo.ColorDefinitions))
            {
                strokeRef = "curLineColor";
                FillColor.AssignColorRGBTex(linecolor, "curLineColor", writer);
            }

            if (!FillColor.isGradientID(fillcolor.ID, rendinfo.GradientDefinitions))
            {
                FillColor.AssignGradientTex(fillcolor, fillcolor.ID, writer);
            }

            // draw the filling
            if (fillcolor.colorList.Count == fillcolor.positionList.Count)
            {
                writer.WriteLine("\\draw [line width = {0}pt, color = {5}{1}, shading = {4}, shading angle = {2} {3}] ",
                    strokewidth,
                    FillColor.AlphaValTex(linecolor),
                    dashed,
                    fillcolor.ID,
                    strokeRef);

                PolygonSegmentsTex(polygon.CurveSegments, bound_rectangle, writer, false);
                PolygonElementsTex(polygon.ListOfElements, writer, bound_rectangle, false);
            }
        }