@@ -147,16 +147,12 @@ void CommandSetGeomAssociation::validGeomEntity()
147147/* ----------------------------------------------------------------------------*/
148148void CommandSetGeomAssociation::project (Block* bloc)
149149{
150- getInfoCommand ().addTopoInfoEntity (bloc, Internal::InfoCommand::DISPMODIFIED);
151- bloc->saveTopoProperty ();
152- bloc->setGeomAssociation (m_geom_entity);
150+ setGeomAssociation (bloc, [bloc](Internal::InfoCommand* icmd) { bloc->saveBlockTopoProperty (icmd); });
153151}
154152/* ----------------------------------------------------------------------------*/
155153void CommandSetGeomAssociation::project (CoFace* coface)
156154{
157- getInfoCommand ().addTopoInfoEntity (coface, Internal::InfoCommand::DISPMODIFIED);
158- coface->saveTopoProperty ();
159- coface->setGeomAssociation (m_geom_entity);
155+ setGeomAssociation (coface, [coface](Internal::InfoCommand* icmd) { coface->saveCoFaceTopoProperty (icmd); });
160156
161157 std::vector<CoEdge*> coedges = coface->getCoEdges ();
162158
@@ -210,9 +206,7 @@ void CommandSetGeomAssociation::project(CoFace* coface)
210206/* ----------------------------------------------------------------------------*/
211207void CommandSetGeomAssociation::project (CoEdge* coedge)
212208{
213- getInfoCommand ().addTopoInfoEntity (coedge, Internal::InfoCommand::DISPMODIFIED);
214- coedge->saveTopoProperty ();
215- coedge->setGeomAssociation (m_geom_entity);
209+ setGeomAssociation (coedge, [coedge](Internal::InfoCommand* icmd) { coedge->saveCoEdgeTopoProperty (icmd); });
216210
217211 const std::vector<Vertex*>& vertices = coedge->getVertices ();
218212 for (auto iter = vertices.begin (); iter != vertices.end (); ++iter){
@@ -229,8 +223,7 @@ void CommandSetGeomAssociation::project(CoEdge* coedge)
229223/* ----------------------------------------------------------------------------*/
230224void CommandSetGeomAssociation::project (Vertex* vtx)
231225{
232- vtx->saveTopoProperty ();
233- vtx->setGeomAssociation (m_geom_entity);
226+ setGeomAssociation (vtx, [vtx](Internal::InfoCommand* icmd) { vtx->saveVertexTopoProperty (icmd); });
234227
235228 // déplace le sommet topologique si la projection implique un déplacement
236229 if (m_geom_entity && m_move_vertices){
@@ -258,14 +251,44 @@ void CommandSetGeomAssociation::project(Vertex* vtx)
258251 }
259252 }
260253 }
261- getInfoCommand ().addTopoInfoEntity (vtx, Internal::InfoCommand::DISPMODIFIED);
262254}
263255/* ----------------------------------------------------------------------------*/
264256void CommandSetGeomAssociation::getPreviewRepresentation (Utils::DisplayRepresentation& dr)
265257{
266258 return getPreviewRepresentationCoedgeDisplayModified (dr);
267259}
268260/* ----------------------------------------------------------------------------*/
261+ void CommandSetGeomAssociation::setGeomAssociation (TopoEntity* e, std::function<void (Internal::InfoCommand* icmd)> saveGroups)
262+ {
263+ getInfoCommand ().addTopoInfoEntity (e, Internal::InfoCommand::DISPMODIFIED);
264+ e->saveTopoProperty ();
265+ e->setGeomAssociation (m_geom_entity);
266+
267+ // si m_geom_entity est dans le même groupe que e => e sort du groupe
268+ // 1. les groupes géométriques
269+ Group::GroupManager& gm = e->getContext ().getGroupManager ();
270+ std::vector<std::string> geom_groups = Utils::toNames (gm.getGroupsFor (m_geom_entity));
271+ std::sort (geom_groups.begin (), geom_groups.end ());
272+ // 2. les groupes topologiques
273+ Group::GroupHelperForCommand helper (getInfoCommand (), gm);
274+ std::vector<std::string> topo_groups = Utils::toNames (helper.getGroupsFor (e));
275+ std::sort (topo_groups.begin (), topo_groups.end ());
276+ // 3. l'intersection
277+ std::vector<std::string> common_groups;
278+ std::set_intersection (
279+ geom_groups.begin (), geom_groups.end (),
280+ topo_groups.begin (), topo_groups.end (),
281+ std::back_inserter (common_groups)
282+ );
283+ // 4. suppression des groupes
284+ if (common_groups.size () > 0 ) {
285+ // au moins un groupe à supprimer, il faut sauvegarder les listes de groupes
286+ saveGroups (&getInfoCommand ());
287+ for (std::string gn : common_groups)
288+ helper.removeFromGroup (gn, e);
289+ }
290+ }
291+ /* ----------------------------------------------------------------------------*/
269292} // end namespace Topo
270293/* ----------------------------------------------------------------------------*/
271294} // end namespace Mgx3D
0 commit comments