2 // C++ : Implementation des groupes
4 // Copyright (C) 2009-2016 CEA/DEN, EDF R&D
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HexGroup.hxx"
24 #include "HexXmlWriter.hxx"
28 static const cpchar kind_name[] = { "HexaCell", "QuadCell", "EdgeCell",
29 "HexaNode", "QuadNode", "EdgeNode", "VertexNode" };
31 // ======================================================== Constructeur
32 Group::Group (Document* dad, cpchar nom, EnumGroup grp)
33 : EltBase (dad, EL_GROUP)
35 string name = std::string(nom);
36 name.erase (name.find_last_not_of (" \n\r\t" ) + 1);
37 name.erase (0, name.find_first_not_of (" \n\r\t" ));
45 case HexaCell : case HexaNode :
49 case QuadCell : case QuadNode :
53 case EdgeNode : case EdgeCell :
57 case VertexNode : default :
58 grp_typelt = EL_VERTEX;
61 // ======================================================== addElement
62 int Group::addElement (EltBase* elt)
64 if (elt==NULL || elt->isDeleted() || grp_typelt != elt->getType())
67 grp_table.push_back (elt);
70 // ======================================================== findElement
71 int Group::findElement (EltBase* elt)
73 int nbelts = grp_table.size ();
74 for (int nro=0 ; nro < nbelts ; nro++)
75 if (grp_table[nro]==elt)
80 // ======================================================== removeElement
81 int Group::removeElement (int nro)
83 int nbelts = grp_table.size ();
85 if (nro<0 || nro >= nbelts)
88 grp_table.erase (grp_table.begin() + nro);
91 // ======================================================== removeElement
92 int Group::removeElement (EltBase* elt)
94 int nro = findElement (elt);
95 int ier = removeElement (nro);
98 // ======================================================== saveXml
99 void Group::saveXml (XmlWriter* xml)
102 int nbelts = grp_table.size ();
104 xml->addMark ("Group");
106 xml->openMark ("Identification");
107 xml->addAttribute ("name", el_name);
108 xml->addAttribute ("kind", kind_name [grp_kind]);
111 for (int nro=0 ; nro<nbelts ; nro++)
113 if (grp_table[nro]->isHere ())
115 xml->openMark ("Element");
116 xml->addAttribute ("id", grp_table[nro]->getName (buffer));
122 // ======================================================== getKind
123 EnumGroup Group::getKind (cpchar kind)
125 int nbk = sizeof (kind_name) / sizeof (cpchar);
126 for (int nro=0; nro<nbk ; nro++)
128 if (Cestegal (kind, kind_name[nro]))
129 return (EnumGroup) nro;