Skip to content

Commit 53b47c2

Browse files
authored
Merge pull request #163 from LIHPC-Computational-Geometry/issue#219
Issue#219
2 parents 60533e5 + 81f16a2 commit 53b47c2

File tree

8 files changed

+231
-26
lines changed

8 files changed

+231
-26
lines changed

src/Core/Group/GroupManager.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
/*----------------------------------------------------------------------------*/
2-
/*
3-
* \file GroupManager.cpp
4-
*
5-
* \author Eric Brière de l'Isle
6-
*
7-
* \date 18/10/2012
8-
*/
9-
/*----------------------------------------------------------------------------*/
102
// pythonerie à mettre au début (pour permettre ifndef Py_PYTHON_H dans GroupManager.h)
113
#include <set>
124
/*----------------------------------------------------------------------------*/
@@ -54,7 +46,7 @@
5446
#include "Mesh/MeshModificationBySepa.h"
5547
#include "Mesh/MeshModificationByProjectionOnP0.h"
5648
#include "Mesh/CommandClearGroupName.h"
57-
49+
#include "Mesh/CommandChangeGroupName.h"
5850
#include "SysCoord/SysCoord.h"
5951

6052
#include "Smoothing/SurfacicSmoothing.h"
@@ -120,7 +112,6 @@ Internal::M3DCommandResult* GroupManager::clearGroup(int dim, const std::string&
120112
Internal::M3DCommandResult* cmdResult =
121113
new Internal::M3DCommandResult (*command);
122114
return cmdResult;
123-
124115
}
125116
/*----------------------------------------------------------------------------*/
126117
bool GroupManager::getPropagate()
@@ -158,6 +149,26 @@ std::string GroupManager::getDefaultName(int dim) const
158149
}
159150
}
160151
/*----------------------------------------------------------------------------*/
152+
Internal::M3DCommandResult*
153+
GroupManager::changeGroupName(const std::string& oldName, const std::string& newName, int dim)
154+
{
155+
Mesh::CommandChangeGroupName* command =
156+
new Mesh::CommandChangeGroupName(getContext(), oldName, newName, dim);
157+
158+
// trace dans le script
159+
TkUtil::UTF8String cmd (TkUtil::Charset::UTF_8);
160+
cmd << getContextAlias() << "." << "getGroupManager().changeGroupName (\""<<oldName<<"\", \""<<newName<<"\", "<<(short)dim<<")";
161+
command->setScriptCommand(cmd);
162+
163+
// on passe au gestionnaire de commandes qui exécute la commande en // ou non
164+
// et la stocke dans le gestionnaire de undo-redo si c'est une réussite
165+
getCommandManager().addCommand(command, Utils::Command::DO);
166+
167+
Internal::M3DCommandResult* cmdResult =
168+
new Internal::M3DCommandResult (*command);
169+
return cmdResult;
170+
}
171+
/*----------------------------------------------------------------------------*/
161172
Group3D* GroupManager::getGroup3D(const std::string& gr_name, const bool exceptionIfNotFound) const
162173
{
163174
std::string name(gr_name.empty()?getDefaultName(3):gr_name);
@@ -2275,13 +2286,13 @@ void GroupManager::setLevel(std::vector<std::string>& vg, int dim, int level)
22752286

22762287
}
22772288
/*----------------------------------------------------------------------------*/
2278-
GroupEntity* GroupManager::getGroup(const std::string& name, const int dim) const
2289+
GroupEntity* GroupManager::getGroup(const std::string& name, const int dim, const bool exceptionIfNotFound) const
22792290
{
22802291
switch(dim){
2281-
case(3): return getGroup3D(name);
2282-
case(2): return getGroup2D(name);
2283-
case(1): return getGroup1D(name);
2284-
case(0): return getGroup0D(name);
2292+
case(3): return getGroup3D(name, exceptionIfNotFound);
2293+
case(2): return getGroup2D(name, exceptionIfNotFound);
2294+
case(1): return getGroup1D(name, exceptionIfNotFound);
2295+
case(0): return getGroup0D(name, exceptionIfNotFound);
22852296
default: {
22862297
throw TkUtil::Exception (TkUtil::UTF8String ("dimension non prévue pour GroupManager::getGroup", TkUtil::Charset::UTF_8));
22872298
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*----------------------------------------------------------------------------*/
2+
#include "Mesh/CommandChangeGroupName.h"
3+
#include "Internal/Context.h"
4+
#include "Group/GroupEntity.h"
5+
#include "Group/GroupManager.h"
6+
/*----------------------------------------------------------------------------*/
7+
namespace Mgx3D {
8+
/*----------------------------------------------------------------------------*/
9+
namespace Mesh {
10+
/*----------------------------------------------------------------------------*/
11+
CommandChangeGroupName::CommandChangeGroupName(Internal::Context& c,
12+
const std::string& oldName,
13+
const std::string& newName,
14+
const int dim)
15+
: CommandCreateMesh(c, (std::string("Change le nom du groupe ") + oldName),0)
16+
, m_old_group_name(oldName)
17+
, m_new_group_name(newName)
18+
, m_dim(dim)
19+
{
20+
}
21+
/*----------------------------------------------------------------------------*/
22+
void CommandChangeGroupName::internalExecute()
23+
{
24+
changeGroupName(m_old_group_name, m_new_group_name, m_dim);
25+
}
26+
/*----------------------------------------------------------------------------*/
27+
void CommandChangeGroupName::internalUndo()
28+
{
29+
changeGroupName(m_new_group_name, m_old_group_name, m_dim);
30+
}
31+
/*----------------------------------------------------------------------------*/
32+
void CommandChangeGroupName::internalRedo()
33+
{
34+
changeGroupName(m_old_group_name, m_new_group_name, m_dim);
35+
}
36+
/*----------------------------------------------------------------------------*/
37+
void CommandChangeGroupName::changeGroupName(const std::string& oldName, const std::string& newName, const int dim)
38+
{
39+
Group::GroupManager& gm = getContext().getGroupManager();
40+
Group::GroupEntity* group = gm.getGroup(newName, dim, false);
41+
if (group == 0) {
42+
// le groupe n'existe pas déjà => on peut autoriser le nouveau nom
43+
group = gm.getGroup(oldName, dim, true);
44+
if (group->isDefaultGroup()) {
45+
throw TkUtil::Exception (TkUtil::UTF8String("Il n'est pas possible de changer le nom du groupe par défaut", TkUtil::Charset::UTF_8));
46+
}
47+
group->setProperties(getContext().newProperty(group->getType(), newName));
48+
getInfoCommand().addGroupInfoEntity(group, Internal::InfoCommand::DISPMODIFIED);
49+
} else {
50+
throw TkUtil::Exception (TkUtil::UTF8String("Nom de groupe déjà existant : " + newName, TkUtil::Charset::UTF_8));
51+
}
52+
}
53+
/*----------------------------------------------------------------------------*/
54+
} // end namespace Mesh
55+
/*----------------------------------------------------------------------------*/
56+
} // end namespace Mgx3D
57+
/*----------------------------------------------------------------------------*/

src/Core/protected/Group/GroupManager.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
/*----------------------------------------------------------------------------*/
2-
/** \file GroupManager.h
3-
*
4-
* \author Eric Brière de l'Isle
5-
*
6-
* \date 18/10/2012
7-
*/
8-
/*----------------------------------------------------------------------------*/
92
#ifndef MGX3D_GROUP_GROUPMANAGER_H_
103
#define MGX3D_GROUP_GROUPMANAGER_H_
114
/*----------------------------------------------------------------------------*/
@@ -103,13 +96,17 @@ class GroupManager final : public Internal::CommandCreator {
10396
bool getPropagate();
10497

10598
/*------------------------------------------------------------------------*/
106-
/** Retourne une string avec les informations relatives à l'entité */
99+
/// Retourne une string avec les informations relatives à l'entité */
107100
std::string getInfos(const std::string& name, int dim) const;
108101

109102
/*------------------------------------------------------------------------*/
110103
/// retourne un nom par défaut pour les entités qui n'en aurait pas
111104
std::string getDefaultName(int dim) const;
112105

106+
/*------------------------------------------------------------------------*/
107+
/// Retourne une string avec les informations relatives à l'entité */
108+
Internal::M3DCommandResult* changeGroupName(const std::string& oldName, const std::string& newName, int dim);
109+
113110
#ifndef SWIG
114111
/*------------------------------------------------------------------------*/
115112
/// retourne l'entité à partir du nom, une exception si elle n'existe pas
@@ -366,6 +363,10 @@ class GroupManager final : public Internal::CommandCreator {
366363
std::map<CoordinateSystem::SysCoord*, uint>& filtre_rep,
367364
uint mark);
368365

366+
/*------------------------------------------------------------------------*/
367+
/** Retourne le groupe correspondant à la dimension */
368+
GroupEntity* getGroup(const std::string& name, const int dim, const bool exceptionIfNotFound=true) const;
369+
369370
/*------------------------------------------------------------------------*/
370371
/** Retourne les volumes géométriques à partir des groupes sélectionnés */
371372
void get(const std::vector<GroupEntity*>& vg, std::vector<Geom::Volume*>& volumes);
@@ -529,9 +530,6 @@ class GroupManager final : public Internal::CommandCreator {
529530

530531

531532
private:
532-
/// Retourne le groupe correspondant à la dimension
533-
GroupEntity* getGroup(const std::string& name, const int dim) const;
534-
535533
/// Conteneur pour les groupes 3D
536534
std::vector<Group3D*> m_group3D;
537535

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*----------------------------------------------------------------------------*/
2+
#ifndef MGX3D_MESH_COMMANDCHANGEGROUPNAME_H_
3+
#define MGX3D_MESH_COMMANDCHANGEGROUPNAME_H_
4+
/*----------------------------------------------------------------------------*/
5+
#include "Mesh/CommandCreateMesh.h"
6+
/*----------------------------------------------------------------------------*/
7+
#include <string>
8+
/*----------------------------------------------------------------------------*/
9+
namespace Mgx3D {
10+
/*----------------------------------------------------------------------------*/
11+
namespace Internal {
12+
class Context;
13+
}
14+
/*----------------------------------------------------------------------------*/
15+
namespace Mesh {
16+
/*----------------------------------------------------------------------------*/
17+
/** \class CommandAddRemoveGroupName
18+
* \brief Commande permettant d'ajouter des entités à un groupe
19+
*/
20+
/*----------------------------------------------------------------------------*/
21+
class CommandChangeGroupName: public CommandCreateMesh
22+
{
23+
public:
24+
/*------------------------------------------------------------------------*/
25+
/** \brief Constructeur avec une liste de volumes
26+
*
27+
* \param c le contexte
28+
* \param oldName ancien nom du groupe
29+
* \param newName ancien nom du groupe
30+
* \param dim dimension du groupe
31+
*/
32+
CommandChangeGroupName(Internal::Context& c, const std::string& oldName, const std::string& newName, const int dim);
33+
34+
/*------------------------------------------------------------------------*/
35+
/** \brief Destructeur
36+
*/
37+
virtual ~CommandChangeGroupName() = default;
38+
39+
/*------------------------------------------------------------------------*/
40+
/** \brief exécute la commande
41+
*/
42+
void internalExecute();
43+
44+
/*------------------------------------------------------------------------*/
45+
/** \brief annule la commande
46+
*/
47+
void internalUndo();
48+
49+
/** \brief rejoue la commande
50+
*/
51+
void internalRedo();
52+
53+
private:
54+
/// change le nom du groupe
55+
void changeGroupName(const std::string& oldName, const std::string& newName, const int dim);
56+
57+
/// ancien nom du groupe
58+
std::string m_old_group_name;
59+
60+
/// nouveau nom du groupe
61+
std::string m_new_group_name;
62+
63+
/// dimension
64+
int m_dim;
65+
};
66+
/*----------------------------------------------------------------------------*/
67+
} // end namespace Mesh
68+
/*----------------------------------------------------------------------------*/
69+
} // end namespace Mgx3D
70+
/*----------------------------------------------------------------------------*/
71+
#endif /* MGX3D_MESH_COMMANDCHANGEGROUPNAME_H_ */
72+
/*----------------------------------------------------------------------------*/

src/QtComponents/QtGroupsPanel.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ void QtGroupsPanel::removeGroups (const vector<Group::GroupEntity*>& groups)
622622
} // QtGroupsPanel::removeGroups
623623

624624

625+
void QtGroupsPanel::updateGroup (const Group::GroupEntity& group)
626+
{
627+
getGroupItem(group)->update(true);
628+
}
629+
630+
625631
vector<Group::GroupEntity*> QtGroupsPanel::getSelectedGroups ( ) const
626632
{
627633
vector<Group::GroupEntity*> groups;
@@ -849,6 +855,26 @@ void QtGroupsPanel::updateQuickButtons ( )
849855
_wireTopoCoEdgeButton->setChecked (0 == rep ? false : true);
850856
} // QtGroupsPanel::updateQuickButtons
851857

858+
void QtGroupsPanel::updateGroupCallback ( )
859+
{
860+
vector<QtGroupTreeWidgetItem*> items = getSelectedGroupsItems ( );
861+
for (vector<QtGroupTreeWidgetItem*>::iterator it = items.begin ( ); items.end ( ) != it; it++)
862+
{
863+
if (true == (*it)->isSelected ( ))
864+
{
865+
QString newName;
866+
bool ok = true;
867+
newName = QInputDialog::getText(this, "Magix 3D", "Renommage de Groupe :",QLineEdit::Normal, "",&ok);
868+
869+
std::string str_newName = newName.toStdString();
870+
871+
GroupEntity* gr = (*it)->getGroup ( );
872+
getContext().getGroupManager().changeGroupName(gr->getName(), str_newName, gr->getDim());
873+
874+
updateGroup(*gr);
875+
}
876+
} // for (vector<QtGroupTreeWidgetItem*>::iterator it = ...
877+
} // QtGroupsPanel::displaySelectedGroups
852878

853879
void QtGroupsPanel::clearGroupCallback ( )
854880
{
@@ -1397,6 +1423,10 @@ void QtGroupsPanel::createPopupMenus ( )
13971423

13981424
_groupsPopupMenu->addSeparator ( );
13991425

1426+
QAction* updateGroupAction = createAction (*_groupsPopupMenu, QString::fromUtf8("Renommer le groupe"),
1427+
QString::fromUtf8("Le groupe change de nom tout en conservant son contenu"),
1428+
SLOT (updateGroupCallback ( )), this, false, OFF);
1429+
14001430
QAction* clearGroupAction = createAction (*_groupsPopupMenu, QString::fromUtf8("Destruction d'un groupe"),
14011431
QString::fromUtf8("Un groupe perd toute les entités qu'il contenait et disparait"),
14021432
SLOT (clearGroupCallback ( )), this, false, OFF);

src/QtComponents/QtMgx3DMainWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4386,6 +4386,7 @@ void QtMgx3DMainWindow::displayCommandError (const TkUtil::UTF8String& message)
43864386
groupsRemoved.push_back((*itg).first);
43874387
break;
43884388
case InfoCommand::DISPMODIFIED :
4389+
getGroupsPanel().updateGroup(*((*itg).first));
43894390
break;
43904391
} // switch ((*itg).second)
43914392
} // for (map<Group::GroupEntity*, type>::const_iterator ...

src/QtComponents/protected/QtComponents/QtGroupsPanel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ class QtGroupsPanel : public QtEntitiesItemViewPanel, public Utils::SelectionMan
385385
*/
386386
virtual void removeGroups (const std::vector<Mgx3D::Group::GroupEntity*>& groups);
387387

388+
/**
389+
* Met à jour l'affichage du groupe.
390+
* \param Instance du groupe à réafficher
391+
*/
392+
virtual void updateGroup (const Group::GroupEntity& group);
393+
388394
/**
389395
* \return Les groupes sélectionnés.
390396
*/
@@ -744,6 +750,11 @@ class QtGroupsPanel : public QtEntitiesItemViewPanel, public Utils::SelectionMan
744750
*/
745751
virtual void unselectMeshCloudsCallback ( );
746752

753+
/**
754+
* Le groupe change de nom tout en conservant son contenu
755+
*/
756+
void updateGroupCallback ( );
757+
747758
/**
748759
* Destruction d'un groupe, on lui retire toute les entités qu'il contient
749760
*/

test_link/test_groups.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
import pyMagix3D as Mgx3D
3+
import pytest
34

45
def test_group_box():
56
ctx = Mgx3D.getStdContext()
@@ -186,3 +187,27 @@ def test_undo_clear_group():
186187
ctx.undo()
187188
# Vol0000 ne devrait pas être dans Hors_Groupe_3D mais seulement dans BOX
188189
assert "Vol0000" not in ctx.getGroupManager().getGeomVolumes("Hors_Groupe_3D", 3)
190+
assert "Vol0000" in ctx.getGroupManager().getGeomVolumes("BOX", 3)
191+
192+
# Issue #219
193+
def test_changeGroupName():
194+
ctx = Mgx3D.getStdContext()
195+
ctx.clearSession() # Clean the session after the previous test
196+
# Création d'une boite avec une topologie
197+
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(0, 0, 0), Mgx3D.Point(1, 1, 1), 10, 10, 10, "BOX")
198+
# Création d'une boite avec une topologie
199+
ctx.getTopoManager().newBoxWithTopo (Mgx3D.Point(1, 0, 0), Mgx3D.Point(2, 1, 1), 10, 10, 10, "BOX2")
200+
# Vol0000 est dans BOX. Vol0001 est dans BOX2.
201+
assert "Vol0000" in ctx.getGroupManager().getGeomVolumes("BOX", 3)
202+
assert "Vol0001" in ctx.getGroupManager().getGeomVolumes("BOX2", 3)
203+
ctx.getGroupManager().changeGroupName("BOX2", "NEW_BOX", 3)
204+
assert "Vol0000" in ctx.getGroupManager().getGeomVolumes("BOX", 3)
205+
assert "Vol0001" in ctx.getGroupManager().getGeomVolumes("NEW_BOX", 3)
206+
ctx.undo()
207+
assert "Vol0000" in ctx.getGroupManager().getGeomVolumes("BOX", 3)
208+
assert "Vol0001" in ctx.getGroupManager().getGeomVolumes("BOX2", 3)
209+
ctx.getGroupManager().clearGroup (3, "BOX")
210+
assert "Vol0000" in ctx.getGroupManager().getGeomVolumes("Hors_Groupe_3D", 3)
211+
with pytest.raises(RuntimeError) as excinfo:
212+
ctx.getGroupManager().changeGroupName("Hors_Groupe_3D", "TOTO", 3)
213+
assert "Il n'est pas possible de changer le nom du groupe par défaut" in str(excinfo.value)

0 commit comments

Comments
 (0)