Skip to content

Commit 5d1999e

Browse files
lelandaisbmpoudot
authored andcommitted
Fix issue#115 : undo on clearGroup command
1 parent d4d7ee1 commit 5d1999e

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

src/Core/Mesh/CommandClearGroupName.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,19 @@ void CommandClearGroupName::internalExecute()
246246
/*----------------------------------------------------------------------------*/
247247
void CommandClearGroupName::internalUndo()
248248
{
249+
Group::GroupManager& gm = getContext().getGroupManager();
250+
std::string default_group_name = gm.getDefaultName(m_dim);
249251

250252
switch(m_dim){
251253
case(0):{
252-
Group::Group0D* grp = getContext().getGroupManager().getNewGroup0D(m_groupName, &getInfoCommand());
254+
Group::Group0D* grp = gm.getNewGroup0D(m_groupName, &getInfoCommand());
253255

254256
for (std::vector<Geom::GeomEntity*>::iterator iter = m_geom_entities.begin();
255257
iter != m_geom_entities.end(); ++iter){
256258
Geom::Vertex* vtx = dynamic_cast<Geom::Vertex*>(*iter);
257259
CHECK_NULL_PTR_ERROR(vtx);
258260

259261
addGroup(m_groupName, vtx);
260-
261262
} // end for iter
262263

263264
for (std::vector<Topo::TopoEntity*>::iterator iter = m_topo_entities.begin();
@@ -266,20 +267,24 @@ void CommandClearGroupName::internalUndo()
266267
CHECK_NULL_PTR_ERROR(te);
267268

268269
addGroup(m_groupName, te);
269-
270270
} // end for iter
271271
}
272272
break;
273273
case(1):{
274-
Group::Group1D* grp = getContext().getGroupManager().getNewGroup1D(m_groupName, &getInfoCommand());
274+
Group::Group1D* grp = gm.getNewGroup1D(m_groupName, &getInfoCommand());
275275

276276
for (std::vector<Geom::GeomEntity*>::iterator iter = m_geom_entities.begin();
277277
iter != m_geom_entities.end(); ++iter){
278278
Geom::Curve* crv = dynamic_cast<Geom::Curve*>(*iter);
279279
CHECK_NULL_PTR_ERROR(crv);
280280

281-
addGroup(m_groupName, crv);
281+
// 1 seul groupe qui est le groupe par défaut ? => on le supprime
282+
std::vector<std::string> groupsName;
283+
crv->getGroupsName(groupsName);
284+
if (groupsName.size() == 1 && groupsName[0] == default_group_name)
285+
removeGroup("", crv);
282286

287+
addGroup(m_groupName, crv);
283288
} // end for iter
284289

285290
for (std::vector<Topo::TopoEntity*>::iterator iter = m_topo_entities.begin();
@@ -288,20 +293,24 @@ void CommandClearGroupName::internalUndo()
288293
CHECK_NULL_PTR_ERROR(te);
289294

290295
addGroup(m_groupName, te);
291-
292296
} // end for iter
293297
}
294298
break;
295299
case(2):{
296-
Group::Group2D* grp = getContext().getGroupManager().getNewGroup2D(m_groupName, &getInfoCommand());
300+
Group::Group2D* grp = gm.getNewGroup2D(m_groupName, &getInfoCommand());
297301

298302
for (std::vector<Geom::GeomEntity*>::iterator iter = m_geom_entities.begin();
299303
iter != m_geom_entities.end(); ++iter){
300304
Geom::Surface* srf = dynamic_cast<Geom::Surface*>(*iter);
301305
CHECK_NULL_PTR_ERROR(srf);
302306

303-
addGroup(m_groupName, srf);
307+
// 1 seul groupe qui est le groupe par défaut ? => on le supprime
308+
std::vector<std::string> groupsName;
309+
srf->getGroupsName(groupsName);
310+
if (groupsName.size() == 1 && groupsName[0] == default_group_name)
311+
removeGroup("", srf);
304312

313+
addGroup(m_groupName, srf);
305314
} // end for iter
306315

307316
for (std::vector<Topo::TopoEntity*>::iterator iter = m_topo_entities.begin();
@@ -310,20 +319,24 @@ void CommandClearGroupName::internalUndo()
310319
CHECK_NULL_PTR_ERROR(te);
311320

312321
addGroup(m_groupName, te);
313-
314322
} // end for iter
315323
}
316324
break;
317325
case(3):{
318-
Group::Group3D* grp = getContext().getGroupManager().getNewGroup3D(m_groupName, &getInfoCommand());
326+
Group::Group3D* grp = gm.getNewGroup3D(m_groupName, &getInfoCommand());
319327

320328
for (std::vector<Geom::GeomEntity*>::iterator iter = m_geom_entities.begin();
321329
iter != m_geom_entities.end(); ++iter){
322330
Geom::Volume* vol = dynamic_cast<Geom::Volume*>(*iter);
323331
CHECK_NULL_PTR_ERROR(vol);
324332

325-
addGroup(m_groupName, vol);
333+
// 1 seul groupe qui est le groupe par défaut ? => on le supprime
334+
std::vector<std::string> groupsName;
335+
vol->getGroupsName(groupsName);
336+
if (groupsName.size() == 1 && groupsName[0] == default_group_name)
337+
removeGroup("", vol);
326338

339+
addGroup(m_groupName, vol);
327340
} // end for iter
328341

329342
for (std::vector<Topo::TopoEntity*>::iterator iter = m_topo_entities.begin();
@@ -332,7 +345,6 @@ void CommandClearGroupName::internalUndo()
332345
CHECK_NULL_PTR_ERROR(te);
333346

334347
addGroup(m_groupName, te);
335-
336348
} // end for iter
337349
}
338350
break;

test_link/test_groups.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,16 @@ def test_undo_add_to_group():
173173
ctx.undo()
174174
# Hors_Groupe_3D n'est plus détruit après fix de l'issue#215
175175
assert "DETRUIT" not in ctx.getGroupManager().getInfos("Hors_Groupe_3D", 3)
176+
177+
# Issue #214
178+
def test_undo_clear_group():
179+
ctx = Mgx3D.getStdContext()
180+
ctx.clearSession() # Clean the session after the previous test
181+
# Création d'une boite avec une topologie
182+
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10, "BOX")
183+
# Vide le groupe BOX
184+
ctx.getGroupManager().clearGroup (3, "BOX")
185+
# Annulation de : Vide le groupe BOX
186+
ctx.undo()
187+
# Vol0000 ne devrait pas être dans Hors_Groupe_3D mais seulement dans BOX
188+
assert "Vol0000" not in ctx.getGroupManager().getGeomVolumes("Hors_Groupe_3D", 3)

test_link/test_unresolved_problems.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,3 @@ def test_ogrids_not_equal():
177177

178178
# le nombre de regions devrait être identique... et non
179179
assert nb_regions_1 > nb_regions_2
180-
181-
# Issue #214
182-
def test_undo_clear_group():
183-
ctx = Mgx3D.getStdContext()
184-
ctx.clearSession() # Clean the session after the previous test
185-
# Création d'une boite avec une topologie
186-
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10, "BOX")
187-
# Vide le groupe BOX
188-
ctx.getGroupManager().clearGroup (3, "BOX")
189-
# Annulation de : Vide le groupe BOX
190-
# ctx.undo()
191-
# Vol0000 ne devrait pas être dans Hors_Groupe_3D mais seulement dans BOX
192-
# assert "Vol0000" not in ctx.getGroupManager().getGeomEntities(["Hors_Groupe_3D"])

0 commit comments

Comments
 (0)