Example #1
0
        public RenderingQueueWindow(RenderingQueue renderingQueue) :
            base(WindowType.Toplevel)
        {
            this.Build();

            title_Label.ModifyFont(FontHelpers.ScaleFontSize(title_Label, 1.4));

            // Adding queue event handlers
            mRenderingQueue = renderingQueue;
            mRenderingQueue.QueueProgressMessageReport += HandleRenderingQueueProgressMessageReport;
            mRenderingQueue.ItemAdded                   += HandleRenderingQueueItemAdded;
            mRenderingQueue.ItemIndexChanged            += HandleRenderingQueueItemIndexChanged;
            mRenderingQueue.ItemRemoved                 += HandleRenderingQueueItemRemoved;
            mRenderingQueue.BeforeItemProcessingStarted += HandleRenderingQueueBeforeItemProcessingStarted;
            mRenderingQueue.AfterItemProcessingFinished += HandleRenderingQueueAfterItemProcessingFinished;
            mRenderingQueue.ThreadStarted               += HandleRenderingQueueThreadStarted;
            mRenderingQueue.ThreadStopped               += HandleRenderingQueueThreadStopped;
            mRenderingQueue.QueueEmpty                  += HandleRenderingQueueQueueEmpty;
            mRenderingQueue.ItemRendering               += HandleRenderingQueueItemRendering;

            // Creating status icon

            string icon_res;

            if (System.Environment.OSVersion.Platform == PlatformID.Unix)
            {
                icon_res = "CatEye.UI.Gtk.res.svg-inkscape.cateye-small.svg";
            }
            else
            {
                // Windows, I hope.
                icon_res = "CatEye.UI.Gtk.res.png.cateye-small-16x16.png";
            }

            mProcessingStatusIcon           = new StatusIcon(Gdk.Pixbuf.LoadFromResource(icon_res));
            mProcessingStatusIcon.Visible   = false;            // In Windows status icon appears visible by default
            mProcessingStatusIcon.Activate += HandleProcessingStatusIconActivate;

            // Preparing queue list
            mQueueNodeStore          = new NodeStore(typeof(RenderingTaskTreeNode));
            queue_nodeview.NodeStore = mQueueNodeStore;

            queue_nodeview.AppendColumn("Source", new CellRendererText(), "text", 0);
            queue_nodeview.AppendColumn("Destination", new CellRendererText(), "text", 1);

            expander1.Expanded    = false;
            queue_GtkLabel.Markup = "<b>Queue (" + mRenderingQueue.Queue.Length + " left)</b>";
        }
        private void RecreateRenderingQueuesOnDXScene()
        {
            // First remove all RenderingQueues
            var allRenderingQueues = CurrentDXScene.RenderingQueues.ToList();

            foreach (var oneRenderingQueue in allRenderingQueues)
            {
                CurrentDXScene.RemoveRenderingQueue(oneRenderingQueue);
            }

            // Now add enabled RenderingQueues
            RenderingQueue previousRenderingQueue = null;

            foreach (var oneRenderingQueue in _allRenderingQueues)
            {
                if (!_disabledRenderingQueues.Contains(oneRenderingQueue))
                {
                    CurrentDXScene.AddRenderingQueueAfter(oneRenderingQueue, previousRenderingQueue);
                    previousRenderingQueue = oneRenderingQueue;
                }
            }
        }
