3DCoat Core API
The 3DCoat API documentation.
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
BaseClass.h
1#pragma once
2
3
4#include <functional>
5
6#include "pool.h"
7#include "BaseClassIO.h"
8class BaseClass;
9class cStruct;
10#ifdef COAT_SG
11
12namespace SG {
13 class SG_Object;
14}
15
16#endif
17
55struct BaseClassElement {
56 comms::cStr RegOpt;
58 BaseClass* BC;
60 void* Ptr;
62 void* Extra;
64 const char* ID;
66 DWORD Mask;
68 bool Visible : 1;
70 bool ReadOnly : 1;
72 bool Serialize : 1;
73 bool ApplyScale : 1;
74 bool Noname : 1;
75 bool Noreset : 1;
76 float Scaling;
79 bool CachedValue : 1;
80 unsigned short CachedIndex;
82 void fill(void* _Ptr, void* _Extra, bool _vis, bool _ui, bool OnlyPointersMode);
83
84 void reset(bool initmask=true);
85 void minimal_reset();
86 BaseClassElement();
87};
88
89typedef void (*voidFunc)();
94class APICALL BaseClass{
95protected:
100public:
101#ifndef PY_PARSER
102 friend BaseClassElement;
103#endif
104 //explicit BaseClass(const BaseClass&);
105 //BaseClass& operator = (const BaseClass&);
107#ifndef PY_PARSER
109#endif
110 BaseClass();
111#ifndef PY_PARSER
112 BaseClass(const BaseClass&);
113#endif
115 virtual ~BaseClass();
116
118 virtual DWORD GetClassMask() { return 0xFFFFFFFF; }
119 DWORD& ClassMask() { return _ClassMask; }
120
121 void runFunction(voidFunc func) { func(); }
122
124 virtual void reset_class(void* DataPtr = nullptr);
125
127
139 virtual void CountObjects(int& required_index, int* counter, HashSummator* hash, BaseClassElement* result, const std::function<bool(BaseClassElement*)>* ForEachElem = nullptr, bool OnlyPointersMode = false) { }
140
146 void ForEach(const std::function<bool(BaseClassElement* el)>& fn, bool OnlyPointsers = false);
147
154 virtual bool CopyBaseClass(BaseClass* Dest, bool Add = false);
155
156
163 virtual void Save(TagsList& xml, void* ClassPtr, void* Extra = NULL);
171 virtual bool Load(TagsList& xml, void* ClassPtr, void* Extra = NULL);
182 virtual bool FullCopy(const void* SrcData, const void* SrcDataExtra, BaseClass* Dest, void* DestData, void* DstDataExtra, CECopyContext* C);
191 virtual void SaveBin(void* Data, void* Extra, BinStream* Out, Enumerator* ExDictionary, Enumerator* SkipList);
199 virtual void LoadBin(void* Data, void* Extra, BinStream* In, Enumerator* ExDictionary);
200#ifndef PY_PARSER
207 virtual void UpdateHash(HashSummator& S, void* data = nullptr, void* extra = nullptr);
208#endif
213
217 virtual cStruct* pySerialize() {
218 return nullptr;
219 }
221
223#ifndef PY_PARSER
224 virtual const char* GetClassName() const;
226 virtual void RegisterMembers();
228 virtual int GetAmountOfElements();
229
234 virtual bool CheckDirectCasting() const { return false; }
235
237 virtual int GetClassSize() const;
238
240 virtual BaseClass* new_element() const;
241#endif
242
244
246
255 virtual bool GetElement(BaseClassElement& res, int idx, const void* Ptr = nullptr, const void* Extra = nullptr);
264 bool GetElementByName(const char* Name, void* Ptr, void* Extra, BaseClassElement& res, bool UI = false, bool Serialize = true);
265 bool GetElementByNameAndType(const char* Name, const char* Type, void* Ptr, void* Extra, BaseClassElement& res, bool UI = false, bool Serialize = true);
266
268
270 void DeleteDefaultSubFields(TagsList& xml, void* ClassPtr, void* Extra = NULL);
272 virtual bool ShouldSaveInShortForm() { return false; }
273
275
277 virtual int ExpandWith(const char* ElmName,void* base){ return -1; }
279 virtual bool DelElement(int Index){return false;}
280
282
284#ifndef PY_PARSER
285 template<class Type = BaseClass>
286 bool valid() const;
287 template<>
288 bool valid<BaseClass>() const;
289#endif
291 BaseClass* auto_cast(void* ptr) const;
292
315 virtual bool ReadFromFile (const char* Name, bool very_safe_with_backup = false);
316 virtual bool WriteToFile (const char* Name);
317 virtual bool WriteToFileIfChanged (const char* Name);
318
319#ifndef PY_PARSER
320 virtual void ToBS(BinStream& bs, bool IncludeLength);
321 virtual void FromBS(BinStream& bs);
322 virtual void ToBS(BinStream& bs, void* data, void* extra, bool IncludeLength);
323 virtual void FromBS(BinStream& bs, void* data, void* extra);
324#endif
325 virtual void ToStr(comms::cStr& bs);
327 virtual void FromStr(const comms::cStr& bs);
328
329
330#ifndef PY_PARSER
332 virtual bool CheckIfFunction() const { return false; }
334 virtual int condition_call(void* ptr) { return -1; }
335
336 virtual BaseClass* GetParent() const {return ParentBC;}
337 template <typename type> type* FindParent();
338#endif
340 virtual void SetParent(BaseClass* Parent);
342 virtual void SimplySetParent(BaseClass* Parent);
343 virtual bool MayBeParent() { return true; }
344
346 virtual bool CheckCompartabilityWith(const char* TypeName,int TypeSize){return true;}
347
348 // Editor events.
352 virtual bool ProcessInEditor(BaseClass* Parent) { return false; }
356 virtual bool RenderInScene(BaseClass* Parent) { return false; }
357 // Editor events.
362 virtual bool HandleKey(int code) { return false; }
368 virtual bool OnChangeMember(BaseClass* MembClass,void* MembPtr,void* MembExtra,const char* MembName){return false;}
374 virtual void BeforeChangeMember(BaseClass* MembClass,void* MembPtr,void* MembExtra,const char* MembName){}
375 virtual int GetElementLevel(const char* EName){return 0;}
386 virtual BaseWidget* OnCreateControlFromScratch(const ClassEditorContext& Context, Rct& Rect){ return NULL; }
396 virtual void OnModifyControl(const char* FieldName, BaseWidget* W, ClassEditorContext& Context){};
397
402 virtual bool CanBeDragged(const char* MemberID,int& dx,int& dy){return false;}
404 virtual bool CanAcceptDrag(const char* MemberID){return false;}
406 virtual bool OnStartDrag( const char* MemberID ){ return false; }
408 virtual bool OnEndDrag( const char* MemberID ){ return false; }
410 virtual bool OnAcceptDrag( BaseClass* DraggedItemParent, const char* DraggedMemberID, const char* AcceptorMemberID, iRct MyRect ){ return false; }
411 virtual bool UsePointerInHashCalculation() { return false; }
412 virtual bool SkipHash(){return false;}
413 virtual bool IsArray() const { return false; }
414 virtual const char* GetCmdID(){return NULL;}
419
420
421 static const char* GetCurrentSaveFile();
422
424 static const char* CurrentSaveFile;
425
426 virtual void UpdateClassMembersAndMask( bool recursive );
427
428 static bool SaveInShortForm;
429#ifndef PY_PARSER
430 virtual bool CallFromScript() const { return bCallFromScript; }
431 virtual void CallFromScript(const bool& b) { bCallFromScript = b; }
432#endif
433 static bool& UI_definition();
434 static bool& Serialization();
435protected:
436 bool bCallFromScript;
437 void test_presence_integrity();
439 static std::mutex& get_bc_mutex();
441 static uni_hash<_empty, cPtrDiff, (1 << 18), 2048>& presence();
442 void register_this();
443 void remove_this();
444#ifdef COAT_SG
445protected:
446 SG::SG_Object* sgObj; // pointer to the script generator base obj
447
448 template <class T> T* toCastSGObj() const {
449 return static_cast<T*>(sgObj);
450 }
451public:
452 SG::SG_Object* GetSGObj() const { return sgObj; }
453 virtual void SetSGObj(SG::SG_Object* obj, bool bInit = false);
454 virtual void OnSetupSG() { ; }
455 virtual bool OnScriptRecorder(BaseClass* MembClass, void* MembPtr, void* MembExtra, const char* MembName);
456#endif // !PY_PARSER
457
458};
459#ifndef PY_PARSER
460inline void HashSummator::operator+=(BaseClass* value) {
461 if(value)value->UpdateHash(*this);
462}
463#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:94
virtual bool CheckIfFunction() const
Special function for integrating in editor.
Definition BaseClass.h:332
bool valid() const
call it to check if this BaseClass pointer is valid
static std::mutex & get_bc_mutex()
mutex for register_this / remove_this
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:362
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:352
virtual BaseWidget * OnCreateControlFromScratch(const ClassEditorContext &Context, Rct &Rect)
Create completely own control for ClassEditor.
Definition BaseClass.h:386
virtual bool OnStartDrag(const char *MemberID)
Definition BaseClass.h:406
virtual bool CheckCompartabilityWith(const char *TypeName, int TypeSize)
Checking for errors of registration.
Definition BaseClass.h:346
virtual DWORD GetClassMask()
Masking elements of class. Each member has mask. Element is serializable/visible only if (it's_mask &...
Definition BaseClass.h:118
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:424
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:410
static uni_hash< _empty, cPtrDiff,(1<< 18), 2048 > & presence()
each BaseClass registered in this list
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:279
virtual cStruct * pySerialize()
returns a list of python-generated properties for serialization and UI
Definition BaseClass.h:217
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:368
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:374
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:272
virtual bool CanBeDragged(const char *MemberID, int &dx, int &dy)
Use it for build a Drag & Drop element.
Definition BaseClass.h:402
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:396
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:404
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:99
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:356
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:139
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:408
virtual bool CheckDirectCasting() const
Definition BaseClass.h:234
BaseClass * ParentBC
pointer to the parent class in the tree
Definition BaseClass.h:97
virtual int ExpandWith(const char *ElmName, void *base)
Expand array with class ElmName.
Definition BaseClass.h:277
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:334
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