Skip to content

Commit 81f16a2

Browse files
authored
Merge branch 'main' into issue#219
2 parents de6ff0c + 60533e5 commit 81f16a2

12 files changed

+300
-183
lines changed

src/Core/Geom/CommandExtrudeDirection.cpp

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ CommandExtrudeDirection::
2020
CommandExtrudeDirection(Internal::Context& c,
2121
std::vector<GeomEntity*>& entities,
2222
const Vector& dp, const bool keep)
23-
: CommandExtrusion(c, "Direction"),
24-
m_entities(entities),
25-
m_vector(dp),
26-
m_keep(keep)
23+
: CommandExtrusion(c, "Direction", entities, keep)
24+
, m_vector(dp)
2725
{
2826
if (m_vector.abs2()==0.0)
2927
throw TkUtil::Exception(TkUtil::UTF8String ("Le vecteur pour l'extrusion ne doit pas être nul", TkUtil::Charset::UTF_8));
@@ -40,84 +38,14 @@ CommandExtrudeDirection(Internal::Context& c,
4038
setName(comments);
4139
}
4240
/*----------------------------------------------------------------------------*/
43-
CommandExtrudeDirection::~CommandExtrudeDirection()
44-
{
45-
if(m_impl)
46-
delete m_impl;
47-
}
48-
/*----------------------------------------------------------------------------*/
4941
void CommandExtrudeDirection::
50-
internalExecute()
42+
internalSpecificExecute()
5143
{
52-
m_impl->prePerform();
53-
m_impl->perform(m_createdEntities,m_v2v, m_v2v_opp,m_v2c,
44+
getImpl()->perform(m_createdEntities,m_v2v, m_v2v_opp,m_v2c,
5445
m_c2c, m_c2c_opp, m_c2s, m_s2s, m_s2s_opp, m_s2v);
55-
std::vector<GeomEntity*>& new_entities = m_impl->getNewEntities();
56-
std::vector<GeomEntity*>& rem_entities = m_impl->getRemovedEntities();
57-
for(int i=0;i<new_entities.size();i++){
58-
GeomEntity* ge = new_entities[i];
59-
getInfoCommand ( ).addGeomInfoEntity (ge, Internal::InfoCommand::CREATED);
60-
getContext().getGeomManager().addEntity(ge);
61-
}
62-
63-
// Si on ne garde pas, alors on transmet les relations géométriques des entités supprimées aux entités copiées pour
64-
// l'extrusion
65-
if(!m_keep) {
66-
67-
//On reconstruit les relations points <-> courbes
68-
for (auto v2v : m_v2v) {
69-
Vertex *v_ref = v2v.first;
70-
Vertex *v_created = v2v.second;
71-
auto curves = v_ref->getCurves();
72-
for (int i = 0; i < curves.size(); i++) {
73-
Curve *c = curves[i];
74-
v_created->add(c);
75-
c->add(v_created);
76-
}
77-
}
78-
79-
//On reconstruit les relations courbes <-> surfaces
80-
for (auto c2c : m_c2c) {
81-
Curve *c_ref = c2c.first;
82-
Curve *c_created = c2c.second;
83-
auto surfaces = c_ref->getSurfaces();
84-
for (int i = 0; i < surfaces.size(); i++) {
85-
Surface *s = surfaces[i];
86-
c_created->add(s);
87-
s->add(c_created);
88-
}
89-
}
90-
91-
//On reconstruit les relations surfaces <-> volumes
92-
for (auto s2s : m_s2s) {
93-
Surface *s_ref = s2s.first;
94-
Surface *s_created = s2s.second;
95-
auto volumes = s_ref->getVolumes();
96-
for (int i = 0; i < volumes.size(); i++) {
97-
Volume *vol = volumes[i];
98-
s_created->add(vol);
99-
vol->add(s_created);
100-
}
101-
}
102-
103-
//On a besoin de gérer que les relations de dimension n <-> n+1, le reste est créé implicitement par ces relations
104-
}
105-
106-
for(int i=0;i<rem_entities.size();i++){
107-
getInfoCommand ( ).addGeomInfoEntity (rem_entities[i], Internal::InfoCommand::DELETED);
108-
}
109-
110-
getInfoCommand().setDestroyAndUpdateConnectivity(rem_entities);
11146

11247
// transmet les groupes du 2D vers le 3D
11348
groups2DTo3D();
114-
115-
for(int i=0;i<new_entities.size();i++){
116-
GeomEntity* ge = new_entities[i];
117-
if (ge->getNbGroups() == 0)
118-
// ajoute à un groupe par défaut
119-
m_group_helper.addToGroup("", ge);
120-
}
12149
}
12250
/*----------------------------------------------------------------------------*/
12351
} // end namespace Geom

src/Core/Geom/CommandExtrudeRevolution.cpp

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ CommandExtrudeRevolution::
2121
CommandExtrudeRevolution(Internal::Context& c,
2222
std::vector<GeomEntity*>& entities,
2323
const Utils::Math::Rotation& rot, const bool keep)
24-
: CommandExtrusion(c, "Revolution"),
25-
m_entities(entities), m_axis1(rot.getAxis1()), m_axis2(rot.getAxis2()),
26-
m_angle(rot.getAngle()), m_keep(keep)
24+
: CommandExtrusion(c, "Revolution", entities, keep)
25+
, m_axis1(rot.getAxis1())
26+
, m_axis2(rot.getAxis2())
27+
, m_angle(rot.getAngle())
2728
{
2829
if (m_angle<0.0 || m_angle>360.0)
2930
throw TkUtil::Exception(TkUtil::UTF8String ("L'angle est en degrés et doit être compris entre 0 et 360", TkUtil::Charset::UTF_8));
@@ -40,30 +41,11 @@ CommandExtrudeRevolution(Internal::Context& c,
4041
setName(comments);
4142
}
4243
/*----------------------------------------------------------------------------*/
43-
CommandExtrudeRevolution::~CommandExtrudeRevolution()
44-
{
45-
if(m_impl)
46-
delete m_impl;
47-
}
48-
/*----------------------------------------------------------------------------*/
4944
void CommandExtrudeRevolution::
50-
internalExecute()
45+
internalSpecificExecute()
5146
{
52-
m_impl->prePerform();
53-
m_impl->perform(m_createdEntities,m_v2v, m_v2v_opp,m_v2c,
47+
getImpl()->perform(m_createdEntities,m_v2v, m_v2v_opp,m_v2c,
5448
m_c2c, m_c2c_opp, m_c2s, m_s2s, m_s2s_opp, m_s2v);
55-
std::vector<GeomEntity*>& new_entities = m_impl->getNewEntities();
56-
std::vector<GeomEntity*>& rem_entities = m_impl->getRemovedEntities();
57-
for(int i=0;i<new_entities.size();i++){
58-
GeomEntity* ge = new_entities[i];
59-
getInfoCommand ( ).addGeomInfoEntity (ge, Internal::InfoCommand::CREATED);
60-
getContext().getGeomManager().addEntity(ge);
61-
}
62-
for(int i=0;i<rem_entities.size();i++){
63-
getInfoCommand ( ).addGeomInfoEntity (rem_entities[i], Internal::InfoCommand::DELETED);
64-
}
65-
66-
getInfoCommand().setDestroyAndUpdateConnectivity(rem_entities);
6749

6850
// transmet les groupes du 2D vers le 3D
6951
groups2DTo3D();
@@ -84,12 +66,6 @@ internalExecute()
8466
prefixGroupsName("P72", m_v2v_opp, m_c2c_opp, m_s2s_opp);
8567
addGroupOnAxis();
8668
}
87-
for(int i=0;i<new_entities.size();i++){
88-
GeomEntity* ge = new_entities[i];
89-
if (ge->getNbGroups() == 0)
90-
// ajoute à un groupe par défaut
91-
m_group_helper.addToGroup("", ge);
92-
}
9369
}
9470
/*----------------------------------------------------------------------------*/
9571
void CommandExtrudeRevolution::
@@ -125,7 +101,6 @@ addGroupOnAxis()
125101
m_group_helper.addToGroup("AXE", crv2);
126102
}
127103
}
128-
129104
}
130105
/*----------------------------------------------------------------------------*/
131106
} // end namespace Geom