Example #3
0
        private void AddLines(Point3D startPosition, int positionsCount, Color lineColor, bool readZBuffer = true, bool writeZBuffer = true, RenderingQueue customRenderingQueue = null)
        {
            Vector3[] positions = new Vector3[positionsCount * 2];
            Vector3   position  = startPosition.ToVector3();

            int index = 0;

            for (int i = 0; i < positionsCount; i++)
            {
                positions[index]     = position;
                positions[index + 1] = position + new Vector3(40, 0, 0);

                index    += 2;
                position += new Vector3(0, 0, 10);
            }

            // ThickLineEffect that renders the 3D lines can use the ReadZBuffer and WriteZBuffer values from LineMaterial.
            //
            // When ReadZBuffer is false (true by default), then line is rendered without checking the depth buffer -
            // so it is always rendered even it is is behind some other 3D object and should not be visible from the camera).
            //
            // When WriteZBuffer is false (true by default), then when rendering the 3D line, the depth of the line is not
            // written to the depth buffer. So No other object will be made hidden by the line even if that object is behind the line.
            var lineMaterial = new LineMaterial()
            {
                LineColor     = lineColor.ToColor4(),
                LineThickness = 2,
                ReadZBuffer   = readZBuffer,
                WriteZBuffer  = writeZBuffer
            };

            _disposables.Add(lineMaterial);


            var screenSpaceLineNode = new ScreenSpaceLineNode(positions, isLineStrip: false, isLineClosed: false, lineMaterial: lineMaterial);

            // It is also needed that the 3D line is put to the Background or Overlay rendering queue so that it is rendered before or after other 3D objects.
            screenSpaceLineNode.CustomRenderingQueue = customRenderingQueue;

            var sceneNodeVisual3D = new SceneNodeVisual3D(screenSpaceLineNode);

            MainViewport.Children.Add(sceneNodeVisual3D);
        }
