예제 #1
0
        private static void OnGetVirtual3DVector(int serialNumber, int propertyId, bool fromBaseClass, ref Vector3d value)
        {
            try
            {
                var texture = FromSerialNumber(serialNumber) as RenderTexture;
                if (texture == null)
                {
                    return;
                }
                var const_pointer = texture.ConstPointer();
                if (fromBaseClass)
                {
                    UnsafeNativeMethods.Rdk_RenderTexture_GetVirtual3dVector(const_pointer, propertyId, true, ref value);
                    return;
                }
                switch (propertyId)
                {
                case REPEAT_MODE:
                    value = texture.GetRepeat();
                    return;

                case OFFSET_MODE:
                    value = texture.GetOffset();
                    return;

                case ROTATION_MODE:
                    value = texture.GetRotation();
                    return;
                }
            }
            catch (Exception exception)
            {
                HostUtils.ExceptionReport(exception);
            }
        }
예제 #2
0
        private static void OnSetVirtual3DVector(int serialNumber, int propertyId, bool callBaseClass, Vector3d value, int changeContext)
        {
            try
            {
                var texture = FromSerialNumber(serialNumber) as RenderTexture;
                if (texture == null)
                {
                    return;
                }
                if (callBaseClass)
                {
                    var pointer = texture.NonConstPointer();
                    UnsafeNativeMethods.Rdk_RenderTexture_SetVirtual3dVector(pointer, propertyId, true, value, changeContext);
                    return;
                }
                switch (propertyId)
                {
                case REPEAT_MODE:
                    texture.SetRepeat(value, (ChangeContexts)changeContext);
                    return;

                case OFFSET_MODE:
                    texture.SetOffset(value, (ChangeContexts)changeContext);
                    return;

                case ROTATION_MODE:
                    texture.SetRotation(value, (ChangeContexts)changeContext);
                    return;
                }
            }
            catch (Exception exception)
            {
                HostUtils.ExceptionReport(exception);
            }
        }
        /// <summary>
        /// For derived class implementers.
        /// <para>This method is called with argument true when class user calls Dispose(), while with argument false when
        /// the Garbage Collector invokes the finalizer, or Finalize() method.</para>
        /// <para>You must reclaim all used unmanaged resources in both cases, and can use this chance to call Dispose on disposable fields if the argument is true.</para>
        /// <para>Also, you must call the base virtual method within your overriding method.</para>
        /// </summary>
        /// <param name="disposing">true if the call comes from the Dispose() method; false if it comes from the Garbage Collector finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (IntPtr.Zero == m_ptr || m__parent is ConstCastHolder)
            {
                return;
            }

            Geometry.MeshHolder mh = m__parent as Geometry.MeshHolder;
            if (mh != null)
            {
                mh.ReleaseMesh();
            }

            if (m_bDestructOnDispose)
            {
                bool in_finalizer = !disposing;
                if (in_finalizer)
                {
                    // 11 Feb 2013 (S. Baer) RH-16157
                    // When running in the finalizer, the destructor is being called on the GC
                    // thread which results in nearly impossible to track down exceptions.
                    // Mask the exception in this case and post information to our logging system
                    // about the exception so we can better analyze and try to figure out what
                    // is going on
                    try
                    {
                        UnsafeNativeMethods.ON_Object_Delete(m_ptr);
                    }
                    catch (Exception ex)
                    {
                        HostUtils.ExceptionReport(ex);
                    }
                }
                else
                {
                    // See above. In this case we are running on the main thread of execution
                    // and throwing an exception is a good thing so we can analyze and quickly
                    // fix whatever is going wrong
                    UnsafeNativeMethods.ON_Object_Delete(m_ptr);
                }
                if (m_unmanaged_memory > 0)
                {
                    GC.RemoveMemoryPressure(m_unmanaged_memory);
                }
            }
            m_ptr      = IntPtr.Zero;
            m_disposed = true;
        }
예제 #4
0
 static void OnSimulateEnvironment(int serial_number, IntPtr pSim, int bDataOnly)
 {
     try
     {
         var texture = FromSerialNumber(serial_number) as RenderEnvironment;
         if (texture != null)
         {
             if (pSim != IntPtr.Zero)
             {
                 var sim = new SimulatedEnvironment(pSim);
                 texture.SimulateEnvironment(ref sim, 1 == bDataOnly);
             }
         }
     }
     catch (Exception exception)
     {
         HostUtils.ExceptionReport(exception);
     }
 }
