00001 #include "Appearance.h" 00002 #include "ShapeNodes.h" 00003 00004 using namespace X3DTK; 00005 00006 Appearance::Appearance() 00007 : X3DAppearanceNode(), material_(0), texture_(0), textureTransform_(0), lineProperties_(0), fillProperties_(0) 00008 { 00009 defineTagName("Appearance", "Shape"); 00010 } 00011 00012 Appearance::Appearance(const X3DMaterialNode *material, const X3DTextureNode *texture, const X3DTextureTransformNode *textureTransform, const LineProperties *lineProperties, const FillProperties *fillProperties) 00013 : X3DAppearanceNode(), material_((SFNode)material), texture_((SFNode)texture), textureTransform_((SFNode)textureTransform), lineProperties_((SFNode)lineProperties), fillProperties_((SFNode)fillProperties) 00014 { 00015 defineTagName("Appearance", "Shape"); 00016 } 00017 00018 Appearance::Appearance(const Appearance &A) 00019 : X3DAppearanceNode(A), material_(A.material_), texture_(A.texture_), textureTransform_(A.textureTransform_), lineProperties_(A.lineProperties_), fillProperties_(A.fillProperties_) 00020 { 00021 defineTagName("Appearance", "Shape"); 00022 } 00023 00024 SFNode Appearance::clone() const 00025 { 00026 return new Appearance(*this); 00027 } 00028 00029 Appearance::~Appearance() 00030 { 00031 } 00032 00033 void Appearance::setMaterial(const X3DMaterialNode *material) 00034 { 00035 removeLink(this, material_); 00036 material_ = (SFNode)material; 00037 addLink(this, material_); 00038 } 00039 00040 void Appearance::setTexture(const X3DTextureNode *texture) 00041 { 00042 removeLink(this, texture_); 00043 texture_ = (SFNode)texture; 00044 addLink(this, texture_); 00045 } 00046 00047 void Appearance::setTextureTransform(const X3DTextureTransformNode *textureTransform) 00048 { 00049 removeLink(this, textureTransform_); 00050 textureTransform_ = (SFNode)textureTransform; 00051 addLink(this, textureTransform_); 00052 } 00053 00054 void Appearance::setLineProperties(const LineProperties *lineProperties) 00055 { 00056 removeLink(this, lineProperties_); 00057 lineProperties_ = (SFNode)lineProperties; 00058 addLink(this, lineProperties_); 00059 } 00060 00061 void Appearance::setFillProperties(const FillProperties *fillProperties) 00062 { 00063 removeLink(this, fillProperties_); 00064 fillProperties_ = (SFNode)fillProperties; 00065 addLink(this, fillProperties_); 00066 } 00067 00068 bool Appearance::addChild(const SFNode &N) 00069 { 00070 if (dynamic_cast<X3DMaterialNode *>(N) != 0) 00071 { 00072 if (material_ != 0) 00073 return false; 00074 00075 setMaterial(static_cast<X3DMaterialNode *>(N)); 00076 return true; 00077 } 00078 00079 if (dynamic_cast<X3DTextureNode *>(N) != 0) 00080 { 00081 if (texture_ != 0) 00082 return false; 00083 00084 setTexture(static_cast<X3DTextureNode *>(N)); 00085 return true; 00086 } 00087 00088 if (dynamic_cast<X3DTextureTransformNode *>(N) != 0) 00089 { 00090 if (textureTransform_ != 0) 00091 return false; 00092 00093 setTextureTransform(static_cast<X3DTextureTransformNode *>(N)); 00094 return true; 00095 } 00096 00097 if (dynamic_cast<LineProperties *>(N) != 0) 00098 { 00099 if (lineProperties_ != 0) 00100 return false; 00101 00102 setLineProperties(static_cast<LineProperties *>(N)); 00103 return true; 00104 } 00105 00106 if (dynamic_cast<FillProperties *>(N) != 0) 00107 { 00108 if (fillProperties_ != 0) 00109 return false; 00110 00111 setFillProperties(static_cast<FillProperties *>(N)); 00112 return true; 00113 } 00114 00115 return false; 00116 } 00117 00118 bool Appearance::setChild(const SFNode &N) 00119 { 00120 if (dynamic_cast<X3DMaterialNode *>(N) != 0) 00121 { 00122 setMaterial(static_cast<X3DMaterialNode *>(N)); 00123 return true; 00124 } 00125 00126 if (dynamic_cast<X3DTextureNode *>(N) != 0) 00127 { 00128 setTexture(static_cast<X3DTextureNode *>(N)); 00129 return true; 00130 } 00131 00132 if (dynamic_cast<X3DTextureTransformNode *>(N) != 0) 00133 { 00134 setTextureTransform(static_cast<X3DTextureTransformNode *>(N)); 00135 return true; 00136 } 00137 00138 if (dynamic_cast<LineProperties *>(N) != 0) 00139 { 00140 setLineProperties(static_cast<LineProperties *>(N)); 00141 return true; 00142 } 00143 00144 if (dynamic_cast<FillProperties *>(N) != 0) 00145 { 00146 setFillProperties(static_cast<FillProperties *>(N)); 00147 return true; 00148 } 00149 00150 return false; 00151 } 00152 00153 bool Appearance::removeChild(const SFNode &N) 00154 { 00155 if (material_ == N) 00156 { 00157 setMaterial(0); 00158 return true; 00159 } 00160 00161 if (texture_ == N) 00162 { 00163 setTexture(0); 00164 return true; 00165 } 00166 00167 if (textureTransform_ == N) 00168 { 00169 setTextureTransform(0); 00170 return true; 00171 } 00172 00173 if (lineProperties_ == N) 00174 { 00175 setLineProperties(0); 00176 return true; 00177 } 00178 00179 if (fillProperties_ == N) 00180 { 00181 setFillProperties(0); 00182 return true; 00183 } 00184 00185 return false; 00186 } 00187 00188 void Appearance::removeScenesToChildren(const MFScene &sceneList) 00189 { 00190 removeScenes(material_, sceneList); 00191 removeScenes(texture_, sceneList); 00192 removeScenes(textureTransform_, sceneList); 00193 removeScenes(lineProperties_, sceneList); 00194 removeScenes(fillProperties_, sceneList); 00195 } 00196 00197 void Appearance::addScenesToChildren(const MFScene &sceneList) 00198 { 00199 addScenes(material_, sceneList); 00200 addScenes(texture_, sceneList); 00201 addScenes(textureTransform_, sceneList); 00202 addScenes(lineProperties_, sceneList); 00203 addScenes(fillProperties_, sceneList); 00204 }