3DCoat Core API
The 3DCoat API documentation.
No Matches
1#pragma once
3#include <functional>
5#include "pool.h"
6#include "BaseClassIO.h"
7class BaseClass;
8class cStruct;
9#ifdef COAT_SG
11namespace SG {
12 class SG_Object;
54struct BaseClassElement {
55 comms::cStr RegOpt;
57 BaseClass* BC;
59 void* Ptr;
61 void* Extra;
63 const char* ID;
65 DWORD Mask;
67 bool Visible : 1;
69 bool ReadOnly : 1;
71 bool Serialize : 1;
72 bool ApplyScale : 1;
73 bool Noname : 1;
74 bool Noreset : 1;
75 float Scaling;
78 bool CachedValue : 1;
79 unsigned short CachedIndex;
81 void fill(void* _Ptr, void* _Extra, bool _vis, bool _ui, bool OnlyPointersMode);
83 void reset(bool initmask=true);
84 void minimal_reset();
85 BaseClassElement();
91class APICALL BaseClass{
98#ifndef PY_PARSER
99 friend BaseClassElement;
101 //explicit BaseClass(const BaseClass&);
102 //BaseClass& operator = (const BaseClass&);
104#ifndef PY_PARSER
107 BaseClass();
108#ifndef PY_PARSER
109 BaseClass(const BaseClass&);
112 virtual ~BaseClass();
115 virtual DWORD GetClassMask() { return 0xFFFFFFFF; }
116 DWORD& ClassMask() { return _ClassMask; }
119 virtual void reset_class(void* DataPtr = nullptr);
134 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result, const std::function<bool(BaseClassElement*)>* ForEachElem = nullptr, bool OnlyPointersMode = false) { }
141 void ForEach(const std::function<bool(BaseClassElement* el)>& fn, bool OnlyPointsers = false);
149 virtual bool CopyBaseClass(BaseClass* Dest, bool Add = false);
156 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL);
164 virtual bool Load(TagsList& xml, void* ClassPtr, void* Extra = NULL);
175 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DstDataExtra, CECopyContext* C);
184 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList);
192 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary);
193#ifndef PY_PARSER
200 virtual void UpdateHash(HashSummator& S, void* data = nullptr, void* extra = nullptr);
210 virtual cStruct* pySerialize() {
211 return nullptr;
212 }
216#ifndef PY_PARSER
217 virtual const char* GetClassName() const;
219 virtual void RegisterMembers();
221 virtual int GetAmountOfElements();
227 virtual bool CheckDirectCasting() const { return false; }
230 virtual int GetClassSize() const;
233 virtual BaseClass* new_element() const;
248 virtual bool GetElement(BaseClassElement& res, int idx, const void* Ptr = nullptr, const void* Extra = nullptr);
257 bool GetElementByName(const char* Name, void* Ptr, void* Extra, BaseClassElement& res, bool UI = false, bool Serialize = true);
258 bool GetElementByNameAndType(const char* Name, const char* Type, void* Ptr, void* Extra, BaseClassElement& res, bool UI = false, bool Serialize = true);
263 void DeleteDefaultSubFields(TagsList& xml, void* ClassPtr, void* Extra = NULL);
265 virtual bool ShouldSaveInShortForm() { return false; }
270 virtual int ExpandWith(const char* ElmName,void* base){ return -1; }
272 virtual bool DelElement(int Index){return false;}
277#ifndef PY_PARSER
278 template<class Type = BaseClass>
280 bool valid() const;
281 template<>
282 bool valid<BaseClass>() const;
284 BaseClass* auto_cast(void* ptr) const;
308 virtual bool ReadFromFile (const char* Name, bool very_safe_with_backup = false);
309 virtual bool WriteToFile (const char* Name);
310 virtual bool WriteToFileIfChanged (const char* Name);
312#ifndef PY_PARSER
313 virtual void ToBS(BinStream& bs, bool IncludeLength);
314 virtual void FromBS(BinStream& bs);
315 virtual void ToBS(BinStream& bs, void* data, void* extra, bool IncludeLength);
316 virtual void FromBS(BinStream& bs, void* data, void* extra);
318 virtual void ToStr(comms::cStr& bs);
320 virtual void FromStr(const comms::cStr& bs);
323#ifndef PY_PARSER
325 virtual bool CheckIfFunction() const { return false; }
327 virtual int condition_call(void* ptr) { return -1; }
329 virtual BaseClass* GetParent() const {return ParentBC;}
330 template <typename type> type* FindParent();
333 virtual void SetParent(BaseClass* Parent);
335 virtual void SimplySetParent(BaseClass* Parent);
336 virtual bool MayBeParent() { return true; }
339 virtual bool CheckCompartabilityWith(const char* TypeName,int TypeSize){return true;}
341 // Editor events.
345 virtual bool ProcessInEditor(BaseClass* Parent) { return false; }
349 virtual bool RenderInScene(BaseClass* Parent) { return false; }
350 // Editor events.
355 virtual bool HandleKey(int code) { return false; }
361 virtual bool OnChangeMember(BaseClass* MembClass,void* MembPtr,void* MembExtra,const char* MembName){return false;}
367 virtual void BeforeChangeMember(BaseClass* MembClass,void* MembPtr,void* MembExtra,const char* MembName){}
368 virtual int GetElementLevel(const char* EName){return 0;}
379 virtual BaseWidget* OnCreateControlFromScratch(const ClassEditorContext& Context, Rct& Rect){ return NULL; }
389 virtual void OnModifyControl(const char* FieldName, BaseWidget* W, ClassEditorContext& Context){};
395 virtual bool CanBeDragged(const char* MemberID,int& dx,int& dy){return false;}
397 virtual bool CanAcceptDrag(const char* MemberID){return false;}
399 virtual bool OnStartDrag( const char* MemberID ){ return false; }
401 virtual bool OnEndDrag( const char* MemberID ){ return false; }
403 virtual bool OnAcceptDrag( BaseClass* DraggedItemParent, const char* DraggedMemberID, const char* AcceptorMemberID, iRct MyRect ){ return false; }
404 virtual bool UsePointerInHashCalculation() { return false; }
405 virtual bool SkipHash(){return false;}
406 virtual bool IsArray() const { return false; }
407 virtual const char* GetCmdID(){return NULL;}
414 static const char* GetCurrentSaveFile();
417 static const char* CurrentSaveFile;
419 virtual void UpdateClassMembersAndMask( bool recursive );
421 static bool SaveInShortForm;
422#ifndef PY_PARSER
423 virtual bool CallFromScript() const { return bCallFromScript; }
424 virtual void CallFromScript(const bool& b) { bCallFromScript = b; }
426 static bool& UI_definition();
427 static bool& Serialization();
429 bool bCallFromScript;
430 void test_presence_integrity();
432 static std::mutex* pmutex;
434 static uni_hash<_empty, cPtrDiff, (1 << 18), 2048> * presence;
435 void register_this();
436 void remove_this();
437#ifdef COAT_SG
439 SG::SG_Object* sgObj; // pointer to the script generator base obj
441 template <class T> T* toCastSGObj() const {
442 return static_cast<T*>(sgObj);
443 }
445 SG::SG_Object* GetSGObj() const { return sgObj; }
446 virtual void SetSGObj(SG::SG_Object* obj, bool bInit = false);
447 virtual void OnSetupSG() { ; }
448 virtual bool OnScriptRecorder(BaseClass* MembClass, void* MembPtr, void* MembExtra, const char* MembName);
449#endif // !PY_PARSER
452#ifndef PY_PARSER
453inline void HashSummator::operator+=(BaseClass* value) {
454 if(value)value->UpdateHash(*this);
456#endif // !PY_PARSER
Use this class for build a class for UI or serialization. see class_reg.h for details about the class...
Definition BaseClass.h:91
virtual bool CheckIfFunction() const
Special function for integrating in editor.
Definition BaseClass.h:325
bool valid() const
call it to check if this BaseClass pointer is valid
virtual void LoadBin(void *Data, void *Extra, BinStream *In, Enumerator *ExDictionary)
Load the class from the memory. Use only for temporary storage in memory!!!
virtual bool HandleKey(int code)
Editor will call next function when key pressed.
Definition BaseClass.h:355
virtual bool CopyBaseClass(BaseClass *Dest, bool Add=false)
Copy base class to other class uning names correspondence.
virtual bool ProcessInEditor(BaseClass *Parent)
Editor will call next function always when it is visible in tree. Return true if overriden.
Definition BaseClass.h:345
virtual BaseWidget * OnCreateControlFromScratch(const ClassEditorContext &Context, Rct &Rect)
Create completely own control for ClassEditor.
Definition BaseClass.h:379
virtual bool OnStartDrag(const char *MemberID)
Definition BaseClass.h:399
virtual bool CheckCompartabilityWith(const char *TypeName, int TypeSize)
Checking for errors of registration.
Definition BaseClass.h:339
virtual DWORD GetClassMask()
Masking elements of class. Each member has mask. Element is serializable/visible only if (it's_mask &...
Definition BaseClass.h:115
void SetParents()
set parents to this for all child members
bool GetElementByName(const char *Name, void *Ptr, void *Extra, BaseClassElement &res, bool UI=false, bool Serialize=true)
The function returns complete information about the member by it's name.
static const char * CurrentSaveFile
If user triggers saving class to file, last filename stored there.
Definition BaseClass.h:417
void DeleteDefaultSubFields(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Short form saving. Fields that are unchanged in comparison to default will be skipped in XML.
virtual bool OnAcceptDrag(BaseClass *DraggedItemParent, const char *DraggedMemberID, const char *AcceptorMemberID, iRct MyRect)
Definition BaseClass.h:403
virtual bool ReadFromFile(const char *Name, bool very_safe_with_backup=false)
Save the object to file or binary stream. Example.
virtual int GetAmountOfElementsInUI()
return amount of elements represented in UI
virtual void FromStr(const comms::cStr &bs)
virtual bool DelElement(int Index)
removes element if the operation supported
Definition BaseClass.h:272
virtual cStruct * pySerialize()
returns a list of python-generated properties for serialization and UI
Definition BaseClass.h:210
virtual int GetClassSize() const
return actual size of this class
virtual bool OnChangeMember(BaseClass *MembClass, void *MembPtr, void *MembExtra, const char *MembName)
Editor will call it every time when member changes and editor is able to recognise it.
Definition BaseClass.h:361
void ForEach(const std::function< bool(BaseClassElement *el)> &fn, bool OnlyPointsers=false)
Calls function for each class member. This function used in _EACH ... _EACH_END cycle.
BaseClass * GetRoot()
BaseClass is like a tree, and you always can get the root of the tree using this function.
virtual void BeforeChangeMember(BaseClass *MembClass, void *MembPtr, void *MembExtra, const char *MembName)
Editor will call it every time before the changes.
Definition BaseClass.h:367
virtual BaseClass * new_element() const
construct pointer to class of the same type like this. Elements will not be copied into the new place
virtual bool Load(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Load the class from the XML structure.
virtual bool ShouldSaveInShortForm()
Return true if class should be saved in short form mandatory.
Definition BaseClass.h:265
virtual bool CanBeDragged(const char *MemberID, int &dx, int &dy)
Use it for build a Drag & Drop element.
Definition BaseClass.h:395
virtual void reset_class(void *DataPtr=nullptr)
Clearing all registered content of the class. If DataPtr is nullptr, this class will be cleared.
virtual void OnModifyControl(const char *FieldName, BaseWidget *W, ClassEditorContext &Context)
Call for every member of registered class registered class.
Definition BaseClass.h:389
virtual void SetParent(BaseClass *Parent)
set parent recursively
virtual const char * GetClassName() const
return class name there if need. Usually you don't need, if you are using AUTONEW or SERIALIZE
virtual void SaveBin(void *Data, void *Extra, BinStream *Out, Enumerator *ExDictionary, Enumerator *SkipList)
Save in binaly form. Use only for temporary storage in memory!!!
virtual int GetAmountOfElements()
return complete amount of elements. Even invisible, masked and non-serialized elements will be counte...
virtual bool CanAcceptDrag(const char *MemberID)
Definition BaseClass.h:397
virtual void Save(TagsList &xml, void *ClassPtr, void *Extra=NULL)
Save class to the XML structure.
DWORD _ClassMask
Result of GetClassMask() written there. GetClassMask() is not const, so can't use it in const functio...
Definition BaseClass.h:96
virtual ~BaseClass()
virtual destructor
virtual int GetAmountOfElementsInXML()
return amount of elements taht will be stored in XML
virtual bool RenderInScene(BaseClass *Parent)
Editor will call next function to render in-scene controls always when it is visible in tree....
Definition BaseClass.h:349
virtual void CountObjects(int &required_index, int *counter, HashSummator *hash, BaseClassElement *result, const std::function< bool(BaseClassElement *)> *ForEachElem=nullptr, bool OnlyPointersMode=false)
This is the main function used for the access to class members. Each class that has SERIALIZE section...
Definition BaseClass.h:134
virtual bool GetElement(BaseClassElement &res, int idx, const void *Ptr=nullptr, const void *Extra=nullptr)
virtual void SimplySetParent(BaseClass *Parent)
set parent directly to this, not affecting members
virtual bool FullCopy(const void *SrcData, const void *SrcDataExtra, BaseClass *Dest, void *DestData, void *DstDataExtra, CECopyContext *C)
Fast copy from one BaseClass to another. Names and types correspondence used to copy.
void SetParentsSafe()
set parents to this for all child members, each child will be tested for validity
BaseClass * auto_cast(void *ptr) const
if class is directly castable the function returns ptr cased to BaseClass, othervice this pointrer re...
virtual bool OnEndDrag(const char *MemberID)
Definition BaseClass.h:401
virtual bool CheckDirectCasting() const
Definition BaseClass.h:227
static std::mutex * pmutex
mutex for register_this / remove_this
Definition BaseClass.h:432
BaseClass * ParentBC
pointer to the parent class in the tree
Definition BaseClass.h:94
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition BaseClass.h:270
virtual void UpdateHash(HashSummator &S, void *data=nullptr, void *extra=nullptr)
returns hash value dependent on data fields of this class
virtual int condition_call(void *ptr)
return -1 to do nothing, 0 if you want to hide everything after this registered member,...
Definition BaseClass.h:327
virtual void RegisterMembers()
Reload this function to register members. Usually you don't need to do this if you are using any of S...
The pointer to the allocated class derived from the BaseClass. It allows serialization/presentation i...
Definition classlist.h:565
This class intended to load/save the class derived from the BaseClass as XML/JSON....
Definition TagsList.h:21