Esempio n. 1
0
        public override void writeBinary(MOStream outstream)
        {
            MOStream instream = new MOStream(MOStream.getCPtr(outstream).Handle, false);

            MStreamUtils.writeDouble(outstream, fValue, true);
            return;
        }
Esempio n. 2
0
        public override void readBinary(MIStream arg0, uint length)
        {
            MIStream instream = new MIStream(MIStream.getCPtr(arg0).Handle, false);

            MStreamUtils.readDouble(arg0, out fValue, true);
            return;
        }
Esempio n. 3
0
        public override int write(Structure dataToWrite, MOStream cDst)
        {
            MStreamUtils.writeCharBuffer(cDst, "<?xml version='1.0' encoding='UTF-8'?>\n");

            // Start with the main structure tag containing the name
            string rootString = "<" + structureTag + " " + structureNameAttribute + "='" + dataToWrite.name + "'>\n";

            MStreamUtils.writeCharBuffer(cDst, rootString);

            // Write out each structure member in its own tag
            for (StructureIterator iterator = dataToWrite.begin(); iterator != dataToWrite.end(); iterator = iterator.next())
            {
                string memberString = "    <" + memberTag + " " + memberNameAttribute + "='" + iterator.memberName() + "'"
                                      + " " + memberTypeAttribute + "='" + Member.typeName(iterator.memberType()) + "'";

                if (iterator.memberLength() != 1)
                {
                    memberString = memberString + " " + memberDimAttribute + "='" + iterator.memberLength() + "'";
                }

                memberString += "/>\n";

                MStreamUtils.writeCharBuffer(cDst, memberString);
            }

            rootString = "</" + structureTag + ">";
            MStreamUtils.writeCharBuffer(cDst, rootString);
            return(0);
        }
Esempio n. 4
0
        public override void writeASCII(MOStream outstream)
        {
            MOStream instream = new MOStream(MOStream.getCPtr(outstream).Handle, false);

            MStreamUtils.writeDouble(outstream, fValue);
            MStreamUtils.writeChar(outstream, ' ');
            return;
        }
Esempio n. 5
0
        public override void doCreate()
        {
            Associations associationsRead = null;
            MIStream     inStream         = MStreamUtils.CreateIFStream(fileName);
            string       errors           = "";

            associationsRead = fSerialize.read(inStream, ref errors);
            if (associationsRead == null)
            {
                String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kImportMetadataFileReadFailed);
                String msg;
                if (errors == null || errors.Length < 1)
                {
                    errors = "No errors was given by the serializer when reading the metadata file.";
                }
                msg = String.Format(fmt, fileName, errors);
                displayError(msg);
                throw new System.ApplicationException(msg);
            }

            String resultFmt = MStringResource.getString(MetaDataRegisterMStringResources.kImportMetadataResult);

            for (int i = 0; i < fMeshes.length; ++i)
            {
                MFnMesh mesh = new MFnMesh(fMeshes[i]);
                // Should have filtered out non-meshes already but check anyway
                if (mesh == null)
                {
                    continue;
                }

                displayInfo(mesh.fullPathName);
                //We dont have the correct interface on MDGModifier to assign metadata so no undo redo for now
                Associations associationsMesh = mesh.metadata;
                associationsMesh.assign(associationsRead);

                for (int c = 0; c < associationsRead.channelCount; ++c)
                {
                    Autodesk.Maya.MetaData.Channel channel = associationsRead.channelAt((uint)c);
                    String cName = channel.nameProperty;
                    for (int s = 0; s < channel.dataStreamCount; ++s)
                    {
                        Autodesk.Maya.MetaData.Stream cStream = channel.dataStream((uint)s);
                        if (cStream != null)
                        {
                            String sName = cStream.name;
                            String msg   = String.Format(resultFmt, mesh.fullPathName, cName, sName);
                            appendToResult(msg);
                        }
                    }
                }
            }
            MStreamUtils.Close(inStream);
            inStream = null;
        }
Esempio n. 6
0
        private static void CurrentDomainOnUnhandledException(
            object sender,
            UnhandledExceptionEventArgs e)
        {
            // write the error the Output Window
            var error = MStreamUtils.stdErrorStream();

            MStreamUtils.writeCharBuffer(error, e.ExceptionObject + "\n");

            // write the error to the status bar
            MGlobal.displayError(e.ExceptionObject.ToString());
        }
