From: akl Date: Fri, 20 Sep 2013 12:03:35 +0000 (+0000) Subject: Modify creation of curves: 1) using QDockWidget instead of QDialog; 2) selection... X-Git-Tag: BR_hydro_v_0_1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4a99ec52027edde83198254124518852a89bc9f4;p=modules%2Fgeom.git Modify creation of curves: 1) using QDockWidget instead of QDialog; 2) selection of new point coordinates by click in viewer. --- diff --git a/src/BasicGUI/BasicGUI.cxx b/src/BasicGUI/BasicGUI.cxx index e40b013bf..6de1396f3 100644 --- a/src/BasicGUI/BasicGUI.cxx +++ b/src/BasicGUI/BasicGUI.cxx @@ -38,6 +38,7 @@ #include #include "GeometryGUI_Operations.h" +#include #include #include @@ -155,7 +156,7 @@ bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin } else { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog @@ -165,32 +166,6 @@ bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin } -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) -{ - V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; - aView->Eye( XEye, YEye, ZEye ); - - aView->At( XAt, YAt, ZAt ); - gp_Pnt EyePoint( XEye, YEye, ZEye ); - gp_Pnt AtPoint( XAt, YAt, ZAt ); - - gp_Vec EyeVector( EyePoint, AtPoint ); - gp_Dir EyeDir( EyeVector ); - - gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); - Standard_Real X, Y, Z; - aView->Convert( x, y, X, Y, Z ); - gp_Pnt ConvertedPoint( X, Y, Z ); - - gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); - gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); - return ResultPoint; -} - //===================================================================================== // EXPORTED METHODS //===================================================================================== diff --git a/src/BasicGUI/BasicGUI.h b/src/BasicGUI/BasicGUI.h index aa4efc994..dd120db2a 100644 --- a/src/BasicGUI/BasicGUI.h +++ b/src/BasicGUI/BasicGUI.h @@ -28,7 +28,6 @@ #define BASICGUI_H #include -#include //================================================================================= // class : BasicGUI @@ -42,8 +41,6 @@ public: bool OnGUIEvent( int, SUIT_Desktop* ); bool OnMousePress( QMouseEvent*, SUIT_Desktop*, SUIT_ViewWindow* ); - - gp_Pnt ConvertClickToPoint( int, int, Handle(V3d_View) ); }; #endif // BASICGUI_H diff --git a/src/BasicGUI/Makefile.am b/src/BasicGUI/Makefile.am index 1d680c9e2..c76757d18 100644 --- a/src/BasicGUI/Makefile.am +++ b/src/BasicGUI/Makefile.am @@ -101,6 +101,7 @@ libBasicGUI_la_CPPFLAGS = \ -I$(srcdir)/../GEOMBase \ -I$(srcdir)/../GEOMImpl \ -I$(srcdir)/../GEOMClient \ + -I$(srcdir)/../GEOMUtils \ -I$(top_builddir)/src/DlgRef \ -I$(top_builddir)/idl @@ -109,6 +110,7 @@ libBasicGUI_la_LDFLAGS = \ ../GEOMFiltersSelection/libGEOMFiltersSelection.la \ ../GEOMBase/libGEOMBase.la \ ../GEOMGUI/libGEOM.la \ + ../GEOMUtils/libGEOMUtils.la \ $(CAS_LDFLAGS) -lTKGeomBase \ $(GUI_LDFLAGS) -lsuit \ - $(OPENCV_LIBS) + $(OPENCV_LIBS) diff --git a/src/CurveCreator/CurveCreator_NewPointDlg.cxx b/src/CurveCreator/CurveCreator_NewPointDlg.cxx index af4bfd724..5af871285 100755 --- a/src/CurveCreator/CurveCreator_NewPointDlg.cxx +++ b/src/CurveCreator/CurveCreator_NewPointDlg.cxx @@ -11,45 +11,52 @@ #include CurveCreator_NewPointDlg::CurveCreator_NewPointDlg(CurveCreator::Dimension theDim, QWidget *parent) : - QDialog(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false), myDim(theDim) + QWidget(parent), myX(NULL), myY(NULL), myZ(NULL), myIsEdit(false), myDim(theDim) { - QGridLayout* aCoordLay = new QGridLayout(); - QString aTitle = QString(tr("ADD_NEW_POINT")); setWindowTitle(aTitle); + QFrame* aFrame = new QFrame( this ); + QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + + QFrame* aCoordFrame = new QFrame( aFrame ); + QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame ); + QLabel* aLbl = new QLabel( tr("X_COORD"), this); myX = new QDoubleSpinBox(this); - aCoordLay->addWidget(aLbl, 0, 0); - aCoordLay->addWidget(myX, 0, 1 ); + aCoordLayout->addWidget(aLbl, 0, 0); + aCoordLayout->addWidget(myX, 0, 1 ); aLbl = new QLabel( tr("Y_COORD"), this); myY = new QDoubleSpinBox(this); - aCoordLay->addWidget(aLbl, 1, 0 ); - aCoordLay->addWidget(myY, 1, 1 ); + aCoordLayout->addWidget(aLbl, 1, 0 ); + aCoordLayout->addWidget(myY, 1, 1 ); myZLabel = new QLabel( tr("Z_COORD"), this); myZ = new QDoubleSpinBox(this); - aCoordLay->addWidget(myZLabel, 2,0 ); - aCoordLay->addWidget(myZ, 2,1 ); + aCoordLayout->addWidget(myZLabel, 2,0 ); + aCoordLayout->addWidget(myZ, 2,1 ); if( theDim != CurveCreator::Dim3d ){ myZ->hide(); myZLabel->hide(); } - myBtnBox = new QDialogButtonBox(this); - myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole ); - myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole ); - myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole ); - - connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept())); - connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject())); - connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) )); - QVBoxLayout* aMainLay = new QVBoxLayout(); - aMainLay->addLayout(aCoordLay); - aMainLay->addWidget(myBtnBox); - setLayout(aMainLay); + myBtnFrame = new QFrame( aFrame ); + QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); + + myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame ); + myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame ); + + connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelPoint() ) ); + + aBtnsLayout->addWidget( myAddBtn ); + aBtnsLayout->addStretch( 1 ); + aBtnsLayout->addWidget( myCancelBtn ); + + aLayout->addWidget( aCoordFrame, 0 ); + aLayout->addWidget( myBtnFrame, 1 ); + clear(); updateTitle(); } @@ -64,12 +71,14 @@ void CurveCreator_NewPointDlg::setEditMode( bool isEdit ) { myIsEdit = isEdit; if( myIsEdit ){ - myContBtn->hide(); myAddBtn->setText(tr("OK")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifyPoint() ) ); } else{ - myContBtn->show(); myAddBtn->setText(tr("ADD_BTN")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addPoint() ) ); } updateTitle(); } @@ -105,13 +114,6 @@ CurveCreator::Coordinates CurveCreator_NewPointDlg::getCoordinates() const return aCoords; } -void CurveCreator_NewPointDlg::onBtnClicked(QAbstractButton* theBtn ) -{ - if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){ - emit addPoint(); - } -} - void CurveCreator_NewPointDlg::clear() { initSpinBox(myX); diff --git a/src/CurveCreator/CurveCreator_NewPointDlg.h b/src/CurveCreator/CurveCreator_NewPointDlg.h index 71dc2e819..d936e51bb 100755 --- a/src/CurveCreator/CurveCreator_NewPointDlg.h +++ b/src/CurveCreator/CurveCreator_NewPointDlg.h @@ -3,15 +3,16 @@ #include "CurveCreator.hxx" -#include +#include class QDoubleSpinBox; class QDialogButtonBox; class QAbstractButton; class QPushButton; class QLabel; +class QFrame; -class CurveCreator_NewPointDlg : public QDialog +class CurveCreator_NewPointDlg : public QWidget { Q_OBJECT public: @@ -24,21 +25,22 @@ public: void setDimension(CurveCreator::Dimension theDim); signals: void addPoint(); + void modifyPoint(); + void cancelPoint(); public slots: protected slots: - void onBtnClicked(QAbstractButton* theBtn ); protected: void updateTitle(); void initSpinBox(QDoubleSpinBox *theSpinBox); private: - QDialogButtonBox* myBtnBox; + QFrame* myBtnFrame; CurveCreator::Dimension myDim; QDoubleSpinBox* myX; QDoubleSpinBox* myY; QDoubleSpinBox* myZ; QLabel* myZLabel; - QPushButton* myContBtn; QPushButton* myAddBtn; + QPushButton* myCancelBtn; bool myIsEdit; QString mySectionName; }; diff --git a/src/CurveCreator/CurveCreator_NewSectionDlg.cxx b/src/CurveCreator/CurveCreator_NewSectionDlg.cxx index 497bef2a6..d7c7745d4 100755 --- a/src/CurveCreator/CurveCreator_NewSectionDlg.cxx +++ b/src/CurveCreator/CurveCreator_NewSectionDlg.cxx @@ -13,14 +13,18 @@ #include CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) : - QDialog(parent) + QWidget(parent) { - std::string aNameStr; - QGridLayout* aLay = new QGridLayout(); + QFrame* aFrame = new QFrame( this ); + QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + + QFrame* aCoordFrame = new QFrame( aFrame ); + QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame ); + QLabel* aLbl = new QLabel(tr("NAME"), this); myName = new QLineEdit(this); - aLay->addWidget(aLbl, 0, 0); - aLay->addWidget(myName, 0 , 1); + aCoordLayout->addWidget(aLbl, 0, 0); + aCoordLayout->addWidget(myName, 0 , 1); aLbl = new QLabel(tr("LINE_TYPE")); myLineType = new QComboBox(this); @@ -34,27 +38,29 @@ CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent ) : myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE")); myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE")); myLineType->setCurrentIndex(0); - aLay->addWidget(aLbl, 1, 0); - aLay->addWidget(myLineType, 1 , 1); + aCoordLayout->addWidget(aLbl, 1, 0); + aCoordLayout->addWidget(myLineType, 1 , 1); aLbl = new QLabel(tr("LINE_CLOSED")); myIsClosed = new QCheckBox(this); - aLay->addWidget(aLbl, 2, 0); - aLay->addWidget(myIsClosed, 2, 1); - - myBtnBox = new QDialogButtonBox(this); - myAddBtn = myBtnBox->addButton(tr("ADD_BTN"), QDialogButtonBox::AcceptRole ); - myContBtn = myBtnBox->addButton(tr("ADD_CONTINUE_BTN"), QDialogButtonBox::ResetRole ); - myBtnBox->addButton(tr("CANCEL"), QDialogButtonBox::RejectRole ); - - connect( myBtnBox, SIGNAL(accepted()), this, SLOT(accept())); - connect( myBtnBox, SIGNAL(rejected()), this, SLOT(reject())); - connect( myBtnBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onBtnClicked(QAbstractButton*) )); - - QVBoxLayout* aMainLay = new QVBoxLayout(); - aMainLay->addLayout(aLay); - aMainLay->addWidget(myBtnBox); - setLayout(aMainLay); + aCoordLayout->addWidget(aLbl, 2, 0); + aCoordLayout->addWidget(myIsClosed, 2, 1); + + myBtnFrame = new QFrame( aFrame ); + QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); + + myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame ); + myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame ); + + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); + connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) ); + + aBtnsLayout->addWidget( myAddBtn ); + aBtnsLayout->addStretch( 1 ); + aBtnsLayout->addWidget( myCancelBtn ); + + aLayout->addWidget( aCoordFrame, 0 ); + aLayout->addWidget( myBtnFrame, 1 ); } void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::Type theType ) @@ -78,12 +84,14 @@ void CurveCreator_NewSectionDlg::setEditMode( bool isEdit ) { myIsEdit = isEdit; if( myIsEdit ){ - myContBtn->hide(); myAddBtn->setText(tr("OK")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) ); } else{ - myContBtn->show(); myAddBtn->setText(tr("ADD_BTN")); + myAddBtn->disconnect( SIGNAL( clicked() ) ); + connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) ); } updateTitle(); } @@ -120,10 +128,3 @@ void CurveCreator_NewSectionDlg::setSectionName( const QString& theName ) { myName->setText(theName); } - -void CurveCreator_NewSectionDlg::onBtnClicked(QAbstractButton* theBtn ) -{ - if( myBtnBox->buttonRole(theBtn) == QDialogButtonBox::ResetRole ){ - emit addSection(); - } -} diff --git a/src/CurveCreator/CurveCreator_NewSectionDlg.h b/src/CurveCreator/CurveCreator_NewSectionDlg.h index d7568fb27..d88b08f13 100755 --- a/src/CurveCreator/CurveCreator_NewSectionDlg.h +++ b/src/CurveCreator/CurveCreator_NewSectionDlg.h @@ -3,7 +3,7 @@ #include "CurveCreator.hxx" -#include +#include class CurveCreator_Curve; @@ -13,8 +13,9 @@ class QCheckBox; class QPushButton; class QAbstractButton; class QDialogButtonBox; +class QFrame; -class CurveCreator_NewSectionDlg : public QDialog +class CurveCreator_NewSectionDlg : public QWidget { Q_OBJECT public: @@ -31,19 +32,20 @@ public: signals: void addSection(); + void modifySection(); + void cancelSection(); public slots: protected slots: - void onBtnClicked(QAbstractButton* theBtn ); protected: void updateTitle(); private: + QFrame* myBtnFrame; QLineEdit* myName; QComboBox* myLineType; QCheckBox* myIsClosed; bool myIsEdit; - QPushButton* myContBtn; QPushButton* myAddBtn; - QDialogButtonBox* myBtnBox; + QPushButton* myCancelBtn; }; #endif // CURVECREATOR_NEWSECTION_H diff --git a/src/CurveCreator/CurveCreator_TreeView.cxx b/src/CurveCreator/CurveCreator_TreeView.cxx index a6eaaaa04..d7ff92f46 100755 --- a/src/CurveCreator/CurveCreator_TreeView.cxx +++ b/src/CurveCreator/CurveCreator_TreeView.cxx @@ -227,6 +227,7 @@ void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePo if( aModel ){ QModelIndex aSectIndx = aModel->sectionIndex( theSection ); rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); + expand( aSectIndx ); } } diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index 66f38c418..c94ab8f4c 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -1,14 +1,24 @@ #include "CurveCreator_Widget.h" #include "CurveCreator_TreeView.h" -#include "QVBoxLayout" #include "CurveCreator_Curve.hxx" #include "CurveCreator_CurveEditor.hxx" #include "CurveCreator.hxx" #include "CurveCreator_NewPointDlg.h" #include "CurveCreator_NewSectionDlg.h" +#include +#include + #include #include +#include + +#include +#include +#include + +#include +#include #include #include @@ -19,6 +29,7 @@ #include #include #include +#include CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, CurveCreator_Curve *theCurve, @@ -28,14 +39,20 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, if( myCurve ) myEdit = new CurveCreator_CurveEditor( myCurve ); - CurveCreator::Dimension aDim = CurveCreator::Dim3d; + CurveCreator::Dimension aDim = CurveCreator::Dim2d; if( myCurve ) aDim = myCurve->getDimension(); - myNewPointEditor = new CurveCreator_NewPointDlg(aDim, this); - connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint())); - - myNewSectionEditor = new CurveCreator_NewSectionDlg(this); - connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection())); + myNewPointEditor = new CurveCreator_NewPointDlg( aDim, this ); + myNewPointEditor->hide(); + connect( myNewPointEditor, SIGNAL(addPoint()), this, SLOT(onAddNewPoint()) ); + connect( myNewPointEditor, SIGNAL(modifyPoint()), this, SLOT(onModifyPoint()) ); + connect( myNewPointEditor, SIGNAL(cancelPoint()), this, SLOT(onCancelPoint()) ); + + myNewSectionEditor = new CurveCreator_NewSectionDlg( this ); + myNewSectionEditor->hide(); + connect( myNewSectionEditor, SIGNAL(addSection()), this, SLOT(onAddNewSection()) ); + connect( myNewSectionEditor, SIGNAL(modifySection()), this, SLOT(onModifySection()) ); + connect( myNewSectionEditor, SIGNAL(cancelSection()), this, SLOT(onCancelSection()) ); QGroupBox* aSectionGroup = new QGroupBox(tr("Sections"),this); @@ -286,9 +303,16 @@ void CurveCreator_Widget::onNewPoint() myNewPointEditor->setEditMode(false); myNewPointEditor->setSectionName(aSectName); myNewPointEditor->setDimension(myCurve->getDimension()); - if( myNewPointEditor->exec() == QDialog::Accepted ){ - onAddNewPoint(); + + SUIT_ViewWindow* aViewWindow = GEOMBase_Helper::getActiveView(); + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + if ( aViewWindow == 0 ) + return; + if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) { + connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); } + emit subOperationStarted( myNewPointEditor ); } void CurveCreator_Widget::onAddNewPoint() @@ -298,7 +322,7 @@ void CurveCreator_Widget::onAddNewPoint() CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates(); myEdit->insertPoints(aCoords, mySection, myPointNum ); mySectionView->pointsAdded( mySection, myPointNum ); - myNewPointEditor->clear(); +// myNewPointEditor->clear(); myPointNum++; onSelectionChanged(); updateUndoRedo(); @@ -312,9 +336,7 @@ void CurveCreator_Widget::onNewSection() myNewSectionEditor->setEditMode(false); QString aSectName = QString( myCurve->getUnicSectionName().c_str() ); myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline ); - if( myNewSectionEditor->exec() == QDialog::Accepted ){ - onAddNewSection(); - } + emit subOperationStarted( myNewSectionEditor ); } void CurveCreator_Widget::onAddNewSection() @@ -330,6 +352,17 @@ void CurveCreator_Widget::onAddNewSection() mySection++; onSelectionChanged(); updateUndoRedo(); + onCancelSection(); +} + +void CurveCreator_Widget::onCancelPoint() +{ + emit subOperationFinished( myNewPointEditor ); +} + +void CurveCreator_Widget::onCancelSection() +{ + emit subOperationFinished( myNewSectionEditor ); } QAction* CurveCreator_Widget::createAction( ActionId theId, const QString& theName, const QPixmap& theImage, @@ -362,38 +395,51 @@ void CurveCreator_Widget::onEditSection( int theSection ) CurveCreator::Type aType = myCurve->getType(theSection); myNewSectionEditor->setEditMode(true); myNewSectionEditor->setSectionParameters( aSectName, isClosed, aType ); - if( myNewSectionEditor->exec() == QDialog::Accepted ){ - QString aName = myNewSectionEditor->getName(); - bool isClosed = myNewSectionEditor->isClosed(); - CurveCreator::Type aSectType = myNewSectionEditor->getSectionType(); - myEdit->startOperation(); - myEdit->setClosed( isClosed, mySection ); - myEdit->setName( aName.toStdString(), mySection ); - myEdit->setType( aSectType, mySection ); - myEdit->finishOperation(); - mySectionView->sectionChanged(mySection); - updateUndoRedo(); - } + + emit subOperationStarted( myNewSectionEditor ); } -void CurveCreator_Widget::onEditPoint( int theSection, int thePoint ) +void CurveCreator_Widget::onModifySection() { - if( !myNewPointEditor ) - return; if( !myEdit ) return; + QString aName = myNewSectionEditor->getName(); + bool isClosed = myNewSectionEditor->isClosed(); + CurveCreator::Type aSectType = myNewSectionEditor->getSectionType(); + myEdit->startOperation(); + myEdit->setClosed( isClosed, mySection ); + myEdit->setName( aName.toStdString(), mySection ); + myEdit->setType( aSectType, mySection ); + myEdit->finishOperation(); + mySectionView->sectionChanged(mySection); + updateUndoRedo(); + onCancelSection(); +} + +void CurveCreator_Widget::onEditPoint( int theSection, int thePoint ) +{ + if( !myNewPointEditor || !myEdit ) + return; + mySection = theSection; + myPointNum = thePoint; QString aSectName = QString::fromStdString( myCurve->getSectionName(theSection)); myNewPointEditor->setEditMode(true); myNewPointEditor->setSectionName(aSectName); myNewPointEditor->setDimension( myCurve->getDimension() ); CurveCreator::Coordinates aCoords = myCurve->getCoordinates(theSection,thePoint); myNewPointEditor->setCoordinates(aCoords); - if( myNewPointEditor->exec() == QDialog::Accepted ){ - aCoords = myNewPointEditor->getCoordinates(); - myEdit->setCoordinates(aCoords, theSection, thePoint); - mySectionView->pointDataChanged(theSection, thePoint ); - updateUndoRedo(); - } + emit subOperationStarted( myNewPointEditor ); +} + +void CurveCreator_Widget::onModifyPoint() +{ + if( !myEdit ) + return; + CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates(); + myEdit->setCoordinates( aCoords, mySection, myPointNum ); + mySectionView->pointDataChanged( mySection, myPointNum ); + updateUndoRedo(); + onCancelPoint(); } void CurveCreator_Widget::onJoin() @@ -689,3 +735,43 @@ QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints() { return mySectionView->getSelectedPoints(); } + +//================================================================================= +// function : GeometryGUI::OnMousePress() +// purpose : Manage mouse press events [static] +//================================================================================= +void CurveCreator_Widget::onMousePress( SUIT_ViewWindow* theViewWindow, QMouseEvent* pe ) +{ + if ( myNewPointEditor && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && + pe->modifiers() != Qt::ControlModifier ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + gp_Pnt aPnt; + + ic->InitSelected(); + if ( pe->modifiers() == Qt::ShiftModifier ) + ic->ShiftSelect(); // Append selection + else + ic->Select(); // New selection + + ic->InitSelected(); + if ( ic->MoreSelected() ) { + TopoDS_Shape aShape = ic->SelectedShape(); + if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) + aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); + } else { + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + } + // set the coordinates into dialog + CurveCreator::Coordinates aCoords; + aCoords.push_back( aPnt.X() ); + aCoords.push_back( aPnt.Y() ); + if ( myCurve->getDimension() == 3 ) { + aCoords.push_back( aPnt.Z() ); + } + myNewPointEditor->setCoordinates( aCoords ); + } +} diff --git a/src/CurveCreator/CurveCreator_Widget.h b/src/CurveCreator/CurveCreator_Widget.h index f5ed9f1db..fe2cd856c 100644 --- a/src/CurveCreator/CurveCreator_Widget.h +++ b/src/CurveCreator/CurveCreator_Widget.h @@ -4,9 +4,10 @@ #include "CurveCreator_Curve.hxx" #include - #include +#include + class QAction; class QPixmap; class CurveCreator_CurveEditor; @@ -29,6 +30,8 @@ public: signals: void selectionChanged(); + void subOperationStarted( QWidget* ); + void subOperationFinished( QWidget* ); public slots: @@ -40,6 +43,10 @@ protected slots: void onAddNewSection(); void onEditSection( int theSection ); void onEditPoint( int theSection, int thePoint ); + void onModifyPoint(); + void onModifySection(); + void onCancelPoint(); + void onCancelSection(); void onJoin(); void onRemove(); void onMoveUp(); @@ -58,6 +65,7 @@ protected slots: void onRedo(); void onUndoSettings(); void onContextMenu(QPoint thePoint); + void onMousePress( SUIT_ViewWindow*, QMouseEvent* ); protected: enum ActionId{ UNDO_ID, REDO_ID, NEW_SECTION_ID, NEW_POINT_ID, REMOVE_ID, REMOVE_ALL_ID, JOIN_ID, JOIN_ALL_ID, UP_ID, DOWN_ID, INSERT_SECTION_BEFORE_ID, INSERT_SECTION_AFTER_ID, diff --git a/src/CurveCreator/Makefile.am b/src/CurveCreator/Makefile.am index 8a44f565d..d92dd4f5c 100644 --- a/src/CurveCreator/Makefile.am +++ b/src/CurveCreator/Makefile.am @@ -81,14 +81,26 @@ endif # additional information to compile and link file -libCurveCreator_la_CPPFLAGS = \ - $(QT_INCLUDES) \ - $(CAS_CPPFLAGS) \ - $(KERNEL_CXXFLAGS) \ - $(GUI_CXXFLAGS) +libCurveCreator_la_CPPFLAGS = \ + $(QT_INCLUDES) \ + $(CAS_CPPFLAGS) \ + $(KERNEL_CXXFLAGS) \ + $(GUI_CXXFLAGS) \ + $(CORBA_CXXFLAGS) \ + $(CORBA_INCLUDES) \ + -I$(srcdir)/../GEOMGUI \ + -I$(srcdir)/../GEOMUtils \ + -I$(srcdir)/../GEOMBase \ + -I$(top_builddir)/idl -libCurveCreator_la_LDFLAGS = \ - $(QT_MT_LIBS) \ - $(CAS_KERNEL) \ - $(KERNEL_LDFLAGS) \ - $(GUI_LDFLAGS) -lqtx -lsuit + +libCurveCreator_la_LDFLAGS = \ + $(QT_MT_LIBS) \ + $(CAS_KERNEL) \ + $(CAS_VIEWER) \ + $(OCCViewer) \ + $(KERNEL_LDFLAGS) \ + $(GUI_LDFLAGS) -lqtx -lsuit \ + ../GEOMUtils/libGEOM.la \ + ../GEOMUtils/libGEOMUtils.la \ + ../GEOMUtils/libGEOMBase.la diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index 705138e36..ae37c0840 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -28,6 +28,7 @@ #include #include "GeometryGUI_Operations.h" +#include #include #include @@ -152,7 +153,7 @@ bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWi } else { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } Qt::KeyboardModifiers modifiers = pe->modifiers(); @@ -240,7 +241,7 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin if ( aSketcherDlg->acceptMouseEvent() ) { OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); - gp_Pnt aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + gp_Pnt aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); Qt::KeyboardModifiers modifiers = pe->modifiers(); if (QApplication::mouseButtons() == Qt::LeftButton ) @@ -251,32 +252,6 @@ bool EntityGUI::OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWin return false; } -//======================================================================= -// function : ConvertClickToPoint() -// purpose : Returns the point clicked in 3D view -//======================================================================= -gp_Pnt EntityGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) -{ - V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; - aView->Eye( XEye, YEye, ZEye ); - - aView->At( XAt, YAt, ZAt ); - gp_Pnt EyePoint( XEye, YEye, ZEye ); - gp_Pnt AtPoint( XAt, YAt, ZAt ); - - gp_Vec EyeVector( EyePoint, AtPoint ); - gp_Dir EyeDir( EyeVector ); - - gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); - Standard_Real X, Y, Z; - aView->Convert( x, y, X, Y, Z ); - gp_Pnt ConvertedPoint( X, Y, Z ); - - gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); - gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); - return ResultPoint; -} - //===================================================================================== // function : DisplaySimulationShape() // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape diff --git a/src/EntityGUI/EntityGUI.h b/src/EntityGUI/EntityGUI.h index 1b84b2901..ccf336999 100644 --- a/src/EntityGUI/EntityGUI.h +++ b/src/EntityGUI/EntityGUI.h @@ -32,7 +32,6 @@ #include #include -#include class TopoDS_Shape; @@ -52,8 +51,6 @@ public : bool OnMouseMove( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow ); bool OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow ); - static gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ); - void DisplaySimulationShape( const TopoDS_Shape&, const TopoDS_Shape& ); void EraseSimulationShape(); diff --git a/src/EntityGUI/Makefile.am b/src/EntityGUI/Makefile.am index 37f0e6f46..b88f96ceb 100644 --- a/src/EntityGUI/Makefile.am +++ b/src/EntityGUI/Makefile.am @@ -112,6 +112,7 @@ libEntityGUI_la_CPPFLAGS = \ -I$(srcdir)/../GEOMImpl \ -I$(srcdir)/../GEOMFiltersSelection \ -I$(srcdir)/../SKETCHER \ + -I$(srcdir)/../GEOMUtils \ -I$(ShapeRec_dir) \ -I$(srcdir)/../GEOM \ -I$(top_builddir)/src/DlgRef \ @@ -123,7 +124,8 @@ libEntityGUI_la_LDFLAGS = \ ../GEOMBase/libGEOMBase.la \ ../SKETCHER/libGEOMSketcher.la \ ../GEOMGUI/libGEOM.la \ + ../GEOMUtils/libGEOMUtils.la \ $(ShapeRec_la) \ $(QT_MT_LIBS) \ $(CAS_TKTopAlgo) -lTKernel \ - $(Opencv_libs) + $(Opencv_libs) diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index 56282b716..e72d96277 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -64,7 +64,7 @@ // Function : getActiveView // Purpose : Get active view window, returns 0 if no open study frame //================================================================ -static SUIT_ViewWindow* getActiveView() +SUIT_ViewWindow* GEOMBase_Helper::getActiveView() { SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy(); if ( activeStudy ) diff --git a/src/GEOMBase/GEOMBase_Helper.h b/src/GEOMBase/GEOMBase_Helper.h index ab5249e1e..37c8a47ce 100755 --- a/src/GEOMBase/GEOMBase_Helper.h +++ b/src/GEOMBase/GEOMBase_Helper.h @@ -61,6 +61,7 @@ class GEOMBASE_EXPORT GEOMBase_Helper public: GEOMBase_Helper( SUIT_Desktop* ); virtual ~GEOMBase_Helper(); + static SUIT_ViewWindow* getActiveView(); protected: static GEOM::GEOM_Gen_ptr getGeomEngine(); diff --git a/src/GEOMUtils/GEOMUtils.cxx b/src/GEOMUtils/GEOMUtils.cxx index f2c53523f..1f8b68b2e 100644 --- a/src/GEOMUtils/GEOMUtils.cxx +++ b/src/GEOMUtils/GEOMUtils.cxx @@ -72,6 +72,9 @@ #include #include +#include +#include + #include #include @@ -600,3 +603,29 @@ TopoDS_Shape GEOMUtils::GetEdgeNearPoint (const TopoDS_Shape& theShape, return aResult; } + +//======================================================================= +// function : ConvertClickToPoint() +// purpose : Returns the point clicked in 3D view +//======================================================================= +gp_Pnt GEOMUtils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView ) +{ + V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; + aView->Eye( XEye, YEye, ZEye ); + + aView->At( XAt, YAt, ZAt ); + gp_Pnt EyePoint( XEye, YEye, ZEye ); + gp_Pnt AtPoint( XAt, YAt, ZAt ); + + gp_Vec EyeVector( EyePoint, AtPoint ); + gp_Dir EyeDir( EyeVector ); + + gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); + Standard_Real X, Y, Z; + aView->Convert( x, y, X, Y, Z ); + gp_Pnt ConvertedPoint( X, Y, Z ); + + gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); + gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); + return ResultPoint; +} diff --git a/src/GEOMUtils/GEOMUtils.hxx b/src/GEOMUtils/GEOMUtils.hxx index 64c34bd85..fd4c1140e 100644 --- a/src/GEOMUtils/GEOMUtils.hxx +++ b/src/GEOMUtils/GEOMUtils.hxx @@ -33,6 +33,8 @@ #include #include +#include + #include #include @@ -132,6 +134,16 @@ class GEOMUtils { Standard_EXPORT static TopoDS_Shape GetEdgeNearPoint (const TopoDS_Shape& theShape, const TopoDS_Vertex& thePoint); + /*! + * \brief Returns the point clicked in 3D view. + * + * \param x The X coordinate in the view. + * \param y The Y coordinate in the view. + * \param theView View where the given point takes place. + * \retval gp_Pnt Returns the point clicked in 3D view + */ + Standard_EXPORT static gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) theView ); + }; #endif diff --git a/src/GEOMUtils/Makefile.am b/src/GEOMUtils/Makefile.am index 73c1ebda4..d1f1cbbea 100644 --- a/src/GEOMUtils/Makefile.am +++ b/src/GEOMUtils/Makefile.am @@ -54,5 +54,5 @@ libGEOMUtils_la_LDFLAGS = \ ../ARCHIMEDE/libGEOMArchimede.la \ ../SKETCHER/libGEOMSketcher.la \ $(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics \ - $(CAS_LDPATH) -lTKCAF -lTKFillet -lTKOffset -lTKFeat \ + $(CAS_LDPATH) -lTKCAF -lTKFillet -lTKOffset -lTKFeat -lTKV3d \ $(STDLIB) diff --git a/src/OperationGUI/OperationGUI.cxx b/src/OperationGUI/OperationGUI.cxx index 9a3d971c3..94db3f396 100644 --- a/src/OperationGUI/OperationGUI.cxx +++ b/src/OperationGUI/OperationGUI.cxx @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -100,7 +102,11 @@ bool OperationGUI::OnGUIEvent (int theCommandID, SUIT_Desktop* parent) static CurveCreator_Curve *aStaticCurve = NULL; if (aStaticCurve == NULL) { - aStaticCurve = new CurveCreator_Curve(CurveCreator::Dim3d); + aStaticCurve = new CurveCreator_Curve(CurveCreator::Dim2d); + } + if (CurveCreator::Dim2d == aStaticCurve->getDimension()) { + OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)getGeometryGUI()->getApp()->activeViewManager()->getActiveView(); + vw->onTopView(); } QDialog *aDialog = new QDialog(parent);