00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #include <sstream> 00020 #include "mitkColorProperty.h" 00021 00022 mitk::ColorProperty::ColorProperty() 00023 : m_Color() 00024 { 00025 00026 } 00027 00028 mitk::ColorProperty::ColorProperty(const float color[3]) : m_Color(color) 00029 { 00030 00031 } 00032 00033 mitk::ColorProperty::ColorProperty(const float red, const float green, const float blue) 00034 { 00035 m_Color.Set(red, green, blue); 00036 } 00037 00038 mitk::ColorProperty::ColorProperty(const mitk::Color & color) : m_Color(color) 00039 { 00040 00041 } 00042 00043 mitk::ColorProperty::~ColorProperty() 00044 { 00045 } 00046 00047 bool mitk::ColorProperty::Assignable(const mitk::BaseProperty& other) const 00048 { 00049 try 00050 { 00051 dynamic_cast<const Self&>(other); // dear compiler, please don't optimize this away! 00052 return true; 00053 } 00054 catch (std::bad_cast) 00055 { 00056 } 00057 return false; 00058 } 00059 00060 mitk::BaseProperty& mitk::ColorProperty::operator=(const mitk::BaseProperty& other) 00061 { 00062 try 00063 { 00064 const Self& otherProp( dynamic_cast<const Self&>(other) ); 00065 00066 if (this->m_Color != otherProp.m_Color) 00067 { 00068 this->m_Color = otherProp.m_Color; 00069 this->Modified(); 00070 } 00071 } 00072 catch (std::bad_cast) 00073 { 00074 // nothing to do then 00075 } 00076 00077 return *this; 00078 } 00079 00080 00081 bool mitk::ColorProperty::operator==(const BaseProperty& property) const 00082 { 00083 try 00084 { 00085 const Self& other = dynamic_cast<const Self&>(property); 00086 return other.m_Color == m_Color; 00087 } 00088 catch (std::bad_cast&) 00089 { 00090 return false; 00091 } 00092 } 00093 00094 const mitk::Color & mitk::ColorProperty::GetColor() const 00095 { 00096 return m_Color; 00097 } 00098 00099 void mitk::ColorProperty::SetColor(const mitk::Color & color ) 00100 { 00101 if(m_Color!=color) 00102 { 00103 m_Color = color; 00104 Modified(); 00105 } 00106 } 00107 00108 void mitk::ColorProperty::SetColor( float red, float green, float blue ) 00109 { 00110 m_Color.Set(red, green, blue); 00111 } 00112 00113 std::string mitk::ColorProperty::GetValueAsString() const { 00114 std::stringstream myStr; 00115 myStr << GetValue() ; 00116 return myStr.str(); 00117 } 00118 const mitk::Color & mitk::ColorProperty::GetValue() const 00119 { 00120 return GetColor(); 00121 }