Esempio n. 7
0
        public override void getFormatDescription(MOStream info)
        {
            string msgPre  = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLInfoPre);
            string msgPost = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLInfoPost);

            MStreamUtils.writeChar(info, msgPre[0]);

            for (uint i = (uint)Member.eDataType.kFirstType; i < (uint)Member.eDataType.kLastType; ++i)
            {
                if (i != (uint)Member.eDataType.kFirstType)
                {
                    MStreamUtils.writeCharBuffer(info, ", ");
                }
            }

            MStreamUtils.writeChar(info, msgPost[0]);
        }
Esempio n. 8
0
        public override void doCreate()
        {
            if (fMeshes.length != 1)
            {
                throw new System.ApplicationException("ExportMetadataCmd: do not support less or more then 1 mesh.");
            }
            MFnMesh mesh = new MFnMesh(fMeshes[0]);

            displayInfo(mesh.fullPathName);

            Associations associationsToWrite = mesh.metadata;

            if (associationsToWrite == null)
            {
                throw new System.ApplicationException("ExportMetadataCmd: no association to write.");
            }

            String errors = "";

            // Dump either to a file or the return string, depending on which was
            // requested.
            //
            MOStream destination = MStreamUtils.CreateOFStream(fileName);

            if (fSerialize.write(associationsToWrite, destination, ref errors) == 0)
            {
                setResult(fileName);
            }
            else
            {
                String msg = MStringResource.getString(MetaDataRegisterMStringResources.kExportMetadataFailedFileWrite);
                displayError(msg);
            }
            MStreamUtils.Close(destination);
            destination = null;

            if (errors != null && errors.Length > 0)
            {
                displayError(errors);
                return;
            }

            return;
        }
Esempio n. 9
0
        public override void redoIt()
        {
            MObject  dependNode   = new MObject();
            MOStream stdoutstream = MStreamUtils.stdOutStream();

            for (; !iter.isDone; iter.next())
            {
                // Get the selected dependency node and create
                // a function set for it
                //
                try
                {
                    iter.getDependNode(dependNode);
                }
                catch (System.Exception)
                {
                    MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error getting the dependency node");
                    continue;
                }

                MFnDependencyNode fnDN;
                try
                {
                    fnDN = new MFnDependencyNode(dependNode);
                }
                catch (System.Exception)
                {
                    MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error creating MFnDependencyNode");
                    continue;
                }

                MFnTypedAttribute fnAttr  = new MFnTypedAttribute();
                MObject           newAttr = fnAttr.create("blindDoubleData", "BDD", blindDoubleData.tid);

                try
                {
                    fnDN.addAttribute(newAttr, MFnDependencyNode.MAttrClass.kLocalDynamicAttr);
                }
                catch (System.Exception)
                {
                    // do nothing
                    // addAttribute only need call once, the redundant calls will return false (throw exception)
                }

                // Create a plug to set and retrieve value off the node.
                //
                MPlug plug = new MPlug(dependNode, newAttr);


                // ----------------------------------- Attention ------------------------------------
                // --------------------------------- Downcast Begin -----------------------------------
                // the following codes are used to get the c# object
                //
                MFnPluginData pdFnCreator = new MFnPluginData();

                // 1. you cannot gain blindDoubleData by the following code
                //    {code}
                //          blindDoubleData newData = new blindDoubleData()
                //    {code}
                //    As we need to keep the relationship between c# impl and c++ instance pointer
                //    We cannot use the above ctor codes, otherwise, the mandatory information used for down casting is omitted

                // 2. you cannot use the tempData gained by the following code
                //    {code}
                //          MObject tempData = pdFnCreator.create(blindDoubleData.tid);
                //    {code}
                //    reason:
                //          tempData is useless, we cannot use tempData to do downcast
                //          the create function gains the tempData by the following code
                //
                //          {code}
                //              newHandle = new MObject(mayaHandle);
                //          {code}
                //
                //     the mayaHandle is the actual pointer, which we store. But we have no information about the newHandle

                // the return object is useless. the data we needed is stored in pdFnCreator
                pdFnCreator.create(blindDoubleData.tid);

                // 3. get "the data" we needed
                blindDoubleData newData = pdFnCreator.data() as blindDoubleData;
                // ---------------------------------- Downcast End -----------------------------------
                if (newData == null)
                {
                    continue;
                }

                newData.value = 3.2;

                plug.setValue(newData);

                // Now try to retrieve the value of the plug as an MObject.
                //
                MObject sData = new MObject();

                try
                {
                    plug.getValue(sData);
                }
                catch (System.Exception)
                {
                    continue;
                }

                // Convert the data back to MPxData.
                //
                MFnPluginData pdFn = new MFnPluginData(sData);

                blindDoubleData data = pdFn.data() as blindDoubleData;

                // Get the value.
                //
                if (null == data)
                {
                    // error
                    MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "error: failed to retrieve data.");
                }
                MStreamUtils.writeLine(stdoutstream);
                MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData binary >>>>>>>>>>>>>>>>>>>>");
                MStreamUtils.writeLine(stdoutstream);
                data.writeBinary(stdoutstream);
                MStreamUtils.writeLine(stdoutstream);
                MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData ascii >>>>>>>>>>>>>>>>>>>>");
                MStreamUtils.writeLine(stdoutstream);
                data.writeASCII(stdoutstream);
            }
            return;
        }