src/Core/Geom/CommandExtrusion.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ namespace Mgx3D {
1818
namespace Geom {
1919
/*----------------------------------------------------------------------------*/
2020
CommandExtrusion::
21-
CommandExtrusion(Internal::Context& c, std::string name)
22-
: CommandCreateGeom(c, name)
21+
CommandExtrusion(Internal::Context& c,
22+
std::string name,
23+
std::vector<GeomEntity*>& entities,
24+
const bool keep)
25+
: CommandEditGeom(c, name)
26+
, m_entities(entities)
27+
, m_keep(keep)
2328
{
2429
}
2530
/*----------------------------------------------------------------------------*/
26-
CommandExtrusion::~CommandExtrusion()
31+
void CommandExtrusion::internalSpecificPreExecute()
2732
{
33+
m_impl->prePerform();
2834
}
2935
/*----------------------------------------------------------------------------*/
3036
std::map<Geom::Vertex*,Geom::Vertex*>& CommandExtrusion::
@@ -145,8 +151,9 @@ void CommandExtrusion::printInfoAssociations() const
145151
void CommandExtrusion::
146152
groups2DTo3D()
147153
{
148-
// [EB] on se sert de la correspondance entre les entités initiales et finales
149-
// pour transmetre les groupes du 2D au 3D (et du 1D au 2D ...)
154+
// Les nouveaux objets ont été mis "hors groupe" à la création
155+
// On se sert de la correspondance entre les entités initiales et finales
156+
// pour transmetre les groupes de la dimension N à la dimension N+1
150157

151158
for (std::map<Geom::Surface*,Geom::Volume*>::iterator iter = m_s2v.begin();
152159
iter != m_s2v.end(); ++iter){
@@ -158,12 +165,10 @@ groups2DTo3D()
158165

159166
for (uint i=0; i<grp.size(); i++){
160167
std::string nom = grp[i]->getName();
161-
// Hors Groupe 2D -> Hors Groupe 3D
162-
if (i == 0 && nom == getContext().getGroupManager().getDefaultName(2))
163-
nom = getContext().getGroupManager().getDefaultName(3);
164-
165-
Group::Group3D* new_grp = m_group_helper.addToGroup(nom, vol);
166-
new_grp->setLevel(grp[i]->getLevel());
168+
if (nom != getContext().getGroupManager().getDefaultName(2)) {
169+
Group::Group3D* new_grp = m_group_helper.addToGroup(nom, vol);
170+
new_grp->setLevel(grp[i]->getLevel());
171+
}
167172
}
168173
}
169174
}
@@ -177,12 +182,10 @@ groups2DTo3D()
177182
curve->getGroups(grp);
178183
for (uint i=0; i<grp.size(); i++){
179184
std::string nom = grp[i]->getName();
180-
// Hors Groupe 1D -> Hors Groupe 2D
181-
if (i == 0 && nom == getContext().getGroupManager().getDefaultName(1))
182-
nom = getContext().getGroupManager().getDefaultName(2);
183-
184-
Group::Group2D* new_grp = m_group_helper.addToGroup(nom, surf);
185-
new_grp->setLevel(grp[i]->getLevel());
185+
if (nom != getContext().getGroupManager().getDefaultName(1)) {
186+
Group::Group2D* new_grp = m_group_helper.addToGroup(nom, surf);
187+
new_grp->setLevel(grp[i]->getLevel());
188+
}
186189
}
187190
}
188191
}
@@ -196,12 +199,10 @@ groups2DTo3D()
196199
vtx->getGroups(grp);
197200
for (uint i=0; i<grp.size(); i++){
198201
std::string nom = grp[i]->getName();
199-
// Hors Groupe 0D -> Hors Groupe 1D
200-
if (i == 0 && nom == getContext().getGroupManager().getDefaultName(0))
201-
nom = getContext().getGroupManager().getDefaultName(1);
202-
203-
Group::Group1D* new_grp = m_group_helper.addToGroup(nom, curve);
204-
new_grp->setLevel(grp[i]->getLevel());
202+
if (nom != getContext().getGroupManager().getDefaultName(0)) {
203+
Group::Group1D* new_grp = m_group_helper.addToGroup(nom, curve);
204+
new_grp->setLevel(grp[i]->getLevel());
205+
}
205206
}
206207
}
207208
}

