@@ -21,21 +21,23 @@ namespace Geom {
2121class Volume ;
2222/* ----------------------------------------------------------------------------*/
2323CommandSectionByPlane::
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()
4951void 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/* ----------------------------------------------------------------------------*/
115156void 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/* ----------------------------------------------------------------------------*/
161206void CommandSectionByPlane::internalSpecificPreExecute ()
162207{
0 commit comments