Esempio n. 10
0
        public override Structure read(MIStream cSrc, ref string errors)
        {
            int       errCount     = 0;
            Structure newStructure = null;

            errors = "";

            uint   size     = MStreamUtils.getLength(cSrc);
            string myString = "";

            // The last argument is true since we don't want to stop reading a stream when a WhiteSpace is encountered.
            MStreamUtils.readCharBuffer(cSrc, out myString, size, true);

            XmlReader reader      = XmlReader.Create(new System.IO.StringReader(myString));
            string    elementName = "";

            while (reader.Read())
            {
                // Skip anything unrecognized, for maximum flexibility
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                elementName = reader.Name;

                // Root must be a <structure> tag
                if (elementName == structureTag)
                {
                    bool isStrucNameFound = reader.MoveToAttribute(structureNameAttribute);
                    if (isStrucNameFound)
                    {
                        string structureName = reader.ReadContentAsString();
                        newStructure = new Structure(structureName);
                    }
                    else
                    {
                        string       msgFmt     = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLStructureNameNotFound);
                        IXmlLineInfo xmlInfo    = (IXmlLineInfo)reader;
                        int          lineNumber = xmlInfo.LineNumber;
                        string       errorMsg   = String.Format(msgFmt, lineNumber.ToString());

                        errors += errorMsg;
                        errCount++;
                        continue;
                    }
                }

                if (newStructure == null)
                {
                    continue;
                }

                // All children must all be <member> tags
                if (elementName == memberTag)
                {
                    uint   memberDim  = 1;
                    string memberName = "";
                    string memberType = "";

                    bool isMemberNameFound = reader.MoveToAttribute(memberNameAttribute);
                    if (isMemberNameFound)
                    {
                        memberName = reader.ReadContentAsString();
                    }
                    else
                    {
                        string       msgFmt     = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLMemberNameNotFound);
                        IXmlLineInfo xmlInfo    = (IXmlLineInfo)reader;
                        int          lineNumber = xmlInfo.LineNumber;
                        string       errorMsg   = String.Format(msgFmt, lineNumber.ToString());
                        errors += errorMsg;
                        continue;
                    }
                    bool isMemberTypeFound = reader.MoveToAttribute(memberTypeAttribute);
                    if (isMemberTypeFound)
                    {
                        memberType = reader.ReadContentAsString();
                    }
                    else
                    {
                        string       msgFmt     = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLMemberTypeNotFound);
                        IXmlLineInfo xmlInfo    = (IXmlLineInfo)reader;
                        int          lineNumber = xmlInfo.LineNumber;
                        string       errorMsg   = String.Format(msgFmt, lineNumber.ToString());
                        errors += errorMsg;
                        continue;
                    }

                    bool isMemberDimFound = reader.MoveToAttribute(memberDimAttribute);
                    if (isMemberDimFound)
                    {
                        memberDim = (uint)reader.ReadContentAsInt();
                    }
                    else
                    {
                        memberDim = 1;
                    }

                    newStructure.addMember(Member.typeFromName(memberType), memberDim, memberName);
                }
            }

            // If there were errors any structure created will be incorrect so pass
            // back nothing rather than bad data.
            if (errCount > 0)
            {
                newStructure = null;
            }

            return(newStructure);
        }