예제 #1
0
        public static bool GetFreePath(string fileName, string fileExtension, out string availableName)
        {
            availableName = "";

            if (String.IsNullOrWhiteSpace(fileName) || String.IsNullOrWhiteSpace(fileExtension))
            {
                return(false);
            }

            var currentPath = WindowsMethods.GetCurrentExplorerPath();

            if (!String.IsNullOrWhiteSpace(currentPath))
            {
                for (byte i = 0; i < 99; i++)
                {
                    var filePath = Path.Combine(currentPath, String.Format(@"{0}{1}.{2}", fileName, i, fileExtension));
                    if (!File.Exists(filePath))
                    {
                        availableName = filePath;
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #2
0
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);

                #region Handle SystemMenu
                if (WindowsMethods.CheckMenuEvent(m, MENU_CLIPBOARD))
                {
                    if (clipboardAction != null)
                    {
                        clipboardAction.Invoke();
                    }
                    return;
                }

                if (WindowsMethods.CheckMenuEvent(m, MENU_TOPMOST))
                {
                    this.TopMost = !this.TopMost;
                    WindowsMethods.SetFormMenuCheckBox(menuHandle, MENU_TOPMOST, this.TopMost);
                    return;
                }

                if (WindowsMethods.CheckMenuEvent(m, MENU_LOCK))
                {
                    if (this.lockControl != null)
                    {
                        this.lockControl.Enabled = !this.lockControl.Enabled;
                        WindowsMethods.SetFormMenuCheckBox(menuHandle, MENU_LOCK, !this.lockControl.Enabled);
                        return;
                    }
                }
                #endregion
            }
예제 #3
0
 public static uint RhTexture2dHandle(IntPtr ptrTexture2d)
 {
     if (Rhino.Runtime.HostUtils.RunningOnWindows)
     {
         return(WindowsMethods.RhTexture2dHandle(ptrTexture2d));
     }
     else
     {
         return(MacMethods.RhTexture2dHandle(ptrTexture2d));
     }
 }
예제 #4
0
 public static void RhTexture2dDelete(IntPtr ptrTexture2d)
 {
     if (Rhino.Runtime.HostUtils.RunningOnWindows)
     {
         WindowsMethods.RhTexture2dDelete(ptrTexture2d);
     }
     else
     {
         MacMethods.RhTexture2dDelete(ptrTexture2d);
     }
 }
예제 #5
0
 public static IntPtr RhTexture2dCreate()
 {
     if (Rhino.Runtime.HostUtils.RunningOnWindows)
     {
         return(WindowsMethods.RhTexture2dCreate());
     }
     else
     {
         return(MacMethods.RhTexture2dCreate());
     }
 }
예제 #6
0
            protected override void OnHandleCreated(EventArgs e)
            {
                base.OnHandleCreated(e);

                // Expand SystemMenu
                menuHandle = WindowsMethods.GetFormMenuHandle(this.Handle);
                WindowsMethods.AddFormMenuSeparator(menuHandle);
                WindowsMethods.AddFormMenuItem(menuHandle, MENU_CLIPBOARD, "Copy to &Clipboard");
                WindowsMethods.AddFormMenuSeparator(menuHandle);
                WindowsMethods.AddFormMenuItem(menuHandle, MENU_TOPMOST, "TopMost");
                WindowsMethods.AddFormMenuItem(menuHandle, MENU_LOCK, "Lock");
            }
예제 #7
0
        public static System.Drawing.Bitmap RhTexture2dToDib(IntPtr ptrTexture2d)
        {
            if (Rhino.Runtime.HostUtils.RunningOnWindows)
            {
                IntPtr ptrRhinoDib = WindowsMethods.RhTexture2dToBitmap(ptrTexture2d);

                var type = typeof(Rhino.Runtime.Interop).Assembly.GetType("Rhino.Runtime.InteropWrappers.RhinoDib");
                var mi   = type.GetMethod("ToBitmap", new Type[] { typeof(IntPtr), typeof(bool) });
                System.Drawing.Bitmap rc = mi.Invoke(null, new object[] { ptrRhinoDib, true }) as System.Drawing.Bitmap;
                return(rc);
            }
            return(null);
        }
예제 #8
0
        public static bool RhTexture2dCapture(Rhino.Display.DisplayPipeline pipeline, IntPtr ptrTexture2d, CaptureFormat captureFormat)
        {
            var    fieldInfo   = pipeline.GetType().GetField("m_ptr", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            IntPtr ptrPipeline = (IntPtr)fieldInfo.GetValue(pipeline);

            if (Rhino.Runtime.HostUtils.RunningOnWindows)
            {
                return(WindowsMethods.RhTexture2dPipelineCapture(ptrPipeline, ptrTexture2d, captureFormat));
            }
            else
            {
                var viewSerialNumber = pipeline.Viewport.ParentView.RuntimeSerialNumber;
                return(MacMethods.RhTexture2dCapture(viewSerialNumber, ptrTexture2d, captureFormat));
            }
        }
예제 #9
0
        public static void UploadFile(string browserName, string filePath)
        {
            var absoluteFilePath = GetAbsoluteExistingPath(filePath);
            var uploadWindow     = Robot.GetUploadWindow(browserName);

            uploadWindow.Activate();
            var fileNameInput = uploadWindow.GetControls("Edit").First();

            fileNameInput.Activate();
            WindowsMethods.SendText(fileNameInput, absoluteFilePath);

            var confirmButton = uploadWindow.GetControls("Button").First();

            confirmButton.Activate();
            WindowsMethods.SendClick(confirmButton);
        }
예제 #10
0
 private void DisplayPipeline_PreDrawObjects(object sender, Rhino.Display.DrawEventArgs e)
 {
     GLShaderComponentBase.UpdateContext(e);
     if (_model.ProgramId != 0)
     {
         if (Rhino.Runtime.HostUtils.RunningOnWindows)
         {
             WindowsMethods.RHC_UpdateShader(_resourceName, _defines, _model.ProgramId);
         }
         else
         {
             MacMethods.RHC_UpdateShader(_resourceName, _defines, _model.ProgramId);
         }
         _model.RecycleCurrentProgram = false;
     }
 }
예제 #11
0
        protected override void SolveInstance(IGH_DataAccess data)
        {
            string resourceName = "";
            string defines      = "";

            data.GetData(0, ref resourceName);
            data.GetData(1, ref defines);
            defines = defines.Replace("\\n", "\n");
            if (!resourceName.Equals(_resourceName) || !defines.Equals(_defines))
            {
                _resourceName = resourceName;
                _defines      = defines;
                _model        = new GLSLViewModel();
            }
            if (_model.ProgramId == 0 &&
                !string.IsNullOrWhiteSpace(_model.VertexShaderCode) &&
                !string.IsNullOrWhiteSpace(_resourceName))
            {
                ActivateGL();
                if (_model.CompileProgram())
                {
                    if (_model.ProgramId != 0)
                    {
                        if (Rhino.Runtime.HostUtils.RunningOnWindows)
                        {
                            WindowsMethods.RHC_UpdateShader(_resourceName, _defines, _model.ProgramId);
                        }
                        else
                        {
                            MacMethods.RHC_UpdateShader(_resourceName, _defines, _model.ProgramId);
                        }
                        _model.RecycleCurrentProgram = false;

                        var doc = Rhino.RhinoDoc.ActiveDoc;
                        if (doc != null)
                        {
                            doc.Views.Redraw();
                        }
                        GLShaderComponentBase.RedrawViewportControl();
                    }
                }
            }
        }
예제 #12
0
        void OpenEditor()
        {
            if (string.IsNullOrWhiteSpace(_resourceName))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(_model.VertexShaderCode))
            {
                using (var vertex = new StringWrapper())
                    using (var tessctrl = new StringWrapper())
                        using (var tesseval = new StringWrapper())
                            using (var geometry = new StringWrapper())
                                using (var fragment = new StringWrapper())
                                {
                                    IntPtr _vertex   = vertex.NonConstPointer;
                                    IntPtr _tessctrl = tessctrl.NonConstPointer;
                                    IntPtr _tesseval = tesseval.NonConstPointer;
                                    IntPtr _geometry = geometry.NonConstPointer;
                                    IntPtr _fragment = fragment.NonConstPointer;
                                    if (Rhino.Runtime.HostUtils.RunningOnWindows)
                                    {
                                        WindowsMethods.RHC_GetShaderSource(_resourceName, _defines, _vertex, _tessctrl, _tesseval, _geometry, _fragment);
                                    }
                                    else
                                    {
                                        MacMethods.RHC_GetShaderSource(_resourceName, _defines, _vertex, _tessctrl, _tesseval, _geometry, _fragment);
                                    }

                                    _model.VertexShaderCode            = vertex.ToString();
                                    _model.TessellationControlCode     = tessctrl.ToString();
                                    _model.TessellationEvalualtionCode = tesseval.ToString();
                                    _model.GeometryShaderCode          = geometry.ToString();
                                    _model.FragmentShaderCode          = fragment.ToString();
                                }
            }

            Rhino.Display.DisplayPipeline.PreDrawObjects += DisplayPipeline_PreDrawObjects;
            string savedVS = _model.VertexShaderCode;
            string savedGS = _model.GeometryShaderCode;
            string savedTC = _model.TessellationControlCode;
            string savedTE = _model.TessellationEvalualtionCode;
            string savedFS = _model.FragmentShaderCode;
            string savedXfrmFeedbackVertex = _model.TransformFeedbackShaderCode;

            bool containsTessShaders = !string.IsNullOrWhiteSpace(_model.TessellationControlCode) ||
                                       !string.IsNullOrWhiteSpace(_model.TessellationEvalualtionCode);
            var dlg    = new GLSLEditorDialog(_model, containsTessShaders, "Built-In");
            var parent = Rhino.UI.Runtime.PlatformServiceProvider.Service.GetEtoWindow(Grasshopper.Instances.DocumentEditor.Handle);

            _model.Modified = false;

            dlg.Closed += (s, e) =>
            {
                if (!dlg.Canceled)
                {
                    if (_model.Modified)
                    {
                        var doc = OnPingDocument();
                        doc?.Modified();
                    }
                }
                else
                {
                    _model.VertexShaderCode            = savedVS;
                    _model.GeometryShaderCode          = savedGS;
                    _model.FragmentShaderCode          = savedFS;
                    _model.TessellationControlCode     = savedTC;
                    _model.TessellationEvalualtionCode = savedTE;
                    _model.TransformFeedbackShaderCode = savedXfrmFeedbackVertex;
                }
                _model.Modified = false;
                //recompile shader if necessary
                if (_model.ProgramId == 0)
                {
                    ExpireSolution(true);
                }
                Rhino.Display.DisplayPipeline.PreDrawObjects -= DisplayPipeline_PreDrawObjects;
            };
            dlg.Title = this.NickName;
            dlg.Owner = parent;
            dlg.Show();
        }