rnc: cleaned the code up

This commit is contained in:
gdd 2011-10-27 09:37:01 +00:00
parent 859f480fc1
commit 8873ba0d36
4 changed files with 183 additions and 294 deletions

View File

@ -179,7 +179,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi
aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
} }
aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog // aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog
QPoint start = QPoint(pe->x(),pe->y()); QPoint start = QPoint(pe->x(),pe->y());
aCornerDlg->setStartPnt( start ); aCornerDlg->setStartPnt( start );

View File

@ -86,27 +86,14 @@ enum {
RADIO_BUTTONS, RADIO_BUTTONS,
MSG, MSG,
PUSH_BUTTON, PUSH_BUTTON,
X_COORD,
Y_COORD,
Z_COORD
}; };
// View // // // View
enum { // // enum {
XY, // // XY,
YZ, // // YZ,
XZ // // XZ
}; // // };
enum {
LABEL1,
SPINBOX11,
// SPINBOX12,
LABEL2,
SPINBOX21,
// SPINBOX22,
NB_COLS
};
//================================================================================= //=================================================================================
@ -135,17 +122,17 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton3->close(); mainFrame()->RadioButton3->close();
myViewGroup = new DlgRef_3Radio(centralWidget()); // myViewGroup = new DlgRef_3Radio(centralWidget());
myViewGroup->GroupBox1->setTitle(tr("GEOM_VIEW")); // myViewGroup->GroupBox1->setTitle(tr("GEOM_VIEW"));
myViewGroup->RadioButton1->setText(tr( "GEOM_TOP" )); // myViewGroup->RadioButton1->setText(tr( "GEOM_TOP" ));
myViewGroup->RadioButton2->setText(tr( "GEOM_FRONT")); // myViewGroup->RadioButton2->setText(tr( "GEOM_FRONT"));
myViewGroup->RadioButton3->setText(tr( "GEOM_LEFT" )); // myViewGroup->RadioButton3->setText(tr( "GEOM_LEFT" ));
myViewButtonGroup = new QButtonGroup( this ); // myViewButtonGroup = new QButtonGroup( this );
myViewButtonGroup->addButton( myViewGroup->RadioButton1, XY ); // Top view // myViewButtonGroup->addButton( myViewGroup->RadioButton1, XY ); // Top view
myViewButtonGroup->addButton( myViewGroup->RadioButton2, YZ ); // Front View // myViewButtonGroup->addButton( myViewGroup->RadioButton2, YZ ); // Front View
myViewButtonGroup->addButton( myViewGroup->RadioButton3, XZ ); // Left View // myViewButtonGroup->addButton( myViewGroup->RadioButton3, XZ ); // Left View
//
myViewGroup->hide(); // myViewGroup->hide();
mySelectionGroup = new QGroupBox(tr("GEOM_DETECT"), centralWidget()); mySelectionGroup = new QGroupBox(tr("GEOM_DETECT"), centralWidget());
QGridLayout* mySelectGrpLayout = new QGridLayout(mySelectionGroup); QGridLayout* mySelectGrpLayout = new QGridLayout(mySelectionGroup);
@ -169,71 +156,11 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
myOutputGroup->RadioButton1->setText(tr( "GEOM_SPLINE")); myOutputGroup->RadioButton1->setText(tr( "GEOM_SPLINE"));
myOutputGroup->RadioButton3->hide(); myOutputGroup->RadioButton3->hide();
myOutputGroup->hide(); //caché pour la demo // myOutputGroup->hide(); //caché pour la demo
// NOTE what follows is mostly unuseful but is kept until end of development as code examples
myCoordGrp1 = new QGroupBox(tr("GEOM_SCALING"), centralWidget());
QGridLayout* myCoordGrpLayout = new QGridLayout(myCoordGrp1);
std::string msg = "Please point the top left and the top right corners \non the backgound image \n";
// in order to determine \n the right scale to use to display the result \n" ;
QLabel* msgLabel = new QLabel(tr(msg.c_str()), myCoordGrp1);
// msgLabel->setAlignment(Qt::AlignHCenter);
myCoordGrpLayout->addWidget(msgLabel
, MSG, 0, 1, NB_COLS);
myPushButton1 = new QPushButton(myCoordGrp1);
myCoordGrpLayout->addWidget(myPushButton1, PUSH_BUTTON, 0);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_PNT1"), myCoordGrp1), PUSH_BUTTON, 1);
myPushButton2 = new QPushButton(myCoordGrp1);
myCoordGrpLayout->addWidget(myPushButton2, PUSH_BUTTON, 2);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_PNT2"), myCoordGrp1), PUSH_BUTTON, 3);
myPushButton1->setIcon(image1);
myPushButton2->setIcon(image1);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp1), X_COORD, 0);
myX = new QLineEdit(myCoordGrp1);
myCoordGrpLayout->addWidget(myX, X_COORD, 1, 1, 1);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp1), Y_COORD, 0);
myY = new QLineEdit(myCoordGrp1);
myCoordGrpLayout->addWidget(myY, Y_COORD, 1, 1, 1);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp1), Z_COORD, 0);
myZ = new QLineEdit(myCoordGrp1);
myCoordGrpLayout->addWidget(myZ, Z_COORD, 1, 1, 1);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_X"), myCoordGrp1), X_COORD, 2);
myX2 = new QLineEdit(myCoordGrp1);
myCoordGrpLayout->addWidget(myX2, X_COORD, 3, 1, 1);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Y"), myCoordGrp1), Y_COORD, 2);
myY2 = new QLineEdit(myCoordGrp1);
myCoordGrpLayout->addWidget(myY2, Y_COORD, 3, 1, 1);
// myCoordGrpLayout->addWidget(new QLabel(tr("GEOM_Z"), myCoordGrp1), Z_COORD, 2);
myZ2 = new QLineEdit(myCoordGrp1);
myCoordGrpLayout->addWidget(myZ2, Z_COORD, 3, 1, 1);
myX->hide();
myY->hide();
myZ->hide();
myX2->hide();
myY2->hide();
myZ2->hide();
myPushButton1->hide();
myPushButton2->hide();
msgLabel->hide();
myCoordGrp1->hide();
myCoordGrpLayout->setColumnStretch(SPINBOX11,1);
myCoordGrpLayout->setColumnStretch(SPINBOX21,1);
QVBoxLayout* layout = new QVBoxLayout(centralWidget()); QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6); layout->setMargin(0); layout->setSpacing(6);
layout->addWidget( myCoordGrp1); // layout->addWidget( myViewGroup);
layout->addWidget( myViewGroup);
layout->addWidget( mySelectionGroup); layout->addWidget( mySelectionGroup);
layout->addWidget( myOutputGroup); layout->addWidget( myOutputGroup);
@ -266,34 +193,12 @@ void EntityGUI_FeatureDetectorDlg::Init()
connect( myPushButton, SIGNAL( toggled( bool ) ), this, SLOT( onButtonToggled( bool ) ) ); connect( myPushButton, SIGNAL( toggled( bool ) ), this, SLOT( onButtonToggled( bool ) ) );
connect( mySelButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect( mySelButton, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( myPushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( myPushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( onViewClicked( int ) ) ); // connect( myViewButtonGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( onViewClicked( int ) ) );
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) ); connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),this, SLOT( SelectionIntoArgument() ) );
// /* Get setting of step value from file configuration */
// SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
// double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
//
// /* min, max, step and decimals for spin boxes */
// initSpinBox(myX, COORD_MIN, COORD_MAX, step, "length_precision");
// initSpinBox(myY, COORD_MIN, COORD_MAX, step, "length_precision");
// initSpinBox(myZ, COORD_MIN, COORD_MAX, step, "length_precision");
// myX->setValue(0.0);
// myY->setValue(0.0);
// myZ->setValue(0.0);
// initSpinBox(myX2, COORD_MIN, COORD_MAX, step, "length_precision");
// initSpinBox(myY2, COORD_MIN, COORD_MAX, step, "length_precision");
// initSpinBox(myZ2, COORD_MIN, COORD_MAX, step, "length_precision");
// myX2->setValue(0.0);
// myY2->setValue(0.0);
// myZ2->setValue(0.0);
myConstructorId = 0; myConstructorId = 0;
myPushButton1->setDown(true);
mySelButton->click(); mySelButton->click();
mySelButton->setDown(true); mySelButton->setDown(true);
@ -301,14 +206,10 @@ void EntityGUI_FeatureDetectorDlg::Init()
// SetEditCurrentArgument(); // SetEditCurrentArgument();
SelectionIntoArgument(); SelectionIntoArgument();
myX2->setEnabled(false);
myY2->setEnabled(false);
myZ2->setEnabled(false);
initName(tr("GEOM_CONTOURS")); initName(tr("GEOM_CONTOURS"));
resize(100,100); resize(100,100);
myViewGroup->RadioButton1->setChecked(true); // myViewGroup->RadioButton1->setChecked(true);
myOutputGroup->RadioButton1->setChecked(true); myOutputGroup->RadioButton1->setChecked(true);
gp_Pnt aOrigin = gp_Pnt(0, 0, 0); gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
@ -383,42 +284,42 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
} }
//================================================================================= // //=================================================================================
// function : OnPointSelected // // function : OnPointSelected
// purpose : // // purpose :
//================================================================================= // //=================================================================================
void EntityGUI_FeatureDetectorDlg::OnPointSelected(const gp_Pnt& thePnt) // void EntityGUI_FeatureDetectorDlg::OnPointSelected(const gp_Pnt& thePnt)
{ // {
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); // SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6); // int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
if (myPushButton1->isDown()) // if (myPushButton1->isDown())
{ // {
// myX->setValue(thePnt.X()); // // myX->setValue(thePnt.X());
// myY->setValue(thePnt.Y()); // // myY->setValue(thePnt.Y());
// myZ->setValue(thePnt.Z()); // // myZ->setValue(thePnt.Z());
myX->setText(DlgRef::PrintDoubleValue(thePnt.X(), aPrecision)); // myX->setText(DlgRef::PrintDoubleValue(thePnt.X(), aPrecision));
myY->setText(DlgRef::PrintDoubleValue(thePnt.Y(), aPrecision)); // myY->setText(DlgRef::PrintDoubleValue(thePnt.Y(), aPrecision));
myZ->setText(DlgRef::PrintDoubleValue(thePnt.Z(), aPrecision)); // myZ->setText(DlgRef::PrintDoubleValue(thePnt.Z(), aPrecision));
x1 = thePnt.X(); // x1 = thePnt.X();
y1 = thePnt.Y(); // y1 = thePnt.Y();
z1 = thePnt.Z(); // z1 = thePnt.Z();
//
myPushButton2->click(); // myPushButton2->click();
} // }
else // else
{ // {
// myX2->setValue(thePnt.X()); // // myX2->setValue(thePnt.X());
// myY2->setValue(thePnt.Y()); // // myY2->setValue(thePnt.Y());
// myZ2->setValue(thePnt.Z()); // // myZ2->setValue(thePnt.Z());
myX2->setText(DlgRef::PrintDoubleValue(thePnt.X(), aPrecision)); // myX2->setText(DlgRef::PrintDoubleValue(thePnt.X(), aPrecision));
myY2->setText(DlgRef::PrintDoubleValue(thePnt.Y(), aPrecision)); // myY2->setText(DlgRef::PrintDoubleValue(thePnt.Y(), aPrecision));
myZ2->setText(DlgRef::PrintDoubleValue(thePnt.Z(), aPrecision)); // myZ2->setText(DlgRef::PrintDoubleValue(thePnt.Z(), aPrecision));
x2 = thePnt.X(); // x2 = thePnt.X();
y2 = thePnt.Y(); // y2 = thePnt.Y();
z2 = thePnt.Z(); // z2 = thePnt.Z();
//
} // }
} // }
//================================================================================= //=================================================================================
// function : acceptMouseEvent() // function : acceptMouseEvent()
@ -450,7 +351,7 @@ bool EntityGUI_FeatureDetectorDlg::ClickOnApply()
return false; return false;
// initName(); // initName();
// ConstructorsClicked(getConstructorId()); ConstructorsClicked(getConstructorId());
return true; return true;
} }
@ -480,37 +381,37 @@ void EntityGUI_FeatureDetectorDlg::ConstructorsClicked(int id)
} }
} }
//================================================================================= // //=================================================================================
// function : onViewClicked() // // function : onViewClicked()
// purpose : // // purpose :
//================================================================================= // //=================================================================================
void EntityGUI_FeatureDetectorDlg::onViewClicked(int id) // void EntityGUI_FeatureDetectorDlg::onViewClicked(int id)
{ // {
gp_Pnt aOrigin = gp_Pnt(0, 0, 0); // gp_Pnt aOrigin = gp_Pnt(0, 0, 0);
gp_Dir aDirZ; // gp_Dir aDirZ;
gp_Dir aDirX; // gp_Dir aDirX;
//
switch(id) // switch(id)
{ // {
case XY: // case XY:
aDirZ = gp_Dir(0, 0, 1); // aDirZ = gp_Dir(0, 0, 1);
aDirX = gp_Dir(1, 0, 0); // aDirX = gp_Dir(1, 0, 0);
break; // break;
case YZ: // case YZ:
aDirZ = gp_Dir(1, 0, 0); // aDirZ = gp_Dir(1, 0, 0);
aDirX = gp_Dir(0, 1, 0); // aDirX = gp_Dir(0, 1, 0);
break; // break;
case XZ: // case XZ:
aDirZ = gp_Dir(0, -1, 0); // aDirZ = gp_Dir(0, -1, 0);
aDirX = gp_Dir(1, 0 , 0); // aDirX = gp_Dir(1, 0 , 0);
break; // break;
} // }
//
myWPlane = gp_Ax3(aOrigin, aDirZ, aDirX); // myWPlane = gp_Ax3(aOrigin, aDirZ, aDirX);
myGeomGUI->SetWorkingPlane( myWPlane ); // myGeomGUI->SetWorkingPlane( myWPlane );
myGeomGUI->ActiveWorkingPlane(); // myGeomGUI->ActiveWorkingPlane();
//
} // }
//================================================================================= //=================================================================================
// function : onButtonToggled() // function : onButtonToggled()
@ -522,6 +423,11 @@ void EntityGUI_FeatureDetectorDlg::onButtonToggled( bool checked)
{ {
myStartPnt = QPoint(0,0); myStartPnt = QPoint(0,0);
myEndPnt = myStartPnt; myEndPnt = myStartPnt;
myLineEdit->setEnabled(true);
}
else
{
myLineEdit->setEnabled(false);
} }
} }
@ -563,7 +469,6 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
bool res = false; bool res = false;
SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow();
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
// QString theImgFileName = vp->backgroundImageFilename();
MESSAGE("myFaceEntry = "<< myFaceEntry.toStdString()); MESSAGE("myFaceEntry = "<< myFaceEntry.toStdString());
std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit; std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
@ -711,6 +616,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
MESSAGE("hierarchy.size() =" << hierarchy.size()) MESSAGE("hierarchy.size() =" << hierarchy.size())
for( ; idx >= 0; idx = hierarchy[idx][0]) for( ; idx >= 0; idx = hierarchy[idx][0])
{ {
// for(int count=0, child=idx; child>=0, count<1; child=hierarchy[idx][2], count++)
// {
// contour = contours[child];
contour = contours[idx]; contour = contours[idx];
std::vector< cv::Point >::iterator it; std::vector< cv::Point >::iterator it;
std::vector< cv::Point >::iterator it_previous; std::vector< cv::Point >::iterator it_previous;
@ -746,7 +654,7 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
(it->y - it_previous->y) * (it_next->y - it->y); (it->y - it_previous->y) * (it_next->y - it->y);
if (u_v_scalar_product < 0) if (u_v_scalar_product < 0)
{ {
double u_v_cross_product = (it->x - it_previous->x) * (it_next->y - it->y) - double u_v_det = (it->x - it_previous->x) * (it_next->y - it->y) -
(it->y - it_previous->y) * (it_next->x - it->x); (it->y - it_previous->y) * (it_next->x - it->x);
double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) + double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) +
@ -755,7 +663,7 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) + double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) +
(it->y - it_next->y)*(it->y - it_next->y) ); (it->y - it_next->y)*(it->y - it_next->y) );
double u_v_sinus = u_v_cross_product / (norme_u * norme_v); double u_v_sinus = u_v_det / (norme_u * norme_v);
if (u_v_sinus < Precision::Confusion()) if (u_v_sinus < Precision::Confusion())
{ {
@ -794,6 +702,7 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
geomContours[contourCount] = aWire; geomContours[contourCount] = aWire;
contourCount++; contourCount++;
} }
// }
} }
GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours); GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours);
if ( !aContoursCompound->_is_nil() ) if ( !aContoursCompound->_is_nil() )

