예제 #1
0
        public static Object get_value_from_descriptor(PhotoshopTypeLibrary.IActionDescriptor desc, int prop_id)
        {
            ///
            ///<summary>
            ///
            /// Given a descriptor and a propid, will return an Object containing
            /// the value
            ///
            /// If there is no prop_id, then returns null
            ///
            /// Workitem: this should really return an exception if the property doesn't
            /// exist or it should return an additional error code.
            ///
            ///</summary>
            ///


            if (!PSX.desc_has_key(desc, prop_id))
            {
                // If the descriptor does not contain the key, return null
                return(null);
            }

            // Stores the object being returned
            Object o = null;

            // Determine the type of the object
            int type = 0;

            type = get_type_from_descriptor(desc, prop_id);

            if (type == (int)con.phTypeChar)
            {
                string v;
                desc.GetString(prop_id, out v);
                o = (string)v;
            }
            else if (type == (int)con.phTypeInteger)
            {
                int v;
                desc.GetInteger(prop_id, out v);
                o = v;
            }
            else if (type == (int)con.phTypeFloat)
            {
                double v;
                desc.GetDouble(prop_id, out v);
                o = v;
            }
            else if (type == (int)con.phTypeBoolean)
            {
                int v;
                desc.GetBoolean(prop_id, out v);
                o = v;
            }
            else if (type == (int)con.phTypeUnitFloat)
            {
                // WORKITEM: Return an array instead
                int    unit_id;
                double v;
                desc.GetUnitDouble(prop_id, out unit_id, out v);
                o = v;
            }
            else if (type == (int)con.phTypeEnumerated)
            {
                // WORKITEM: Return an array instead
                int enum_type;
                int enum_value;
                desc.GetEnumerated(prop_id, out enum_type, out enum_value);
                o = enum_value;
            }
            else if (type == (int)con.phTypeObject)
            {
                // WORKITEM: Return an array instead
                int class_id;
                PhotoshopTypeLibrary.IActionDescriptor v;
                desc.GetObject(prop_id, out class_id, out v);
                o = v;
            }
            else if (type == (int)con.phTypePath)
            {
                string v;
                desc.GetPath(prop_id, out v);
                o = v;
            }
            else
            {
                string type_name = GetNameFromTypeID(type);
                string msg       = "Unsupported type " + type_name;
                var    e         = new Photoshop6OM.PhotoshoProxyError(msg);
                throw (e);
            }


            return(o);
        }
예제 #2
0
        public static void dump_descriptor(PhotoshopTypeLibrary.IActionDescriptor desc1, int indent)
        {
            string indent_text = "  ";
            int    num_items;

            desc1.GetCount(out num_items);

            log.WriteLine("Descriptor ({0} items)", num_items);
            for (int i = 0; i < num_items; i++)
            {
                int child_key;
                int child_type;

                desc1.GetKey(i, out child_key);
                desc1.GetType(child_key, out child_type);

                string indent_str = " ";///commoncs.libstring.Multiply(indent_text, indent + 1);

                log.Write(indent_str);
                log.Write("[{0}] ", i.ToString());
                log.WriteLine(" ( {0} ) ", PSX.IDToStr(child_type));

                log.Write(indent_str + "-");

                if (child_type == (int)con.phTypeObject)
                {
                    PhotoshopTypeLibrary.IActionDescriptor child_desc;
                    int child_class_id;

                    desc1.GetObject(child_key, out child_class_id, out child_desc);

                    string sss = string.Format(" ( {0} ) ( {1} ) ", PSX.IDToStr(child_key), PSX.IDToStr(child_class_id));
                    log.WriteLine(sss);

                    PSX.dump_descriptor(child_desc, indent + 1);
                }
                else if (child_type == (int)con.phTypeObjectReference)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)con.phTypeText)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)con.phTypeBoolean)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)con.phTypeEnumerated)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)con.phTypeType)
                {
                    log.WriteLine("<handled type>");
                }
                else if (child_type == (int)con.phTypePath)
                {
                    log.WriteLine("<handled type>");
                }
                else
                {
                    log.WriteLine("<unhandled type>");
                }
            }
        }
예제 #3
0
        public static void PlayEvent(int event_id, PhotoshopTypeLibrary.IActionDescriptor parameter_desc, int show_ui, PlayBehavior action)
        {
            /*event_id - the event to play
             * parameter_descriptor - a descriptor containing the parameters for the event
             * dialog_options - whether to show UI or not
             * action - the kind of error checking to use. Possilble values are checkresult,checknonresult, and checknone
             *
             *
             * checkresult and checknonresult will cause
             * ExtensionError exceptions to be thrown if Photoshop
             * says there is an error. Regardless of the value used
             * for action, a number of ExtensionError exceptions may
             * be thrown.
             *
             */

            string event_id_str = GetNameFromEventID(event_id);

            //self.log.Header( "Play %s (0x%d) " % (event_id_str, event_id ) )


            PhotoshopTypeLibrary.IActionDescriptor result_desc = m_control.Play(event_id, parameter_desc, show_ui);

            // phKeyMessage may be present and contain more information about the event
            // store the value in msg
            string msg = null;


            if (result_desc != null)
            {
                object msg_o = get_value_from_descriptor(result_desc, (int)con.phKeyMessage);
                msg = (string)msg_o;;

                dump_descriptor(result_desc, 0);
            }

            bool success = false;

            // Depending on the action there are different criterias for success
            if (action == PlayBehavior.checkresult)
            {
                // Succes is one of the following:
                // - Play() did not return a descriptor
                // - Play() did return a descriptor and that did not contain phKeyMessage
                success = ((result_desc == null) || ((result_desc != null) && (msg == null)));
            }
            else if (action == PlayBehavior.checknonresult)
            {
                // Success is:
                // - Play() did return a descriptor and there is a message
                success = ((result_desc != null) && (msg != null));
            }
            else
            {
                // action == self.checknone ) :
                // Whatever happened is success
                // checknone is for temporary code, callers should end up using checkresult or checknonresult
                success = true;
            }

            if (!success)
            {
                string error_msg = "Photoshop ExtensionError: Failure on Event " + event_id_str;
                if (msg != null)
                {
                    error_msg += msg;
                    var e = new Photoshop6OM.PhotoshoProxyError(error_msg);
                    throw (e);
                }
            }

            //self.log.Header( "PLAY" )
            //self.DumpDescriptor( result_desc, 0)
        }