Example #4
0
        public static void Main(string[] args)
        {
            // Initializing remote control
            mRemoteControlService = new RemoteControlService("localhost", 21985);
            mRemoteControlService.RemoteCommandReceived += HandleRemoteControlServiceRemoteCommandReceived;

            // Parsing command line. Formulating command and it's arguments
            List <string> argslist = new List <string>(args);

            List <string>         commands           = new List <string>();
            List <List <string> > commands_arguments = new List <List <string> >();

            if (argslist.Contains("-q") || argslist.Contains("--queue"))
            {
                argslist.Remove("-q"); argslist.Remove("--queue");
                // Queue launch mode

                // Searching for "--default" option
                int d_inx = -1;
                d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx;
                d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx;
                string d_cestage_name = "";

                if (d_inx >= 0)
                {
                    if (d_inx < argslist.Count - 1)
                    {
                        d_cestage_name = argslist[d_inx + 1];
                        // Removing readed "-d"
                        argslist.RemoveRange(d_inx, 2);

                        if (!ReceiptsManager.IsReceipt(d_cestage_name))
                        {
                            Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file.");
                            d_cestage_name = "";
                        }
                    }
                    else if (d_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d");
                        argslist.RemoveAt(d_inx);
                    }
                }

                // Searching for "--target-type"
                int tt_inx = -1;
                tt_inx = argslist.IndexOf("-t") >= 0 ? argslist.IndexOf("-t") : tt_inx;
                tt_inx = argslist.IndexOf("--target-type") >= 0 ? argslist.IndexOf("--target-type") : tt_inx;
                string target_type = "";

                if (tt_inx >= 0)
                {
                    if (tt_inx < argslist.Count - 1)
                    {
                        target_type = argslist[tt_inx + 1];
                        // Removing readed "-t"
                        argslist.RemoveRange(tt_inx, 2);

                        if (target_type != "jpeg" && target_type != "png" && target_type != "bmp")
                        {
                            Console.WriteLine("Incorrect target type specified: " + target_type + ". It should be \"jpeg\", \"png\" or \"bmp\".");
                            target_type = "";
                        }
                    }
                    else if (tt_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: target type should be provided after --target-type or -t");
                        argslist.RemoveAt(tt_inx);
                    }
                }

                // Searching for "--prescale"
                int p_inx = -1;
                p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx;
                p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx;
                int prescale = 2;

                if (p_inx >= 0)
                {
                    if (p_inx < argslist.Count - 1)
                    {
                        if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8)
                        {
                            Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8.");
                        }

                        // Removing readed "-t"
                        argslist.RemoveRange(p_inx, 2);
                    }
                    else if (p_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p");
                        argslist.RemoveAt(p_inx);
                    }
                }

                // Now when all the additional parameters are parsed and removed,
                // we're analysing, what's left. The options:
                if (argslist.Count == 2 && ((ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1])) ||
                                            (ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0]))))
                {
                    // Two file names: one cestage and one raw

                    string cestage_filename;
                    string raw_filename;
                    if (ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1]))
                    {
                        cestage_filename = argslist[0];
                        raw_filename     = argslist[1];
                    }
                    else                     // if (IsCEStageFile(argslist[1]) && DCRawConnection.IsRaw(argslist[0]))
                    {
                        cestage_filename = argslist[1];
                        raw_filename     = argslist[0];
                    }

                    // Guessing target filename
                    if (target_type == "")
                    {
                        target_type = "jpeg";
                    }
                    string target_name = System.IO.Path.ChangeExtension(raw_filename, target_type);
                    target_name = CheckIfFileExistsAndAddIndex(target_name);

                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("AddToQueue");
                    commands_arguments.Add(new List <string>(new string[]
                    {
                        cestage_filename,
                        raw_filename,
                        target_name,
                        target_type,
                        prescale.ToString()
                    }));
                }
                else
                {
                    // Searching for cestage for each raw and for raws for each cestage
                    for (int i = 0; i < argslist.Count; i++)
                    {
                        if (RawLoader.IsRaw(argslist[i]))
                        {
                            // The current file is a raw

                            // Guessing target filename
                            if (target_type == "")
                            {
                                target_type = "jpeg";
                            }
                            string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type);
                            target_name = CheckIfFileExistsAndAddIndex(target_name);

                            string[] cestages = ReceiptsManager.FindReceiptsForRaw(argslist[i]);
                            if (cestages.Length > 0)
                            {
                                // At least one found

                                // Launching StageEditor with the cestage file and the raw file
                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    cestages[0],
                                    argslist[i],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else if (d_cestage_name != "")
                            {
                                // Nothing found, but default name is present
                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    d_cestage_name,
                                    argslist[i],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                Console.WriteLine("Can't open " + argslist[i] + ": can't find it's .cestage file");
                            }
                        }
                        else if (ReceiptsManager.IsReceipt(argslist[i]))
                        {
                            // The current file is a cestage

                            // Guessing target filename
                            if (target_type == "")
                            {
                                target_type = "jpeg";
                            }
                            string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type);
                            target_name = CheckIfFileExistsAndAddIndex(target_name);

                            string[] raws = new string[] {};
                            try
                            {
                                raws = ReceiptsManager.FindRawsForReceipt(argslist[i]);
                            }
                            catch (System.IO.DirectoryNotFoundException dnfe)
                            {
                                Console.WriteLine("Error: " + dnfe.Message);
                            }
                            if (raws.Length > 0)
                            {
                                // At least one found

                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    argslist[i],
                                    raws[0],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                Console.WriteLine("Can't open " + argslist[i] + ": can't find it's raw file");
                            }
                        }
                    }
                }
            }
            else
            {
                // Not a queue launch mode

                // If we don't have 1 cestage and 1 raw, let's open as many windows as possible.

                // But, at first, trying to find "--default" option
                int d_inx = -1;
                d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx;
                d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx;
                string d_cestage_name = "";

                if (d_inx >= 0)
                {
                    if (d_inx < argslist.Count - 1)
                    {
                        d_cestage_name = argslist[d_inx + 1];
                        // Removing readed "-d"
                        argslist.RemoveRange(d_inx, 2);

                        if (!ReceiptsManager.IsReceipt(d_cestage_name))
                        {
                            Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file.");
                            d_cestage_name = "";
                        }
                    }
                    else if (d_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d");
                        argslist.RemoveAt(d_inx);
                    }
                }

                // Searching for "--prescale"
                int p_inx = -1;
                p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx;
                p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx;
                int prescale = 2;

                if (p_inx >= 0)
                {
                    if (p_inx < argslist.Count - 1)
                    {
                        if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8)
                        {
                            Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8.");
                        }

                        // Removing readed "-p"
                        argslist.RemoveRange(p_inx, 2);
                    }
                    else if (p_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p");
                        argslist.RemoveAt(p_inx);
                    }
                }

                if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1]))
                {
                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("StageEditor_CEStage_RAW");
                    commands_arguments.Add(new List <string>(new string[]
                    {
                        argslist[0],
                        argslist[1],
                        prescale.ToString()
                    }));
                }
                else
                if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0]))
                {
                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("StageEditor_CEStage_RAW");
                    commands_arguments.Add(new List <string>(new string[]
                    {
                        argslist[1],
                        argslist[0],
                        prescale.ToString()
                    }));
                }
                else
                {
                    // Searching for cestage for each raw and for raws for each cestage
                    for (int i = 0; i < argslist.Count; i++)
                    {
                        if (RawLoader.IsRaw(argslist[i]))
                        {
                            // The current file is a raw

                            if (d_cestage_name != "")
                            {
                                // Nothing found, but default name is present
                                commands.Add("StageEditor_CEStage_RAW");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    d_cestage_name,
                                    argslist[i],
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                commands.Add("StageEditor_RAW");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    argslist[i],
                                    prescale.ToString()
                                }));
                            }
                        }
                        else if (ReceiptsManager.IsReceipt(argslist[i]))
                        {
                            // The current file is a cestage

                            string[] raws = ReceiptsManager.FindRawsForReceipt(argslist[i]);
                            if (raws.Length > 0)
                            {
                                // At least one found
                                // Launching StageEditor with the cestage file and the raw file
                                commands.Add("StageEditor_CEStage_RAW");
                                commands_arguments.Add(new List <string>(new string[]
                                {
                                    argslist[i],
                                    raws[0],
                                    prescale.ToString()
                                }));
                            }
                            else if (raws.Length == 0)
                            {
                                Gtk.MessageDialog md = new Gtk.MessageDialog(
                                    null, DialogFlags.Modal,
                                    MessageType.Error, ButtonsType.Ok,
                                    false, "Can't find raw file for {0}", argslist[i]);

                                md.Title = MainClass.APP_NAME;

                                md.Run();
                                md.Destroy();
                            }
                            else                             // raws.Length > 1
                            {
                                Gtk.MessageDialog md = new Gtk.MessageDialog(
                                    null, DialogFlags.Modal,
                                    MessageType.Error, ButtonsType.Ok,
                                    false, "More than one raw file found for {0}", argslist[i]);

                                md.Title = MainClass.APP_NAME;

                                md.Run();
                                md.Destroy();
                            }
                        }
                    }
                }
            }

            bool ownServerStarted = mRemoteControlService.Start();

            if (ownServerStarted)
            {
                string mylocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location);
                windowsGtkStyle = new WindowsGtkStyle(mylocation +
                                                      Path.DirectorySeparatorChar +
                                                      "res" +
                                                      Path.DirectorySeparatorChar +
                                                      "win-gtkrc");
                Application.Init();

                // Creating render queue and its window
                mRenderingQueue       = new RenderingQueue();
                mRenderingQueueWindow = new RenderingQueueWindow(mRenderingQueue);
                mRenderingQueue.StartThread();
            }

            // No files asked
            if (commands.Count == 0)
            {
                // No command line arguments passed.
                // Sending the "StageEditor" command with no arguments
                commands.Add("StageEditor");
                commands_arguments.Add(new List <string>());
            }

            // Sending the commands
            List <string> packed_commands = new List <string>();

            for (int i = 0; i < commands.Count; i++)
            {
                packed_commands.Add(RemoteControlService.PackCommand(commands[i], commands_arguments[i].ToArray()));
            }
            mRemoteControlService.SendCommands(packed_commands.ToArray());


            if (ownServerStarted)
            {
                GLib.Idle.Add(delegate {
                    // Checking if something is already started
                    if (RenderingQueue.IsProcessingItem || StageEditorWindows.Count > 0)
                    {
                        mLoadedSomethingAlready = true;
                    }

                    // Removing all destroyed
                    StageEditorWindows.RemoveAll(delegate(StageEditorWindow wnd)
                    {
                        return(wnd.IsDestroyed);
                    });

                    // Checking is there any activity or no
                    if (mLoadedSomethingAlready &&
                        StageEditorWindows.Count == 0 &&
                        !RenderingQueue.IsProcessingItem)
                    {
                        RenderingQueue.StopThread();
                        Application.Quit();
                    }
                    return(true);
                });

                Application.Run();
            }
            mRemoteControlService.Stop();
        }
