Computer Assited Medical Intervention Tool Kit  version 5.0
modeling/libraries/pml/Component.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef COMPONENT_H
27 #define COMPONENT_H
28 
29 #include "RenderingMode.h"
30 #include "Properties.h"
31 #include <string>
32 #include <vector>
33 #include <algorithm> // for remove
34 class Cell;
35 class MultiComponent;
48 class Component {
49 public:
53  Component(PhysicalModel*, std::string n = "");
54 
56  virtual ~Component();
57 
59  bool isExclusive() const;
60 
62  void setExclusive(const bool);
63 
65  virtual bool isInstanceOf(const char*) const = 0;
66 
68  const std::string getName() const;
69 
71  void setName(const std::string);
72 
75  virtual void xmlPrint(std::ostream&) const = 0;
76 
78  virtual unsigned int getNumberOfCells() const = 0;
79 
81  virtual Cell* getCell(unsigned int) const = 0;
82 
84  virtual bool isVisible(const RenderingMode::Mode mode) const = 0;
85 
87  virtual void setVisible(const RenderingMode::Mode mode, const bool b) = 0;
88 
92  std::vector <MultiComponent*> getAllParentMultiComponents();
94 
96  unsigned int getNumberOfParentMultiComponents() const;
97 
100 
103 
108  virtual void setPhysicalModel(PhysicalModel*);
110 
113 
116 
117 protected:
119 
125  void removeFromParents();
126 
128  void deleteProperties();
129 
130 private:
131  bool exclusive;
132 
136  std::vector <MultiComponent*> parentMultiComponentList;
137 
138 };
139 
140 // -------------- inline -------------
141 inline void Component::setExclusive(const bool b) {
142  exclusive = b;
143 }
144 inline bool Component::isExclusive() const {
145  return exclusive;
146 }
147 inline const std::string Component::getName() const {
148  return properties->getName();
149 }
150 inline void Component::setName(const std::string n) {
151  properties->setName(n);
152 }
153 
154 // -------------- parent Multi Component admin -------------
155 
156 inline std::vector <MultiComponent*> Component::getAllParentMultiComponents() {
158 }
159 inline unsigned int Component::getNumberOfParentMultiComponents() const {
160  return (unsigned int) parentMultiComponentList.size();
161 }
163  if (i < parentMultiComponentList.size()) {
164  return parentMultiComponentList[i];
165  }
166  else {
167  return nullptr;
168  }
169 }
171  parentMultiComponentList.push_back(c);
172 }
174  auto it = std::find(parentMultiComponentList.begin(), parentMultiComponentList.end(), c);
175  if (it != parentMultiComponentList.end()) {
176  parentMultiComponentList.erase(it);
177  }
178 }
179 
182 }
183 
185  return properties->getPhysicalModel();
186 }
187 
189  return properties;
190 }
191 
192 
193 #endif //COMPONENT_H
Component::removeFromParents
void removeFromParents()
this tell the parent components that this component is removed from memory.
Definition: modeling/libraries/pml/Component.cpp:48
Component::parentMultiComponentList
std::vector< MultiComponent * > parentMultiComponentList
list of Component that are using this component (if another component is using this component,...
Definition: modeling/libraries/pml/Component.h:136
Component::properties
Properties * properties
Definition: modeling/libraries/pml/Component.h:118
Properties.h
RenderingMode.h
Component::isInstanceOf
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
Component::setExclusive
void setExclusive(const bool)
set the exclusive flag
Definition: modeling/libraries/pml/Component.h:141
Component::deleteProperties
void deleteProperties()
delete the "properties" pointer and set it to NULL
Definition: modeling/libraries/pml/Component.cpp:42
Component::getParentMultiComponent
MultiComponent * getParentMultiComponent(unsigned int)
get a particular MultiComponent that is using this Component (a particular parent component)
Definition: modeling/libraries/pml/Component.h:162
Properties::getName
std::string getName() const
get the name (be careful, this method DOES NOT return a copy, so you got the direct ptr to the name!...
Definition: Properties.h:250
Component::addParentMultiComponent
void addParentMultiComponent(MultiComponent *)
add a particular parent MultiComponent in the list
Definition: modeling/libraries/pml/Component.h:170
PhysicalModel
This is the main class of this project. Following a nice concept, a physical model is able to represe...
Definition: PhysicalModel.h:86
Component::xmlPrint
virtual void xmlPrint(std::ostream &) const =0
print to an output stream in "pseudo" XML format.
Component::getProperties
Properties * getProperties()
get the component structural properties (guarantied to be non NULL)
Definition: modeling/libraries/pml/Component.h:188
Component::getNumberOfCells
virtual unsigned int getNumberOfCells() const =0
get the total nr of cell of the component
Properties::getPhysicalModel
PhysicalModel * getPhysicalModel() const
get the physical model
Definition: Properties.h:262
Cell
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:46
Properties::setPhysicalModel
void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: Properties.h:258
Component::getName
const std::string getName() const
get the name of the component
Definition: modeling/libraries/pml/Component.h:147
Component::getCell
virtual Cell * getCell(unsigned int) const =0
conveniant method to get cell by order number (not cell index)
Component::exclusive
bool exclusive
Definition: modeling/libraries/pml/Component.h:131
Component::setVisible
virtual void setVisible(const RenderingMode::Mode mode, const bool b)=0
set the state of a visibility mode
Component::isVisible
virtual bool isVisible(const RenderingMode::Mode mode) const =0
return the state of a visibility mode
Component::getNumberOfParentMultiComponents
unsigned int getNumberOfParentMultiComponents() const
get the number of MultiComponent that are using this Component (= nr of parent component)
Definition: modeling/libraries/pml/Component.h:159
Properties::setName
void setName(std::string)
set the name (use the string = operator)
Definition: Properties.h:254
RenderingMode::Mode
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:63
Component
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
Component::setName
void setName(const std::string)
set the name of the component
Definition: modeling/libraries/pml/Component.h:150
Component::getAllParentMultiComponents
std::vector< MultiComponent * > getAllParentMultiComponents()
get the list of all the Multi Component that are using this Component
Definition: modeling/libraries/pml/Component.h:156
Component::removeParentMultiComponent
void removeParentMultiComponent(MultiComponent *)
remove a particular parent MultiComponent
Definition: modeling/libraries/pml/Component.h:173
Properties
Describes the properties common to all structures and components.
Definition: Properties.h:59
Component::Component
Component(PhysicalModel *, std::string n="")
Default constructor, a component needs to know the PM it is in.
Definition: modeling/libraries/pml/Component.cpp:30
Component::~Component
virtual ~Component()
Virtual destructor needed here as this is an abstract class (pure virtual)
Definition: modeling/libraries/pml/Component.cpp:36
MultiComponent
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44
Component::isExclusive
bool isExclusive() const
tell if this component is exclusive or not
Definition: modeling/libraries/pml/Component.h:144
Component::setPhysicalModel
virtual void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: modeling/libraries/pml/Component.h:180
Component::getPhysicalModel
PhysicalModel * getPhysicalModel() const
get the physical model
Definition: modeling/libraries/pml/Component.h:184