3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
square_volume.cpp

Iterate over the sculpt tree, show the basic stats - square, volume

// Iterate over the sculpt tree, show the basic stats - square, volume
#include <CoreAPI.h>
//If you need the release build at full speed please change the Debug below to Release
//@config: Debug
class OneLine :public BaseClass {
public:
OneLine() {
Square = Volume = 0;
}
OneLine(coat::SceneElement el) {
name = el.name();
Square = el.Volume().getSquare();
Volume = el.Volume().getVolume();
}
coat::str name;
float Square;
float Volume;
SERIALIZE() {
UI_LAYOUT("3");
//"!identifier" means that it is readonly and it's name does not appear in UI
READONLY REG_AUTO(name, "!name");
READONLY REG_AUTO(Square, "!Square");
READONLY REG_AUTO(Volume, "!Volume");
}
};
// This is the class to represent the information about all volumes
class Stats:public BaseClass {
public:
Stats() {
}
void Calculate() {
// get the sculpt root
// iterate through all sculpt objects
r.iterateSubtree(
[&](coat::SceneElement el) -> bool {
// adding the element to ClassArray to represent in UI
if (el.isSculptObject())lines.Add(new OneLine(el));
return false;
});
}
// This is the list of volumes, ClassArray is the array of pointers to BaseClass-derived items
// ClassArray<...> may be registered with REG_AUTO(...)
SERIALIZE() {
// making the header, 3 columns
UI_LAYOUT("3");
// "*name" means it is left-aligned text
TEXTMSG2("*Name");
TEXTMSG2("*Square");
TEXTMSG2("*Volume");
// the lines with info, ClassArray<...> may be registered with REG_AUTO
// and will appear in the UI
REG_AUTO(lines);
}
};
EXPORT
int main(){
{
Stats stats;
// calculate the stats
stats.Calculate();
coat::dialog().ok().params(&stats).show();
}
return 0;
}
Use this class for build a class for UI or serialization. see class_reg.h for details about the class...
Definition BaseClass.h:91
The array of elements derived from the BaseClass. If you create ClassArray and register if with the R...
Definition classlist.h:340
The scene element, like sculpt object or curve.
Definition CoreAPI.h:1632
const char * name() const
get the element name
bool isSculptObject() const
Check if it is the sculpt object.
static SceneElement sculptRoot()
get the root of all sculpt objects
the rich dialog. You may customize it, show your custom parameters and custom buttons.
Definition CoreAPI.h:3811
dialog & params(BaseClass *params)
The important core feature. BaseClass allows to create the custom controls in the dialog....
dialog & ok()
add Ok button
int show()
Show the dialog. This is usually the last command in the chain.
comms::cStr str
the string that is compatible with the 3DCoat engine, see the cStr
Definition CoreAPI.h:67