예제 #5
0
        static void OnSetVirtualInt(int serialNumber, int propertyId, bool callBaseClass, int value, int changeContext)
        {
            try
            {
                var texture = FromSerialNumber(serialNumber) as RenderTexture;
                if (texture == null)
                {
                    return;
                }
                if (callBaseClass)
                {
                    var pointer = texture.NonConstPointer();
                    UnsafeNativeMethods.Rdk_RenderTexture_SetVirtualIntValue(pointer, propertyId, true, value, changeContext);
                    return;
                }
                switch (propertyId)
                {
                case PROJECTION_MODE:
                    texture.SetProjectionMode((TextureProjectionMode)value, (ChangeContexts)changeContext);
                    break;

                case WRAP_TYPE_MODE:
                    texture.SetWrapType((TextureWrapType)value, (ChangeContexts)changeContext);
                    break;

                case REPEAT_LOCKED_MODE:
                    texture.SetRepeatLocked(value != 0, (ChangeContexts)changeContext);
                    break;

                case OFFSET_LOCKED_MODE:
                    texture.SetOffsetLocked(value != 0, (ChangeContexts)changeContext);
                    break;

                case PREVIEW_IN_3D_MODE:
                    texture.SetPreviewIn3D(value != 0, (ChangeContexts)changeContext);
                    break;
                }
            }
            catch (Exception exception)
            {
                HostUtils.ExceptionReport(exception);
            }
        }
예제 #6
0
 static void OnSimulateTexture(int serialNumber, IntPtr pSim, int bDataOnly)
 {
     try
     {
         RenderTexture texture = FromSerialNumber(serialNumber) as RenderTexture;
         if (texture != null)
         {
             if (pSim != IntPtr.Zero)
             {
                 SimulatedTexture sim = new SimulatedTexture(pSim);
                 texture.SimulateTexture(ref sim, 1 == bDataOnly);
             }
         }
     }
     catch (Exception exception)
     {
         HostUtils.ExceptionReport(exception);
     }
 }
예제 #7
0
        /// <summary>
        /// Deletes the underlying native pointer during a Dispose call or GC collection
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            DestroySubDDisplay();
            ReleaseNonConstPointer();

            IntPtr subd_ref_ptr = m_ptr_subd_ref;

            m_ptr_subd_ref = IntPtr.Zero;

            if (IntPtr.Zero != subd_ref_ptr)
            {
                bool in_finalizer = !disposing;
                if (in_finalizer)
                {
                    // 11 Feb 2013 (S. Baer) RH-16157
                    // When running in the finalizer, the destructor is being called on the GC
                    // thread which results in nearly impossible to track down exceptions.
                    // Mask the exception in this case and post information to our logging system
                    // about the exception so we can better analyze and try to figure out what
                    // is going on
                    try
                    {
                        UnsafeNativeMethods.ON_SubDRef_Delete(subd_ref_ptr);
                    }
                    catch (Exception ex)
                    {
                        HostUtils.ExceptionReport(ex);
                    }
                }
                else
                {
                    // See above. In this case we are running on the main thread of execution
                    // and throwing an exception is a good thing so we can analyze and quickly
                    // fix whatever is going wrong
                    UnsafeNativeMethods.ON_SubDRef_Delete(subd_ref_ptr);
                }
            }

            base.Dispose(disposing);
        }
예제 #8
0
        static int OnGetVirtualInt(int serialNumber, int propertyId, bool fromBaseClass)
        {
            try
            {
                var texture = FromSerialNumber(serialNumber) as RenderTexture;
                if (texture == null)
                {
                    return(-1);
                }
                if (fromBaseClass)
                {
                    return(UnsafeNativeMethods.Rdk_RenderTexture_GetVirtualIntValue(texture.ConstPointer(), propertyId, true));
                }
                switch (propertyId)
                {
                case PROJECTION_MODE:
                    return((int)texture.GetProjectionMode());

                case WRAP_TYPE_MODE:
                    return((int)texture.GetWrapType());

                case REPEAT_LOCKED_MODE:
                    return(texture.GetRepeatLocked() ? 1 : 0);

                case OFFSET_LOCKED_MODE:
                    return(texture.GetOffsetLocked() ? 1 : 0);

                case PREVIEW_IN_3D_MODE:
                    return(texture.GetPreviewIn3D() ? 1 : 0);
                }
                return(-1);
            }
            catch (Exception exception)
            {
                HostUtils.ExceptionReport(exception);
            }
            return(-1);
        }