src/Core/Geom/GeomExtrudeImplementation.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Geom/Volume.h"
77
#include "Geom/EntityFactory.h"
88
#include "Geom/OCCHelper.h"
9+
#include "Geom/IncidentGeomEntitiesVisitor.h"
910
/*----------------------------------------------------------------------------*/
1011
#include <TopoDS_Shape.hxx>
1112
#include <BRepPrimAPI_MakePrism.hxx>
@@ -19,6 +20,7 @@
1920
/*----------------------------------------------------------------------------*/
2021
#include <TkUtil/UTF8String.h>
2122
#include <TkUtil/MemoryError.h>
23+
#include <TkUtil/TraceLog.h>
2224
/*----------------------------------------------------------------------------*/
2325
#include <list>
2426
/*----------------------------------------------------------------------------*/
@@ -74,7 +76,7 @@ void GeomExtrudeImplementation::perform(std::vector<GeomEntity*>& res,
7476
for(unsigned int i=1;i<m_init_entities.size();i++){
7577
int dimi = m_init_entities[i]->getDim();
7678
if(dimi==3)
77-
throw TkUtil::Exception(TkUtil::UTF8String ("l'extrusion ne s'applique qu'à des objets de dimension inférieur à 3", TkUtil::Charset::UTF_8));
79+
throw TkUtil::Exception(TkUtil::UTF8String ("L'extrusion ne s'applique qu'à des objets de dimension inférieure à 3", TkUtil::Charset::UTF_8));
7880
}
7981

8082
/* le vecteur d'extrusion ne doit pas être de longueur nulle */
@@ -105,15 +107,37 @@ void GeomExtrudeImplementation::perform(std::vector<GeomEntity*>& res,
105107
}
106108

107109
if(!m_keep) {
108-
for (int i = 0; i < 3; i++) {
109-
std::list<GeomEntity *>::iterator it_rem;
110-
for (it_rem = m_ref_entities[i].begin(); it_rem != m_ref_entities[i].end(); it_rem++) {
111-
m_removedEntities.push_back(*it_rem);
110+
// m_keep à vrai => l'utilisateur demande la suppression des entités de départ
111+
// impliquées dans la révolution. Néanmoins, ces dernières ne seront pas
112+
// détruites si elles ont une adjacence "up" sur une autre entité (pas impliquée)
113+
Utils::EntitySet<GeomEntity*> cleanable_entities(Utils::Entity::compareEntity);
114+
Utils::EntitySet<GeomEntity*> uncleanable_entities(Utils::Entity::compareEntity);
115+
for(int i=2;i>=0;i--){
116+
for (GeomEntity* ge : m_ref_entities[i]) {
117+
GetUpIncidentGeomEntitiesVisitor v_up;
118+
ge->accept(v_up);
119+
Utils::EntitySet<GeomEntity*> up_entities = v_up.get();
120+
if (std::includes(cleanable_entities.begin(), cleanable_entities.end(), up_entities.begin(), up_entities.end(), Utils::Entity::compareEntity)) {
121+
cleanable_entities.insert(ge);
122+
} else {
123+
uncleanable_entities.insert(ge);
124+
}
112125
}
113126
}
114-
}
115127

128+
if (uncleanable_entities.size() > 0) {
129+
TkUtil::UTF8String warning;
130+
warning << "Certaines entités ne peuvent pas être supprimées ";
131+
warning << "car elles sont incidentes/adjacentes à des entités non supprimées : ";
132+
for (GeomEntity* ge : uncleanable_entities)
133+
warning << ge->getName() << " ";
134+
m_context.getLogStream()->log(TkUtil::TraceLog(warning));
135+
std::cout << warning << std::endl;
136+
}
116137

138+
for (GeomEntity* ge : cleanable_entities)
139+
m_removedEntities.push_back(ge);
140+
}
117141
}
118142
/*----------------------------------------------------------------------------*/
119143
void GeomExtrudeImplementation::makeExtrude(Vertex* v,std::vector<GeomEntity*>& res,
@@ -190,8 +214,6 @@ void GeomExtrudeImplementation::makeExtrude(Vertex* v,std::vector<GeomEntity*>&
190214

191215
}
192216
/*----------------------------------------------------------------------------*/
193-
/*----------------------------------------------------------------------------*/
194-
/*----------------------------------------------------------------------------*/
195217
void GeomExtrudeImplementation::makeExtrudeComposite(Curve* curve,std::vector<GeomEntity*>& res,
196218
std::map<Geom::Vertex*,Geom::Vertex*> & v2v,
197219
std::map<Geom::Vertex*,Geom::Vertex*> & v2vOpp,

0 commit comments

Comments
 (0)