FEDEM Model Database  R8.0
Source code of the FEDEM model database
FmBase.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FM_BASE_H
14 #define FM_BASE_H
15 
19 
20 #include "vpmDB/FmArray.H"
21 #include "vpmDB/FmTypeCheck.H"
22 
23 class FmRingStart;
24 class FmSubAssembly;
25 
26 
36 class FmBase : public FFaFieldContainer
37 {
41 
42 public:
44  FmBase* getNext() const { return itsNextRingPt; }
46  FmBase* getPrev() const { return itsPrevRingPt; }
47 
48  // Description text
49 
51  virtual std::string getUserDescription(size_t maxLength = 0) const;
53  virtual bool setUserDescription(const std::string& descr);
54 
56  bool makeCopyDescr();
57 
59  virtual std::string getInfoString() const;
61  virtual std::string getIdPath(bool withBrackets = true) const;
63  std::string getIdString(bool withDescription = false) const;
64 
66  int getID() const { return myID.getValue(); }
68  void setID(int Id) { myID.setValue(Id); }
69 
71  void getAssemblyID(IntVec& assID) const;
75  FmBase* getCommonAncestor(const FmBase* other) const;
77  void setParentAssembly(FmBase* subAss);
79  void setParentAssembly(int Id, int classType = -1);
80 
81  // Reimplemented from FFaFieldContainer
82 
83  int getResolvedID() const final { return this->getID(); }
85  void getResolvedAssemblyID(IntVec& assID) const final;
86 
87  // Topology
88 
90  bool cloneOrConnect();
92  virtual bool connect() { return this->mainConnect(); }
94  virtual bool disconnect() { return this->mainDisconnect(); }
96  virtual void drawObject() {}
97 
99  bool isPartOf(const FmSubAssembly* subAss) const;
100 
101  // File IO
102 
104  std::ostream& writeFields(std::ostream& os) const;
105 
107  virtual std::ostream& writeFMF(std::ostream& os) { return os; }
109  virtual bool clone(FmBase*, int) { return false; }
111  virtual FmBase* clone(int) const { return NULL; }
112 
114  virtual const char* getUITypeName() const;
115 
117  virtual void onMainConnected() {}
119  virtual void onMainDisconnected() {}
121  virtual void onMainAboutToDisconnect() {}
122 
124  enum CopyMode {
129  DEEP_REPLACE
130  };
131 
132 private:
135 
140 
143 
144 protected:
146  explicit FmBase(bool isDummy = false);
148  virtual ~FmBase();
149 
151  bool eraseOrConnect();
153  bool mainConnect(bool allowNonUniqueIDs = false);
155  bool mainDisconnect();
156 
158  void insertAfter(FmBase* afterPt);
159 
161  static bool localParse(const char* keyWord, std::istream& activeStatement,
162  FmBase* obj);
164  virtual bool cloneLocal(FmBase* obj, int depth);
165 };
166 
167 #endif
Base class for the FEDEM model database structure.
Template class for field representation in the FEDEM model database.
std::vector< int > IntVec
Convenience type alias.
Definition: FFaField.H:25
Classes representing guarded pointers.
Type checking control.
#define Fmd_DB_HEADER_INIT()
Macro enabling type checking for a class.
Definition: FmTypeCheck.H:24
Base class for the FEDEM model database structure.
Definition: FFaFieldContainer.H:39
bool setValue(const ValueT &newData, bool checkChanged=true)
Assigns a new value to the field.
Definition: FFaField.H:66
const ValueT & getValue() const
Returns a const reference to myData.
Definition: FFaField.H:56
Type * getPointer() const
Returns the type-casted pointer this reference points to.
Definition: FFaReference.H:234
Base parent class for the model data structure entries.
Definition: FmBase.H:37
virtual std::string getInfoString() const
Returns a composed string describing this object.
Definition: FmBase.C:387
virtual void drawObject()
Visualization interface for objects that can be rendered.
Definition: FmBase.H:96
virtual std::ostream & writeFMF(std::ostream &os)
Writes out this object in the model database file format.
Definition: FmBase.H:107
bool cloneOrConnect()
Inserts or copies this object into the model database.
Definition: FmBase.C:194
bool mainConnect(bool allowNonUniqueIDs=false)
Inserts this object into the model database, unless aready present.
Definition: FmBase.C:228
int getID() const
Returns the user ID of this object.
Definition: FmBase.H:66
void insertAfter(FmBase *afterPt)
Inserts *this after *afterPt in the database ring.
Definition: FmBase.C:276
bool makeCopyDescr()
Prepends "Copy of " to the user description.
Definition: FmBase.C:421
FFaField< FFaReferenceBase * > myParentAssemblyField
Data field for the reference to the parent sub-assembly.
Definition: FmBase.H:139
int getResolvedID() const final
Returns the user Id of *this, for use in I/O and resolving.
Definition: FmBase.H:83
FFaReference< FmBase > myParentAssembly
Reference to the parent sub-assembly of this object, if any.
Definition: FmBase.H:137
void getAssemblyID(IntVec &assID) const
Retrieves the assembly ID of this object.
Definition: FmBase.C:126
bool isPartOf(const FmSubAssembly *subAss) const
Returns true if *this is part of the specified sub-assembly.
Definition: FmBase.C:108
bool eraseOrConnect()
Conditionally inserts this object into the model database.
Definition: FmBase.C:176
FmBase * itsPrevRingPt
Pointer to the previous entry in the main ring.
Definition: FmBase.H:142
FmBase * getPrev() const
Returns the previous object in the linked list.
Definition: FmBase.H:46
virtual FmBase * clone(int) const
Returns an unconnected copy of this object.
Definition: FmBase.H:111
virtual bool setUserDescription(const std::string &descr)
Sets the user-defined description of this object.
Definition: FmBase.C:344
FmBase * getCommonAncestor(const FmBase *other) const
Returns the sub-assembly both *this and *other descent from.
Definition: FmBase.C:153
CopyMode
Enumerator for the different copying modes.
Definition: FmBase.H:124
@ SHALLOW
Copy all data fields, but not the references.
Definition: FmBase.H:126
@ DEEP_APPEND
Also copy and resolve references.
Definition: FmBase.H:128
@ DEEP_REPLACE
Also copy references, replacing existing ones.
Definition: FmBase.H:129
@ NOTHING
Don't copy any data fields.
Definition: FmBase.H:125
@ DEEP_UNRESOLVED
Also copy references, but leave them unresolved.
Definition: FmBase.H:127
FmBase * itsNextRingPt
Pointer to the next entry in the main ring.
Definition: FmBase.H:141
void getResolvedAssemblyID(IntVec &assID) const final
Gets the assembly path of *this, for use in I/O and resolving.
Definition: FmBase.C:143
virtual std::string getUserDescription(size_t maxLength=0) const
Returns the user-defined description of this object.
Definition: FmBase.C:371
virtual std::string getIdPath(bool withBrackets=true) const
Returns the user ID including the sub-assembly path.
Definition: FmBase.C:69
virtual bool connect()
Inserts this object into the model database.
Definition: FmBase.H:92
void setID(int Id)
Sets the user ID of this object.
Definition: FmBase.H:68
virtual bool clone(FmBase *, int)
Copies the fields of another object into *this.
Definition: FmBase.H:109
FmBase * getNext() const
Returns the next object in the linked list.
Definition: FmBase.H:44
virtual void onMainDisconnected()
Invokes call-backs after this object is removed from the database.
Definition: FmBase.H:119
FmBase * getParentAssembly() const
Returns the sub-assembly this object is part of, if any.
Definition: FmBase.H:73
virtual const char * getUITypeName() const
Returns the type name of this object for use in the GUI.
Definition: FmBase.C:409
virtual void onMainAboutToDisconnect()
Invokes call-backs before this object is removed from the database.
Definition: FmBase.H:121
FmBase(bool isDummy=false)
Default constructor.
Definition: FmBase.C:37
virtual ~FmBase()
Empty destructor.
Definition: FmBase.C:59
std::ostream & writeFields(std::ostream &os) const
Writes all data fields of this object to the given output stream.
Definition: FmBase.C:302
virtual bool cloneLocal(FmBase *obj, int depth)
Clones the data fields of *obj into *this.
Definition: FmBase.C:317
FFaField< std::string > myDescription
User-defined description text.
Definition: FmBase.H:133
virtual void onMainConnected()
Invokes call-backs after this object is inserted into the database.
Definition: FmBase.H:117
bool mainDisconnect()
Removes this object from the model database, if present.
Definition: FmBase.C:285
FFaNoCopyField< int > myID
User ID, unique only within one type.
Definition: FmBase.H:134
virtual bool disconnect()
Removes this object from the model database.
Definition: FmBase.H:94
void setParentAssembly(FmBase *subAss)
Sets the parent sub-assembly for this object.
Definition: FmBase.C:100
std::string getIdString(bool withDescription=false) const
Returns a composed string describing this object.
Definition: FmBase.C:398
static bool localParse(const char *keyWord, std::istream &activeStatement, FmBase *obj)
Parses the keyWord field for *obj, if it is a defined field.
Definition: FmBase.C:329
Definition: FmRingStart.H:16
Base class for all sub-assembly objects.
Definition: FmSubAssembly.H:28