00001
00002
00003
00004
00005
00006 #include <boost/filesystem/path.hpp>
00007 #include <boost/filesystem/operations.hpp>
00008 #include <boost/filesystem/exception.hpp>
00009 #include <Base/PyObjectBase.h>
00010 #include <Base/Console.h>
00011 #include <Base/Exception.h>
00012 #include <CXX/Objects.hxx>
00013
00014 #define new DEBUG_CLIENTBLOCK
00015
00016 using Base::streq;
00017 using namespace App;
00018
00020 PyTypeObject MaterialPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "App.Material",
00024 sizeof(MaterialPy),
00025 0,
00026
00027 PyDestructor,
00028 0,
00029 __getattr,
00030 __setattr,
00031 0,
00032 __repr,
00033 0,
00034 0,
00035 0,
00036 0,
00037 0,
00038 0,
00039 0,
00040 0,
00041
00042 0,
00043
00044 Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS,
00045 "This is the Material class",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 App::MaterialPy::Methods,
00053 0,
00054 App::MaterialPy::GetterSetter,
00055 &Base::PyObjectBase::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 App::MaterialPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef MaterialPy::Methods[] = {
00075 {"set",
00076 (PyCFunction) staticCallback_set,
00077 METH_VARARGS,
00078 "\nSet(string) -- Set the material.\n\nThe material must be one of the following values:\nBrass, Bronze, Copper, Gold, Pewter, Plaster, Plastic, Silver, Steel, Stone, Shiny plastic,\nSatin, Metalized, Neon GNC, Chrome, Aluminium, Obsidian, Neon PHC, Jade, Ruby or Emerald.\n "
00079 },
00080 {NULL, NULL, 0, NULL}
00081 };
00082
00083
00084
00086 PyGetSetDef MaterialPy::GetterSetter[] = {
00087 {"AmbientColor",
00088 (getter) staticCallback_getAmbientColor,
00089 (setter) staticCallback_setAmbientColor,
00090 "Ambient color",
00091 NULL
00092 },
00093 {"DiffuseColor",
00094 (getter) staticCallback_getDiffuseColor,
00095 (setter) staticCallback_setDiffuseColor,
00096 "Diffuse color",
00097 NULL
00098 },
00099 {"EmissiveColor",
00100 (getter) staticCallback_getEmissiveColor,
00101 (setter) staticCallback_setEmissiveColor,
00102 "Emissive color",
00103 NULL
00104 },
00105 {"SpecularColor",
00106 (getter) staticCallback_getSpecularColor,
00107 (setter) staticCallback_setSpecularColor,
00108 "Specular color",
00109 NULL
00110 },
00111 {"Shininess",
00112 (getter) staticCallback_getShininess,
00113 (setter) staticCallback_setShininess,
00114 "Shininess",
00115 NULL
00116 },
00117 {"Transparency",
00118 (getter) staticCallback_getTransparency,
00119 (setter) staticCallback_setTransparency,
00120 "Transparency",
00121 NULL
00122 },
00123 {NULL, NULL, NULL, NULL, NULL}
00124 };
00125
00126
00127
00128
00129 PyObject * MaterialPy::staticCallback_set (PyObject *self, PyObject *args)
00130 {
00131
00132 if (!((PyObjectBase*) self)->isValid()){
00133 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00134 return NULL;
00135 }
00136
00137
00138 if (((PyObjectBase*) self)->isConst()){
00139 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00140 return NULL;
00141 }
00142
00143 try {
00144 PyObject* ret = ((MaterialPy*)self)->set(args);
00145 if (ret != 0)
00146 ((MaterialPy*)self)->startNotify();
00147 return ret;
00148 }
00149 catch(const Base::Exception& e)
00150 {
00151 std::string str;
00152 str += "FreeCAD exception thrown (";
00153 str += e.what();
00154 str += ")";
00155 e.ReportException();
00156 PyErr_SetString(PyExc_Exception,str.c_str());
00157 return NULL;
00158 }
00159 catch(const boost::filesystem::filesystem_error& e)
00160 {
00161 std::string str;
00162 str += "File system exception thrown (";
00163
00164
00165 str += e.what();
00166 str += ")\n";
00167 Base::Console().Error(str.c_str());
00168 PyErr_SetString(PyExc_Exception,str.c_str());
00169 return NULL;
00170 }
00171 catch(const Py::Exception&)
00172 {
00173
00174 return NULL;
00175 }
00176 catch(const char* e)
00177 {
00178 Base::Console().Error(e);
00179 PyErr_SetString(PyExc_Exception,e);
00180 return NULL;
00181 }
00182
00183 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00184 catch(const std::exception& e)
00185 {
00186 std::string str;
00187 str += "FC++ exception thrown (";
00188 str += e.what();
00189 str += ")";
00190 Base::Console().Error(str.c_str());
00191 PyErr_SetString(PyExc_Exception,str.c_str());
00192 return NULL;
00193 }
00194 catch(...)
00195 {
00196 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00197 return NULL;
00198 }
00199 #endif
00200 }
00201
00202
00203
00204
00205 PyObject * MaterialPy::staticCallback_getAmbientColor (PyObject *self, void * )
00206 {
00207 if (!((PyObjectBase*) self)->isValid()){
00208 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00209 return NULL;
00210 }
00211
00212 try {
00213 return Py::new_reference_to(((MaterialPy*)self)->getAmbientColor());
00214 } catch (const Py::Exception&) {
00215
00216 return NULL;
00217 } catch (...) {
00218 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'AmbientColor' of object 'Material'");
00219 return NULL;
00220 }
00221 }
00222
00223 int MaterialPy::staticCallback_setAmbientColor (PyObject *self, PyObject *value, void * )
00224 {
00225 if (!((PyObjectBase*) self)->isValid()){
00226 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00227 return -1;
00228 }
00229 if (((PyObjectBase*) self)->isConst()){
00230 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00231 return -1;
00232 }
00233
00234 try {
00235 ((MaterialPy*)self)->setAmbientColor(Py::Tuple(value,false));
00236 return 0;
00237 } catch (const Py::Exception&) {
00238
00239 return -1;
00240 } catch (...) {
00241 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'AmbientColor' of object 'Material'");
00242 return -1;
00243 }
00244 }
00245
00246
00247
00248
00249 PyObject * MaterialPy::staticCallback_getDiffuseColor (PyObject *self, void * )
00250 {
00251 if (!((PyObjectBase*) self)->isValid()){
00252 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00253 return NULL;
00254 }
00255
00256 try {
00257 return Py::new_reference_to(((MaterialPy*)self)->getDiffuseColor());
00258 } catch (const Py::Exception&) {
00259
00260 return NULL;
00261 } catch (...) {
00262 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'DiffuseColor' of object 'Material'");
00263 return NULL;
00264 }
00265 }
00266
00267 int MaterialPy::staticCallback_setDiffuseColor (PyObject *self, PyObject *value, void * )
00268 {
00269 if (!((PyObjectBase*) self)->isValid()){
00270 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00271 return -1;
00272 }
00273 if (((PyObjectBase*) self)->isConst()){
00274 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00275 return -1;
00276 }
00277
00278 try {
00279 ((MaterialPy*)self)->setDiffuseColor(Py::Tuple(value,false));
00280 return 0;
00281 } catch (const Py::Exception&) {
00282
00283 return -1;
00284 } catch (...) {
00285 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'DiffuseColor' of object 'Material'");
00286 return -1;
00287 }
00288 }
00289
00290
00291
00292
00293 PyObject * MaterialPy::staticCallback_getEmissiveColor (PyObject *self, void * )
00294 {
00295 if (!((PyObjectBase*) self)->isValid()){
00296 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00297 return NULL;
00298 }
00299
00300 try {
00301 return Py::new_reference_to(((MaterialPy*)self)->getEmissiveColor());
00302 } catch (const Py::Exception&) {
00303
00304 return NULL;
00305 } catch (...) {
00306 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'EmissiveColor' of object 'Material'");
00307 return NULL;
00308 }
00309 }
00310
00311 int MaterialPy::staticCallback_setEmissiveColor (PyObject *self, PyObject *value, void * )
00312 {
00313 if (!((PyObjectBase*) self)->isValid()){
00314 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00315 return -1;
00316 }
00317 if (((PyObjectBase*) self)->isConst()){
00318 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00319 return -1;
00320 }
00321
00322 try {
00323 ((MaterialPy*)self)->setEmissiveColor(Py::Tuple(value,false));
00324 return 0;
00325 } catch (const Py::Exception&) {
00326
00327 return -1;
00328 } catch (...) {
00329 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'EmissiveColor' of object 'Material'");
00330 return -1;
00331 }
00332 }
00333
00334
00335
00336
00337 PyObject * MaterialPy::staticCallback_getSpecularColor (PyObject *self, void * )
00338 {
00339 if (!((PyObjectBase*) self)->isValid()){
00340 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00341 return NULL;
00342 }
00343
00344 try {
00345 return Py::new_reference_to(((MaterialPy*)self)->getSpecularColor());
00346 } catch (const Py::Exception&) {
00347
00348 return NULL;
00349 } catch (...) {
00350 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'SpecularColor' of object 'Material'");
00351 return NULL;
00352 }
00353 }
00354
00355 int MaterialPy::staticCallback_setSpecularColor (PyObject *self, PyObject *value, void * )
00356 {
00357 if (!((PyObjectBase*) self)->isValid()){
00358 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00359 return -1;
00360 }
00361 if (((PyObjectBase*) self)->isConst()){
00362 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00363 return -1;
00364 }
00365
00366 try {
00367 ((MaterialPy*)self)->setSpecularColor(Py::Tuple(value,false));
00368 return 0;
00369 } catch (const Py::Exception&) {
00370
00371 return -1;
00372 } catch (...) {
00373 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'SpecularColor' of object 'Material'");
00374 return -1;
00375 }
00376 }
00377
00378
00379
00380
00381 PyObject * MaterialPy::staticCallback_getShininess (PyObject *self, void * )
00382 {
00383 if (!((PyObjectBase*) self)->isValid()){
00384 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00385 return NULL;
00386 }
00387
00388 try {
00389 return Py::new_reference_to(((MaterialPy*)self)->getShininess());
00390 } catch (const Py::Exception&) {
00391
00392 return NULL;
00393 } catch (...) {
00394 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Shininess' of object 'Material'");
00395 return NULL;
00396 }
00397 }
00398
00399 int MaterialPy::staticCallback_setShininess (PyObject *self, PyObject *value, void * )
00400 {
00401 if (!((PyObjectBase*) self)->isValid()){
00402 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00403 return -1;
00404 }
00405 if (((PyObjectBase*) self)->isConst()){
00406 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00407 return -1;
00408 }
00409
00410 try {
00411 ((MaterialPy*)self)->setShininess(Py::Float(value,false));
00412 return 0;
00413 } catch (const Py::Exception&) {
00414
00415 return -1;
00416 } catch (...) {
00417 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Shininess' of object 'Material'");
00418 return -1;
00419 }
00420 }
00421
00422
00423
00424
00425 PyObject * MaterialPy::staticCallback_getTransparency (PyObject *self, void * )
00426 {
00427 if (!((PyObjectBase*) self)->isValid()){
00428 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00429 return NULL;
00430 }
00431
00432 try {
00433 return Py::new_reference_to(((MaterialPy*)self)->getTransparency());
00434 } catch (const Py::Exception&) {
00435
00436 return NULL;
00437 } catch (...) {
00438 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Transparency' of object 'Material'");
00439 return NULL;
00440 }
00441 }
00442
00443 int MaterialPy::staticCallback_setTransparency (PyObject *self, PyObject *value, void * )
00444 {
00445 if (!((PyObjectBase*) self)->isValid()){
00446 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00447 return -1;
00448 }
00449 if (((PyObjectBase*) self)->isConst()){
00450 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00451 return -1;
00452 }
00453
00454 try {
00455 ((MaterialPy*)self)->setTransparency(Py::Float(value,false));
00456 return 0;
00457 } catch (const Py::Exception&) {
00458
00459 return -1;
00460 } catch (...) {
00461 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Transparency' of object 'Material'");
00462 return -1;
00463 }
00464 }
00465
00466
00467
00468
00469
00470
00471 PyParentObject MaterialPy::Parents[] = { PARENTSAppMaterialPy };
00472
00473
00474
00475
00476 MaterialPy::MaterialPy(Material *pcObject, PyTypeObject *T)
00477 : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
00478 {
00479 }
00480
00481 PyObject *MaterialPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00482 {
00483
00484 PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'MaterialPy'.");
00485
00486 return 0;
00487 }
00488
00489 int MaterialPy::PyInit(PyObject* , PyObject* )
00490 {
00491 return 0;
00492 }
00493
00494
00495
00496
00497 MaterialPy::~MaterialPy()
00498 {
00499
00500 MaterialPy::PointerType ptr = reinterpret_cast<MaterialPy::PointerType>(_pcTwinPointer);
00501 delete ptr;
00502 }
00503
00504
00505
00506
00507 PyObject *MaterialPy::_repr(void)
00508 {
00509 return Py_BuildValue("s", representation().c_str());
00510 }
00511
00512
00513
00514
00515 PyObject *MaterialPy::_getattr(char *attr)
00516 {
00517 try {
00518
00519 PyObject *r = getCustomAttributes(attr);
00520 if(r) return r;
00521 }
00522 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00523 catch(const Base::Exception& e)
00524 {
00525 std::string str;
00526 str += "FreeCAD exception thrown (";
00527 str += e.what();
00528 str += ")";
00529 e.ReportException();
00530 PyErr_SetString(PyExc_Exception,str.c_str());
00531 return NULL;
00532 }
00533 catch(const std::exception& e)
00534 {
00535 std::string str;
00536 str += "FC++ exception thrown (";
00537 str += e.what();
00538 str += ")";
00539 Base::Console().Error(str.c_str());
00540 PyErr_SetString(PyExc_Exception,str.c_str());
00541 return NULL;
00542 }
00543 catch(const Py::Exception&)
00544 {
00545
00546 return NULL;
00547 }
00548 catch(...)
00549 {
00550 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00551 return NULL;
00552 }
00553 #else // DONT_CATCH_CXX_EXCEPTIONS
00554 catch(const Base::Exception& e)
00555 {
00556 std::string str;
00557 str += "FreeCAD exception thrown (";
00558 str += e.what();
00559 str += ")";
00560 e.ReportException();
00561 PyErr_SetString(PyExc_Exception,str.c_str());
00562 return NULL;
00563 }
00564 catch(const Py::Exception&)
00565 {
00566
00567 return NULL;
00568 }
00569 #endif // DONT_CATCH_CXX_EXCEPTIONS
00570
00571 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00572 if (rvalue == NULL)
00573 {
00574 PyErr_Clear();
00575 return PyObjectBase::_getattr(attr);
00576 }
00577 else
00578 {
00579 return rvalue;
00580 }
00581 }
00582
00583 int MaterialPy::_setattr(char *attr, PyObject *value)
00584 {
00585 try {
00586
00587 int r = setCustomAttributes(attr, value);
00588 if(r==1) return 0;
00589 }
00590 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00591 catch(const Base::Exception& e)
00592 {
00593 std::string str;
00594 str += "FreeCAD exception thrown (";
00595 str += e.what();
00596 str += ")";
00597 e.ReportException();
00598 PyErr_SetString(PyExc_Exception,str.c_str());
00599 return -1;
00600 }
00601 catch(const std::exception& e)
00602 {
00603 std::string str;
00604 str += "FC++ exception thrown (";
00605 str += e.what();
00606 str += ")";
00607 Base::Console().Error(str.c_str());
00608 PyErr_SetString(PyExc_Exception,str.c_str());
00609 return -1;
00610 }
00611 catch(const Py::Exception&)
00612 {
00613
00614 return -1;
00615 }
00616 catch(...)
00617 {
00618 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00619 return -1;
00620 }
00621 #else // DONT_CATCH_CXX_EXCEPTIONS
00622 catch(const Base::Exception& e)
00623 {
00624 std::string str;
00625 str += "FreeCAD exception thrown (";
00626 str += e.what();
00627 str += ")";
00628 e.ReportException();
00629 PyErr_SetString(PyExc_Exception,str.c_str());
00630 return -1;
00631 }
00632 catch(const Py::Exception&)
00633 {
00634
00635 return -1;
00636 }
00637 #endif // DONT_CATCH_CXX_EXCEPTIONS
00638
00639 return PyObjectBase::_setattr(attr, value);
00640 }
00641
00642 Material *MaterialPy::getMaterialPtr(void) const
00643 {
00644 return static_cast<Material *>(_pcTwinPointer);
00645 }
00646
00647 #if 0
00648
00649
00650
00651
00652
00653
00654 std::string MaterialPy::representation(void) const
00655 {
00656 return std::string("<Material object>");
00657 }
00658
00659 PyObject* MaterialPy::set(PyObject *args)
00660 {
00661 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00662 return 0;
00663 }
00664
00665
00666
00667 Py::Tuple MaterialPy::getAmbientColor(void) const
00668 {
00669
00670 throw Py::AttributeError("Not yet implemented");
00671 }
00672
00673 void MaterialPy::setAmbientColor(Py::Tuple arg)
00674 {
00675 throw Py::AttributeError("Not yet implemented");
00676 }
00677
00678 Py::Tuple MaterialPy::getDiffuseColor(void) const
00679 {
00680
00681 throw Py::AttributeError("Not yet implemented");
00682 }
00683
00684 void MaterialPy::setDiffuseColor(Py::Tuple arg)
00685 {
00686 throw Py::AttributeError("Not yet implemented");
00687 }
00688
00689 Py::Tuple MaterialPy::getEmissiveColor(void) const
00690 {
00691
00692 throw Py::AttributeError("Not yet implemented");
00693 }
00694
00695 void MaterialPy::setEmissiveColor(Py::Tuple arg)
00696 {
00697 throw Py::AttributeError("Not yet implemented");
00698 }
00699
00700 Py::Tuple MaterialPy::getSpecularColor(void) const
00701 {
00702
00703 throw Py::AttributeError("Not yet implemented");
00704 }
00705
00706 void MaterialPy::setSpecularColor(Py::Tuple arg)
00707 {
00708 throw Py::AttributeError("Not yet implemented");
00709 }
00710
00711 Py::Float MaterialPy::getShininess(void) const
00712 {
00713
00714 throw Py::AttributeError("Not yet implemented");
00715 }
00716
00717 void MaterialPy::setShininess(Py::Float arg)
00718 {
00719 throw Py::AttributeError("Not yet implemented");
00720 }
00721
00722 Py::Float MaterialPy::getTransparency(void) const
00723 {
00724
00725 throw Py::AttributeError("Not yet implemented");
00726 }
00727
00728 void MaterialPy::setTransparency(Py::Float arg)
00729 {
00730 throw Py::AttributeError("Not yet implemented");
00731 }
00732
00733 PyObject *MaterialPy::getCustomAttributes(const char* attr) const
00734 {
00735 return 0;
00736 }
00737
00738 int MaterialPy::setCustomAttributes(const char* attr, PyObject *obj)
00739 {
00740 return 0;
00741 }
00742 #endif
00743
00744
00745