Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 170- Creation of a block in bounding box mode of a list of selected entities. #79

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Core/Internal/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,21 @@ std::vector<Utils::Entity*> Context::get (
return entities;
} // ContextIfc::get
/*----------------------------------------------------------------------------*/
std::vector<Utils::Entity*> Context::get (
const std::vector<std::string>& names, bool raises) const
{
std::vector<Utils::Entity*> entities;
for (std::vector<std::string>::const_iterator it = names.begin ( );
names.end ( ) != it; it++)
{
for (std::map<unsigned long, Utils::Entity*>::const_iterator ite = _entities.begin();
ite != _entities.end(); ++ite)
if (*it == (*ite).second->getName())
entities.push_back((*ite).second);
}
return entities;
}
/*----------------------------------------------------------------------------*/
void Context::clearIdToEntity()
{
TkUtil::AutoMutex autoMutex (&_entitiesMutex);
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Internal/ContextIfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ std::vector<Utils::Entity*> ContextIfc::get (
throw TkUtil::Exception ("ContextIfc::get.");
} // ContextIfc::get
/*----------------------------------------------------------------------------*/
std::vector<Utils::Entity*> ContextIfc::get (
const std::vector<std::string>&, bool) const
{
throw TkUtil::Exception ("ContextIfc::get.");
} // ContextIfc::get
/*----------------------------------------------------------------------------*/
Utils::Entity& ContextIfc::uniqueIdToEntity (unsigned long uid) const
{
throw TkUtil::Exception ("ContextIfc::uniqueIdToEntity.");
Expand Down
23 changes: 23 additions & 0 deletions src/Core/Internal/EntitiesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <TkUtil/MemoryError.h>
#include <TkUtil/NumericServices.h>

#include <values.h>
nicolaslg marked this conversation as resolved.
Show resolved Hide resolved


/*----------------------------------------------------------------------------*/
namespace Mgx3D {
Expand Down Expand Up @@ -663,6 +665,27 @@ double EntitiesHelper::angle(const Utils::Entity* cec, const Utils::Entity* ce1,
return angle;
}
/*----------------------------------------------------------------------------*/
bool EntitiesHelper::getBounds (const std::vector<Utils::Entity*>& entities, double bounds [6])
{
bounds [0] = bounds [2] = bounds [4] = DBL_MAX;
bounds [1] = bounds [3] = bounds [5] = -DBL_MAX;
nicolaslg marked this conversation as resolved.
Show resolved Hide resolved
if (true == entities.empty ( ))
return false;

for (std::vector<Utils::Entity*>::const_iterator ite = entities.begin ( ); ite != entities.end ( ); ite++)
{
double entityBounds [6];
(*ite)->getBounds (entityBounds);
for (int i = 0; i < 6; i += 2)
{
bounds [i] = bounds [i] <= entityBounds [i] ? bounds [i] : entityBounds [i];
bounds [i + 1] = bounds [i + 1] >= entityBounds [i + 1] ? bounds [i + 1] : entityBounds [i + 1];
} // for (int i = 0; i < 6; i += 2)
} // for (std::vector<Utils::Entity*>::const_iterator ite = entities.begin ( ); ite != entities.end ( ); ite++)

return true;
}
/*----------------------------------------------------------------------------*/
} // end namespace Internal
/*----------------------------------------------------------------------------*/
} // end namespace Mgx3D
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Topo/CommandCreateTopo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace Topo {
/*----------------------------------------------------------------------------*/
CommandCreateTopo::CommandCreateTopo(Internal::Context& c, std::string name)
: CommandEditTopo (c, name)
, m_blocks ( )
, m_cofaces ( )
, m_bounding_entities ( )
, m_geom_entity(0)
, m_command_create_geom(0)
, m_structured(true)
Expand Down
17 changes: 17 additions & 0 deletions src/Core/Topo/CommandNewTopoOnGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Utils/Common.h"
#include "Internal/ServiceGeomToTopo.h"
#include "Internal/Context.h"
#include "Internal/EntitiesHelper.h"
#include "Group/Group3D.h"
#include "Group/Group2D.h"
/*----------------------------------------------------------------------------*/
Expand Down Expand Up @@ -268,6 +269,22 @@ internalExecute()
bl->getVertex(false, true, true )->setCoord(Utils::Math::Point(pmin.getX(), pmax.getY(), pmax.getZ()));
bl->getVertex(true, true, true )->setCoord(Utils::Math::Point(pmax.getX(), pmax.getY(), pmax.getZ()));
}
else // Pas de geom entity associée : une sélection pour positionner les sommets ?
{
const std::vector<Utils::Entity*>& boundingEntities = getBoundingEntities ( );
double bounds [6] = { 0., 0., 0., 0., 0., 0. };
if (false == Internal::EntitiesHelper::getBounds (boundingEntities, bounds))
throw TkUtil::Exception (TkUtil::UTF8String ("Erreur Interne, CommandNewTopoOnGeometry sans entité pour définir la position des sommets", TkUtil::Charset::UTF_8));

bl->getVertex (false, false, false)->setCoord (Utils::Math::Point (bounds [0], bounds [2], bounds [4]));
bl->getVertex (false, false, true)->setCoord (Utils::Math::Point (bounds [0], bounds [2], bounds [5]));
bl->getVertex (false, true, false)->setCoord (Utils::Math::Point (bounds [0], bounds [3], bounds [4]));
bl->getVertex (false, true, true)->setCoord (Utils::Math::Point (bounds [0], bounds [3], bounds [5]));
bl->getVertex (true, false, false)->setCoord (Utils::Math::Point (bounds [1], bounds [2], bounds [4]));
bl->getVertex (true, false, true)->setCoord (Utils::Math::Point (bounds [1], bounds [2], bounds [5]));
bl->getVertex (true, true, false)->setCoord (Utils::Math::Point (bounds [1], bounds [3], bounds [4]));
bl->getVertex (true, true, true)->setCoord (Utils::Math::Point (bounds [1], bounds [3], bounds [5]));
}
}
// stockage dans le InfoCommand des différentes entités (bloc et niveau inférieur)
split();
Expand Down
23 changes: 23 additions & 0 deletions src/Core/Topo/TopoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,29 @@ TopoManager::newFreeTopoInGroup(std::string ng, int dim)
return cmdResult;
}
/*----------------------------------------------------------------------------*/
Mgx3D::Internal::M3DCommandResultIfc*
TopoManager::newFreeBoundedTopoInGroup(std::string ng, int dim, const std::vector<std::string>& ve)
{
TkUtil::UTF8String message (TkUtil::Charset::UTF_8);
message <<"TopoManager::newFreeBoundedTopoInGroup("<<ng<<")";
log (TkUtil::TraceLog (message, TkUtil::Log::TRACE_4));

Topo::CommandNewTopoOnGeometry* command = new Topo::CommandNewTopoOnGeometry(getLocalContext(), ng, dim);
std::vector<Utils::Entity*> entities = getLocalContext ( ).get (ve, true);
command->setBoundingEntities (entities);

TkUtil::UTF8String cmd (TkUtil::Charset::UTF_8);
cmd << getContextAlias() << "." << "getTopoManager().newFreeBoundedTopoInGroup (\""
<<ng<<"\", "<< (short)dim << ", " << Internal::entitiesToPythonList<Mgx3D::Utils::Entity> (entities) << ")";
command->setScriptCommand(cmd);

getCommandManager().addCommand(command, Utils::Command::DO);

Internal::M3DCommandResultIfc* cmdResult =
new Internal::M3DCommandResult (*command);
return cmdResult;
}
/*----------------------------------------------------------------------------*/
Mgx3D::Internal::M3DCommandResultIfc* TopoManager::
newBoxWithTopo(const Utils::Math::Point& pmin, const Utils::Math::Point& pmax,
bool meshStructured, std::string groupName)
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Topo/TopoManagerIfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ TopoManagerIfc::newFreeTopoInGroup(std::string ne, int dim)
}
/*----------------------------------------------------------------------------*/
Mgx3D::Internal::M3DCommandResultIfc*
TopoManagerIfc::newFreeBoundedTopoInGroup(std::string ng, int dim, const std::vector<std::string>& ve)
{
throw TkUtil::Exception ("TopoManagerIfc::newFreeBoundedTopoInGroup should be overloaded.");
}
/*----------------------------------------------------------------------------*/
Mgx3D::Internal::M3DCommandResultIfc*
TopoManagerIfc::newBoxWithTopo(
const Utils::Math::Point& pmin, const Utils::Math::Point& pmax, bool meshStructured, std::string groupName)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Core/protected/Internal/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ class Context : public ContextIfc {
*/
virtual std::vector<Utils::Entity*> get(const std::vector<unsigned long>& ids, bool raisesIfNotFound) const;

/** \brief Retourne les entités dont les noms sont transmis en argument.
* Une exception est levée si une entité n'est pas dans le contexte
* et si le second argument vaut true.
*/
virtual std::vector<Utils::Entity*> get(const std::vector<std::string>& names, bool raisesIfNotFound) const;

/** Vide la table de correspondance entre un unique id et l'objet
*
Expand Down
6 changes: 6 additions & 0 deletions src/Core/protected/Internal/ContextIfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ class ContextIfc{
* et si le second argument vaut true.
*/
virtual std::vector<Utils::Entity*> get(const std::vector<unsigned long>& ids, bool raisesIfNotFound) const;

/** \brief Retourne les entités dont les noms sont transmis en argument.
* Une exception est levée si une entité n'est pas dans le contexte
* et si le second argument vaut true.
*/
virtual std::vector<Utils::Entity*> get(const std::vector<std::string>& names, bool raisesIfNotFound) const;
#endif

/*------------------------------------------------------------------------*/
Expand Down
4 changes: 4 additions & 0 deletions src/Core/protected/Internal/EntitiesHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class EntitiesHelper

/// recherche le type d'un objet en fonction de son nom
static Utils::Entity::objectType getObjectType(TkUtil::UTF8String& nomObj);

/// retourne la boite englobante d'un ensemble d'entités. Le bouléen retourné vaut false en cas d'échec.
static bool getBounds (const std::vector<Utils::Entity*>& entities, double bounds [6]);


private :

Expand Down
12 changes: 12 additions & 0 deletions src/Core/protected/Topo/CommandCreateTopo.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ class CommandCreateTopo: public CommandEditTopo {
/** \brief retourne l'entité géométrique pour la construction de la topologie
*/
Geom::GeomEntity* getGeomEntity() const {return m_geom_entity;}

/*------------------------------------------------------------------------*/
/** \brief permet de spécifier une boite englobante de positionnement des sommets via une liste d'entités
*/
void setBoundingEntities (const std::vector<Utils::Entity*>& ve) { m_bounding_entities = ve; }

/** \brief permet de connaître les entités définissant la boite englobante de positionnement des sommets
*/
const std::vector<Utils::Entity*> getBoundingEntities ( ) const { return m_bounding_entities; }

/*------------------------------------------------------------------------*/
/** \brief permet de spécifier une commande de construction géométrique
Expand Down Expand Up @@ -118,6 +127,9 @@ class CommandCreateTopo: public CommandEditTopo {

/** resultat de l'opération (on ne stocke que les nouvelles CoFaces) */
std::vector<CoFace* > m_cofaces;

/** Les entités définissant la boite englobante de positionnement des sommets */
std::vector<Utils::Entity*> m_bounding_entities;

/** parametre optionnel de l'opération */
Geom::GeomEntity* m_geom_entity;
Expand Down
13 changes: 13 additions & 0 deletions src/Core/protected/Topo/TopoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ class TopoManager: public Topo::TopoManagerIfc {
virtual Mgx3D::Internal::M3DCommandResultIfc*
newFreeTopoInGroup(std::string ng, int dim);

/** \brief Création d'un block topologique structuré sans association
*
* L'entité topologique est mise dans un groupe et ses sommets aux coins de la boite
* englobante définie par les entités transmises en arguments
*
* \param ng le nom du groupe dans lequel sera mis le bloc ou la face
* \param dim la dimension (2 ou 3) de ce que l'on veut créer
* \param ve est la liste des noms d'entités définissant la boite englobante de positionnement
* des sommets
*/
virtual Mgx3D::Internal::M3DCommandResultIfc*
newFreeBoundedTopoInGroup(std::string ng, int dim, const std::vector<std::string>& ve);

/*------------------------------------------------------------------------*/
/** \brief Création d'une topologie structurée en o-grid
*
Expand Down
14 changes: 14 additions & 0 deletions src/Core/protected/Topo/TopoManagerIfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ class TopoManagerIfc: public Internal::CommandCreator
newFreeTopoInGroup(std::string ng, int dim);
SET_SWIG_COMPLETABLE_METHOD(newFreeTopoInGroup)

/** \brief Création d'un block topologique structuré sans association
*
* L'entité topologique est mise dans un groupe et ses sommets aux coins de la boite
* englobante définie par les entités transmises en arguments
*
* \param ng le nom du groupe dans lequel sera mis le bloc ou la face
* \param dim la dimension (2 ou 3) de ce que l'on veut créer
* \param ve est la liste des noms d'entités définissant la boite englobante de positionnement
* des sommets
*/
virtual Mgx3D::Internal::M3DCommandResultIfc*
newFreeBoundedTopoInGroup(std::string ng, int dim, const std::vector<std::string>& ve);
SET_SWIG_COMPLETABLE_METHOD(newFreeBoundedTopoInGroup)

/*------------------------------------------------------------------------*/
/** \brief Création d'une boite parallèle aux axes Ox,Oy et Oz à partir des
* points pmin et pmax où pmin est le point de plus petites
Expand Down
43 changes: 19 additions & 24 deletions src/QtComponents/QtTopologyBlockCreationAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ namespace QtComponents
// LA CLASSE QtTopologyBlockCreationPanel
// ===========================================================================

QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (
QWidget* parent, const string& panelName,
QtMgx3DMainWindow& mainWindow, QtMgx3DOperationAction* action)
QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (QWidget* parent, const string& panelName, QtMgx3DMainWindow& mainWindow, QtMgx3DOperationAction* action)
: QtTopologyCreationPanel (
parent, panelName, mainWindow, action, SelectionManagerIfc::D3,
QtTopologyPanel::STRUCTURED_TOPOLOGY,
Expand All @@ -51,8 +49,7 @@ QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (
} // QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel


QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (
const QtTopologyBlockCreationPanel& cao)
QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (const QtTopologyBlockCreationPanel& cao)
: QtTopologyCreationPanel (
0, "Invalid panel", *new QtMgx3DMainWindow(0),
0, SelectionManagerIfc::D0,
Expand All @@ -65,8 +62,7 @@ QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (
} // QtTopologyBlockCreationPanel::QtTopologyBlockCreationPanel (const QtTopologyBlockCreationPanel&)


QtTopologyBlockCreationPanel& QtTopologyBlockCreationPanel::operator = (
const QtTopologyBlockCreationPanel&)
QtTopologyBlockCreationPanel& QtTopologyBlockCreationPanel::operator = (const QtTopologyBlockCreationPanel&)
{
MGX_FORBIDDEN ("QtTopologyBlockCreationPanel assignment operator is not allowed.");
return *this;
Expand Down Expand Up @@ -94,30 +90,22 @@ void QtTopologyBlockCreationPanel::autoUpdate ( )
// LA CLASSE QtTopologyBlockCreationAction
// ===========================================================================

QtTopologyBlockCreationAction::QtTopologyBlockCreationAction (
const QIcon& icon, const QString& text,
QtMgx3DMainWindow& mainWindow, const QString& tooltip)
QtTopologyBlockCreationAction::QtTopologyBlockCreationAction (const QIcon& icon, const QString& text, QtMgx3DMainWindow& mainWindow, const QString& tooltip)
: QtTopologyCreationAction (icon, text, mainWindow, tooltip)
{
QtTopologyCreationPanel* operationPanel =
new QtTopologyBlockCreationPanel (
&getOperationPanelParent ( ), text.toStdString ( ),
mainWindow, this);
QtTopologyCreationPanel* operationPanel = new QtTopologyBlockCreationPanel (&getOperationPanelParent ( ), text.toStdString ( ), mainWindow, this);
setOperationPanel (operationPanel);
} // QtTopologyBlockCreationAction::QtTopologyBlockCreationAction


QtTopologyBlockCreationAction::QtTopologyBlockCreationAction (
const QtTopologyBlockCreationAction&)
: QtTopologyCreationAction (
QIcon (""), "", *new QtMgx3DMainWindow (0), "")
QtTopologyBlockCreationAction::QtTopologyBlockCreationAction (const QtTopologyBlockCreationAction&)
: QtTopologyCreationAction (QIcon (""), "", *new QtMgx3DMainWindow (0), "")
{
MGX_FORBIDDEN ("QtTopologyBlockCreationAction copy constructor is not allowed.")
} // QtTopologyBlockCreationAction::QtTopologyBlockCreationAction


QtTopologyBlockCreationAction& QtTopologyBlockCreationAction::operator = (
const QtTopologyBlockCreationAction&)
QtTopologyBlockCreationAction& QtTopologyBlockCreationAction::operator = (const QtTopologyBlockCreationAction&)
{
MGX_FORBIDDEN ("QtTopologyBlockCreationAction assignment operator is not allowed.")
return *this;
Expand All @@ -139,9 +127,10 @@ void QtTopologyBlockCreationAction::executeOperation ( )
QtTopologyCreationAction::executeOperation ( );

// Récupération des paramètres d'association des entités topologiques :
string name = panel->getGeomEntityName ( );
string groupName = panel->getGroupName ( );
QtTopologyPanel::TOPOLOGY_TYPE type = panel->getTopologyType ( );
string name = panel->getGeomEntityName ( );
string groupName = panel->getGroupName ( );
QtTopologyPanel::TOPOLOGY_TYPE type = panel->getTopologyType ( );
bool verticesOnSelection = panel->placeVerticesOnSelectionBounds ( );

switch (type)
{
Expand All @@ -165,7 +154,13 @@ void QtTopologyBlockCreationAction::executeOperation ( )
if (0 != QMessageBox::warning (0, "Magix 3D", UTF8TOQSTRING (warning), "Oui", "Non", "", 0, 2))
return;
} // if (0 == groupName.length ( ))
cmdResult = getContext ( ).getTopoManager( ).newFreeTopoInGroup (groupName, 3);
if (false == verticesOnSelection)
cmdResult = getContext ( ).getTopoManager( ).newFreeTopoInGroup (groupName, 3);
else
{
vector<string> names = panel->getBoundingEntities ( );
cmdResult = getContext ( ).getTopoManager( ).newFreeBoundedTopoInGroup (groupName, 3, names);
} // else if (false == verticesOnSelection)
}
break;
case QtTopologyPanel::OGRID_BLOCKS :
Expand Down
Loading