OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
node.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_NODE_HPP__
10 #define CMZN_NODE_HPP__
11 
12 #include "zinc/node.h"
13 #include "zinc/field.hpp"
14 #include "zinc/timesequence.hpp"
15 
16 namespace OpenCMISS
17 {
18 namespace Zinc
19 {
20 
21 class Fieldmodule;
22 class Nodeset;
23 class Nodetemplate;
24 
37 class Node
38 {
39 private:
40 
41  cmzn_node_id id;
42 
43 public:
44 
45  Node() : id(0)
46  { }
47 
48  // takes ownership of C handle, responsibility for destroying it
49  explicit Node(cmzn_node_id node_id) : id(node_id)
50  { }
51 
52  Node(const Node& node) :
53  id(cmzn_node_access(node.id))
54  { }
55 
60  {
61  CHANGE_FLAG_NONE = CMZN_NODE_CHANGE_FLAG_NONE,
63  CHANGE_FLAG_ADD = CMZN_NODE_CHANGE_FLAG_ADD,
65  CHANGE_FLAG_REMOVE = CMZN_NODE_CHANGE_FLAG_REMOVE,
67  CHANGE_FLAG_IDENTIFIER = CMZN_NODE_CHANGE_FLAG_IDENTIFIER,
69  CHANGE_FLAG_DEFINITION = CMZN_NODE_CHANGE_FLAG_DEFINITION,
71  CHANGE_FLAG_FIELD = CMZN_NODE_CHANGE_FLAG_FIELD
73  };
74 
78  typedef int ChangeFlags;
79 
84  {
85  VALUE_LABEL_INVALID = CMZN_NODE_VALUE_LABEL_INVALID,
87  VALUE_LABEL_VALUE = CMZN_NODE_VALUE_LABEL_VALUE,
89  VALUE_LABEL_D_DS1 = CMZN_NODE_VALUE_LABEL_D_DS1,
91  VALUE_LABEL_D_DS2 = CMZN_NODE_VALUE_LABEL_D_DS2,
93  VALUE_LABEL_D2_DS1DS2 = CMZN_NODE_VALUE_LABEL_D2_DS1DS2,
95  VALUE_LABEL_D_DS3 = CMZN_NODE_VALUE_LABEL_D_DS3,
97  VALUE_LABEL_D2_DS1DS3 = CMZN_NODE_VALUE_LABEL_D2_DS1DS3,
99  VALUE_LABEL_D2_DS2DS3 = CMZN_NODE_VALUE_LABEL_D2_DS2DS3,
101  VALUE_LABEL_D3_DS1DS2DS3 = CMZN_NODE_VALUE_LABEL_D3_DS1DS2DS3,
103  };
104 
105  Node& operator=(const Node& node)
106  {
107  cmzn_node_id temp_id = cmzn_node_access(node.id);
108  if (0 != id)
109  {
110  cmzn_node_destroy(&id);
111  }
112  id = temp_id;
113  return *this;
114  }
115 
116  ~Node()
117  {
118  if (0 != id)
119  {
120  cmzn_node_destroy(&id);
121  }
122  }
123 
129  bool isValid() const
130  {
131  return (0 != id);
132  }
133 
139  cmzn_node_id getId() const
140  {
141  return id;
142  }
143 
152  {
153  return cmzn_node_get_identifier(id);
154  }
155 
164  int setIdentifier(int identifier)
165  {
166  return cmzn_node_set_identifier(id, identifier);
167  }
168 
174  inline Nodeset getNodeset() const;
175 
176  int merge(const Nodetemplate& nodeTemplate);
177 
178 };
179 
180 inline bool operator==(const Node& a, const Node& b)
181 {
182  return a.getId() == b.getId();
183 }
184 
193 {
194 private:
195 
196  cmzn_nodetemplate_id id;
197 
198 public:
199 
200  Nodetemplate() : id(0)
201  { }
202 
203  // takes ownership of C handle, responsibility for destroying it
204  explicit Nodetemplate(cmzn_nodetemplate_id node_template_id) :
205  id(node_template_id)
206  { }
207 
208  Nodetemplate(const Nodetemplate& nodeTemplate) :
209  id(cmzn_nodetemplate_access(nodeTemplate.id))
210  { }
211 
212  Nodetemplate& operator=(const Nodetemplate& nodeTemplate)
213  {
214  cmzn_nodetemplate_id temp_id = cmzn_nodetemplate_access(nodeTemplate.id);
215  if (0 != id)
216  {
217  cmzn_nodetemplate_destroy(&id);
218  }
219  id = temp_id;
220  return *this;
221  }
222 
223  ~Nodetemplate()
224  {
225  if (0 != id)
226  {
227  cmzn_nodetemplate_destroy(&id);
228  }
229  }
230 
236  bool isValid() const
237  {
238  return (0 != id);
239  }
240 
246  cmzn_nodetemplate_id getId() const
247  {
248  return id;
249  }
250 
260  int defineField(const Field& field)
261  {
262  return cmzn_nodetemplate_define_field(id, field.getId());
263  }
264 
279  int setTimesequence(const Field& field, const Timesequence& timesequence)
280  {
281  return cmzn_nodetemplate_set_timesequence(id, field.getId(), timesequence.getId());
282  }
283 
297  int getValueNumberOfVersions(const Field& field, int componentNumber,
298  Node::ValueLabel valueLabel)
299  {
300  return cmzn_nodetemplate_get_value_number_of_versions(id, field.getId(),
301  componentNumber, static_cast<cmzn_node_value_label>(valueLabel));
302  }
303 
327  int setValueNumberOfVersions(const Field& field, int componentNumber,
328  Node::ValueLabel valueLabel, int numberOfVersions)
329  {
330  return cmzn_nodetemplate_set_value_number_of_versions(id, field.getId(),
331  componentNumber, static_cast<cmzn_node_value_label>(valueLabel), numberOfVersions);
332  }
333 
343  int undefineField(const Field& field)
344  {
345  return cmzn_nodetemplate_undefine_field(id, field.getId());
346  }
347 };
348 
355 {
356 private:
357 
358  cmzn_nodeiterator_id id;
359 
360 public:
361 
362  Nodeiterator() : id(0)
363  { }
364 
365  // takes ownership of C handle, responsibility for destroying it
366  explicit Nodeiterator(cmzn_nodeiterator_id node_iterator_id) :
367  id(node_iterator_id)
368  { }
369 
370  Nodeiterator(const Nodeiterator& nodeIterator) :
371  id(cmzn_nodeiterator_access(nodeIterator.id))
372  { }
373 
374  Nodeiterator& operator=(const Nodeiterator& nodeIterator)
375  {
376  cmzn_nodeiterator_id temp_id = cmzn_nodeiterator_access(nodeIterator.id);
377  if (0 != id)
378  {
379  cmzn_nodeiterator_destroy(&id);
380  }
381  id = temp_id;
382  return *this;
383  }
384 
385  ~Nodeiterator()
386  {
387  if (0 != id)
388  {
389  cmzn_nodeiterator_destroy(&id);
390  }
391  }
392 
398  bool isValid() const
399  {
400  return (0 != id);
401  }
402 
411  {
412  return Node(cmzn_nodeiterator_next(id));
413  }
414 };
415 
421 class Nodeset
422 {
423 protected:
424 
425  cmzn_nodeset_id id;
426 
427 public:
428 
429  Nodeset() : id(0)
430  { }
431 
432  // takes ownership of C handle, responsibility for destroying it
433  explicit Nodeset(cmzn_nodeset_id nodeset_id) : id(nodeset_id)
434  { }
435 
436  Nodeset(const Nodeset& nodeset) :
437  id(cmzn_nodeset_access(nodeset.id))
438  { }
439 
440  Nodeset& operator=(const Nodeset& nodeset)
441  {
442  cmzn_nodeset_id temp_id = cmzn_nodeset_access(nodeset.id);
443  if (0 != id)
444  {
445  cmzn_nodeset_destroy(&id);
446  }
447  id = temp_id;
448  return *this;
449  }
450 
451  ~Nodeset()
452  {
453  if (0 != id)
454  {
455  cmzn_nodeset_destroy(&id);
456  }
457  }
458 
464  bool isValid() const
465  {
466  return (0 != id);
467  }
468 
474  cmzn_nodeset_id getId() const
475  {
476  return id;
477  }
478 
485  bool containsNode(const Node& node)
486  {
487  return cmzn_nodeset_contains_node(id, node.getId());
488  }
489 
498  {
499  return Nodetemplate(cmzn_nodeset_create_nodetemplate(id));
500  }
501 
512  Node createNode(int identifier, const Nodetemplate& nodeTemplate)
513  {
514  return Node(cmzn_nodeset_create_node(id, identifier, nodeTemplate.getId()));
515  }
516 
528  {
529  return Nodeiterator(cmzn_nodeset_create_nodeiterator(id));
530  }
531 
539  {
540  return cmzn_nodeset_destroy_all_nodes(id);
541  }
542 
550  int destroyNode(const Node& node)
551  {
552  return cmzn_nodeset_destroy_node(id, node.getId());
553  }
554 
566  int destroyNodesConditional(const Field& conditionalField)
567  {
568  return cmzn_nodeset_destroy_nodes_conditional(id, conditionalField.getId());
569  }
570 
577  Node findNodeByIdentifier(int identifier)
578  {
579  return Node(cmzn_nodeset_find_node_by_identifier(id, identifier));
580  }
581 
587  inline Fieldmodule getFieldmodule() const;
588 
596  {
597  return Nodeset(cmzn_nodeset_get_master_nodeset(id));
598  }
599 
607  char *getName()
608  {
609  return cmzn_nodeset_get_name(id);
610  }
611 
617  int getSize()
618  {
619  return cmzn_nodeset_get_size(id);
620  }
621 
622 };
623 
624 inline bool operator==(const Nodeset& a, const Nodeset& b)
625 {
626  return cmzn_nodeset_match(a.getId(), b.getId());
627 }
628 
629 inline Nodeset Node::getNodeset() const
630 {
631  return Nodeset(cmzn_node_get_nodeset(id));
632 }
633 
639 class NodesetGroup : public Nodeset
640 {
641 
642 public:
643 
644  // takes ownership of C handle, responsibility for destroying it
645  explicit NodesetGroup(cmzn_nodeset_group_id nodeset_id) : Nodeset(reinterpret_cast<cmzn_nodeset_id>(nodeset_id))
646  { }
647 
653  cmzn_nodeset_group_id getId() const
654  {
655  return (cmzn_nodeset_group_id)(id);
656  }
657 
664  int addNode(const Node& node)
665  {
666  return cmzn_nodeset_group_add_node(
667  reinterpret_cast<cmzn_nodeset_group_id>(id), node.getId());
668  }
669 
676  {
677  return cmzn_nodeset_group_remove_all_nodes(
678  reinterpret_cast<cmzn_nodeset_group_id>(id));
679  }
680 
687  int removeNode(const Node& node)
688  {
689  return cmzn_nodeset_group_remove_node(reinterpret_cast<cmzn_nodeset_group_id>(id),
690  node.getId());
691  }
692 
702  int removeNodesConditional(const Field& conditionalField)
703  {
704  return cmzn_nodeset_group_remove_nodes_conditional(
705  reinterpret_cast<cmzn_nodeset_group_id>(id), conditionalField.getId());
706  }
707 
708 };
709 
716 {
717 private:
718 
719  cmzn_nodesetchanges_id id;
720 
721 public:
722 
723  Nodesetchanges() : id(0)
724  { }
725 
726  // takes ownership of C handle, responsibility for destroying it
727  explicit Nodesetchanges(cmzn_nodesetchanges_id nodesetchanges_id) :
728  id(nodesetchanges_id)
729  { }
730 
731  Nodesetchanges(const Nodesetchanges& nodesetchanges) :
732  id(cmzn_nodesetchanges_access(nodesetchanges.id))
733  { }
734 
735  Nodesetchanges& operator=(const Nodesetchanges& nodesetchanges)
736  {
737  cmzn_nodesetchanges_id temp_id = cmzn_nodesetchanges_access(nodesetchanges.id);
738  if (0 != id)
739  cmzn_nodesetchanges_destroy(&id);
740  id = temp_id;
741  return *this;
742  }
743 
744  ~Nodesetchanges()
745  {
746  if (0 != id)
747  cmzn_nodesetchanges_destroy(&id);
748  }
749 
755  bool isValid() const
756  {
757  return (0 != id);
758  }
759 
760  Node::ChangeFlags getNodeChangeFlags(const Node& node)
761  {
762  return cmzn_nodesetchanges_get_node_change_flags(id, node.getId());
763  }
764 
773  {
774  return cmzn_nodesetchanges_get_number_of_changes(id);
775  }
776 
777  Node::ChangeFlags getSummaryNodeChangeFlags()
778  {
779  return cmzn_nodesetchanges_get_summary_node_change_flags(id);
780  }
781 };
782 
783 inline int Node::merge(const Nodetemplate& nodeTemplate)
784 {
785  return cmzn_node_merge(id, nodeTemplate.getId());
786 }
787 
788 } // namespace Zinc
789 }
790 
791 #endif
An iterator for looping through all the nodes in a nodeset.
Definition: node.hpp:354
bool isValid() const
Definition: node.hpp:755
Object describing changes to a nodeset in a fieldmoduleevent.
Definition: node.hpp:715
bool isValid() const
Definition: node.hpp:464
int setTimesequence(const Field &field, const Timesequence &timesequence)
Definition: node.hpp:279
int addNode(const Node &node)
Definition: node.hpp:664
cmzn_nodetemplate_id getId() const
Definition: node.hpp:246
int setValueNumberOfVersions(const Field &field, int componentNumber, Node::ValueLabel valueLabel, int numberOfVersions)
Definition: node.hpp:327
A description of field parameters to define at a node.
Definition: node.hpp:192
int removeNode(const Node &node)
Definition: node.hpp:687
ValueLabel
Definition: node.hpp:83
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
int removeNodesConditional(const Field &conditionalField)
Definition: node.hpp:702
int getIdentifier()
Definition: node.hpp:151
A subset of a master nodeset.
Definition: node.hpp:639
cmzn_nodeset_id getId() const
Definition: node.hpp:474
int destroyAllNodes()
Definition: node.hpp:538
Node next()
Definition: node.hpp:410
bool isValid() const
Definition: node.hpp:236
cmzn_nodeset_group_id getId() const
Definition: node.hpp:653
ChangeFlag
Definition: node.hpp:59
Node findNodeByIdentifier(int identifier)
Definition: node.hpp:577
int undefineField(const Field &field)
Definition: node.hpp:343
Nodetemplate createNodetemplate()
Definition: node.hpp:497
int getValueNumberOfVersions(const Field &field, int componentNumber, Node::ValueLabel valueLabel)
Definition: node.hpp:297
cmzn_field_id getId() const
Definition: field.hpp:98
Nodeiterator createNodeiterator()
Definition: node.hpp:527
int destroyNode(const Node &node)
Definition: node.hpp:550
int setIdentifier(int identifier)
Definition: node.hpp:164
bool isValid() const
Definition: node.hpp:398
Nodeset getMasterNodeset()
Definition: node.hpp:595
Nodeset getNodeset() const
Definition: node.hpp:629
int getSize()
Definition: node.hpp:617
char * getName()
Definition: node.hpp:607
cmzn_node_id getId() const
Definition: node.hpp:139
int getNumberOfChanges()
Definition: node.hpp:772
int defineField(const Field &field)
Definition: node.hpp:260
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:126
bool isValid() const
Definition: node.hpp:129
A non-decreasing list of times at which nodal parameters can be stored.
Definition: timesequence.hpp:35
Node createNode(int identifier, const Nodetemplate &nodeTemplate)
Definition: node.hpp:512
cmzn_timesequence_id getId() const
Definition: timesequence.hpp:88
int ChangeFlags
Definition: node.hpp:78
bool containsNode(const Node &node)
Definition: node.hpp:485
Point object used to represent finite element nodes.
Definition: node.hpp:37
int removeAllNodes()
Definition: node.hpp:675
int destroyNodesConditional(const Field &conditionalField)
Definition: node.hpp:566
A set of nodes or points.
Definition: node.hpp:421
Fieldmodule getFieldmodule() const
Definition: fieldmodule.hpp:1582