Skip to content

Commit

Permalink
Issue#163. Possibility of adding the current selection to the Python …
Browse files Browse the repository at this point in the history
…console instructions via the context menu. Fix: entities displayed in wireframe + isolinear and selected by elastic rectangle are only added once to the selection.
  • Loading branch information
Charles PIGNEROL committed Dec 10, 2024
1 parent fe12849 commit 9cf6e72
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 2 deletions.
159 changes: 157 additions & 2 deletions src/QtComponents/QtMgx3DPythonConsole.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Internal/ContextIfc.h"
#include "Internal/PythonWriter.h"

#include "QtComponents/QtMgx3DPythonConsole.h"
#include "QtComponents/Qt3DGraphicalWidget.h"
Expand Down Expand Up @@ -77,15 +78,45 @@ namespace QtComponents

QtMgx3DPythonConsole::QtMgx3DPythonConsole (QWidget* parent, QtMgx3DMainWindow* mainWindow, const string& title)
: QtPythonConsole (parent, title),
_mgxUserScriptingManager (0), _mainWindow (mainWindow), _graphicalWidget (0), _cmdMgrPolicy ((CommandManagerIfc::POLICY)-1)
_mgxUserScriptingManager (0), _mainWindow (mainWindow), _graphicalWidget (0), _cmdMgrPolicy ((CommandManagerIfc::POLICY)-1),
_insertSelectedVolumesAction (0), _insertSelectedSurfacesAction (0), _insertSelectedCurvesAction (0), _insertSelectedGeomVerticesAction (0),
_insertSelectedBlocksAction (0), _insertSelectedFacesAction (0), _insertSelectedEdgesAction (0), _insertSelectedTopoVerticesAction (0),
_insertSelectedMeshVolumesAction (0), _insertSelectedMeshSurfacesAction (0), _insertSelectedLinesAction (0), _insertSelectedCloudsAction (0)
{
hideResult ("proxy of <Swig Object of type");
_insertSelectedVolumesAction = new QAction (UTF8TOQSTRING (UTF8String ("Volumes Géométriques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedVolumesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::GeomVolume); });
_insertSelectedSurfacesAction = new QAction (UTF8TOQSTRING (UTF8String ("Surfaces Géométriques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedSurfacesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::GeomSurface); });
_insertSelectedCurvesAction = new QAction (UTF8TOQSTRING (UTF8String ("Courbes Géométriques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedCurvesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::GeomCurve); });
_insertSelectedGeomVerticesAction = new QAction (UTF8TOQSTRING (UTF8String ("Sommets Géométriques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedGeomVerticesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::GeomVertex); });
_insertSelectedBlocksAction = new QAction (UTF8TOQSTRING (UTF8String ("Blocs Topologiques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedBlocksAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::TopoBlock); });
_insertSelectedFacesAction = new QAction (UTF8TOQSTRING (UTF8String ("Faces Topologiques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedFacesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::TopoCoFace); });
_insertSelectedEdgesAction = new QAction (UTF8TOQSTRING (UTF8String ("Arêtes Topologiques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedEdgesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::TopoCoEdge); });
_insertSelectedTopoVerticesAction = new QAction (UTF8TOQSTRING (UTF8String ("Sommets Topologiques", Charset::UTF_8)), this);
QObject::connect (_insertSelectedTopoVerticesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::TopoVertex); });
_insertSelectedMeshVolumesAction = new QAction (UTF8TOQSTRING (UTF8String ("Volumes de Mailles", Charset::UTF_8)), this);
QObject::connect (_insertSelectedMeshVolumesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::MeshVolume); });
_insertSelectedMeshSurfacesAction = new QAction (UTF8TOQSTRING (UTF8String ("Surfaces de Mailles", Charset::UTF_8)), this);
QObject::connect (_insertSelectedMeshSurfacesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::MeshSurface); });
_insertSelectedLinesAction = new QAction (UTF8TOQSTRING (UTF8String ("Lignes de Mailles", Charset::UTF_8)), this);
QObject::connect (_insertSelectedLinesAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::MeshLine); });
_insertSelectedCloudsAction = new QAction (UTF8TOQSTRING (UTF8String ("Nuages de Mailles", Charset::UTF_8)), this);
QObject::connect (_insertSelectedCloudsAction, &QAction::triggered, this, [this]( ){ insertSelectionCallback (Utils::Entity::MeshCloud); });
} // QtMgx3DPythonConsole::QtMgx3DPythonConsole


QtMgx3DPythonConsole::QtMgx3DPythonConsole (const QtMgx3DPythonConsole&)
: QtPythonConsole (0, ""),
_mgxUserScriptingManager (0), _mainWindow (0), _graphicalWidget (0), _cmdMgrPolicy ((CommandManagerIfc::POLICY)-1)
_mgxUserScriptingManager (0), _mainWindow (0), _graphicalWidget (0), _cmdMgrPolicy ((CommandManagerIfc::POLICY)-1),
_insertSelectedVolumesAction (0), _insertSelectedSurfacesAction (0), _insertSelectedCurvesAction (0), _insertSelectedGeomVerticesAction (0),
_insertSelectedBlocksAction (0), _insertSelectedFacesAction (0), _insertSelectedEdgesAction (0), _insertSelectedTopoVerticesAction (0),
_insertSelectedMeshVolumesAction (0), _insertSelectedMeshSurfacesAction (0), _insertSelectedLinesAction (0), _insertSelectedCloudsAction (0)
{
assert (0 && "QtMgx3DPythonConsole copy constructor is forbidden.");
} // QtMgx3DPythonConsole::QtMgx3DPythonConsole (const QtMgx3DPythonConsole&)
Expand Down Expand Up @@ -393,6 +424,130 @@ void QtMgx3DPythonConsole::saveConsoleScript (const string filePath, Charset cha
} // QtMgx3DPythonConsole::saveConsoleScript


void QtMgx3DPythonConsole::insertSelectionCallback (Utils::Entity::objectType type)
{
SelectionManagerIfc* sm = 0 == getMainWindow ( ) ? 0 : getMainWindow ( )->getSelectionManager ( );
if (0 != sm)
{
vector<Utils::Entity*> entities = sm->getEntities (type);
const string entitiesNames = Internal::entitiesToPythonList<Entity>(entities);
insertPlainText (entitiesNames.c_str ( ));
} // if (0 != sm)
} // QtMgx3DPythonConsole::insertSelectionCallback


QMenu* QtMgx3DPythonConsole::createPopupMenu ( )
{
QMenu* menu = QtPythonConsole::createPopupMenu ( );
if (0 != menu)
{
menu->addSeparator ( );
QMenu* entry = new QMenu ("Insérer sélection", menu);
menu->addMenu (entry);
entry->addAction (&insertSelectedVolumesAction ( ));
entry->addAction (&insertSelectedSurfacesAction ( ));
entry->addAction (&insertSelectedCurvesAction ( ));
entry->addAction (&insertSelectedGeomVerticesAction ( ));
entry->addSeparator ( );
entry->addAction (&insertSelectedBlocksAction ( ));
entry->addAction (&insertSelectedFacesAction ( ));
entry->addAction (&insertSelectedEdgesAction ( ));
entry->addAction (&insertSelectedTopoVerticesAction ( ));
entry->addSeparator ( );
entry->addAction (&insertSelectedMeshVolumesAction ( ));
entry->addAction (&insertSelectedMeshSurfacesAction ( ));
entry->addAction (&insertSelectedLinesAction ( ));
entry->addAction (&insertSelectedCloudsAction ( ));
} // if (0 != menu)

return menu;
} // QtMgx3DPythonConsole::createPopupMenu


QAction& QtMgx3DPythonConsole::insertSelectedVolumesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedVolumesAction)
return *_insertSelectedVolumesAction;
} // QtMgx3DPythonConsole::insertSelectedVolumesAction


QAction& QtMgx3DPythonConsole::insertSelectedSurfacesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedSurfacesAction)
return *_insertSelectedSurfacesAction;
} // QtMgx3DPythonConsole::insertSelectedSurfacesAction


QAction& QtMgx3DPythonConsole::insertSelectedCurvesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedCurvesAction)
return *_insertSelectedCurvesAction;
} // QtMgx3DPythonConsole::insertSelectedCurvesAction


QAction& QtMgx3DPythonConsole::insertSelectedGeomVerticesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedGeomVerticesAction)
return *_insertSelectedGeomVerticesAction;
} // QtMgx3DPythonConsole::insertSelectedGeomVerticesAction


QAction& QtMgx3DPythonConsole::insertSelectedBlocksAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedBlocksAction)
return *_insertSelectedBlocksAction;
} // QtMgx3DPythonConsole::insertSelectedBlocksAction


QAction& QtMgx3DPythonConsole::insertSelectedFacesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedFacesAction)
return *_insertSelectedFacesAction;
} // QtMgx3DPythonConsole::insertSelectedFacesAction


QAction& QtMgx3DPythonConsole::insertSelectedEdgesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedEdgesAction)
return *_insertSelectedEdgesAction;
} // QtMgx3DPythonConsole::insertSelectedEdgesAction


