2 // C++ : Implementation des groupes
4 // Copyright (C) 2009-2012 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.
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 "HexEltBase.hxx"
25 #include "HexXmlWriter.hxx"
29 int Group::last_grp_id = 0;
30 static const cpchar kind_name[] = { "HexaCell", "QuadCell", "EdgeCell",
31 "HexaNode", "QuadNode", "EdgeNode", "VertexNode" };
33 // ======================================================== Constructeur
34 Group::Group (cpchar nom, EnumGroup grp)
36 grp_id = last_grp_id++;
38 //Initialisation du nom du groupe: un nom par défaut est donné s'il n'est pas fourni
39 std::string _nom = std::string(nom);
40 _nom.erase (_nom.find_last_not_of (" \n\r\t" ) + 1);
41 _nom.erase (0, _nom.find_first_not_of (" \n\r\t" ));
46 sprintf (buffer, "g%04d", grp_id);
47 grp_name = std::string(buffer);
54 case HexaCell : case HexaNode :
58 case QuadCell : case QuadNode :
62 case EdgeNode : case EdgeCell :
66 case VertexNode : default :
67 grp_typelt = EL_VERTEX;
70 // ======================================================== addElement
71 int Group::addElement (EltBase* elt)
73 if (elt==NULL || elt->isDeleted() || grp_typelt != elt->getType())
76 grp_table.push_back (elt);
79 // ======================================================== findElement
80 int Group::findElement (EltBase* elt)
82 int nbelts = grp_table.size ();
83 for (int nro=0 ; nro < nbelts ; nro++)
84 if (grp_table[nro]==elt)
89 // ======================================================== removeElement
90 int Group::removeElement (int nro)
92 int nbelts = grp_table.size ();
94 if (nro<0 || nro >= nbelts)
97 grp_table.erase (grp_table.begin() + nro);
100 // ======================================================== removeElement
101 int Group::removeElement (EltBase* elt)
103 int nro = findElement (elt);
104 int ier = removeElement (nro);
107 // ======================================================== saveXml
108 void Group::saveXml (XmlWriter* xml)
111 int nbelts = grp_table.size ();
113 xml->addMark ("Group");
115 xml->openMark ("Identification");
116 xml->addAttribute ("name", grp_name);
117 xml->addAttribute ("kind", kind_name [grp_kind]);
120 for (int nro=0 ; nro<nbelts ; nro++)
122 if (grp_table[nro]->isHere ())
124 xml->openMark ("Element");
125 xml->addAttribute ("id", grp_table[nro]->getName (buffer));
132 // ========================================================= getNextName
133 char* Group::getNextName (pchar buffer)
135 sprintf (buffer, "g%04d", last_grp_id);
139 // ======================================================== getKind
140 EnumGroup Group::getKind (cpchar kind)
142 int nbk = sizeof (kind_name) / sizeof (cpchar);
143 for (int nro=0; nro<nbk ; nro++)
145 if (Cestegal (kind, kind_name[nro]))
146 return (EnumGroup) nro;