예제 #9
0
        private static void ExecConduit(IntPtr pPipeline, uint conduitSerialNumber, uint channel)
        {
            if (_enabledConduits.TryGetValue(conduitSerialNumber, out DisplayConduit conduit) && conduit != null)
            {
                try
                {
                    switch (channel)
                    {
                    case (uint)CSupportChannels.SC_CALCBOUNDINGBOX:
                        conduit._CalculateBoundingBox(null, new CalculateBoundingBoxEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_CALCCLIPPINGPLANES:
                        break;

                    case (uint)CSupportChannels.SC_DRAWBACKGROUND:
                        break;

                    case (uint)CSupportChannels.SC_DRAWFOREGROUND:
                        conduit._DrawForeground(null, new DrawEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_DRAWOBJECT:
                        conduit._PreDrawObject(null, new DrawObjectEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_DRAWOVERLAY:
                        conduit._DrawOverlay(null, new DrawEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_INITFRAMEBUFFER:
                        break;

                    case (uint)CSupportChannels.SC_MESHINGPARAMETERS:
                        break;

                    case (uint)CSupportChannels.SC_OBJECTCULLING:
                        conduit._ObjectCulling(null, new CullObjectEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_OBJECTDISPLAYATTRS:
                        break;

                    case (uint)CSupportChannels.SC_POSTDRAWOBJECTS:
                        conduit._PostDrawObjects(null, new DrawEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_POSTOBJECTDRAW:
                        break;

                    case (uint)CSupportChannels.SC_POSTPROCESSFRAMEBUFFER:
                        break;

                    case (uint)CSupportChannels.SC_PREDRAWMIDDLEGROUND:
                        break;

                    case (uint)CSupportChannels.SC_PREDRAWOBJECTS:
                        conduit._PreDrawObjects(null, new DrawEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    case (uint)CSupportChannels.SC_PREDRAWTRANSPARENTOBJECTS:
                        break;

                    case (uint)CSupportChannels.SC_PREOBJECTDRAW:
                        break;

                    case (uint)CSupportChannels.SC_SETUPFRUSTUM:
                        break;

                    case (uint)CSupportChannels.SC_SETUPLIGHTING:
                        break;

                    case (uint)CSupportChannels.SC_VIEWEXTENTS:
                        conduit._CalculateBoundingBoxZoomExtents(null, new CalculateBoundingBoxEventArgs(pPipeline, conduitSerialNumber));
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    HostUtils.ExceptionReport("DisplayConduit", ex);
                }
            }
        }
예제 #10
0
            public int Compare(string x, string y)
            {
                bool xExists = File.Exists(x);
                bool yExists = File.Exists(y);

                if (!xExists && !yExists)
                {
                    return(0);
                }

                if (!xExists)
                {
                    return(+1);
                }
                if (!yExists)
                {
                    return(-1);
                }

                // This can be made a lot smarter with substring searches.
                string xFileName = Path.GetFileName(x);
                string yFileName = Path.GetFileName(y);

                int xIndex = xFileName == null ? -1 : xFileName.IndexOf(m_search, StringComparison.OrdinalIgnoreCase);
                int yIndex = yFileName == null ? -1 : yFileName.IndexOf(m_search, StringComparison.OrdinalIgnoreCase);

                // 4 April 2012 - S. Baer
                // If the file names are the same, the highest version number or most
                // recent file date is sorted to the top.  Plug-ins like PanelingTools
                // have historically moved around on where they are installed on a user's
                // computer, so we may end up with duplicates
                if (xIndex >= 0 && yIndex >= 0 && string.Compare(xFileName, yFileName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    try
                    {
                        // 25 August 2015 - David Rutten:
                        // Error reports:
                        // http://mcneel.myjetbrains.com/youtrack/issue/RH-30818
                        // https://app.raygun.io/dashboard/6bsfxg/errors/561473847
                        // seem to originate on one of the ReflectionOnlyLoadFrom calls below,
                        // but they're already in a try_catch block. I'm really not sure how to
                        // determine whether an assembly will load prior to loading it.

                        // 3 Oct 2017 - S. Baer (RH-35794)
                        // Reflection loading two assemblies into the same appdomain is asking for exceptions
                        // Luckily, there is another way... Use AssemblyName.GetAssemblyName

                        var     xAssemblyName = AssemblyName.GetAssemblyName(x);
                        var     yAssemblyName = AssemblyName.GetAssemblyName(y);
                        Version xVersion      = xAssemblyName.Version;
                        Version yVersion      = yAssemblyName.Version;
                        int     rc            = xVersion.CompareTo(yVersion);
                        if (rc != 0)
                        {
                            return(rc);
                        }

                        // Same version. Try using the file date
                        FileInfo xInfo = new FileInfo(x);
                        FileInfo yInfo = new FileInfo(y);
                        rc = xInfo.LastAccessTimeUtc.CompareTo(yInfo.LastAccessTimeUtc);
                        if (rc != 0)
                        {
                            return(rc);
                        }
                    }
                    catch (Exception ex)
                    {
                        HostUtils.ExceptionReport("duplicate assembly resolve", ex);
                    }
                }

                if (xIndex < 0)
                {
                    xIndex = int.MaxValue;
                }
                if (yIndex < 0)
                {
                    yIndex = int.MaxValue;
                }
                return(xIndex.CompareTo(yIndex));
            }
예제 #11
0
        private static void UnpackScriptResources()
        {
            if (g_resources_unpacked)
            {
                return;
            }
            Guid python_plugin_id = new Guid("814d908a-e25c-493d-97e9-ee3861957f49");
            var  plugin           = Rhino.PlugIns.PlugIn.Find(python_plugin_id);

            if (plugin == null)
            {
                return;
            }

            g_resources_unpacked = true;

            // Unpack ghcomponents.py to the Python plug directory
            string settings_directory = plugin.SettingsDirectory;
            string marker_file        = Path.Combine(settings_directory, "ghpy_version.txt");

            try
            {
                if (File.Exists(marker_file))
                {
                    string  text          = File.ReadAllText(marker_file);
                    Version markedversion = new Version(text);
                    Version this_version  = typeof(ZuiPythonComponent).Assembly.GetName().Version;
                    if (markedversion == this_version)
                    {
#if !DEBUG
                        // everything looks good, bail out
                        return;
#endif
                    }
                }
            }
            catch (Exception ex)
            {
                HostUtils.ExceptionReport(ex);
            }

            try
            {
                // if we get to here, we need to unpack the resources
                if (!Directory.Exists(settings_directory))
                {
                    Directory.CreateDirectory(settings_directory);
                }
                string ghpython_package_dir = Path.Combine(settings_directory, "lib", PythonEnvironment.GHPYTHONLIB_NAME);
                if (Directory.Exists(ghpython_package_dir))
                {
                    Directory.Delete(ghpython_package_dir, true);
                }
                Directory.CreateDirectory(ghpython_package_dir);
                System.Reflection.Assembly a = typeof(ZuiPythonComponent).Assembly;
                string[] names = a.GetManifestResourceNames();

                const string prefix = "GhPython.package.";

                foreach (string name in names)
                {
                    if (!name.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    Stream resource_stream = a.GetManifestResourceStream(name);
                    if (resource_stream == null)
                    {
                        continue;
                    }
                    StreamReader stream = new StreamReader(resource_stream);
                    string       s      = stream.ReadToEnd();
                    stream.Close();
                    string filename = name.Replace(prefix, "");
                    string path     = Path.Combine(ghpython_package_dir, filename);
                    File.WriteAllText(path, s);
                }

                // Write the marker file at the very end to ensure that we actually got to this point.
                // If an exception occured for some reason like a file was in use, then the plug-in
                // will just attempt to unpack the resources next time.
                string str = a.GetName().Version.ToString();
                File.WriteAllText(marker_file, str);
            }
            catch (Exception ex)
            {
                HostUtils.DebugString("Exception while unpacking resources: " + ex.Message);
            }
        }