View File

@ -46,9 +46,10 @@ public:
~EntityGUI_FeatureDetectorDlg(); ~EntityGUI_FeatureDetectorDlg();
bool acceptMouseEvent() const; bool acceptMouseEvent() const;
void OnPointSelected( const gp_Pnt& ); // void OnPointSelected( const gp_Pnt& );
void setStartPnt ( const QPoint& ); void setStartPnt ( const QPoint& );
void setEndPnt ( const QPoint& ); void setEndPnt ( const QPoint& );
int getConstructorId() {return myConstructorId;};
protected: protected:
// redefined from GEOMBase_Helper // redefined from GEOMBase_Helper
@ -57,13 +58,13 @@ protected:
private: private:
void Init(); void Init();
// void createCorners();
private slots: private slots:
void SetEditCurrentArgument(); void SetEditCurrentArgument();
void SelectionIntoArgument(); void SelectionIntoArgument();
void ConstructorsClicked( int ); void ConstructorsClicked( int );
void onViewClicked( int ); // void onViewClicked( int );
void onButtonToggled( bool ); void onButtonToggled( bool );
void ClickOnOk(); void ClickOnOk();
bool ClickOnApply(); bool ClickOnApply();
@ -75,29 +76,12 @@ private:
int myConstructorId; int myConstructorId;
QGroupBox* myCoordGrp1;
QGroupBox* mySelectionGroup; QGroupBox* mySelectionGroup;
QLabel* mySnapshotLabel; QLabel* mySnapshotLabel;
DlgRef_1Sel* mySelWidget; DlgRef_1Sel* mySelWidget;
QLineEdit* myX;
QLineEdit* myY;
QLineEdit* myZ;
double x1;
double y1;
double z1;
QLineEdit* myX2;
QLineEdit* myY2;
QLineEdit* myZ2;
double x2;
double y2;
double z2;
QPoint myStartPnt; QPoint myStartPnt;
QPoint myEndPnt; QPoint myEndPnt;
@ -109,11 +93,8 @@ private:
QLineEdit* myLineEdit; QLineEdit* myLineEdit;
QPushButton* myPushButton1; // DlgRef_3Radio* myViewGroup;
QPushButton* myPushButton2;
DlgRef_3Radio* myViewGroup;
DlgRef_3Radio* myOutputGroup; DlgRef_3Radio* myOutputGroup;
QButtonGroup* myViewButtonGroup; // QButtonGroup* myViewButtonGroup;
}; };

View File

@ -42,7 +42,6 @@
#include <OCCViewer_FeatureDetector.h> #include <OCCViewer_FeatureDetector.h>
#include <QFileDialog> #include <QFileDialog>
//================================================================================= //=================================================================================