Salome HOME
First publish of HEXABLOCKcomponant
[modules/hexablock.git] / src / HEXABLOCK_I / HexGroup_impl.cxx
1 using namespace std;
2 #include "HEXABLOCK.hxx"
3 #include "utilities.h"
4
5 #include <string>
6
7 #include "hexa_base.hxx"
8 #include "HexEltBase.hxx"
9 #include "HexGroups.hxx"
10
11 #include "HexElements_impl.hxx"
12
13 #include "HexVertex_impl.hxx"
14 #include "HexEdge_impl.hxx"
15 #include "HexQuad_impl.hxx"
16 #include "HexHexa_impl.hxx"
17 #include "HexGroup_impl.hxx"
18
19 Group_impl::Group_impl( HEXA_NS::Group *ptrCpp ):_group_cpp(ptrCpp)
20 {
21 }
22
23 HEXA_NS::Group* Group_impl::GetImpl() throw (SALOME::SALOME_Exception)
24 {
25   return _group_cpp;
26 }
27
28 char* Group_impl::getName() throw (SALOME::SALOME_Exception)
29 {
30   _group_cpp->getName();
31 }
32
33 void Group_impl::setName(const char* name) throw (SALOME::SALOME_Exception)
34 {
35   _group_cpp->setName( name );
36 }
37
38
39 GroupKind Group_impl::getKind() throw (SALOME::SALOME_Exception)
40 {
41   HEXA_NS::EnumGroup k = _group_cpp->getKind();
42
43   switch (k){
44     case HEXA_NS::HexaCell:  return HEXA_GROUP;
45     case HEXA_NS::QuadCell:  return QUAD_GROUP;
46     case HEXA_NS::EdgeCell:  return EDGE_GROUP;
47     case HEXA_NS::HexaNode:  return HEXANODE_GROUP;
48     case HEXA_NS::QuadNode:  return QUADNODE_GROUP;
49     case HEXA_NS::EdgeNode:  return EDGENODE_GROUP;
50     case HEXA_NS::Vertex_Node:  return VERTEXNODE_GROUP;
51     default : ASSERT(false);
52   }
53 }
54
55
56 ::CORBA::Long  Group_impl::addElement(Element_ptr eIn) throw (SALOME::SALOME_Exception)
57 {
58   ::CORBA::Long ok;
59   Vertex_impl* vInServant = ::DownCast<Vertex_impl*>( eIn );
60   Edge_impl*   eInServant = ::DownCast<Edge_impl*>( eIn );
61   Quad_impl*   qInServant = ::DownCast<Quad_impl*>( eIn );
62   Hexa_impl*   hInServant = ::DownCast<Hexa_impl*>( eIn );
63
64   ASSERT( vInServant or eInServant or qInServant or hInServant );
65   HEXA_NS::EltBase* e = NULL;
66   if ( vInServant ) {
67     e = vInServant->GetImpl();
68   } else if ( eInServant ) {
69     e = eInServant->GetImpl();
70   } else if ( qInServant ) {
71     e = qInServant->GetImpl();
72   } else if ( hInServant ) {
73     e = hInServant->GetImpl();
74   }
75   ok = _group_cpp->addElement(e);
76
77   return ok;
78 }
79
80
81 ::CORBA::Long Group_impl::countElement() throw (SALOME::SALOME_Exception)
82 {
83   return _group_cpp->countElement();
84 }
85
86
87 Element_ptr Group_impl::getElement(::CORBA::Long index) throw (SALOME::SALOME_Exception)
88 {
89   HEXA_NS::EltBase* elt = _group_cpp->getElement(index);
90
91   HEXA_NS::Vertex* v = dynamic_cast<HEXA_NS::Vertex*>(elt);
92   HEXA_NS::Edge* e   = dynamic_cast<HEXA_NS::Edge*>(elt);
93   HEXA_NS::Quad* q   = dynamic_cast<HEXA_NS::Quad*>(elt);
94   HEXA_NS::Hexa* h   = dynamic_cast<HEXA_NS::Hexa*>(elt);
95
96   ASSERT( v or e or q or h );
97
98   if (v){
99     Vertex_impl* servantCorba = new Vertex_impl(v);
100     return servantCorba->_this();
101   } else if (e){
102     Edge_impl*   servantCorba = new Edge_impl(e);
103     return servantCorba->_this();
104   } else if (q){
105     Quad_impl*   servantCorba = new Quad_impl(q);
106     return servantCorba->_this();
107   } else if (h){
108     Hexa_impl*   servantCorba = new Hexa_impl(h);
109     return servantCorba->_this();
110   } else {
111     return Element::_nil();
112   }
113 }
114
115
116 ::CORBA::Long Group_impl::removeElement(::CORBA::Long index) throw (SALOME::SALOME_Exception)
117 {
118   return _group_cpp->removeElement(index);
119 }
120
121 void Group_impl::clearElement() throw (SALOME::SALOME_Exception)
122 {
123   _group_cpp->clearElement();
124 }
125