ElementChemistryClr.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "stdafx.h"
  2. #include "ElementChemistryClr.h"
  3. namespace OTSINTERFACE {
  4. CElementChemistryClr::CElementChemistryClr()
  5. {
  6. m_LpElementChemistry = new CElementChemistryPtr(new CElementChemistry());
  7. }
  8. CElementChemistryClr::CElementChemistryClr(String^ a_strName, double a_dPercentage)
  9. {
  10. ASSERT(a_strName);
  11. if (!a_strName)
  12. {
  13. LogErrorTrace(__FILE__, __LINE__, _T("CElementChemistryClr: Generate CElementChemistryClr pointer failed."));
  14. return;
  15. }
  16. m_LpElementChemistry = new CElementChemistryPtr(new CElementChemistry(a_strName, a_dPercentage));
  17. }
  18. CElementChemistryClr::CElementChemistryClr(CElementChemistryPtr a_pElementChemistry)
  19. {
  20. ASSERT(a_pElementChemistry);
  21. if (!a_pElementChemistry)
  22. {
  23. LogErrorTrace(__FILE__, __LINE__, _T("CElementChemistryClr: Generate CElementChemistryClr pointer failed."));
  24. return;
  25. }
  26. m_LpElementChemistry = new CElementChemistryPtr(a_pElementChemistry);
  27. }
  28. CElementChemistryClr::CElementChemistryClr(CElementChemistry* a_pSource)
  29. {
  30. ASSERT(a_pSource);
  31. if (!a_pSource)
  32. {
  33. LogErrorTrace(__FILE__, __LINE__, _T("CElementChemistryClr: Generate CElementChemistryClr pointer failed."));
  34. return;
  35. }
  36. m_LpElementChemistry = new CElementChemistryPtr(new CElementChemistry(a_pSource));
  37. }
  38. CElementChemistryClr::~CElementChemistryClr()
  39. {
  40. if (m_LpElementChemistry != nullptr)
  41. {
  42. delete m_LpElementChemistry;
  43. m_LpElementChemistry = nullptr;
  44. }
  45. }
  46. CElementChemistryClr::!CElementChemistryClr()
  47. {
  48. if (m_LpElementChemistry != nullptr)
  49. {
  50. delete m_LpElementChemistry;
  51. m_LpElementChemistry = nullptr;
  52. }
  53. }
  54. CElementChemistryPtr CElementChemistryClr::GetElementChemistryPtr()
  55. {
  56. return *m_LpElementChemistry;
  57. }
  58. String^ CElementChemistryClr::GetName()
  59. {
  60. String^ NameClr;
  61. if (m_LpElementChemistry != nullptr)
  62. {
  63. CString sName = m_LpElementChemistry->get()->GetName();
  64. NameClr = gcnew String(sName);
  65. }
  66. return NameClr;
  67. }
  68. void CElementChemistryClr::SetName(String^ strName)
  69. {
  70. ASSERT(strName);
  71. if (!strName)
  72. {
  73. LogErrorTrace(__FILE__, __LINE__, _T("SetFileVersion: invalid version."));
  74. }
  75. if (m_LpElementChemistry != nullptr)
  76. {
  77. m_LpElementChemistry->get()->SetName(strName);
  78. }
  79. }
  80. double CElementChemistryClr::GetPercentage()
  81. {
  82. double nPercentage = -1;
  83. if (m_LpElementChemistry != nullptr)
  84. {
  85. nPercentage = m_LpElementChemistry->get()->GetPercentage();
  86. }
  87. return nPercentage;
  88. }
  89. void CElementChemistryClr::SetPercentage(double a_dPercentage)
  90. {
  91. if (m_LpElementChemistry != nullptr)
  92. {
  93. m_LpElementChemistry->get()->SetPercentage( a_dPercentage);
  94. }
  95. }
  96. double CElementChemistryClr::GetMolar()
  97. {
  98. if (m_LpElementChemistry != nullptr)
  99. {
  100. return m_LpElementChemistry->get()->GetMolarPercentage();
  101. }
  102. else
  103. {
  104. return 0.0;
  105. }
  106. }
  107. int CElementChemistryClr::GetAtomNum(String^ a_strElementName)
  108. {
  109. if (m_LpElementChemistry != nullptr)
  110. {
  111. return CElement::GetAtomicNum(a_strElementName);
  112. }
  113. else
  114. {
  115. return 0;
  116. }
  117. }
  118. }