[cgkit-commits] maya/maya_wrapper/src_aux mdatahandle.cpp,NONE,1.1 mdatahandle.h,NONE,1.1 mitselecti
Brought to you by:
mbaas
From: Matthias B. <mb...@us...> - 2006-04-05 07:43:40
|
Update of /cvsroot/cgkit/maya/maya_wrapper/src_aux In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19297 Modified Files: creatorfuncmanager.cpp creatorfuncmanager.h mfnplugin.cpp mfnplugin.h Added Files: mdatahandle.cpp mdatahandle.h mitselectionlist.cpp mitselectionlist.h mplug.cpp mplug.h mpointarray.cpp mpointarray.h mselectionlist.cpp mselectionlist.h mvectorarray.cpp mvectorarray.h Log Message: 1) Updated the plugin function set so that all required creator functions can be implemented in Python 2) Added some more customizations to particular classes. Index: mfnplugin.cpp =================================================================== RCS file: /cvsroot/cgkit/maya/maya_wrapper/src_aux/mfnplugin.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mfnplugin.cpp 23 Mar 2006 10:44:52 -0000 1.1 --- mfnplugin.cpp 5 Apr 2006 07:43:28 -0000 1.2 *************** *** 25,62 **** #include "mfnplugin.h" ! static const unsigned int MAX_CREATOR_FUNCTIONS = 100; ! //static object pycreatorfuncs[MAX_CREATOR_FUNCTIONS]; ! void* createFunc000() { ! return 0; ! } ! typedef void* (*CreatorFunc)(); ! class CreatorFuncManager ! { ! public: ! CreatorFuncManager() {} ! CreatorFunc acquireCFunc(object callable) { ! return createFunc000; } - void releaseCFunc(CreatorFunc cfunc) {} - }; ! static CreatorFuncManager creatorfuncmanager; ! // MFnPlugin methods: ! namespace pyMFnPlugin ! { ! // registerFileTranslator method ! MStatus registerFileTranslator(MFnPlugin& self, const MString& translateName, char* pixmapName, object creatorFunction, char* optionsScriptName, char* defaultOptionsString, bool requiresFullMel) { ! CreatorFunc func = creatorfuncmanager.acquireCFunc(creatorFunction); ! return self.registerFileTranslator(translateName, pixmapName, func, optionsScriptName, defaultOptionsString, requiresFullMel); } } --- 25,117 ---- #include "mfnplugin.h" + #include "creatorfuncmanager.h" + #include <iostream> ! static CreatorFuncManager creatorfuncmanager; ! // MFnPlugin methods: ! namespace pyMFnPlugin { ! // registerCommand method ! // createSyntaxFunction may be None. ! tuple registerCommand(MFnPlugin& self, const MString& commandName, object creatorFunction, object createSyntaxFunction) ! { ! // Acquire a C creator function... ! CreatorFunc cfunc = creatorfuncmanager.acquireCFunc(creatorFunction); ! if (cfunc==0) ! { ! return boost::python::make_tuple(MStatus::kFailure, 0, 0); ! } ! // Acquare a C syntax creator (if the function is not None)... ! CreateSyntaxFunc csfunc = 0; ! if (createSyntaxFunction!=object()) ! { ! csfunc = creatorfuncmanager.acquireCSFunc(createSyntaxFunction); ! if (csfunc==0) ! { ! creatorfuncmanager.releaseCFunc(cfunc); ! return boost::python::make_tuple(MStatus::kFailure, 0, 0); ! } ! } ! return boost::python::make_tuple( ! self.registerCommand(commandName, cfunc, csfunc), ! (long)cfunc, (long)csfunc); ! } ! // registerFileTranslator method ! tuple registerFileTranslator(MFnPlugin& self, const MString& translatorName, char* pixmapName, object creatorFunction, char* optionsScriptName, char* defaultOptionsString, bool requiresFullMel) ! { ! CreatorFunc func = creatorfuncmanager.acquireCFunc(creatorFunction); ! if (func==0) ! { ! return boost::python::make_tuple(MStatus::kFailure, 0); ! } ! return boost::python::make_tuple( ! self.registerFileTranslator(translatorName, pixmapName, func, optionsScriptName, defaultOptionsString, requiresFullMel), ! (long)func); ! } ! // registerNode method ! tuple registerNode(MFnPlugin& self, const MString& typeName, const MTypeId& typeId, object creatorFunction, object initFunction, MPxNode::Type type, const MString* classification) { ! CreatorFunc cfunc = creatorfuncmanager.acquireCFunc(creatorFunction); ! if (cfunc==0) ! { ! return boost::python::make_tuple(MStatus::kFailure, 0, 0); ! } ! InitFunc initfunc = creatorfuncmanager.acquireInitFunc(initFunction); ! if (initfunc==0) ! { ! creatorfuncmanager.releaseCFunc(cfunc); ! return boost::python::make_tuple(MStatus::kFailure, 0, 0); ! } ! ! return boost::python::make_tuple( ! self.registerNode(typeName, typeId, cfunc, initfunc, type, classification), ! (long)cfunc, (long)initfunc); } ! // Invoke the releaseCFunc() method of the CreatorFuncManager object. ! // handle is the actual function reference as long (or 0 in which case ! // the functions return immediately). ! // This function must not be called when the corresponding plugin class ! // is still in use! ! bool _releaseCreatorFunc(MFnPlugin& self, long handle) ! { ! if (handle!=0) ! return creatorfuncmanager.releaseCFunc((CreatorFunc)handle); ! } ! bool _releaseCreateSyntaxFunc(MFnPlugin& self, long handle) { ! if (handle!=0) ! return creatorfuncmanager.releaseCSFunc((CreateSyntaxFunc)handle); } + bool _releaseInitFunc(MFnPlugin& self, long handle) + { + if (handle!=0) + return creatorfuncmanager.releaseInitFunc((InitFunc)handle); + } } --- NEW FILE: mpointarray.cpp --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MPointArray class. */ #include <sstream> #include "mpointarray.h" namespace pyMPointArray { // get() method returning a list boost::python::list get1(MPointArray& self) { boost::python::list res; for(unsigned int i=0; i<self.length(); i++) { MPoint& p = self[i]; res.append(boost::python::make_tuple(p.x, p.y, p.z, p.w)); } return res; } // get() method filling a user-provided list void get2(MPointArray& self, boost::python::list lst) { // Delete any existing element.. lst.slice(boost::python::_, boost::python::_) = boost::python::list(); // Fill the list... for(unsigned int i=0; i<self.length(); i++) { MPoint& p = self[i]; lst.append(boost::python::make_tuple(p.x, p.y, p.z, p.w)); } } // __setitem__ method void __setitem__(MPointArray& self, int key, MPoint& val) { self.set(val, key); } // __str__ method boost::python::str __str__(MPointArray& self) { std::ostringstream s; s<<self; return boost::python::str(s.str()); } } --- NEW FILE: mpointarray.h --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MPointArray class. */ #include <boost/python.hpp> #include <maya/MPointArray.h> namespace pyMPointArray { boost::python::list get1(MPointArray& self); void get2(MPointArray& self, boost::python::list lst); void __setitem__(MPointArray& self, int key, MPoint& val); boost::python::str __str__(MPointArray& self); } --- NEW FILE: mitselectionlist.h --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MItSelectionList class. */ #include <boost/python.hpp> #include <maya/MItSelectionList.h> using boost::python::object; namespace pyMItSelectionList { boost::python::str __str__(MItSelectionList& self); } Index: mfnplugin.h =================================================================== RCS file: /cvsroot/cgkit/maya/maya_wrapper/src_aux/mfnplugin.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mfnplugin.h 23 Mar 2006 10:44:52 -0000 1.1 --- mfnplugin.h 5 Apr 2006 07:43:28 -0000 1.2 *************** *** 28,36 **** using boost::python::object; namespace pyMFnPlugin { ! MStatus registerFileTranslator(MFnPlugin& self, const MString& translateName, char* pixmapName, object creatorFunction, char* optionsScriptName, char* defaultOptionsString, bool requiresFullMel); } --- 28,44 ---- using boost::python::object; + using boost::python::tuple; namespace pyMFnPlugin { + bool _releaseCreatorFunc(MFnPlugin& self, long handle); + bool _releaseCreateSyntaxFunc(MFnPlugin& self, long handle); + bool _releaseInitFunc(MFnPlugin& self, long handle); ! tuple registerCommand(MFnPlugin& self, const MString& commandName, object creatorFunction, object createSyntaxFunction); ! ! tuple registerFileTranslator(MFnPlugin& self, const MString& translatorName, char* pixmapName, object creatorFunction, char* optionsScriptName, char* defaultOptionsString, bool requiresFullMel); ! ! tuple registerNode(MFnPlugin& self, const MString& typeName, const MTypeId& typeId, object creatorFunction, object initFunction, MPxNode::Type type, const MString* classification); } --- NEW FILE: mvectorarray.cpp --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MVectorArray class. */ #include <sstream> #include "mvectorarray.h" namespace pyMVectorArray { // get() method returning a list boost::python::list get1(MVectorArray& self) { boost::python::list res; for(unsigned int i=0; i<self.length(); i++) { MVector& v = self[i]; res.append(boost::python::make_tuple(v.x, v.y, v.z)); } return res; } // get() method filling a user-provided list void get2(MVectorArray& self, boost::python::list lst) { // Delete any existing element.. lst.slice(boost::python::_, boost::python::_) = boost::python::list(); // Fill the list... for(unsigned int i=0; i<self.length(); i++) { MVector& v = self[i]; lst.append(boost::python::make_tuple(v.x, v.y, v.z)); } } // __setitem__ method void __setitem__(MVectorArray& self, int key, MVector& val) { self.set(val, key); } // __str__ method boost::python::str __str__(MVectorArray& self) { std::ostringstream s; s<<self; return boost::python::str(s.str()); } } --- NEW FILE: mselectionlist.h --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MSelectionList class. */ #include <boost/python.hpp> #include <maya/MSelectionList.h> using boost::python::object; namespace pyMSelectionList { boost::python::str __str__(MSelectionList& self); } --- NEW FILE: mdatahandle.h --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MDataHandle class. */ #include <boost/python.hpp> #include <maya/MDataHandle.h> using boost::python::object; using boost::python::tuple; namespace pyMDataHandle { bool asBool(MDataHandle& self); int asChar(MDataHandle& self); int asUChar(MDataHandle& self); int asShort(MDataHandle& self); int asLong(MDataHandle& self); int asInt(MDataHandle& self); double asFloat(MDataHandle& self); double asDouble(MDataHandle& self); tuple asShort2(MDataHandle& self); tuple asLong2(MDataHandle& self); tuple asInt2(MDataHandle& self); tuple asFloat2(MDataHandle& self); tuple asDouble2(MDataHandle& self); tuple asShort3(MDataHandle& self); tuple asLong3(MDataHandle& self); tuple asInt3(MDataHandle& self); tuple asFloat3(MDataHandle& self); tuple asDouble3(MDataHandle& self); MString asString(MDataHandle& self); } Index: creatorfuncmanager.h =================================================================== RCS file: /cvsroot/cgkit/maya/maya_wrapper/src_aux/creatorfuncmanager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** creatorfuncmanager.h 30 Mar 2006 07:38:19 -0000 1.1 --- creatorfuncmanager.h 5 Apr 2006 07:43:28 -0000 1.2 *************** *** 21,27 **** #include <boost/python.hpp> ! // Define a type "CreatorFunc" for the C creator functions typedef void* (*CreatorFunc)(); /** --- 21,31 ---- #include <boost/python.hpp> + #include <maya/MStatus.h> + #include <maya/MSyntax.h> ! // Define the types of the C creator/init functions typedef void* (*CreatorFunc)(); + typedef MSyntax (*CreateSyntaxFunc)(); + typedef MStatus (*InitFunc)(); /** *************** *** 34,41 **** CreatorFunc acquireCFunc(boost::python::object callable); bool releaseCFunc(CreatorFunc cfunc); private: ! int getFreeIndex(); ! int getFuncIndex(CreatorFunc func); }; --- 38,53 ---- CreatorFunc acquireCFunc(boost::python::object callable); + CreateSyntaxFunc acquireCSFunc(boost::python::object callable); + InitFunc acquireInitFunc(boost::python::object callable); bool releaseCFunc(CreatorFunc cfunc); + bool releaseCSFunc(CreateSyntaxFunc csfunc); + bool releaseInitFunc(InitFunc initfunc); private: ! int getFreeCIndex(); ! int getFreeCSIndex(); ! int getFreeInitIndex(); ! int getCFuncIndex(CreatorFunc func); ! int getCSFuncIndex(CreateSyntaxFunc func); ! int getInitFuncIndex(InitFunc func); }; --- NEW FILE: mselectionlist.cpp --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MSelectionList class. */ #include <iostream> #include <sstream> #include "mselectionlist.h" #include "exceptions.h" namespace pyMSelectionList { // __str__ method boost::python::str __str__(MSelectionList& self) { std::ostringstream s; s<<"<MSelectionList: "; MStatus stat; unsigned int len = self.length(&stat); if (stat) s<<len<<" items>"; else s<<stat.errorString()<<">"; return boost::python::str(s.str()); } } --- NEW FILE: mplug.cpp --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MPlug class. */ #include <iostream> #include <sstream> #include "mplug.h" #include "exceptions.h" namespace pyMPlug { // __str__ method boost::python::str __str__(MPlug& self) { std::ostringstream s; s<<"<MPlug "; MStatus stat; MString name = self.name(&stat); if (stat) s<<"'"<<name<<"'>"; else s<<stat.errorString()<<">"; return boost::python::str(s.str()); } } --- NEW FILE: mvectorarray.h --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MVectorArray class. */ #include <boost/python.hpp> #include <maya/MVectorArray.h> namespace pyMVectorArray { boost::python::list get1(MVectorArray& self); void get2(MVectorArray& self, boost::python::list lst); void __setitem__(MVectorArray& self, int key, MVector& val); boost::python::str __str__(MVectorArray& self); } --- NEW FILE: mplug.h --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MPlug class. */ #include <boost/python.hpp> #include <maya/MPlug.h> using boost::python::object; namespace pyMPlug { boost::python::str __str__(MPlug& self); } --- NEW FILE: mdatahandle.cpp --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MDataHandle class. */ #include <iostream> #include <sstream> #include "mdatahandle.h" #include "exceptions.h" namespace pyMDataHandle { bool asBool(MDataHandle& self) { return self.asBool(); } int asChar(MDataHandle& self) { return self.asChar(); } int asUChar(MDataHandle& self) { return self.asUChar(); } int asShort(MDataHandle& self) { return self.asShort(); } int asLong(MDataHandle& self) { return self.asLong(); } int asInt(MDataHandle& self) { return self.asInt(); } double asFloat(MDataHandle& self) { return self.asFloat(); } double asDouble(MDataHandle& self) { return self.asDouble(); } tuple asShort2(MDataHandle& self) { short2& v = self.asShort2(); return boost::python::make_tuple(v[0], v[1]); } tuple asLong2(MDataHandle& self) { long2& v = self.asLong2(); return boost::python::make_tuple(v[0], v[1]); } tuple asInt2(MDataHandle& self) { int2& v = self.asInt2(); return boost::python::make_tuple(v[0], v[1]); } tuple asFloat2(MDataHandle& self) { float2& v = self.asFloat2(); return boost::python::make_tuple(v[0], v[1]); } tuple asDouble2(MDataHandle& self) { double2& v = self.asDouble2(); return boost::python::make_tuple(v[0], v[1]); } tuple asShort3(MDataHandle& self) { short3& v = self.asShort3(); return boost::python::make_tuple(v[0], v[1]); } tuple asLong3(MDataHandle& self) { long3& v = self.asLong3(); return boost::python::make_tuple(v[0], v[1]); } tuple asInt3(MDataHandle& self) { int3& v = self.asInt3(); return boost::python::make_tuple(v[0], v[1]); } tuple asFloat3(MDataHandle& self) { float3& v = self.asFloat3(); return boost::python::make_tuple(v[0], v[1]); } tuple asDouble3(MDataHandle& self) { double3& v = self.asDouble3(); return boost::python::make_tuple(v[0], v[1]); } MString asString(MDataHandle& self) { return self.asString(); } } --- NEW FILE: mitselectionlist.cpp --- /*====================================================================== cgkit - Python Computer Graphics Kit Copyright (C) 2006 Matthias Baas (ba...@ir...) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cgkit homepage: http://cgkit.sourceforge.net ======================================================================*/ /* Additional methods for the MItSelectionList class. */ #include <maya/MDagPath.h> #include <iostream> #include <sstream> #include "mitselectionlist.h" #include "exceptions.h" namespace pyMItSelectionList { // __str__ method boost::python::str __str__(MItSelectionList& self) { std::ostringstream s; s<<"<MItSelectionList: "; MDagPath dp; MStatus stat = self.getDagPath(dp); if (stat) s<<dp.fullPathName(); else s<<"["<<stat.errorString()<<"]"; s<<">"; return boost::python::str(s.str()); } } Index: creatorfuncmanager.cpp =================================================================== RCS file: /cvsroot/cgkit/maya/maya_wrapper/src_aux/creatorfuncmanager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** creatorfuncmanager.cpp 30 Mar 2006 07:38:19 -0000 1.1 --- creatorfuncmanager.cpp 5 Apr 2006 07:43:28 -0000 1.2 *************** *** 30,35 **** CreatorFunc CreatorFuncManager::acquireCFunc(boost::python::object callable) { ! int idx = getFreeIndex(); ! std::cout<<"Creator index: "<<idx<<std::endl; if (idx==-1) return 0; --- 30,35 ---- CreatorFunc CreatorFuncManager::acquireCFunc(boost::python::object callable) { ! int idx = getFreeCIndex(); ! // std::cout<<"Creator index: "<<idx<<std::endl; if (idx==-1) return 0; *************** *** 38,41 **** --- 38,59 ---- } + CreateSyntaxFunc CreatorFuncManager::acquireCSFunc(boost::python::object callable) + { + int idx = getFreeCSIndex(); + if (idx==-1) + return 0; + pycreatesyntaxfuncs[idx] = callable; + return ccreatesyntaxfuncs[idx]; + } + + InitFunc CreatorFuncManager::acquireInitFunc(boost::python::object callable) + { + int idx = getFreeInitIndex(); + if (idx==-1) + return 0; + pyinitfuncs[idx] = callable; + return cinitfuncs[idx]; + } + /** Release a creator function. *************** *** 49,55 **** bool CreatorFuncManager::releaseCFunc(CreatorFunc cfunc) { ! std::cout<<"CreatorFuncManager::releaseCFunc("<<(long)cfunc<<")"<<std::endl; ! int idx = getFuncIndex(cfunc); ! std::cout<<" Func index: "<<idx; if (idx==-1) return false; --- 67,73 ---- bool CreatorFuncManager::releaseCFunc(CreatorFunc cfunc) { ! // std::cout<<"CreatorFuncManager::releaseCFunc("<<(long)cfunc<<")"<<std::endl; ! int idx = getCFuncIndex(cfunc); ! // std::cout<<" Func index: "<<idx; if (idx==-1) return false; *************** *** 61,64 **** --- 79,106 ---- } + bool CreatorFuncManager::releaseCSFunc(CreateSyntaxFunc csfunc) + { + int idx = getCSFuncIndex(csfunc); + if (idx==-1) + return false; + + bool res = (pycreatesyntaxfuncs[idx]!=boost::python::object()); + // Set the Python callable to None + pycreatesyntaxfuncs[idx] = boost::python::object(); + return res; + } + + bool CreatorFuncManager::releaseInitFunc(InitFunc initfunc) + { + int idx = getInitFuncIndex(initfunc); + if (idx==-1) + return false; + + bool res = (pyinitfuncs[idx]!=boost::python::object()); + // Set the Python callable to None + pyinitfuncs[idx] = boost::python::object(); + return res; + } + /** Return the index of an unused creator function. *************** *** 68,78 **** \returns Function index (0-MAX_CREATOR_FUNCTIONS-1) or -1 */ ! int CreatorFuncManager::getFreeIndex() { ! boost::python::object None; // Search for the first index that has None as its Python callable... for(int i=0; i<MAX_CREATOR_FUNCTIONS; i++) { ! if (pycreatorfuncs[i]==None) return i; } --- 110,144 ---- \returns Function index (0-MAX_CREATOR_FUNCTIONS-1) or -1 */ ! int CreatorFuncManager::getFreeCIndex() { ! boost::python::object none; // Search for the first index that has None as its Python callable... for(int i=0; i<MAX_CREATOR_FUNCTIONS; i++) { ! if (pycreatorfuncs[i]==none) ! return i; ! } ! return -1; ! } ! ! int CreatorFuncManager::getFreeCSIndex() ! { ! boost::python::object none; ! // Search for the first index that has None as its Python callable... ! for(int i=0; i<MAX_CREATESYNTAX_FUNCTIONS; i++) ! { ! if (pycreatesyntaxfuncs[i]==none) ! return i; ! } ! return -1; ! } ! ! int CreatorFuncManager::getFreeInitIndex() ! { ! boost::python::object none; ! // Search for the first index that has None as its Python callable... ! for(int i=0; i<MAX_INIT_FUNCTIONS; i++) ! { ! if (pyinitfuncs[i]==none) return i; } *************** *** 86,90 **** at all). */ ! int CreatorFuncManager::getFuncIndex(CreatorFunc func) { // Search for the given function... --- 152,156 ---- at all). */ ! int CreatorFuncManager::getCFuncIndex(CreatorFunc func) { // Search for the given function... *************** *** 94,98 **** return i; } ! std::cerr<<"ERROR: CreatorFuncManager::getFuncIndex() received an invalid creator function handle!"<<std::endl; return -1; } --- 160,188 ---- return i; } ! std::cerr<<"ERROR: CreatorFuncManager::getCFuncIndex() received an invalid creator function handle!"<<std::endl; ! return -1; ! } ! ! int CreatorFuncManager::getCSFuncIndex(CreateSyntaxFunc func) ! { ! // Search for the given function... ! for(int i=0; i<MAX_CREATESYNTAX_FUNCTIONS; i++) ! { ! if (ccreatesyntaxfuncs[i]==func) ! return i; ! } ! std::cerr<<"ERROR: CreatorFuncManager::getCSFuncIndex() received an invalid syntax creator function handle!"<<std::endl; ! return -1; ! } ! ! int CreatorFuncManager::getInitFuncIndex(InitFunc func) ! { ! // Search for the given function... ! for(int i=0; i<MAX_INIT_FUNCTIONS; i++) ! { ! if (cinitfuncs[i]==func) ! return i; ! } ! std::cerr<<"ERROR: CreatorFuncManager::getInitFuncIndex() received an invalid initialization function handle!"<<std::endl; return -1; } |