From: nds Date: Wed, 4 Dec 2013 03:47:13 +0000 (+0000) Subject: OCC functionality moving out from the widget X-Git-Tag: BR_hydro_v_0_4~72 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bc94f7ba1f12d74aee550ceae01684f1438bd8ac;p=modules%2Fhydro.git OCC functionality moving out from the widget --- diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx index 12952013..26268884 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.cxx @@ -1015,6 +1015,8 @@ CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) std::vector CurveCreator_Curve::constructWire() const { std::vector aCurveRepresentation; + +#ifndef ONE_SHAPE std::vector aSectionObjects; for( int iSection = 0 ; iSection < getNbSections() ; iSection++ ){ aSectionObjects = constructSection( iSection ); @@ -1022,6 +1024,14 @@ std::vector CurveCreator_Curve::constructWire() co aCurveRepresentation.push_back( aSectionObjects.at(iObject) ); } } +#else + TopoDS_Shape aShape; + CurveCreator_Utils::constructShape( this, aShape ); + + AIS_Shape* anAISShape = new AIS_Shape( aShape ); + //aShape->SetSelectionMode( AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) ); + aCurveRepresentation.push_back( anAISShape ); +#endif return aCurveRepresentation; } diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.cxx b/src/HYDROCurveCreator/CurveCreator_TableView.cxx index 99499221..52a8f492 100644 --- a/src/HYDROCurveCreator/CurveCreator_TableView.cxx +++ b/src/HYDROCurveCreator/CurveCreator_TableView.cxx @@ -18,6 +18,7 @@ // #include "CurveCreator_TableView.h" +#include "CurveCreator_UtilsICurve.hxx" #include #include @@ -27,6 +28,11 @@ const double DBL_MINIMUM = -10000000.; const double DBL_MAXIMUM = 10000000.; +const int SECTION_NAME_COLUMN_WIDTH = 75; +const int POINT_INDEX_COLUMN_WIDTH = 40; + +const double LOCAL_SELECTION_TOLERANCE = 0.0001; + CurveCreator_TableItemDelegate::CurveCreator_TableItemDelegate( QObject* theParent ) : QItemDelegate( theParent ) { @@ -92,3 +98,91 @@ void CurveCreator_TableItemDelegate::setModelData( QWidget* theEditor, QItemDelegate::setModelData( theEditor, theModel, theIndex ); } +CurveCreator_TableView::CurveCreator_TableView( CurveCreator_ICurve* theCurve, QWidget* theParent ) +: QTableWidget( theParent ), myCurve( theCurve ) +{ + setItemDelegate( new CurveCreator_TableItemDelegate( this ) ); + setVisible( false ); + setColumnCount( 4 ); + setColumnWidth( 0, SECTION_NAME_COLUMN_WIDTH ); + setColumnWidth( 1, POINT_INDEX_COLUMN_WIDTH ); + QStringList aLabels; + //aLabels << tr( "SECTION_LABEL" ) << tr( "IDENTIFIER_LABEL" ) << tr( "X_POSITION_LBL" ) << tr( "Y_POSITION_LBL" ); + aLabels << tr( "Section" ) << "Index" << tr( "X" ) << tr( "Y" ); + setHorizontalHeaderLabels( aLabels ); +} + +void CurveCreator_TableView::setCurve( CurveCreator_ICurve* theCurve ) +{ + myCurve = theCurve; +} + +void CurveCreator_TableView::addLocalPointToTable( const double theX, const double theY ) +{ + CurveCreator_ICurve::SectionToPointList aPoints; + CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, aPoints ); + + CurveCreator_ICurve::SectionToPointList aSkipList; + // table could not contain two equal value rows + int aRowId = rowCount(); + double aCurrentX, aCurrentY; + int aSectionId, aPointId; + CurveCreator_ICurve::SectionToPoint aPoint; + for ( int i = 0; i < aRowId; i++ ) { + aCurrentX = item( i, 2 )->data( Qt::UserRole ).toDouble(); + aCurrentY = item( i, 3 )->data( Qt::UserRole ).toDouble(); + if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE && + fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) { + aPoint = std::make_pair( getSectionId( i ), getPointId( i ) ); + if ( !CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) ) + aSkipList.push_back( aPoint ); + } + } + if ( aSkipList.size() == aPoints.size() ) + return; + + QTableWidgetItem* anItem; + CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(), + aLast = aPoints.end(); + for ( ; anIt != aLast; anIt++ ) { + aPoint = *anIt; + if ( CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) ) + continue; + + setRowCount( aRowId+1 ); + aSectionId = aPoint.first; + aPointId = aPoint.second; + + anItem = new QTableWidgetItem( myCurve->getSectionName( aSectionId ).c_str() ); + anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); + anItem->setData( Qt::UserRole, aSectionId ); + setItem( aRowId, 0, anItem ); + + anItem = new QTableWidgetItem( QString::number( aPointId + 1 ) ); + anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); + anItem->setData( Qt::UserRole, aPointId ); + setItem( aRowId, 1, anItem ); + + anItem = new QTableWidgetItem( QString::number( theX ) ); + anItem->setData( Qt::UserRole, theX ); + setItem( aRowId, 2, anItem ); + + anItem = new QTableWidgetItem( QString::number( theY ) ); + anItem->setData( Qt::UserRole, theY ); + setItem( aRowId, 3, anItem ); + } +} + +int CurveCreator_TableView::getSectionId( const int theRowId ) const +{ + return item( theRowId, 0 )->data( Qt::UserRole ).toInt(); +} + +/** + * Returns a point index from the table + * \param theRowId a table row + */ +int CurveCreator_TableView::getPointId( const int theRowId ) const +{ + return item( theRowId, 1 )->data( Qt::UserRole ).toInt(); +} diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.h b/src/HYDROCurveCreator/CurveCreator_TableView.h index a1e185ae..ffbd3da7 100644 --- a/src/HYDROCurveCreator/CurveCreator_TableView.h +++ b/src/HYDROCurveCreator/CurveCreator_TableView.h @@ -20,7 +20,10 @@ #ifndef CURVECREATOR_TABLEVIEW_H #define CURVECREATOR_TABLEVIEW_H +#include "CurveCreator_ICurve.hxx" + #include +#include class CurveCreator_TableItemDelegate : public QItemDelegate { @@ -36,4 +39,30 @@ public: const QModelIndex& theIndex ) const; }; +class CurveCreator_TableView : public QTableWidget +{ +public: + CurveCreator_TableView( CurveCreator_ICurve* theCurve, QWidget* theParent = 0 ); + ~CurveCreator_TableView() {}; + + void setCurve( CurveCreator_ICurve* theCurve ); + + void addLocalPointToTable( const double theX, const double theY ); + + /** + * Returns a section index from the table + * \param theRowId a table row + */ + int getSectionId( const int theRowId ) const; + /** + * Returns a point index from the table + * \param theRowId a table row + */ + int getPointId( const int theRowId ) const; + +private: + CurveCreator_ICurve* myCurve; + +}; + #endif // CURVECREATOR_TABLEVIEW_H diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx index f4e49253..0007e660 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Utils.cxx @@ -213,6 +213,76 @@ void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, } } +void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, + TopoDS_Shape& theShape ) +{ + BRep_Builder aBuilder; + TopoDS_Compound aComp; + aBuilder.MakeCompound( aComp ); + for( int iSection = 0 ; iSection < theCurve->getNbSections() ; iSection++ ) + { + int theISection = iSection; + + CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection ); + int aPointSize = theCurve->getNbPoints( theISection ); + bool aSectIsClosed = theCurve->isClosed( theISection ); + bool isPolyline = aSectType == CurveCreator::Polyline; + int iPoint = 0; + gp_Pnt aPrevPoint, aPoint; + if ( aPointSize == 1 ) { + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); + TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + } + else if ( aPointSize > 1 ) { + Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aPointSize); + int aHIndex = 1; + + TopoDS_Edge aPointEdge; + TopoDS_Vertex aVertex; + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); + aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + aHCurvePoints->SetValue(aHIndex++, aPoint); + aPrevPoint = aPoint; + iPoint++; + for( ; iPoint < aPointSize; iPoint++ ) { + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint ); + aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + aHCurvePoints->SetValue(aHIndex++, aPoint); + if ( isPolyline ) { + aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); + aBuilder.Add( aComp, aPointEdge ); + } + aPrevPoint = aPoint; + } + if( aSectIsClosed && ( aPointSize > 2 ) ) { + CurveCreator_UtilsICurve::getPoint( theCurve, theISection, 0, aPoint ); + aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex(); + aBuilder.Add( aComp, aVertex ); + if ( isPolyline ) { + aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge(); + aBuilder.Add( aComp, aPointEdge ); + } + } + if( !isPolyline ) { + // compute BSpline + Handle(Geom_BSplineCurve) aBSplineCurve; + GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution()); + aGBC.Perform(); + if ( aGBC.IsDone() ) + aBSplineCurve = aGBC.Curve(); + TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge(); + TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire(); + aBuilder.Add( aComp, aWire ); + } + } + } + theShape = aComp; +} + + std::list CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext ) { std::list aSelectedPoints; diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.h b/src/HYDROCurveCreator/CurveCreator_Utils.h index cc0817fa..b81f4cf2 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.h +++ b/src/HYDROCurveCreator/CurveCreator_Utils.h @@ -62,7 +62,7 @@ public: Handle(V3d_View) theView ); /** - * Generates shape on the curve + * Generates shape on the curve with a fixed section index * \param theCurve a curve object, that contains data * \param theISection a curve section index * \param theShape a generated shape @@ -72,6 +72,14 @@ public: TopoDS_Shape& theShape, std::vector& theAdditional ); + /** + * Generates shape on the curve + * \param theCurve a curve object, that contains data + * \param theShape a generated shape + */ + CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve, + TopoDS_Shape& theShape ); + /** * Find selected points in the context * \param theContext the viewer context diff --git a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx index 979a246d..d8b5d2de 100644 --- a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx @@ -94,11 +94,23 @@ void CurveCreator_UtilsICurve::getPoint( const CurveCreator_ICurve* theCurve, co thePoint = gp_Pnt( anX, anY, aZ); } -/** - * Returns whethe the container has the value - * \param theList a container of values - * \param theValue a value - */ +std::string CurveCreator_UtilsICurve::getUniqSectionName( CurveCreator_ICurve* theCurve ) +{ + for( int i = 0 ; i < 1000000 ; i++ ){ + char aBuffer[255]; + sprintf( aBuffer, "Section_%d", i+1 ); + std::string aName(aBuffer); + int j; + for( j = 0 ; j < theCurve->getNbSections() ; j++ ){ + if( theCurve->getSectionName(j) == aName ) + break; + } + if( j == theCurve->getNbSections() ) + return aName; + } + return ""; +} + bool CurveCreator_UtilsICurve::contains( const CurveCreator_ICurve::SectionToPointList& theList, const CurveCreator_ICurve::SectionToPoint& theValue ) { diff --git a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx index c749e47b..9681552e 100644 --- a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx +++ b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx @@ -48,6 +48,13 @@ public: CURVECREATOR_EXPORT static void getPoint( const CurveCreator_ICurve* theCurve, const int theISection, const int theIPoint, gp_Pnt& thePoint ); + /*! + * Returns a unique section name + * \param theCurve a curve interface + */ + CURVECREATOR_EXPORT static std::string getUniqSectionName( + CurveCreator_ICurve* theCurve ); + /** * Returns whethe the container has the value * \param theList a container of values diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 96a838c6..719a58a7 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -73,10 +73,6 @@ #include const double LOCAL_SELECTION_TOLERANCE = 0.0001; -const int SECTION_NAME_COLUMN_WIDTH = 75; -const int POINT_INDEX_COLUMN_WIDTH = 40; - -const int SCENE_PIXEL_TOLERANCE = 10; CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, CurveCreator_ICurve *theCurve, @@ -98,16 +94,7 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) ); connect( mySectionView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onContextMenu(QPoint)) ); - myLocalPointView = new QTableWidget(); - myLocalPointView->setItemDelegate( new CurveCreator_TableItemDelegate( myLocalPointView ) ); - myLocalPointView->setVisible( false ); - myLocalPointView->setColumnCount( 4 ); - myLocalPointView->setColumnWidth( 0, SECTION_NAME_COLUMN_WIDTH ); - myLocalPointView->setColumnWidth( 1, POINT_INDEX_COLUMN_WIDTH ); - QStringList aLabels; - //aLabels << tr( "SECTION_LABEL" ) << tr( "IDENTIFIER_LABEL" ) << tr( "X_POSITION_LBL" ) << tr( "Y_POSITION_LBL" ); - aLabels << tr( "Section" ) << "Index" << tr( "X" ) << tr( "Y" ); - myLocalPointView->setHorizontalHeaderLabels( aLabels ); + myLocalPointView = new CurveCreator_TableView( myCurve, this ); connect( myLocalPointView, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); @@ -218,7 +205,9 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, // aLay->addLayout(aNameLayout); aLay->addWidget(aSectionGroup); setLayout(aLay); - onSelectionChanged(); + + updateActionsStates(); + updateUndoRedo(); } /** @@ -333,36 +322,23 @@ void CurveCreator_Widget::reset() { } -//======================================================================= -// function: getUniqSectionName -// purpose: return unique section name -//======================================================================= -std::string CurveCreator_Widget::getUniqSectionName( CurveCreator_ICurve* theCurve ) const -{ - for( int i = 0 ; i < 1000000 ; i++ ){ - char aBuffer[255]; - sprintf( aBuffer, "Section_%d", i+1 ); - std::string aName(aBuffer); - int j; - for( j = 0 ; j < theCurve->getNbSections() ; j++ ){ - if( theCurve->getSectionName(j) == aName ) - break; - } - if( j == theCurve->getNbSections() ) - return aName; - } - return ""; -} - void CurveCreator_Widget::setCurve( CurveCreator_ICurve* theCurve ) { myCurve = theCurve; - mySectionView->setCurve(myCurve); - onSelectionChanged(); + mySectionView->setCurve( myCurve ); + myLocalPointView->setCurve( myCurve ); + updateActionsStates(); updateUndoRedo(); } void CurveCreator_Widget::onSelectionChanged() +{ + updateActionsStates(); + updateUndoRedo(); + emit selectionChanged(); +} + +void CurveCreator_Widget::updateActionsStates() { QList anEnabledAct; if( myCurve ){ @@ -459,8 +435,6 @@ void CurveCreator_Widget::onSelectionChanged() } } } - updateUndoRedo(); - emit selectionChanged(); } void CurveCreator_Widget::onAdditionMode(bool checked) @@ -526,7 +500,8 @@ void CurveCreator_Widget::onModeChanged(bool checked) break; } } - onSelectionChanged(); + updateActionsStates(); + updateUndoRedo(); setLocalPointContext( aMode == ModificationMode, true ); } @@ -544,7 +519,7 @@ void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoor int aSection = aSections[0]; myCurve->addPoints(theCoords, aSection); // add to the end of section mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) ); - onSelectionChanged(); + updateActionsStates(); updateUndoRedo(); } @@ -554,7 +529,7 @@ void CurveCreator_Widget::onNewSection() return; myNewSectionEditor->clear(); myNewSectionEditor->setEditMode(false); - QString aSectName = QString( getUniqSectionName(myCurve).c_str() ); + QString aSectName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() ); myNewSectionEditor->setSectionParameters(aSectName, true, CurveCreator::Polyline ); emit subOperationStarted( myNewSectionEditor ); } @@ -563,12 +538,13 @@ void CurveCreator_Widget::onAddNewSection() { if( !myCurve ) return; - myCurve->addSection( myNewSectionEditor->getName().toStdString(), myNewSectionEditor->getSectionType(), - myNewSectionEditor->isClosed() ); + myCurve->addSection( myNewSectionEditor->getName().toStdString(), + myNewSectionEditor->getSectionType(), + myNewSectionEditor->isClosed() ); mySectionView->sectionAdded( -1 ); // add a new section to the end of list - QString aNewName = QString(getUniqSectionName(myCurve).c_str()); + QString aNewName = QString( CurveCreator_UtilsICurve::getUniqSectionName( myCurve ).c_str() ); myNewSectionEditor->setSectionName(aNewName); - onSelectionChanged(); + updateActionsStates(); updateUndoRedo(); onCancelSection(); } @@ -720,7 +696,7 @@ void CurveCreator_Widget::onClearAll() return; myCurve->clear(); mySectionView->reset(); - onSelectionChanged(); + updateActionsStates(); updateUndoRedo(); } @@ -730,7 +706,7 @@ void CurveCreator_Widget::onJoinAll() return; myCurve->join(); mySectionView->reset(); - onSelectionChanged(); + updateActionsStates(); updateUndoRedo(); } @@ -1059,8 +1035,8 @@ void CurveCreator_Widget::onMouseMove( QMouseEvent* theEvent ) void CurveCreator_Widget::onCellChanged( int theRow, int theColumn ) { - int aCurrSect = getSectionId( theRow ); - int aPntIndex = getPointId( theRow ); + int aCurrSect = myLocalPointView->getSectionId( theRow ); + int aPntIndex = myLocalPointView->getPointId( theRow ); if ( aPntIndex < 0 ) return; @@ -1251,7 +1227,7 @@ void CurveCreator_Widget::updateLocalPointView() float anY = *anIt; anIt++; float aZ = *anIt; - addLocalPointToTable( aX, anY ); + myLocalPointView->addLocalPointToTable( aX, anY ); } myLocalPointView->blockSignals(isBlocked); } @@ -1266,62 +1242,6 @@ void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool i updateLocalPointView(); } -void CurveCreator_Widget::addLocalPointToTable( const double theX, const double theY ) -{ - CurveCreator_ICurve::SectionToPointList aPoints; - findSectionsToPoints( theX, theY, aPoints ); - - CurveCreator_ICurve::SectionToPointList aSkipList; - // table could not contain two equal value rows - int aRowId = myLocalPointView->rowCount(); - double aCurrentX, aCurrentY; - int aSectionId, aPointId; - CurveCreator_ICurve::SectionToPoint aPoint; - for ( int i = 0; i < aRowId; i++ ) { - aCurrentX = myLocalPointView->item( i, 2 )->data( Qt::UserRole ).toDouble(); - aCurrentY = myLocalPointView->item( i, 3 )->data( Qt::UserRole ).toDouble(); - if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE && - fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) { - aPoint = std::make_pair( getSectionId( i ), getPointId( i ) ); - if ( !contains( aSkipList, aPoint ) ) - aSkipList.push_back( aPoint ); - } - } - if ( aSkipList.size() == aPoints.size() ) - return; - - QTableWidgetItem* anItem; - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(), - aLast = aPoints.end(); - for ( ; anIt != aLast; anIt++ ) { - aPoint = *anIt; - if ( contains( aSkipList, aPoint ) ) - continue; - - myLocalPointView->setRowCount( aRowId+1 ); - aSectionId = aPoint.first; - aPointId = aPoint.second; - - anItem = new QTableWidgetItem( myCurve->getSectionName( aSectionId ).c_str() ); - anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); - anItem->setData( Qt::UserRole, aSectionId ); - myLocalPointView->setItem( aRowId, 0, anItem ); - - anItem = new QTableWidgetItem( QString::number( aPointId + 1 ) ); - anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled ); - anItem->setData( Qt::UserRole, aPointId ); - myLocalPointView->setItem( aRowId, 1, anItem ); - - anItem = new QTableWidgetItem( QString::number( theX ) ); - anItem->setData( Qt::UserRole, theX ); - myLocalPointView->setItem( aRowId, 2, anItem ); - - anItem = new QTableWidgetItem( QString::number( theY ) ); - anItem->setData( Qt::UserRole, theY ); - myLocalPointView->setItem( aRowId, 3, anItem ); - } -} - /** * Set drag operation started. Save the position and a list of dragged points * \param theState the drag operation state: started/finished @@ -1351,7 +1271,8 @@ void CurveCreator_Widget::getSelectedPonts( CurveCreator_ICurve::SectionToPointL { thePoints.clear(); for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ ) - thePoints.push_back( std::make_pair( getSectionId( i ), getPointId( i ) ) ); + thePoints.push_back( std::make_pair( myLocalPointView->getSectionId( i ), + myLocalPointView->getPointId( i ) ) ); } @@ -1359,22 +1280,15 @@ bool CurveCreator_Widget::isIntersectVertexToPoint( const TopoDS_Vertex& theVert const CurveCreator_ICurve::SectionToPoint& theSToPoint ) { bool isIntersect = false; - if ( theVertex.IsNull() ) return isIntersect; - gp_Pnt aPnt = BRep_Tool::Pnt( theVertex ); - - CurveCreator_ICurve::SectionToPointList aPoints; - findSectionsToPoints( aPnt.X(), aPnt.Y(), aPoints ); - - CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(), - aLast = aPoints.end(); - CurveCreator_ICurve::SectionToPoint aPoint; - for ( ; anIt != aLast && !isIntersect; anIt++ ) { - aPoint = *anIt; - isIntersect = aPoint.first == theSToPoint.first && aPoint.second == theSToPoint.second; - } + gp_Pnt aSPoint; + CurveCreator_UtilsICurve::getPoint( myCurve, theSToPoint.first, theSToPoint.second, + aSPoint ); + gp_Pnt aVertexPoint = BRep_Tool::Pnt( theVertex ); + isIntersect = fabs( aVertexPoint.X() - aSPoint.X() ) < LOCAL_SELECTION_TOLERANCE && + fabs( aVertexPoint.Y() - aSPoint.Y() ) < LOCAL_SELECTION_TOLERANCE; return isIntersect; } @@ -1400,7 +1314,6 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionTo bool isSelectedVertex = false; for( ; anIt != aLast; anIt++ ) { aSToPoint = *anIt; - for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() ) { Handle(AIS_InteractiveObject) anAIS = it.Value(); @@ -1491,24 +1404,6 @@ void CurveCreator_Widget::convert( const CurveCreator_ICurve::SectionToPointList return CurveCreator_UtilsICurve::convert( thePoints, theConvPoints ); } -/** - * Returns a section index from the table - * \param theRowId a table row - */ -int CurveCreator_Widget::getSectionId( const int theRowId ) const -{ - return myLocalPointView->item( theRowId, 0 )->data( Qt::UserRole ).toInt(); -} - -/** - * Returns a point index from the table - * \param theRowId a table row - */ -int CurveCreator_Widget::getPointId( const int theRowId ) const -{ - return myLocalPointView->item( theRowId, 1 )->data( Qt::UserRole ).toInt(); -} - /** * Returns whethe the container has the value * \param theList a container of values diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index 6f073f16..fcb6cc34 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -43,7 +43,7 @@ class AIS_ListOfInteractive; class QAction; class QPixmap; -class QTableWidget; +class CurveCreator_TableView; class CurveCreator_TreeView; class CurveCreator_NewPointDlg; class CurveCreator_NewSectionDlg; @@ -65,10 +65,6 @@ public: void setObjectsSelected(const AIS_ListOfInteractive& theList); void reset(); - - //! Return unique section name - std::string getUniqSectionName(CurveCreator_ICurve* theCurve) const; - void setCurve( CurveCreator_ICurve* theCurve ); QList getSelectedSections(); @@ -155,7 +151,8 @@ private: QAction* getAction(ActionId theId); ActionMode getActionMode() const; - void updateUndoRedo(); + void updateActionsStates(); + void updateUndoRedo(); void removeSection(); void removePoint(); @@ -164,7 +161,6 @@ private: void moveSelectedPoints( const int theXPosition, const int theYPosition ); void updateLocalPointView(); void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false ); - void addLocalPointToTable( const double theX, const double theY ); void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() ); @@ -186,18 +182,14 @@ private: void convert( const CurveCreator_ICurve::SectionToPointList& thePoints, QMap >& theConvPoints ); - // local point view table methods - int getSectionId( const int theRowId ) const; - int getPointId( const int theRowId ) const; - bool contains( const CurveCreator_ICurve::SectionToPointList& theList, const CurveCreator_ICurve::SectionToPoint& theValue ) const; private: QMap myActionMap; - CurveCreator_ICurve* myCurve; + CurveCreator_ICurve* myCurve; CurveCreator_TreeView* mySectionView; - QTableWidget* myLocalPointView; + CurveCreator_TableView* myLocalPointView; CurveCreator_NewSectionDlg* myNewSectionEditor; OCCViewer_Viewer* myOCCViewer; int mySection;