Skip to content

Commit

Permalink
GUI for creating ellipses. PLEASE NOTE: the points (of the circumscri…
Browse files Browse the repository at this point in the history
…bed circle) for creating the circle are reordered (point 1, point 2, point 3 instead of point 3, point 1, point 2) in the panel.
  • Loading branch information
Charles PIGNEROL committed Jul 9, 2024
1 parent eac8cd2 commit 95427d9
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 139 deletions.
106 changes: 62 additions & 44 deletions src/QtComponents/Qt3VerticiesPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Geom/Vertex.h"
#include "Topo/Vertex.h"
#include <QtUtil/QtErrorManagement.h>
#include <QtUtil/QtUnicodeHelper.h>
#include "QtComponents/Qt3VerticiesPanel.h"
#include "QtComponents/QtMgx3DMainWindow.h"

Expand Down Expand Up @@ -42,11 +43,9 @@ namespace QtComponents
// ===========================================================================


Qt3VerticiesPanel::Qt3VerticiesPanel (
QWidget* parent, const string& appTitle, QtMgx3DMainWindow& window,
Mgx3D::Utils::FilterEntity::objectType types, bool extremities)
Qt3VerticiesPanel::Qt3VerticiesPanel (QWidget* parent, const string& appTitle, QtMgx3DMainWindow& window, Mgx3D::Utils::FilterEntity::objectType types, bool extremities)
: QtMgx3DOperationsSubPanel (parent, window),
_mainWindow (&window), _vertex1Panel (0), _vertex2Panel (0), _vertex3Panel (0)
_mainWindow (&window), _vertex1Panel (0), _vertex2Panel (0), _vertex3Panel (0), _vertex1Label (0), _vertex2Label (0), _vertex3Label (0)
{
// setContentsMargins (0, 0, 0, 0);
QGridLayout* layout = new QGridLayout (this);
Expand All @@ -55,50 +54,38 @@ Qt3VerticiesPanel::Qt3VerticiesPanel (
layout->setSpacing (5);

// Les 3 vertex :
QLabel* label;

label = new QLabel (QString::fromUtf8(extremities?"Centre :":"Point 3:"), this);
layout->addWidget (label, 0, 0);
_vertex3Panel = new QtMgx3DEntityPanel (
this, "", true, "", "", &window, SelectionManagerIfc::D0, types);
layout->addWidget (_vertex3Panel, 0, 1);
connect (_vertex3Panel, SIGNAL (entitiesAddedToSelection (QString)), this,
SLOT (pointsAddedToSelectionCallback (QString)));
connect (_vertex3Panel, SIGNAL (entitiesRemovedFromSelection (QString)),
this, SLOT (pointsRemovedFromSelectionCallback (QString)));

label = new QLabel (QString::fromUtf8(extremities?"Départ :":"Point 1:"), this);
layout->addWidget (label, 1, 0);
_vertex1Panel = new QtMgx3DEntityPanel (
this, "", true, "", "", &window, SelectionManagerIfc::D0, types);
layout->addWidget (_vertex1Panel, 1, 1);
connect (_vertex1Panel, SIGNAL (entitiesAddedToSelection (QString)), this,
SLOT (pointsAddedToSelectionCallback (QString)));
connect (_vertex1Panel, SIGNAL (entitiesRemovedFromSelection (QString)),
this, SLOT (pointsRemovedFromSelectionCallback (QString)));

label = new QLabel (QString::fromUtf8(extremities?"Fin :":"Point 2:"), this);
layout->addWidget (label, 2, 0);
_vertex2Panel = new QtMgx3DEntityPanel (
this, "", true, "", "", &window, SelectionManagerIfc::D0, types);
layout->addWidget (_vertex2Panel, 2, 1);
connect (_vertex2Panel, SIGNAL (entitiesAddedToSelection (QString)), this,
SLOT (pointsAddedToSelectionCallback (QString)));
connect (_vertex2Panel, SIGNAL (entitiesRemovedFromSelection (QString)),
this, SLOT (pointsRemovedFromSelectionCallback (QString)));
_vertex1Label = new QLabel (QString::fromUtf8(extremities?"Centre :":"Point 1:"), this);
layout->addWidget (_vertex1Label, 0, 0);
_vertex1Panel = new QtMgx3DEntityPanel (this, "", true, "", "", &window, SelectionManagerIfc::D0, types);
layout->addWidget (_vertex1Panel, 0, 1);
connect (_vertex1Panel, SIGNAL (entitiesAddedToSelection (QString)), this,SLOT (pointsAddedToSelectionCallback (QString)));
connect (_vertex1Panel, SIGNAL (entitiesRemovedFromSelection (QString)), this, SLOT (pointsRemovedFromSelectionCallback (QString)));

_vertex2Label = new QLabel (QString::fromUtf8(extremities?"Départ :":"Point 2:"), this);
layout->addWidget (_vertex2Label, 1, 0);
_vertex2Panel = new QtMgx3DEntityPanel (this, "", true, "", "", &window, SelectionManagerIfc::D0, types);
layout->addWidget (_vertex2Panel, 1, 1);
connect (_vertex2Panel, SIGNAL (entitiesAddedToSelection (QString)), this, SLOT (pointsAddedToSelectionCallback (QString)));
connect (_vertex2Panel, SIGNAL (entitiesRemovedFromSelection (QString)), this, SLOT (pointsRemovedFromSelectionCallback (QString)));

_vertex3Label = new QLabel (QString::fromUtf8(extremities?"Fin :":"Point 3:"), this);
layout->addWidget (_vertex3Label, 2, 0);
_vertex3Panel = new QtMgx3DEntityPanel (this, "", true, "", "", &window, SelectionManagerIfc::D0, types);
layout->addWidget (_vertex3Panel, 2, 1);
connect (_vertex3Panel, SIGNAL (entitiesAddedToSelection (QString)), this, SLOT (pointsAddedToSelectionCallback (QString)));
connect (_vertex3Panel, SIGNAL (entitiesRemovedFromSelection (QString)), this, SLOT (pointsRemovedFromSelectionCallback (QString)));

CHECK_NULL_PTR_ERROR (_vertex1Panel->getNameTextField( ))
CHECK_NULL_PTR_ERROR (_vertex2Panel->getNameTextField( ))
CHECK_NULL_PTR_ERROR (_vertex3Panel->getNameTextField( ))
_vertex3Panel->getNameTextField( )->setLinkedSeizureManagers (0, _vertex1Panel->getNameTextField( ));
_vertex1Panel->getNameTextField( )->setLinkedSeizureManagers (_vertex3Panel->getNameTextField( ), _vertex2Panel->getNameTextField( ));
_vertex2Panel->getNameTextField( )->setLinkedSeizureManagers (_vertex3Panel->getNameTextField( ), 0);
_vertex1Panel->getNameTextField( )->setLinkedSeizureManagers (0, _vertex2Panel->getNameTextField( ));
_vertex2Panel->getNameTextField( )->setLinkedSeizureManagers (_vertex1Panel->getNameTextField( ), _vertex3Panel->getNameTextField( ));
_vertex3Panel->getNameTextField( )->setLinkedSeizureManagers (_vertex2Panel->getNameTextField( ), 0);
} // Qt3VerticiesPanel::Qt3VerticiesPanel


Qt3VerticiesPanel::Qt3VerticiesPanel (const Qt3VerticiesPanel& p)
: QtMgx3DOperationsSubPanel (p),
_mainWindow (0), _vertex1Panel (0), _vertex2Panel (0), _vertex3Panel (0)
: QtMgx3DOperationsSubPanel (p), _mainWindow (0), _vertex1Panel (0), _vertex2Panel (0), _vertex3Panel (0), _vertex1Label (0), _vertex2Label (0), _vertex3Label (0)
{
MGX_FORBIDDEN ("Qt3VerticiesPanel copy constructor is not allowed.");
} // Qt3VerticiesPanel::Qt3VerticiesPanel
Expand Down Expand Up @@ -151,10 +138,8 @@ void Qt3VerticiesPanel::autoUpdate ( )
{
BEGIN_QT_TRY_CATCH_BLOCK

const FilterEntity::objectType types =
_vertex1Panel->getFilteredTypes ( );
vector<string> selectedVertices =
getSelectionManager ( ).getEntitiesNames (types);
const FilterEntity::objectType types = _vertex1Panel->getFilteredTypes ( );
vector<string> selectedVertices = getSelectionManager ( ).getEntitiesNames (types);
if (3 <= selectedVertices.size ( ))
{
_vertex1Panel->setUniqueName (selectedVertices [0]);
Expand Down Expand Up @@ -197,6 +182,39 @@ string Qt3VerticiesPanel::getCenterVertexUniqueName ( ) const
} // Qt3VerticiesPanel::getCenterVertexUniqueName


QtMgx3DEntityPanel& Qt3VerticiesPanel::getStartVertexPanel ( )
{
CHECK_NULL_PTR_ERROR (_vertex1Panel)
return *_vertex1Panel;
} // Qt3VerticiesPanel::getStartVertexPanel


QtMgx3DEntityPanel& Qt3VerticiesPanel::getEndVertexPanel ( )
{
CHECK_NULL_PTR_ERROR (_vertex2Panel)
return *_vertex2Panel;
} // Qt3VerticiesPanel::getEndVertexPanel


QtMgx3DEntityPanel& Qt3VerticiesPanel::getCenterVertexPanel ( )
{
CHECK_NULL_PTR_ERROR (_vertex3Panel)
return *_vertex3Panel;
} // Qt3VerticiesPanel::getCenterVertexPanel


void Qt3VerticiesPanel::setLabels (const UTF8String& start, const UTF8String& end, const UTF8String& center)
{
CHECK_NULL_PTR_ERROR (_vertex1Label)
CHECK_NULL_PTR_ERROR (_vertex2Label)
CHECK_NULL_PTR_ERROR (_vertex3Label)
_vertex1Label->setText (UTF8TOQSTRING (start));
_vertex2Label->setText (UTF8TOQSTRING (end));
_vertex3Label->setText (UTF8TOQSTRING (center));

} // Qt3VerticiesPanel::setLabels


void Qt3VerticiesPanel::getPoints (Math::Point& p1, Math::Point& p2, Math::Point& p3) const
{
p1 = getPoint (getStartVertexUniqueName ( ));
Expand Down
106 changes: 46 additions & 60 deletions src/QtComponents/QtCircleOperationAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ namespace QtComponents
// ===========================================================================

QtCircleOperationPanel::QtCircleOperationPanel (
QWidget* parent, const string& panelName,
QtMgx3DGroupNamePanel::POLICY creationPolicy,
QtMgx3DMainWindow& mainWindow, QtMgx3DOperationAction* action)
: QtMgx3DOperationPanel (parent, mainWindow, action,
QtMgx3DApplication::HelpSystem::instance ( ).circleOperationURL,
QtMgx3DApplication::HelpSystem::instance ( ).circleOperationTag),
QWidget* parent, const string& panelName, QtMgx3DGroupNamePanel::POLICY creationPolicy, QtMgx3DMainWindow& mainWindow, QtMgx3DOperationAction* action)
: QtMgx3DOperationPanel (parent, mainWindow, action, QtMgx3DApplication::HelpSystem::instance ( ).circleOperationURL, QtMgx3DApplication::HelpSystem::instance ( ).circleOperationTag),
_namePanel (0), _operationMethodComboBox (0),
_currentParentWidget (0), _currentPanel (0),
_verticesPanel (0)
Expand All @@ -74,8 +70,7 @@ QtCircleOperationPanel::QtCircleOperationPanel (
layout->addWidget (label);

// Nom groupe :
_namePanel = new QtMgx3DGroupNamePanel (
this, "Groupe", mainWindow, 1, creationPolicy, "");
_namePanel = new QtMgx3DGroupNamePanel (this, "Groupe", mainWindow, 1, creationPolicy, "");
layout->addWidget (_namePanel);
addValidatedField (*_namePanel);

Expand All @@ -85,15 +80,14 @@ QtCircleOperationPanel::QtCircleOperationPanel (
label = new QLabel (QString::fromUtf8("Méthode"), this);
hlayout->addWidget (label);
_operationMethodComboBox = new QComboBox (this);
_operationMethodComboBox->addItem ("Par saisie de 3 points");
connect (_operationMethodComboBox, SIGNAL (currentIndexChanged (int)),
this, SLOT (operationMethodCallback ( )));
_operationMethodComboBox->addItem ("Cercle (saisie de 3 points)");
_operationMethodComboBox->addItem ("Ellipse (saisie de 3 points)");
connect (_operationMethodComboBox, SIGNAL (currentIndexChanged (int)), this, SLOT (operationMethodCallback ( )));
hlayout->addWidget (_operationMethodComboBox);
hlayout->addStretch (10);

// Définition du cercle :
QtGroupBox* groupBox =
new QtGroupBox(QString::fromUtf8("Paramètres du cercle"), this);
QtGroupBox* groupBox = new QtGroupBox (QString::fromUtf8 ("Paramètres du cercle"), this);
QVBoxLayout* vlayout = new QVBoxLayout (groupBox);
vlayout->setContentsMargins (
Resources::instance ( )._margin.getValue ( ),
Expand All @@ -109,35 +103,25 @@ QtCircleOperationPanel::QtCircleOperationPanel (
vlayout->addWidget (_currentParentWidget);
QHBoxLayout* currentLayout = new QHBoxLayout (_currentParentWidget);
_currentParentWidget->setLayout (currentLayout);
_verticesPanel = new Qt3VerticiesPanel (
0, "Définition d'un cercle par 3 points",
mainWindow, FilterEntity::GeomVertex,
false);
connect (_verticesPanel, SIGNAL (pointAddedToSelection (QString)), this,
SLOT (entitiesAddedToSelectionCallback (QString)));
connect (_verticesPanel, SIGNAL (pointRemovedFromSelection (QString)), this,
SLOT (entitiesRemovedFromSelectionCallback (QString)));
_verticesPanel = new Qt3VerticiesPanel (0, "Définition d'un cercle par 3 points", mainWindow, FilterEntity::GeomVertex, false);
connect (_verticesPanel, SIGNAL (pointAddedToSelection (QString)), this, SLOT (entitiesAddedToSelectionCallback (QString)));
connect (_verticesPanel, SIGNAL (pointRemovedFromSelection (QString)), this, SLOT (entitiesRemovedFromSelectionCallback (QString)));
_verticesPanel->hide ( );
operationMethodCallback ( );

vlayout->addStretch (2);
} // QtCircleOperationPanel::QtCircleOperationPanel


QtCircleOperationPanel::QtCircleOperationPanel (
const QtCircleOperationPanel& cao)
: QtMgx3DOperationPanel (
0, *new QtMgx3DMainWindow(0), 0, "", ""),
_namePanel (0), _operationMethodComboBox (0),
_currentParentWidget (0), _currentPanel (0),
_verticesPanel (0)
QtCircleOperationPanel::QtCircleOperationPanel (const QtCircleOperationPanel& cao)
: QtMgx3DOperationPanel (0, *new QtMgx3DMainWindow(0), 0, "", ""),
_namePanel (0), _operationMethodComboBox (0), _currentParentWidget (0), _currentPanel (0), _verticesPanel (0)
{
MGX_FORBIDDEN ("QtCircleOperationPanel copy constructor is not allowed.");
} // QtCircleOperationPanel::QtCircleOperationPanel (const QtCircleOperationPanel&)


QtCircleOperationPanel& QtCircleOperationPanel::operator = (
const QtCircleOperationPanel&)
QtCircleOperationPanel& QtCircleOperationPanel::operator = (const QtCircleOperationPanel&)
{
MGX_FORBIDDEN ("QtCircleOperationPanel assignment operator is not allowed.");
return *this;
Expand All @@ -156,8 +140,7 @@ string QtCircleOperationPanel::getGroupName ( ) const
} // QtCircleOperationPanel::getGroupName


QtCircleOperationPanel::OPERATION_METHOD
QtCircleOperationPanel::getOperationMethod ( ) const
QtCircleOperationPanel::OPERATION_METHOD QtCircleOperationPanel::getOperationMethod ( ) const
{
CHECK_NULL_PTR_ERROR (_operationMethodComboBox);
return (QtCircleOperationPanel::OPERATION_METHOD)_operationMethodComboBox->currentIndex ( );
Expand Down Expand Up @@ -205,11 +188,6 @@ void QtCircleOperationPanel::reset ( )

void QtCircleOperationPanel::validate ( )
{
// CP : suite discussion EBL/FL, il est convenu que la validation des
// paramètres de l'opération est effectuée par le "noyau" et qu'un mauvais
// paramétrage est remonté sous forme d'exception à la fonction appelante, donc
// avant exécution de la commande.
// Les validations des valeurs des paramètres sont donc ici commentées.
TkUtil::UTF8String error (TkUtil::Charset::UTF_8);

try
Expand All @@ -229,20 +207,18 @@ void QtCircleOperationPanel::validate ( )
CHECK_NULL_PTR_ERROR (_operationMethodComboBox)
switch (_operationMethodComboBox->currentIndex ( ))
{
case QtCircleOperationPanel::THREE_POINTS :
case QtCircleOperationPanel::THREE_POINTS :
case QtCircleOperationPanel::ELLIPSE_THREE_POINTS :
break;
case -1 :
if (0 != error.length ( ))
error << "\n";
error << "Absence de méthode d'opération de création/modification "
<< "d'un cercle sélectionnée.";
error << "Absence de méthode d'opération de création/modification d'un cercle sélectionnée.";
break;
default :
if (0 != error.length ( ))
error << "\n";
error << "QtCircleOperationPanel::validate : index de méthode "
<< "d'opération de création/modification d'un cercle "
<< "invalide ("
error << "QtCircleOperationPanel::validate : index de méthode d'opération de création/modification d'un cercle invalide ("
<< (long)_operationMethodComboBox->currentIndex ( ) << ").";
} // switch (_operationMethodComboBox->currentIndex ( ))

Expand Down Expand Up @@ -313,15 +289,25 @@ void QtCircleOperationPanel::operationMethodCallback ( )
}
_currentPanel = 0;

QGroupBox* parent = dynamic_cast<QGroupBox*>(_currentParentWidget->parent ( ));
switch (getOperationMethod ( ))
{
case QtCircleOperationPanel::THREE_POINTS :
_currentPanel = _verticesPanel; break;
_currentPanel = _verticesPanel;
_verticesPanel->setLabels (UTF8String ("Point 1"), UTF8String ("Point 2"), UTF8String ("Point 3"));
if (0 != parent)
parent->setTitle (QString::fromUtf8 ("Paramètres du cercle"));
break;
case QtCircleOperationPanel::ELLIPSE_THREE_POINTS :
_currentPanel = _verticesPanel;
_verticesPanel->setLabels (UTF8String ("Point 1"), UTF8String ("Point 2"), UTF8String ("Centre"));
if (0 != parent)
parent->setTitle (QString::fromUtf8 ("Paramètres de l'ellipse"));
break;
default :
{
TkUtil::UTF8String message (TkUtil::Charset::UTF_8);
message << "Méthode d'opération non supportée ("
<< (unsigned long)getOperationMethod ( ) << ").";
message << "Méthode d'opération non supportée (" << (unsigned long)getOperationMethod ( ) << ").";
INTERNAL_ERROR (exc, message, "QtCircleOperationPanel::operationMethodCallback")
throw exc;
}
Expand All @@ -343,29 +329,22 @@ void QtCircleOperationPanel::operationMethodCallback ( )
// LA CLASSE QtCircleOperationAction
// ===========================================================================

QtCircleOperationAction::QtCircleOperationAction (
const QIcon& icon, const QString& text, QtMgx3DMainWindow& mainWindow,
const QString& tooltip, QtMgx3DGroupNamePanel::POLICY creationPolicy)
QtCircleOperationAction::QtCircleOperationAction (const QIcon& icon, const QString& text, QtMgx3DMainWindow& mainWindow, const QString& tooltip, QtMgx3DGroupNamePanel::POLICY creationPolicy)
: QtMgx3DGeomOperationAction (icon, text, mainWindow, tooltip)
{
QtCircleOperationPanel* operationPanel =
new QtCircleOperationPanel (
&getOperationPanelParent ( ), text.toStdString ( ), creationPolicy,
mainWindow, this);
QtCircleOperationPanel* operationPanel = new QtCircleOperationPanel (&getOperationPanelParent ( ), text.toStdString ( ), creationPolicy, mainWindow, this);
setOperationPanel (operationPanel);
} // QtCircleOperationAction::QtCircleOperationAction


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


QtCircleOperationAction& QtCircleOperationAction::operator = (
const QtCircleOperationAction&)
QtCircleOperationAction& QtCircleOperationAction::operator = (const QtCircleOperationAction&)
{
MGX_FORBIDDEN ("QtCircleOperationAction assignment operator is not allowed.")
return *this;
Expand Down Expand Up @@ -395,6 +374,7 @@ void QtCircleOperationAction::executeOperation ( )
const string name = panel->getGroupName ( );
switch (getCirclePanel ( )->getOperationMethod ( ))
{

case QtCircleOperationPanel::THREE_POINTS :
{
const string vertex1 = getCirclePanel ( )->getVertex1UniqueName ( );
Expand All @@ -403,12 +383,18 @@ void QtCircleOperationAction::executeOperation ( )
cmdResult = getContext ( ).getGeomManager ( ).newCircle (vertex1, vertex2, vertex3, name);
}
break;
case QtCircleOperationPanel::ELLIPSE_THREE_POINTS :
{
const string vertex1 = getCirclePanel ( )->getVertex1UniqueName ( );
const string vertex2 = getCirclePanel ( )->getVertex2UniqueName ( );
const string vertex3 = getCirclePanel ( )->getVertex3UniqueName ( );
cmdResult = getContext ( ).getGeomManager ( ).newEllipse (vertex1, vertex2, vertex3, name);
}
break;
default :
{
TkUtil::UTF8String message (TkUtil::Charset::UTF_8);
message << "Méthode d'opération non supportée ("
<< (unsigned long)getCirclePanel ( )->getOperationMethod ( )
<< ").";
message << "Méthode d'opération non supportée (" << (unsigned long)getCirclePanel ( )->getOperationMethod ( ) << ").";
INTERNAL_ERROR (exc, message, "QtCircleOperationAction::executeOperation")
throw exc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/QtComponents/QtMgx3DMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2754,8 +2754,8 @@ void QtMgx3DMainWindow::showReady ( )
QtMgx3DOperationAction *circleAction =
new QtCircleOperationAction(
QIcon(":/images/geom_create_circle.png"),
QString::fromUtf8("Création d'un cercle"), *this,
QString::fromUtf8("Création d'un cercle."),
QString::fromUtf8("Création d'un cercle/d'une ellipse"), *this,
QString::fromUtf8("Création d'un cercle/d'une ellipse."),
QtMgx3DGroupNamePanel::CREATION
);
registerOperationAction(
Expand Down
Loading

0 comments on commit 95427d9

Please sign in to comment.