Example #5
0
        internal override void Draw(Size availableSpace)
        {
            var lines = DivideTextItemsIntoLines(availableSpace.Width, availableSpace.Height).ToList();

            if (!lines.Any())
            {
                return;
            }

            var heightOffset = 0f;
            var widthOffset  = 0f;

            foreach (var line in lines)
            {
                widthOffset = 0f;

                var alignmentOffset = GetAlignmentOffset(line.Width);

                Canvas.Translate(new Position(alignmentOffset, 0));
                Canvas.Translate(new Position(0, -line.Ascent));

                foreach (var item in line.Elements)
                {
                    var textDrawingRequest = new TextDrawingRequest
                    {
                        Canvas      = Canvas,
                        PageContext = PageContext,

                        StartIndex = item.Measurement.StartIndex,
                        EndIndex   = item.Measurement.EndIndex,

                        TextSize    = new Size(item.Measurement.Width, line.LineHeight),
                        TotalAscent = line.Ascent
                    };

                    item.Item.Draw(textDrawingRequest);

                    Canvas.Translate(new Position(item.Measurement.Width, 0));
                    widthOffset += item.Measurement.Width;
                }

                Canvas.Translate(new Position(-alignmentOffset, 0));
                Canvas.Translate(new Position(-line.Width, line.Ascent));
                Canvas.Translate(new Position(0, line.LineHeight));

                heightOffset += line.LineHeight;
            }

            Canvas.Translate(new Position(0, -heightOffset));

            lines
            .SelectMany(x => x.Elements)
            .GroupBy(x => x.Item)
            .Where(x => x.Any(y => y.Measurement.IsLast))
            .Select(x => x.Key)
            .ToList()
            .ForEach(x => RenderingQueue.Dequeue());

            var lastElementMeasurement = lines.Last().Elements.Last().Measurement;

            CurrentElementIndex = lastElementMeasurement.IsLast ? 0 : lastElementMeasurement.EndIndex;

            if (!RenderingQueue.Any())
            {
                ResetState();
            }

            float GetAlignmentOffset(float lineWidth)
            {
                if (Alignment == HorizontalAlignment.Left)
                {
                    return(0);
                }

                var emptySpace = availableSpace.Width - lineWidth;

                if (Alignment == HorizontalAlignment.Right)
                {
                    return(emptySpace);
                }

                if (Alignment == HorizontalAlignment.Center)
                {
                    return(emptySpace / 2);
                }

                throw new ArgumentException();
            }
        }
        private void ChangeLineMaterial(BaseLineVisual3D visual3D, ILineMaterial newDXMaterial, RenderingQueue customRenderingQueue = null)
        {
            // First get the DXEngine's SceneNode that was created from WPF's Visual3D
            var sceneNode = GetSceneNodeForWpfObject(visual3D);

            // Otherwise we need to get the ScreenSpaceLineNode.
            var screenSpaceLineNode = sceneNode as ScreenSpaceLineNode;

            if (screenSpaceLineNode == null)
            {
                // ScreenSpaceLineNode is usually created as a child node of a WpfModelVisual3DNode:
                // WpfModelVisual3DNode is created for LineArcVisual3D (because it is derived from BaseLineVisual3D and that is derived from ModelVisual3D)
                if (sceneNode != null && sceneNode.ChildNodesCount == 1)
                {
                    screenSpaceLineNode = sceneNode.ChildNodes[0] as ScreenSpaceLineNode;
                }
            }

            if (screenSpaceLineNode != null)
            {
                // Once we have the ScreenSpaceLineNode, we can get the used LineMaterial that has ReadZBuffer
                screenSpaceLineNode.LineMaterial = newDXMaterial;

                // IMPORTANT:
                // When we manually change the properties of materials or SceneNodes,
                // we also need to notify the changed SceneNode about the change.
                // Without this the DXEngine will not re-render the scene because it will think that there is no change.
                screenSpaceLineNode.NotifySceneNodeChange(SceneNode.SceneNodeDirtyFlags.MaterialChanged);


                if (customRenderingQueue != null)
                {
                    screenSpaceLineNode.CustomRenderingQueue = customRenderingQueue;
                    screenSpaceLineNode.NotifySceneNodeChange(SceneNode.SceneNodeDirtyFlags.RenderingQueueChanged);
                }
            }
        }