]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCK_I/HexGroup_impl.cxx
Salome HOME
Merge from V6_main 01/04/2013
[modules/hexablock.git] / src / HEXABLOCK_I / HexGroup_impl.cxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 using namespace std;
20 #include "HEXABLOCK.hxx"
21 #include "utilities.h"
22
23 #include <string>
24
25 #include "hexa_base.hxx"
26 #include "HexEltBase.hxx"
27 #include "HexGroup.hxx"
28
29 #include "HexElements_impl.hxx"
30
31 #include "HexVertex_impl.hxx"
32 #include "HexEdge_impl.hxx"
33 #include "HexQuad_impl.hxx"
34 #include "HexHexa_impl.hxx"
35 #include "HexGroup_impl.hxx"
36
37 Group_impl::Group_impl( HEXA_NS::Group *ptrCpp ):_group_cpp(ptrCpp)
38 {
39 }
40
41 HEXA_NS::Group* Group_impl::GetImpl() throw (SALOME::SALOME_Exception)
42 {
43   return _group_cpp;
44 }
45
46 char* Group_impl::getName() throw (SALOME::SALOME_Exception)
47 {
48    return CORBA::string_dup (_group_cpp->getName());
49 }
50
51 void Group_impl::setName(const char* name) throw (SALOME::SALOME_Exception)
52 {
53   _group_cpp->setName( name );
54 }
55
56
57 GroupKind Group_impl::getKind() throw (SALOME::SALOME_Exception)
58 {
59   HEXA_NS::EnumGroup k = _group_cpp->getKind();
60
61   switch (k){
62     case HEXA_NS::HexaCell:  return HEXA_GROUP;
63     case HEXA_NS::QuadCell:  return QUAD_GROUP;
64     case HEXA_NS::EdgeCell:  return EDGE_GROUP;
65     case HEXA_NS::HexaNode:  return HEXANODE_GROUP;
66     case HEXA_NS::QuadNode:  return QUADNODE_GROUP;
67     case HEXA_NS::EdgeNode:  return EDGENODE_GROUP;
68     case HEXA_NS::VertexNode:  return VERTEXNODE_GROUP;
69     default : ASSERT(false);
70   }
71 }
72
73
74 ::CORBA::Long  Group_impl::addElement(Element_ptr eIn) throw (SALOME::SALOME_Exception)
75 {
76   ::CORBA::Long ok;
77   Vertex_impl* vInServant = ::DownCast<Vertex_impl*>( eIn );
78   Edge_impl*   eInServant = ::DownCast<Edge_impl*>( eIn );
79   Quad_impl*   qInServant = ::DownCast<Quad_impl*>( eIn );
80   Hexa_impl*   hInServant = ::DownCast<Hexa_impl*>( eIn );
81
82   ASSERT( vInServant or eInServant or qInServant or hInServant );
83   HEXA_NS::EltBase* e = NULL;
84   if ( vInServant ) {
85     e = vInServant->GetImpl();
86   } else if ( eInServant ) {
87     e = eInServant->GetImpl();
88   } else if ( qInServant ) {
89     e = qInServant->GetImpl();
90   } else if ( hInServant ) {
91     e = hInServant->GetImpl();
92   }
93   ok = _group_cpp->addElement(e);
94
95   return ok;
96 }
97
98
99 ::CORBA::Long Group_impl::countElement() throw (SALOME::SALOME_Exception)
100 {
101   return _group_cpp->countElement();
102 }
103
104
105 Element_ptr Group_impl::getElement(::CORBA::Long index) throw (SALOME::SALOME_Exception)
106 {
107   HEXA_NS::EltBase* elt = _group_cpp->getElement(index);
108
109   HEXA_NS::Vertex* v = dynamic_cast<HEXA_NS::Vertex*>(elt);
110   HEXA_NS::Edge* e   = dynamic_cast<HEXA_NS::Edge*>(elt);
111   HEXA_NS::Quad* q   = dynamic_cast<HEXA_NS::Quad*>(elt);
112   HEXA_NS::Hexa* h   = dynamic_cast<HEXA_NS::Hexa*>(elt);
113
114   ASSERT( v or e or q or h );
115
116   if (v){
117     Vertex_impl* servantCorba = new Vertex_impl(v);
118     return servantCorba->_this();
119   } else if (e){
120     Edge_impl*   servantCorba = new Edge_impl(e);
121     return servantCorba->_this();
122   } else if (q){
123     Quad_impl*   servantCorba = new Quad_impl(q);
124     return servantCorba->_this();
125   } else if (h){
126     Hexa_impl*   servantCorba = new Hexa_impl(h);
127     return servantCorba->_this();
128   } else {
129     return Element::_nil();
130   }
131 }
132
133
134 ::CORBA::Long Group_impl::removeElement(Element_ptr eIn) 
135                           throw (SALOME::SALOME_Exception)
136 {
137   Vertex_impl* vInServant = ::DownCast<Vertex_impl*>( eIn );
138   Edge_impl*   eInServant = ::DownCast<Edge_impl*  >( eIn );
139   Quad_impl*   qInServant = ::DownCast<Quad_impl*  >( eIn );
140   Hexa_impl*   hInServant = ::DownCast<Hexa_impl*  >( eIn );
141
142   ASSERT( vInServant or eInServant or qInServant or hInServant );
143   HEXA_NS::EltBase* elt = NULL;
144   if (vInServant != NULL)
145        elt = vInServant->GetImpl();
146   else if (eInServant != NULL) 
147        elt = eInServant->GetImpl();
148   else if (qInServant != NULL)
149        elt = qInServant->GetImpl();
150   else if (hInServant != NULL)
151        elt = hInServant->GetImpl();
152
153   ::CORBA::Long ier = _group_cpp->removeElement (elt);
154   return ier;
155 }
156
157 void Group_impl::clearElement() throw (SALOME::SALOME_Exception)
158 {
159   _group_cpp->clearElement();
160 }
161