Skip to content

Commit 49c5a09

Browse files
mpoudotnicolaslg
authored andcommitted
Fix bug on newSphere with angle (125) in python script
1 parent d670853 commit 49c5a09

9 files changed

Lines changed: 133 additions & 111 deletions

File tree

src/Core/Geom/CommandNewSphere.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,11 @@ CommandNewSphere::CommandNewSphere(Internal::Context& c,
1818
const double& angle,
1919
const std::string& groupName)
2020
:CommandCreateGeom(c, "Création d'une sphère", groupName), m_center(pcentre), m_dr(dr),
21-
m_angle(angle),m_type(Utils::Portion::ANGLE_DEF)
21+
m_angle(angle),m_type(Utils::Portion::getTypeFromAngle(angle))
2222
{
2323
validate();
2424
}
2525
/*----------------------------------------------------------------------------*/
26-
CommandNewSphere::CommandNewSphere(Internal::Context& c,
27-
const Utils::Math::Point& pcentre,
28-
const double& dr,
29-
const Utils::Portion::Type& dp,
30-
const std::string& groupName)
31-
:CommandCreateGeom(c, "Création d'une sphère", groupName), m_center(pcentre), m_dr(dr),
32-
m_angle(0), m_type(dp)
33-
{
34-
if (dp == 0){
35-
MGX_FORBIDDEN("Sphère pleine avec portion indéfinie")
36-
}
37-
validate();
38-
}
39-
/*----------------------------------------------------------------------------*/
4026
CommandNewSphere::~CommandNewSphere()
4127
{}
4228
/*----------------------------------------------------------------------------*/
@@ -53,7 +39,7 @@ internalExecute()
5339
<<" Type "<<Utils::Portion::getName(m_type)
5440
<<", angle "<<Utils::Math::MgxNumeric::userRepresentation (m_angle);
5541
Volume* vol = EntityFactory(getContext()).newSphere(
56-
new PropertySphere(m_center, m_dr,m_type,m_angle));
42+
new PropertySphere(m_center, m_dr, m_type,m_angle));
5743

5844
m_createdEntities.push_back(vol);
5945

src/Core/Geom/EntityFactory.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -990,40 +990,28 @@ Volume* EntityFactory::newSphere(PropertySphere* prop)
990990

