Skip to content

Commit e7dd41f

Browse files
committed
Revert "Fix second part of issue#208: split 2 volumes with a volume in a middle"
1 parent 335a5ae commit e7dd41f

File tree

7 files changed

+155
-101
lines changed

7 files changed

+155
-101
lines changed

src/Core/Geom/CommandSectionByPlane.cpp

Lines changed: 105 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@ namespace Geom {
2121
class Volume;
2222
/*----------------------------------------------------------------------------*/
2323
CommandSectionByPlane::
24-
CommandSectionByPlane(Internal::Context& c,
25-
GeomEntity* e,
24+
CommandSectionByPlane(Internal::Context& c,std::vector<GeomEntity*>& entities,
2625
Utils::Math::Plane* p,
2726
std::string planeGroupName)
28-
: CommandEditGeom(c, "Section par un plan de " + e->getName(), ""),
29-
m_entity(e), m_tool(p), m_planeName(planeGroupName)
27+
: CommandEditGeom(c, "Section par un plan",""),
28+
m_entities(entities), m_tool(p), m_planeName(planeGroupName)
3029
{
3130
validate();
3231

33-
m_impl = new GeomSectionByPlaneImplementation(c, m_entity, p);
32+
m_impl = new GeomSectionByPlaneImplementation(c, m_entities,p);
3433

3534
TkUtil::UTF8String comments (TkUtil::Charset::UTF_8);
3635
comments << "Section par un plan de";
37-
comments << " " << e->getName();
38-
comments << " suivant " << *m_tool;
36+
for (uint i=0; i<entities.size() && i<5; i++)
37+
comments << " " << entities[i]->getName();
38+
if (entities.size()>5)
39+
comments << " ... ";
40+
comments << " suivant "<<*m_tool;
3941
setScriptComments(comments);
4042
setName(comments);
4143
}
@@ -49,81 +51,122 @@ CommandSectionByPlane::~CommandSectionByPlane()
4951
void CommandSectionByPlane::validate()
5052
{
5153
#ifdef _DEBUG2
52-
std::cout<<"CommandSectionByPlane::validate()"<<std::endl;
54+
std::cout<<"CommandSectionByPlane::validate() m_entities.size() = "<<m_entities.size()<<std::endl;
5355
#endif
56+
int nbDim2=0;
57+
int nbDim3=0;
58+
for(unsigned int i=0;i<m_entities.size();i++)
59+
{
60+
int dim_i =m_entities[i]->getDim();
61+
if(dim_i==2)
62+
nbDim2++;
63+
else if (dim_i==3)
64+
nbDim3++;
65+
}
66+
if(nbDim2!=m_entities.size() && nbDim3!=m_entities.size())
67+
throw TkUtil::Exception(TkUtil::UTF8String ("La coupe par un plan ne s'applique qu'à un ensemble de volumes ou un ensemble de surfaces", TkUtil::Charset::UTF_8));
5468

55-
if(m_entity->getDim() == 2) {
56-
setDimensionGroup(1);
57-
Surface* si = dynamic_cast<Surface*>(m_entity);
58-
if (si->getVolumes().size() > 0) {
59-
TkUtil::UTF8String msg(TkUtil::Charset::UTF_8);
60-
msg << m_entity->getName();
61-
msg << " non traitée car connectée à des volumes. Il faut couper les volumes.";
62-
throw TkUtil::Exception(msg);
69+
if(nbDim2==m_entities.size()){
70+
// On n'a que des surfaces
71+
short nbSurfConnected2Vol=0;
72+
std::vector<GeomEntity*> validEntities;
73+
for(unsigned int i=0;i<m_entities.size();i++)
74+
{
75+
Surface* si = dynamic_cast<Surface*>(m_entities[i]);
76+
auto vols = si->getVolumes();
77+
if(!vols.empty())
78+
nbSurfConnected2Vol++;
79+
else validEntities.push_back(si);
6380
}
64-
} else if (m_entity->getDim() == 3) {
65-
setDimensionGroup(2);
81+
m_entities = validEntities;
82+
if(nbSurfConnected2Vol!=0)
83+
throw TkUtil::Exception(TkUtil::UTF8String ("Surfaces non traitées car connectées à des volumes\n(=> couper les volumes)", TkUtil::Charset::UTF_8));
6684
}
85+
86+
if (nbDim2)
87+
setDimensionGroup(1);
88+
else if (nbDim3)
89+
setDimensionGroup(2);
90+
#ifdef _DEBUG2
91+
std::cout<<" en sortie ==> m_entities.size() = "<<m_entities.size()<<std::endl;
92+
#endif
6793
}
6894
/*----------------------------------------------------------------------------*/
69-
bool CommandSectionByPlane::isIntersected()
95+
void CommandSectionByPlane::removeNonIntersectedEntities()
7096
{
71-
double bounds[6];
72-
m_entity->getBounds(bounds);
97+
std::vector<GeomEntity*> cleanEntities;
98+
for(unsigned int i=0;i<m_entities.size();i++)
99+
{
100+
GeomEntity* ei = m_entities[i];
101+
double bounds[6];
102+
ei->getBounds(bounds);
73103

74-
double xmin = bounds[0];
75-
double xmax = bounds[1];
76-
double ymin = bounds[2];
77-
double ymax = bounds[3];
78-
double zmin = bounds[4];
79-
double zmax = bounds[5];
104+
double xmin = bounds[0];
105+
double xmax = bounds[1];
106+
double ymin = bounds[2];
107+
double ymax = bounds[3];
108+
double zmin = bounds[4];
109+
double zmax = bounds[5];
80110

81-
// si tous les sommets de la BB sont du même côté du plan de coupe
82-
// on ne traite pas cet objet geometrique
83-
Utils::Math::Point p1(xmin,ymin,zmin);
84-
Utils::Math::Point p2(xmax,ymin,zmin);
85-
Utils::Math::Point p3(xmax,ymax,zmin);
86-
Utils::Math::Point p4(xmin,ymax,zmin);
87-
Utils::Math::Point p5(xmin,ymin,zmax);
88-
Utils::Math::Point p6(xmax,ymin,zmax);
89-
Utils::Math::Point p7(xmax,ymax,zmax);
90-
Utils::Math::Point p8(xmin,ymax,zmax);
111+
// si tous les sommets de la BB sont du même côté du plan de coupe
112+
// on ne traite pas cet objet geometrique
113+
Utils::Math::Point p1(xmin,ymin,zmin);
114+
Utils::Math::Point p2(xmax,ymin,zmin);
115+
Utils::Math::Point p3(xmax,ymax,zmin);
116+
Utils::Math::Point p4(xmin,ymax,zmin);
117+
Utils::Math::Point p5(xmin,ymin,zmax);
118+
Utils::Math::Point p6(xmax,ymin,zmax);
119+
Utils::Math::Point p7(xmax,ymax,zmax);
120+
Utils::Math::Point p8(xmin,ymax,zmax);
91121

92-
Utils::Math::Point plane_pnt = m_tool->getPoint();
93-
Utils::Math::Vector plane_vec = m_tool->getNormal();
122+
Utils::Math::Point plane_pnt = m_tool->getPoint();
123+
Utils::Math::Vector plane_vec = m_tool->getNormal();
94124

95-
Utils::Math::Vector v[8];
96-
v[0]=Utils::Math::Vector(plane_pnt,p1);
97-
v[1]=Utils::Math::Vector(plane_pnt,p2);
98-
v[2]=Utils::Math::Vector(plane_pnt,p3);
99-
v[3]=Utils::Math::Vector(plane_pnt,p4);
100-
v[4]=Utils::Math::Vector(plane_pnt,p5);
101-
v[5]=Utils::Math::Vector(plane_pnt,p6);
102-
v[6]=Utils::Math::Vector(plane_pnt,p7);
103-
v[7]=Utils::Math::Vector(plane_pnt,p8);
125+
Utils::Math::Vector v[8];
126+
v[0]=Utils::Math::Vector(plane_pnt,p1);
127+
v[1]=Utils::Math::Vector(plane_pnt,p2);
128+
v[2]=Utils::Math::Vector(plane_pnt,p3);
129+
v[3]=Utils::Math::Vector(plane_pnt,p4);
130+
v[4]=Utils::Math::Vector(plane_pnt,p5);
131+
v[5]=Utils::Math::Vector(plane_pnt,p6);
132+
v[6]=Utils::Math::Vector(plane_pnt,p7);
133+
v[7]=Utils::Math::Vector(plane_pnt,p8);
104134

105-
int sidePos=0, sideNeg=0;
106-
for(short j=0;j<8;j++){
107-
if(plane_vec.dot(v[j])>0.0)
108-
sidePos++;
109-
else
110-
sideNeg++;
135+
int sidePos=0, sideNeg=0;
136+
for(short j=0;j<8;j++){
137+
if(plane_vec.dot(v[j])>0.0)
138+
sidePos++;
139+
else
140+
sideNeg++;
141+
}
142+
if(sidePos!=0 && sideNeg!=0)
143+
cleanEntities.push_back(ei);
144+
145+
}
146+
if(cleanEntities.size()!=m_entities.size()){
147+
#ifdef _DEBUG2
148+
std::cout<<"CommandSectionByPlane::removeNonIntersectedEntities() m_entities.size() = "
149+
<<m_entities.size()<<" et cleanEntities.size() = "<<cleanEntities.size()<<std::endl;
150+
#endif
151+
m_entities.clear();
152+
m_entities.insert(m_entities.end(),cleanEntities.begin(),cleanEntities.end());
111153
}
112-
return (sidePos!=0 && sideNeg!=0);
113154
}
114155
/*----------------------------------------------------------------------------*/
115156
void CommandSectionByPlane::internalSpecificExecute()
116157
{
117158
#ifdef _DEBUG2
118-
std::cout<<"CommandSectionByPlane::internalSpecificExecute() avec m_planeName = "<< m_planeName
119-
<<" m_entity.getName()" << std::endl;
159+
std::cout<<"CommandSectionByPlane::internalSpecificExecute() avec m_planeName = "<<m_planeName
160+
<<" m_entities.size() = "<<m_entities.size()<<std::endl;
120161
#endif
121162

122-
if (!m_entity) return;
123-
if (!isIntersected()) return;
163+
if(m_entities.empty())
164+
return;
165+
166+
removeNonIntersectedEntities();
124167
m_impl->perform(m_createdEntities);
125168

126-
// [EB] inutile (et fait double emploi) depuis utilisation de CommandEditGeom::updateGroups
169+
// [EB] inutile (et fait double emploi) depuis utilisation de CommandEditGeom::updateGroups
127170
//on place dans le groupe les entites intersectees
128171
GeomSectionByPlaneImplementation* impl = dynamic_cast<GeomSectionByPlaneImplementation*>(m_impl);
129172
CHECK_NULL_PTR_ERROR(impl);
@@ -156,7 +199,9 @@ void CommandSectionByPlane::internalSpecificExecute()
156199
getInfoCommand().addGroupInfoEntity(group,Internal::InfoCommand::DISPMODIFIED);
157200
}
158201
}
202+
159203
}
204+
160205
/*----------------------------------------------------------------------------*/
161206
void CommandSectionByPlane::internalSpecificPreExecute()
162207
{

src/Core/Geom/GeomManager.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,27 +4405,25 @@ sectionByPlane( std::vector<Geom::GeomEntity*>& entities,
44054405

44064406
Internal::CommandInternal* command = 0;
44074407

4408-
if (entities.size() == 1 && !Internal::EntitiesHelper::hasTopoRef(entities)) {
4409-
command = new CommandSectionByPlane(getContext(), entities[0], tool, planeGroupName);
4410-
} else {
4408+
if (Internal::EntitiesHelper::hasTopoRef(entities)){
4409+
44114410
Internal::CommandComposite* commandCompo =
44124411
new Internal::CommandComposite(getContext(), "Section par un plan entre géométries avec topologies");
44134412

4414-
for (GeomEntity* e : entities) {
4415-
Geom::CommandEditGeom *commandGeom =
4416-
new CommandSectionByPlane(getContext(), e, tool, planeGroupName);
4417-
commandCompo->addCommand(commandGeom);
4413+
Geom::CommandEditGeom *commandGeom =
4414+
new CommandSectionByPlane(getContext(), entities, tool, planeGroupName);
44184415

4419-
std::vector<Geom::GeomEntity*> es = {e};
4420-
if (Internal::EntitiesHelper::hasTopoRef(es)) {
4421-
Topo::CommandModificationTopo* commandTopo = new Topo::CommandModificationTopo(getContext(),
4422-
commandGeom);
4423-
commandCompo->addCommand(commandTopo);
4424-
}
4425-
}
4416+
commandCompo->addCommand(commandGeom);
4417+
4418+
Topo::CommandModificationTopo* commandTopo = new Topo::CommandModificationTopo(getContext(),
4419+
commandGeom);
4420+
commandCompo->addCommand(commandTopo);
44264421

44274422
command = commandCompo;
44284423
}
4424+
else {
4425+
command = new CommandSectionByPlane(getContext(),entities,tool,planeGroupName);
4426+
}
44294427

44304428
// trace dans le script
44314429
TkUtil::UTF8String cmd (TkUtil::Charset::UTF_8);

src/Core/Geom/GeomModificationBaseClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,10 @@ void GeomModificationBaseClass::rebuildAdjacencyEntities(const TopoDS_Shape& sha
794794

795795
for(unsigned int is=0;is<surfs.size();is++)
796796
{
797-
std::map<GeomEntity*,std::vector<GeomEntity*> >::const_iterator it=m_replacedEntities.find(surfs[is]);
798797
#ifdef _DEBUG2
799-
std::cout<<" \t surf. "<<surfs[is]->getName()<<(it==m_replacedEntities.end()?" modifiée":" intacte")<<std::endl;
798+
std::cout<<" \t surf. "<<surfs[is]->getName()<<std::endl;
800799
#endif
800+
std::map<GeomEntity*,std::vector<GeomEntity*> >::const_iterator it=m_replacedEntities.find(surfs[is]);
801801
if(it!=m_replacedEntities.end())
802802
{
803803
surf_modified=true;

src/Core/Geom/GeomSectionByPlaneImplementation.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ namespace Geom
4040
/*----------------------------------------------------------------------------*/
4141
GeomSectionByPlaneImplementation::GeomSectionByPlaneImplementation(
4242
Internal::Context& c,
43-
GeomEntity* e, Utils::Math::Plane* p)
44-
: GeomModificationBaseClass(c)
45-
, m_plane(p)
46-
, m_entity_param(e)
43+
std::vector<GeomEntity*>& es, Utils::Math::Plane* p) :
44+
GeomModificationBaseClass(c), m_plane(p)
4745
{
46+
m_entities_param.insert(m_entities_param.end(),es.begin(),es.end());
47+
4848
}
4949
/*----------------------------------------------------------------------------*/
5050
GeomSectionByPlaneImplementation::~GeomSectionByPlaneImplementation()
@@ -56,19 +56,18 @@ void GeomSectionByPlaneImplementation::prePerform()
5656
//========================================================================
5757
// Mise à jour des connectivés de références
5858
//========================================================================
59-
std::vector<GeomEntity*> es = {m_entity_param};
60-
init(es);
59+
init(m_entities_param);
6160
}
6261
/*----------------------------------------------------------------------------*/
6362
void GeomSectionByPlaneImplementation::perform(std::vector<GeomEntity*>& res)
6463
{
65-
split(res);
64+
splitEntities(res);
6665
}
6766
/*----------------------------------------------------------------------------*/
68-
void GeomSectionByPlaneImplementation::split(std::vector<GeomEntity*>& res)
67+
void GeomSectionByPlaneImplementation::splitEntities(std::vector<GeomEntity*>& res)
6968
{
7069
#ifdef _DEBUG2
71-
std::cout<<"GeomSectionByPlaneImplementation::split ..."<<std::endl;
70+
std::cout<<"GeomSectionByPlaneImplementation::splitEntities ..."<<std::endl;
7271
#endif
7372
//========================================================================
7473
// 1 - Définition du plan de coupe

src/Core/protected/Geom/CommandSectionByPlane.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class CommandSectionByPlane: public CommandEditGeom{
2424
/** \brief Constructeur
2525
*
2626
* \param c le contexte
27-
* \param e l'entité à découper
27+
* \param es les entités à découper
2828
* \param p le plan de coupe
2929
*/
30-
CommandSectionByPlane(Internal::Context& c, GeomEntity* e,
30+
CommandSectionByPlane(Internal::Context& c, std::vector<GeomEntity*>& es,
3131
Utils::Math::Plane* p,
3232
std::string planeGroupName);
3333

@@ -46,18 +46,21 @@ class CommandSectionByPlane: public CommandEditGeom{
4646
*/
4747
void internalSpecificPreExecute();
4848

49+
50+
void removeNonIntersectedEntities();
51+
4952
protected:
50-
bool isIntersected();
5153

5254
/// valide les paramètres
5355
void validate();
5456

55-
/* entité à découper*/
56-
GeomEntity* m_entity;
57+
/* entités à découper*/
58+
std::vector<GeomEntity*> m_entities;
5759

5860
/* outil de découpe */
5961
Utils::Math::Plane* m_tool;
6062

63+
6164
/* outil de découpe */
6265
std::string m_planeName;
6366

src/Core/protected/Geom/GeomSectionByPlaneImplementation.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class GeomSectionByPlaneImplementation: public GeomModificationBaseClass
3535
/*------------------------------------------------------------------------*/
3636
/** \brief Constructeur.
3737
*
38-
* \param e l' entité à traiter
38+
* \param e les entités à traiter
3939
* \param p le plan de coupe
4040
4141
*/
42-
GeomSectionByPlaneImplementation(Internal::Context& c, GeomEntity* e,
42+
GeomSectionByPlaneImplementation(Internal::Context& c, std::vector<GeomEntity*>& e,
4343
Utils::Math::Plane* p);
4444

4545
/*------------------------------------------------------------------------*/
@@ -71,7 +71,7 @@ class GeomSectionByPlaneImplementation: public GeomModificationBaseClass
7171
/** \brief réalisation de la découpe.
7272
* Les entités créées sont stockées dans res
7373
*/
74-
void split(std::vector<GeomEntity*>& res);
74+
void splitEntities(std::vector<GeomEntity*>& res);
7575

7676
/**
7777
* Methodes surchargée pour mettre à jour la shape OCC d'entités M3D adjacentes
@@ -90,8 +90,17 @@ class GeomSectionByPlaneImplementation: public GeomModificationBaseClass
9090
void getUniqueOCCShape(GeomEntity* ge, TopoDS_Shape& sh) const;
9191

9292
private:
93-
/* entité passée en argument à la commande. */
94-
GeomEntity* m_entity_param;
93+
94+
/** Entités qui vont être modifiées par l'algorithme. Purement technique pour
95+
* faire le lien entre initialize() et finalize()
96+
*
97+
*/
98+
std::vector<GeomEntity*> entities_to_update;
99+
std::vector<GeomEntity*> entities_new;
100+
101+
102+
/* entités passées en argument à la commande. */
103+
std::vector<GeomEntity*> m_entities_param;
95104

96105
TopoDS_Shape m_restricted_section_tool;
97106
};

0 commit comments

Comments
 (0)