#include "CurveCreator_TableView.h"
#include "CurveCreator_UtilsICurve.hxx"
+#include <gp_Pnt.hxx>
+
#include <QTableWidget>
#include <QTableWidgetItem>
myCurve = theCurve;
}
-void CurveCreator_TableView::addLocalPointToTable( const double theX, const double theY )
+void CurveCreator_TableView::addLocalPointToTable(
+ const CurveCreator_ICurve::SectionToPoint& theSToPoint )
{
- 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<int, int>( getSectionId( i ), getPointId( i ) );
- if ( !CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) )
- aSkipList.push_back( aPoint );
- }
- }
- if ( aSkipList.size() == aPoints.size() )
+ int anISection = theSToPoint.first;
+ int anIPoint = theSToPoint.second;
+ bool isFoundPoint = false;
+ for ( int i = 0; i < aRowId && !isFoundPoint; i++ )
+ isFoundPoint = getSectionId( i ) == anISection &&
+ getPointId( i ) == anIPoint;
+ if ( isFoundPoint )
return;
+ setRowCount( aRowId+1 );
+
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, 'f', 2 ) );
- anItem->setData( Qt::UserRole, theX );
- setItem( aRowId, 2, anItem );
-
- anItem = new QTableWidgetItem( QString::number( theY, 'f', 2 ) );
- anItem->setData( Qt::UserRole, theY );
- setItem( aRowId, 3, anItem );
- }
+ anItem = new QTableWidgetItem( myCurve->getSectionName( anISection ).c_str() );
+ anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
+ anItem->setData( Qt::UserRole, anISection );
+ setItem( aRowId, 0, anItem );
+
+ anItem = new QTableWidgetItem( QString::number( anIPoint + 1 ) );
+ anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
+ anItem->setData( Qt::UserRole, anIPoint );
+ setItem( aRowId, 1, anItem );
+
+ gp_Pnt aPoint;
+ CurveCreator_UtilsICurve::getPoint( myCurve, anISection, anIPoint, aPoint );
+
+ anItem = new QTableWidgetItem( QString::number( aPoint.X(), 'f', 2 ) );
+ anItem->setData( Qt::UserRole, aPoint.X() );
+ setItem( aRowId, 2, anItem );
+
+ anItem = new QTableWidgetItem( QString::number( aPoint.Y(), 'f', 2 ) );
+ anItem->setData( Qt::UserRole, aPoint.Y() );
+ setItem( aRowId, 3, anItem );
}
int CurveCreator_TableView::getSectionId( const int theRowId ) const
void setCurve( CurveCreator_ICurve* theCurve );
- void addLocalPointToTable( const double theX, const double theY );
+ void addLocalPointToTable( const CurveCreator_ICurve::SectionToPoint& thePoint );
/**
* Returns a section index from the table
gp_Pnt myPoint;
};
-std::list<float> CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext )
+void CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
+ const CurveCreator_ICurve* theCurve,
+ CurveCreator_ICurve::SectionToPointList& thePoints )
{
- std::list<float> aSelectedPoints;
+ thePoints.clear();
+ std::list<float> aSelectedPoints;
gp_Pnt aPnt;
std::map<ComparePnt, int> aPntMap;
+ CurveCreator_ICurve::SectionToPointList aPoints;
for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) {
TopoDS_Vertex aVertex;
TopoDS_Shape aShape = theContext->SelectedShape();
if ( aPntMap.find( aPnt ) != aPntMap.end() )
continue;
aPntMap[aPnt] = 0;
- aSelectedPoints.push_back( aPnt.X() );
- aSelectedPoints.push_back( aPnt.Y() );
- aSelectedPoints.push_back( aPnt.Z() );
- }
- return aSelectedPoints;
+ CurveCreator_UtilsICurve::findSectionsToPoints( theCurve, aPnt.X(), aPnt.Y(), aPoints );
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(),
+ aLast = aPoints.end();
+ for ( ; anIt != aLast; anIt++ )
+ thePoints.push_back( *anIt );
+ }
}
+
//=======================================================================
// function : setLocalPointContext
// purpose : Open/close the viewer local context
#define CURVECREATOR_UTILS_H
#include "CurveCreator_Macro.hxx"
+#include "CurveCreator_ICurve.hxx"
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx> // TODO: remove
#include <list>
#include <vector> // TODO: remove
-class CurveCreator_ICurve;
class CurveCreator_Utils
{
* Find selected points in the context
* \param theContext the viewer context
*/
- CURVECREATOR_EXPORT static std::list<float> getSelectedPoints(
- Handle(AIS_InteractiveContext) theContext );
+ CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
+ const CurveCreator_ICurve* theCurve,
+ CurveCreator_ICurve::SectionToPointList& thePoints );
/*!
* \brief Sets the local point context for the 3D viewer.
const double LOCAL_SELECTION_TOLERANCE = 0.0001;
-int CurveCreator_UtilsICurve::findLocalPointIndex( CurveCreator_ICurve* theCurve,
+int CurveCreator_UtilsICurve::findLocalPointIndex( const CurveCreator_ICurve* theCurve,
int theSectionId, float theX, float theY )
{
int aPntIndex = -1;
return aPntIndex;
}
-void CurveCreator_UtilsICurve::findSectionsToPoints( CurveCreator_ICurve* theCurve,
+void CurveCreator_UtilsICurve::findSectionsToPoints( const CurveCreator_ICurve* theCurve,
const double theX, const double theY,
CurveCreator_ICurve::SectionToPointList& thePoints )
{
* \param theX the X coordinate of the point
* \param theY the Y coordinate of the point
*/
- CURVECREATOR_EXPORT static int findLocalPointIndex( CurveCreator_ICurve* theCurve,
+ CURVECREATOR_EXPORT static int findLocalPointIndex( const CurveCreator_ICurve* theCurve,
int theSectionId, float theX, float theY );
- CURVECREATOR_EXPORT static void findSectionsToPoints( CurveCreator_ICurve* theCurve,
+ CURVECREATOR_EXPORT static void findSectionsToPoints( const CurveCreator_ICurve* theCurve,
const double theX, const double theY,
CurveCreator_ICurve::SectionToPointList& thePoints );
CURVECREATOR_EXPORT static void convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
if ( aDraggedPoints.size() > 0 )
{
START_MEASURE_TIME;
- setSelectedPonts( aDraggedPoints );
+ setSelectedPoints( aDraggedPoints );
END_MEASURE_TIME( "drop" );
}
}
void CurveCreator_Widget::removePoint()
{
CurveCreator_ICurve::SectionToPointList aPoints;
- getSelectedPonts( aPoints );
+ getSelectedPoints( aPoints );
if ( aPoints.size() == 0 )
return;
finishCurveModification( aSelPoints );
- setSelectedPonts();
+ setSelectedPoints();
}
void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
if ( aContext.IsNull() )
return;
- std::list<float> aSelectedList = CurveCreator_Utils::getSelectedPoints( aContext );
- /*int aNbPoints = aSelectedList.size()/3;
+ CurveCreator_Utils::getSelectedPoints( aContext, myCurve, myLocalPoints );
+ int aNbPoints = myLocalPoints.size();
bool isRowLimit = aNbPoints > myLocalPointRowLimit;
myLocalPointView->setVisible( !isRowLimit );
- if ( isRowLimit )
- return;
- */
- std::list<float>::const_iterator anIt = aSelectedList.begin(), aLast = aSelectedList.end();
- bool isBlocked = myLocalPointView->blockSignals(true);
- myLocalPointView->setRowCount( 0 );
- for ( ; anIt != aLast; anIt++ )
- {
- float aX = *anIt;
- anIt++;
- float anY = *anIt;
- anIt++;
- float aZ = *anIt;
- myLocalPointView->addLocalPointToTable( aX, anY );
+ if ( !isRowLimit ) {
+ bool isBlocked = myLocalPointView->blockSignals(true);
+ myLocalPointView->setRowCount( 0 );
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myLocalPoints.begin(),
+ aLast = myLocalPoints.end();
+ for ( ; anIt != aLast; anIt++ )
+ myLocalPointView->addLocalPointToTable( *anIt );
+
+ myLocalPointView->blockSignals( isBlocked );
}
- myLocalPointView->blockSignals(isBlocked);
}
/**
void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
{
if ( theState ) {
- getSelectedPonts( myDragPoints );
+ getSelectedPoints( myDragPoints );
myDragStarted = myDragPoints.size();
myDragStartPosition = thePoint;
if ( myDragStarted ) {
myDragged = false;
}
-void CurveCreator_Widget::getSelectedPonts( CurveCreator_ICurve::SectionToPointList& thePoints )
+void CurveCreator_Widget::getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints )
{
thePoints.clear();
- for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ )
- thePoints.push_back( std::make_pair( myLocalPointView->getSectionId( i ),
- myLocalPointView->getPointId( i ) ) );
+ thePoints = myLocalPoints;
}
}
-void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionToPointList& thePoints )
+void CurveCreator_Widget::setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& thePoints )
{
if ( myDragStarted )
return;
{
if ( theFillPoints ) {
thePoints.clear();
- getSelectedPonts( thePoints );
+ getSelectedPoints( thePoints );
}
setLocalPointContext( false );
}
{
if ( getActionMode() == ModificationMode )
setLocalPointContext( true );
- setSelectedPonts( thePoints );
+ setSelectedPoints( thePoints );
updateUndoRedo();
}
void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
- void getSelectedPonts( CurveCreator_ICurve::SectionToPointList& thePoints );
+ void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints );
bool isIntersectVertexToPoint( const TopoDS_Vertex& theVertex,
const CurveCreator_ICurve::SectionToPoint& theSToPoint );
- void setSelectedPonts( const CurveCreator_ICurve::SectionToPointList& =
+ void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& =
CurveCreator_ICurve::SectionToPointList() );
void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints,
CurveCreator_ICurve* myCurve;
CurveCreator_TreeView* mySectionView;
CurveCreator_TableView* myLocalPointView;
+ CurveCreator_ICurve::SectionToPointList myLocalPoints;
CurveCreator_NewSectionDlg* myNewSectionEditor;
OCCViewer_Viewer* myOCCViewer;
int myLocalPointRowLimit;