991991
TopoDS_Solid s;
992992
switch(type){
993-
case (Utils::Portion::ENTIER):{
994-
BRepPrimAPI_MakeSphere mkSphere(center,radius);
995-
s = mkSphere.Solid();
996-
}
997-
break;
998-
case (Utils::Portion::TROIS_QUARTS):{
999-
BRepPrimAPI_MakeSphere mkSphere(center,radius,3*M_PI/4);
1000-
s = mkSphere.Solid();
1001-
}
1002-
break;
1003-
case (Utils::Portion::DEMI):{
1004-
BRepPrimAPI_MakeSphere mkSphere(center,radius,M_PI);
1005-
s = mkSphere.Solid();
1006-
}
1007-
break;
1008-
case (Utils::Portion::QUART):{
1009-
BRepPrimAPI_MakeSphere mkSphere(center,radius,M_PI/2);
1010-
s = mkSphere.Solid();
1011-
}
1012-
break;
1013-
case (Utils::Portion::HUITIEME):{
1014-
BRepPrimAPI_MakeSphere mkSphere(center,radius,0,M_PI/2,M_PI/2);
1015-
s = mkSphere.Solid();
1016-
}
1017-
break;
1018-
case (Utils::Portion::ANGLE_DEF):{
1019-
// l'angle est supposé en degré et non pas en radians
1020-
BRepPrimAPI_MakeSphere mkSphere(center,radius,(angle*M_PI)/180.0);
1021-
s = mkSphere.Solid();
1022-
}
1023-
break;
993+
case (Utils::Portion::ENTIER):{
994+
BRepPrimAPI_MakeSphere mkSphere(center,radius);
995+
s = mkSphere.Solid();
996+
}
997+
break;
998+
case (Utils::Portion::HUITIEME):{
999+
BRepPrimAPI_MakeSphere mkSphere(center,radius,0,M_PI/2,M_PI/2);
1000+
s = mkSphere.Solid();
1001+
}
1002+
break;
1003+
case (Utils::Portion::ANGLE_DEF):{
1004+
// l'angle est supposé en degré et non pas en radians
1005+
BRepPrimAPI_MakeSphere mkSphere(center,radius,(angle*M_PI)/180.0);
1006+
s = mkSphere.Solid();
1007+
}
1008+
break;
1009+
default:{
1010+
BRepPrimAPI_MakeSphere mkSphere(center,radius,Utils::Portion::getAngleInRadian(type));
1011+
s = mkSphere.Solid();
1012+
}
1013+
break;
10241014
}
1025-
1026-
10271015
try{
10281016
Volume* volume = new Volume(m_context,
10291017
m_context.newProperty(Utils::Entity::GeomVolume),

src/Core/Geom/GeomManager.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,8 @@ newSphere(const Utils::Math::Point& pcentre, const double& dr,
18311831
message<<")";
18321832
log (TkUtil::TraceLog (message, TkUtil::Log::TRACE_3));
18331833

1834-
CommandNewSphere *command = new CommandNewSphere(getContext(), pcentre, dr,da, groupName);
1834+
Utils::Portion::Type dt(Utils::Portion::ANGLE_DEF);
1835+
CommandNewSphere *command = new CommandNewSphere(getContext(), pcentre, dr, da, groupName);
18351836

18361837
// trace dans le script
18371838
TkUtil::UTF8String cmd (TkUtil::Charset::UTF_8);
@@ -1850,35 +1851,6 @@ newSphere(const Utils::Math::Point& pcentre, const double& dr,
18501851
return cmdResult;
18511852
}
18521853
/*----------------------------------------------------------------------------*/
1853-
Internal::M3DCommandResult* GeomManager::
1854-
newSphere(const Utils::Math::Point& pcentre, const double& dr,
1855-
const Utils::Portion::Type& dt, std::string groupName)
1856-
{
1857-
TkUtil::UTF8String message (TkUtil::Charset::UTF_8);
1858-
message << "GeomManager::newSphere("<<pcentre<<", "<<dr<<", "<<Utils::Portion::getName(dt);
1859-
if (!groupName.empty())
1860-
message<<", "<<groupName;
1861-
message<<")";
1862-
log (TkUtil::TraceLog (message, TkUtil::Log::TRACE_3));
1863-
1864-
CommandNewSphere *command = new CommandNewSphere(getContext(), pcentre, dr,dt, groupName);
1865-
// trace dans le script
1866-
TkUtil::UTF8String cmd (TkUtil::Charset::UTF_8);
1867-
cmd << getContextAlias() << "." << "getGeomManager().newSphere ("
1868-
<<pcentre.getScriptCommand()<<", "<< Utils::Math::MgxNumeric::userRepresentation (dr) <<", "
1869-
<<Utils::Portion::getName(dt);
1870-
if (!groupName.empty())
1871-
cmd<<", \""<<groupName<<"\"";
1872-
cmd<<")";
1873-
command->setScriptCommand(cmd);
1874-
1875-
getCommandManager().addCommand(command, Utils::Command::DO);
1876-
1877-
Internal::M3DCommandResult* cmdResult =
1878-
new Internal::M3DCommandResult (*command);
1879-
return cmdResult;
1880-
}
1881-
/*----------------------------------------------------------------------------*/
18821854
Internal::M3DCommandResult *GeomManager::
18831855
newSpherePart(const double& dr,
18841856
const double& angleY,

src/Core/Topo/TopoManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,8 @@ newSphereWithTopo(const Point& pcentre, const double& dr,
12671267
log (TkUtil::TraceLog (message, TkUtil::Log::TRACE_4));
12681268

12691269
// creation de la commande de création de la géométrie
1270-
Geom::CommandNewSphere *commandGeom = new Geom::CommandNewSphere(getContext(),pcentre, dr, dt, groupName);
1270+
double da = Utils::Portion::getAngleInDegree(dt);
1271+
Geom::CommandNewSphere *commandGeom = new Geom::CommandNewSphere(getContext(),pcentre, dr, da, groupName);
12711272

12721273
// creation de la commande de création de la topologie
12731274
// avec un volume à récupérer dans la commande

src/Core/protected/Geom/CommandNewSphere.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ class CommandNewSphere: public Geom::CommandCreateGeom{
3434
const double& angle,
3535
const std::string& groupName);
3636
/*------------------------------------------------------------------------*/
37-
/** \brief Constructeur
38-
*
39-
* \param c le contexte
40-
* \param pcentre le centre de la sphère
41-
* \param dr le rayon de la sphère
42-
* \param dp type de portion de sphere
43-
* \param groupName un nom de groupe (qui peut être vide)
44-
*/
45-
CommandNewSphere(Internal::Context& c,
46-
const Utils::Math::Point& pcentre,
47-
const double& dr,
48-
const Utils::Portion::Type& dp,
49-
const std::string& groupName);
50-
51-
/*------------------------------------------------------------------------*/
5237
/** \brief Destructeur
5338
*/
5439
virtual ~CommandNewSphere();

src/Core/protected/Geom/GeomManager.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -546,20 +546,6 @@ class GeomManager final : public Internal::CommandCreator {
546546
Mgx3D::Internal::M3DCommandResult*
547547
newSphere(const Point& pcentre, const double& radius,
548548
const double& angle, std::string groupName="");
549-
550-
/*------------------------------------------------------------------------*/
551-
/** \brief Création d'une sphère.
552-
*
553-
* \param pcentre Le centre de la sphère
554-
* \param radius Le rayon de la sphère
555-
* \param dt portion de sphere à créer
556-
* \param groupName optionnellement un nom de groupe
557-
*/
558-
/*------------------------------------------------------------------------*/
559-
Mgx3D::Internal::M3DCommandResult*
560-
newSphere(const Point& pcentre, const double& radius,
561-
const Utils::Portion::Type& dt, std::string groupName="");
562-
563549
/*------------------------------------------------------------------------*/
564550
/** \brief Création d'une aiguille du type partie de sphère.
565551
*

src/QtComponents/QtSphereOperationAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ void QtSphereOperationPanel::preview (bool show, bool destroyInteractor)
566566
else
567567
{ // Portion prédéfinie
568568
if (false == hollowed)
569-
command = new CommandNewSphere(*context, center, externalRadius, portion, "");
569+
command = new CommandNewSphere(*context, center, externalRadius, angle, "");
570570
else
571571
command = new CommandNewHollowSphere(*context, center, internalRadius, externalRadius, portion, "");
572572
} // else if ((Portion::Type)0 == portion)

src/Utils/protected/Utils/Constants.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Portion{
8080
angle = M_PI;
8181
break;
8282
case Portion::TIERS:
83-
angle = M_PI/3;
83+
angle = 2*M_PI/3;
8484
break;
8585
case Portion::QUART:
8686
angle = M_PI/2;
@@ -131,6 +131,40 @@ class Portion{
131131
}
132132
return angle;
133133
}
134+
135+
static Type getTypeFromAngle(double angle) {
136+
Type type;
137+
switch((int)angle){
138+
case 360:
139+
type = ENTIER;
140+
break;
141+
case 72:
142+
type = CINQUIEME;
143+
break;
144+
case 60:
145+
type = SIXIEME;
146+
break;
147+
case 180:
148+
type = DEMI;
149+
break;
150+
case 120:
151+
type = TIERS;
152+
break;
153+
case 90:
154+
type = QUART;
155+
break;
156+
case 270:
157+
type = TROIS_QUARTS;
158+
break;
159+
case 45:
160+
type = HUITIEME;
161+
break;
162+
default:
163+
type = ANGLE_DEF;
164+
break;
165+
}
166+
return type;
167+
}
134168
};/*----------------------------------------------------------------------------*/
135169
} // end namespace Utils
136170
/*----------------------------------------------------------------------------*/

test_link/test_new_sphere.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pyMagix3D as Mgx3D
2+
import pytest
3+
import math
4+
5+
def test_new_sphere(capfd):
6+
ctx = Mgx3D.getStdContext()
7+
ctx.clearSession() # Clean the session after the previous test
8+
gm = ctx.getGeomManager()
9+
tm = ctx.getTopoManager()
10+
mm = ctx.getMeshManager()
11+
12+
# Création du volume Vol0000
13+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.ENTIER, "AAA")
14+
assert gm.getNbVolumes()==1
15+
assert gm.getInfos("Vol0000", 3).area==pytest.approx(4/3 * math.pi, abs=1e-7)
16+
17+
# Création du volume Vol0001
18+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.TROIS_QUARTS, "AAA")
19+
assert gm.getNbVolumes()==2
20+
assert gm.getInfos("Vol0001", 3).area==pytest.approx(math.pi, abs=1e-7)
21+
22+
# Création du volume Vol0002
23+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.DEMI, "AAA")
24+
assert gm.getNbVolumes()==3
25+
assert gm.getInfos("Vol0002", 3).area==pytest.approx(2/3 * math.pi, abs=1e-7)
26+
27+
# Création du volume Vol0003
28+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.TIERS)
29+
assert gm.getNbVolumes()==4
30+
assert gm.getInfos("Vol0003", 3).area==pytest.approx(4/9 * math.pi, abs=1e-7)
31+
32+
# Création du volume Vol0004
33+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.QUART)
34+
assert gm.getNbVolumes()==5
35+
assert gm.getInfos("Vol0004", 3).area==pytest.approx(1/3 * math.pi, abs=1e-7)
36+
37+
# Création du volume Vol0005
38+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.CINQUIEME)
39+
assert gm.getNbVolumes()==6
40+
assert gm.getInfos("Vol0005", 3).area==pytest.approx(4/15 * math.pi, abs=1e-7)
41+
42+
# Création du volume Vol0006
43+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.SIXIEME)
44+
assert gm.getNbVolumes()==7
45+
assert gm.getInfos("Vol0006", 3).area==pytest.approx(2/9 * math.pi, abs=1e-7)
46+
47+
# Création du volume Vol0007
48+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, Mgx3D.Portion.SIXIEME)
49+
assert gm.getNbVolumes()==8
50+
assert gm.getInfos("Vol0007", 3).area==pytest.approx(2/9 * math.pi, abs=1e-7)
51+
52+
# Création du volume Vol0008
53+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, 360)
54+
assert gm.getNbVolumes()==9
55+
assert gm.getInfos("Vol0008", 3).area==pytest.approx(4/3 * math.pi, abs=1e-7)
56+
57+
# Création du volume Vol0009
58+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, 180)
59+
assert gm.getNbVolumes()==10
60+
assert gm.getInfos("Vol0009", 3).area==pytest.approx(2/3 * math.pi, abs=1e-7)
61+
62+
# Création du volume Vol0010
63+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, 90)
64+
assert gm.getNbVolumes()==11
65+
assert gm.getInfos("Vol0010", 3).area==pytest.approx(1/3 * math.pi, abs=1e-7)
66+
67+
# Création du volume Vol0011
68+
ctx.getGeomManager().newSphere (Mgx3D.Point(0, 0, 0), 1, 100)
69+
assert gm.getNbVolumes()==12
70+
assert gm.getInfos("Vol0011", 3).area==pytest.approx((100/360) * (4/3) * math.pi, abs=1e-7)

0 commit comments

Comments
 (0)