yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #25994
Re: [Question #698253]: Access to body material properties
Question #698253 on Yade changed:
https://answers.launchpad.net/yade/+question/698253
Status: Open => Answered
Jan Stránský proposed the following answer:
Hi,
body->material is "by default" an abstract base Material instance [1]. It has no CP1, CP2, ..., K1, ...
If you want to access those properties defined on derived classes, you have to cast the instance.
(You have something already in your code).
WhateverMat* mat = dynamic_cast<WhateverMat*>(B->material.get());
A robust code should count with the possibility, that B->material is not
WhateverMat, but some else material, like:
WhateverMat* mat = dynamic_cast<WhateverMat*>(B->material.get());
if (mat) { // if true, mat is WhateverMat. If false, mat is NOT WhateverMat
// do something with WhateverMat
} else {
// do something for the case it is not WhateverMat (different code, error, ...)
}
a note:
CpmPhys* mat = dynamic_cast<CpmPhys*>(B->material.get());
also being valid code, casting B->material (a Material) to CpmPhys (IPhys) will always result into null pointer.
Cheers
Jan
--
You received this question notification because your team yade-users is
an answer contact for Yade.