QAction& QtMgx3DPythonConsole::insertSelectedTopoVerticesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedTopoVerticesAction)
return *_insertSelectedTopoVerticesAction;
} // QtMgx3DPythonConsole::insertSelectedTopoVerticesAction


QAction& QtMgx3DPythonConsole::insertSelectedMeshVolumesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedMeshVolumesAction)
return *_insertSelectedMeshVolumesAction;
} // QtMgx3DPythonConsole::insertSelectedMeshVolumesAction


QAction& QtMgx3DPythonConsole::insertSelectedMeshSurfacesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedMeshSurfacesAction)
return *_insertSelectedMeshSurfacesAction;
} // QtMgx3DPythonConsole::insertSelectedMeshSurfacesAction


QAction& QtMgx3DPythonConsole::insertSelectedLinesAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedLinesAction)
return *_insertSelectedLinesAction;
} // QtMgx3DPythonConsole::insertSelectedLinesAction


QAction& QtMgx3DPythonConsole::insertSelectedCloudsAction ( )
{
CHECK_NULL_PTR_ERROR (_insertSelectedCloudsAction)
return *_insertSelectedCloudsAction;
} // QtMgx3DPythonConsole::insertSelectedCloudsAction


void QtMgx3DPythonConsole::storePolicy ( )
{
if ((0 != getMainWindow ( )) && ((CommandManagerIfc::POLICY)-1 == _cmdMgrPolicy))
Expand Down
35 changes: 35 additions & 0 deletions src/QtComponents/protected/QtComponents/QtMgx3DPythonConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class QtMgx3DMainWindow;
*/
class QtMgx3DPythonConsole : public QtPythonConsole
{
Q_OBJECT

public :

/** Constructeur
Expand Down Expand Up @@ -107,10 +109,38 @@ class QtMgx3DPythonConsole : public QtPythonConsole
* de la console doit être enregistré.
*/
virtual void saveConsoleScript (const std::string filePath, TkUtil::Charset coding, bool environment);


public slots :

/**
* Insère à l'emplacement du curseur la sélection courante correspondant au type transmis en argument.
*/
virtual void insertSelectionCallback (Utils::Entity::objectType type);


protected :

/**
* @return Un menu contextuel.
* @see updateActions
*/
virtual QMenu* createPopupMenu ( );

/** Les actions d'insertion de la sélection courante. */
virtual QAction& insertSelectedVolumesAction ( );
virtual QAction& insertSelectedSurfacesAction ( );
virtual QAction& insertSelectedCurvesAction ( );
virtual QAction& insertSelectedGeomVerticesAction ( );
virtual QAction& insertSelectedBlocksAction ( );
virtual QAction& insertSelectedFacesAction ( );
virtual QAction& insertSelectedEdgesAction ( );
virtual QAction& insertSelectedTopoVerticesAction ( );
virtual QAction& insertSelectedMeshVolumesAction ( );
virtual QAction& insertSelectedMeshSurfacesAction ( );
virtual QAction& insertSelectedLinesAction ( );
virtual QAction& insertSelectedCloudsAction ( );

/**
* Récupère/réaffecte la politique de fonctionnement du gestionnaire de commandes.
*/
Expand Down Expand Up @@ -142,6 +172,11 @@ class QtMgx3DPythonConsole : public QtPythonConsole
* aura fini de fonctionner.
*/
Mgx3D::Utils::CommandManagerIfc::POLICY _cmdMgrPolicy;

/** Les actions d'insertion de la sélection courante. */
QAction *_insertSelectedVolumesAction, *_insertSelectedSurfacesAction, *_insertSelectedCurvesAction, *_insertSelectedGeomVerticesAction,
*_insertSelectedBlocksAction, *_insertSelectedFacesAction, *_insertSelectedEdgesAction, *_insertSelectedTopoVerticesAction,
*_insertSelectedMeshVolumesAction, *_insertSelectedMeshSurfacesAction, *_insertSelectedLinesAction, *_insertSelectedCloudsAction;
}; // class QtMgx3DPythonConsole

} // namespace QtComponents
Expand Down
7 changes: 7 additions & 0 deletions src/Utils/SelectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <assert.h>
#include <float.h>
#include <algorithm>

using namespace TkUtil;
using namespace std;
Expand Down Expand Up @@ -369,6 +370,12 @@ void SelectionManager::addToSelection (const vector<Entity*>& entities, bool und
{
CHECK_NULL_PTR_ERROR (*it)

// On filtre, certaines entités peuvent être présentes 2 fois (acteurs VTK filaire + isofilaire par ex) :
vector<Entity*>::const_iterator itnext = it; itnext++;
vector<Entity*>::const_iterator itfound = find (itnext, entities.end ( ), *it);
if (entities.end ( ) != itfound)
continue; // La dernière occurence sera ajoutée

if (true == isSelected (**it))
{
hasAlreadySelected = true;
Expand Down

0 comments on commit 9cf6e72

Please sign in to comment.