const double LOCAL_SELECTION_TOLERANCE = 0.0001;
const int POINT_INDEX_COLUMN_WIDTH = 50;
-const int SCENE_PIXEL_TOLERANCE = 4;
+const int SCENE_PIXEL_TOLERANCE = 10;
CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
CurveCreator_ICurve *theCurve,
*/
void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
{
+ if ( myOCCViewer == theViewer )
+ return;
+
if ( myOCCViewer ) {
OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
( myOCCViewer->getViewManager() );
this, SLOT( onMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
disconnect( aViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
+ // all local contexts should be closed if the viewer is not more used
+ setLocalPointContext( false, true );
}
myOCCViewer = theViewer;
void CurveCreator_Widget::onModificationMode(bool checked)
{
myLocalPointView->setVisible( checked );
- setLocalPointContext( true );
}
void CurveCreator_Widget::onDetectionMode(bool checked)
void CurveCreator_Widget::onModeChanged(bool checked)
{
- setLocalPointContext( false );
+ ActionMode aMode = NoneMode;
if (checked) {
QAction* anAction = (QAction*)sender();
switch(myActionMap.key(anAction)) {
case ADDITION_MODE_ID:
+ aMode = AdditionMode;
if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
myActionMap[MODIFICATION_MODE_ID]->trigger();
else if (myActionMap[DETECTION_MODE_ID]->isChecked())
myActionMap[DETECTION_MODE_ID]->trigger();
break;
case MODIFICATION_MODE_ID:
+ aMode = ModificationMode;
if (myActionMap[ADDITION_MODE_ID]->isChecked())
myActionMap[ADDITION_MODE_ID]->trigger();
else if (myActionMap[DETECTION_MODE_ID]->isChecked())
myActionMap[DETECTION_MODE_ID]->trigger();
break;
case DETECTION_MODE_ID:
+ aMode = DetectionMode;
if (myActionMap[ADDITION_MODE_ID]->isChecked())
myActionMap[ADDITION_MODE_ID]->trigger();
else if (myActionMap[MODIFICATION_MODE_ID]->isChecked())
}
}
onSelectionChanged();
+ setLocalPointContext( aMode == ModificationMode, true );
}
void CurveCreator_Widget::onAddNewPoint(const CurveCreator::Coordinates& theCoords)
//=================================================================================
void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent )
{
- if ( getActionMode() != ModificationMode || !myDragStarted )
+ if ( getActionMode() != ModificationMode )
return;
- setDragStarted( false );
- //store initial cursor position for Drag&Drop
- //QPoint aPos = theEvent->pos();
- //if (pe->button() == Qt::LeftButton)
- // myDragStartPosition = pe->pos();
-
- QPoint aPos = theEvent->pos();
- // check whether the segment is clicked an a new point should be added to the segment
- if ( insertPointToSelectedSegment( aPos.x(), aPos.y() ) ) {
- setSelectedPonts( 0 );
- updateUndoRedo();
- }
+ if ( myDragStarted )
+ setDragStarted( false );
+ else // check whether the segment is clicked an a new point should be added to the segment
+ insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
// updates the input panel table to show the selected point coordinates
updateLocalPointView();
if ( getActionMode() != ModificationMode || !myDragStarted )
return;
- OCCViewer_Viewer* aViewer = getOCCViewer();
- if ( !aViewer )
- return;
-
- //if ( !(pe->buttons() & Qt::LeftButton) )
- // return;
QPoint aPos = theEvent->pos();
if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
return;
- //setLocalPointContext( false );
- OCCViewer_ViewWindow* aWindow =
- (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView();
- gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(), myDragStartPosition.y(),
- aWindow->getViewPort()->getView() );
- gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( aPos.x(), aPos.y(),
- aWindow->getViewPort()->getView() );
- double aXDelta = aStartPnt.X() - anEndPnt.X();
- double anYDelta = aStartPnt.Y() - anEndPnt.Y();
-
- int aSectionId = 0;
- int aPointId;
- std::deque<float> aChangedPos;
- for ( int i = 0, aNb = myDragPoints.size(); i < aNb; i++ ) {
- aPointId = myDragPoints[i];
- aChangedPos = myCurve->getPoint( aSectionId, aPointId );
- if ( aChangedPos.size() < 2 )
- continue;
- aChangedPos[0] = aChangedPos[0] - aXDelta;
- aChangedPos[1] = aChangedPos[1] - anYDelta;
- myCurve->setPoint( aSectionId, aPointId, aChangedPos );
- }
-
- //setLocalPointContext( true );
- setSelectedPonts( aSectionId, myDragPoints );
-
+ moveSelectedPoints( aPos.x(), aPos.y() );
myDragStartPosition = aPos;
- /*
- QDrag *drag = new QDrag(this);
- QMimeData *mimeData = new QMimeData;
-
- mimeData->setData(mimeType, data);
- drag->setMimeData(mimeData);
-
- Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
- */
}
void CurveCreator_Widget::onLocalPointChanged( int theRow, int theColumn )
int aSection = aSelSections[0];
QList<int> aSelPoints;
- getSelectedPonts( aSection, aSelPoints );
- setLocalPointContext( false );
+ startCurveModification( aSelPoints );
int aPntIndex = -1;
int aCurrSect=-1;
myCurve->setPoint( aCurrSect, aPntIndex, aChangedPos );
}
//}
- setLocalPointContext( true );
- setSelectedPonts( aSection, aSelPoints );
+ finishCurveModification( aSelPoints );
}
/**
qSort( aPoints );
getSelectedPonts( aSectionId, aPoints );
- int aCurrSect=-1;
- int aRemoveCnt = 0;
+ if ( aPoints.size() == 0 )
+ return;
+
+ QList<int> aSelPoints;
+ startCurveModification( aSelPoints, false );
for( int i = aPoints.size()-1; i >= 0; i-- ){
int aPntIndx = aPoints[i];
myCurve->removePoint( aSectionId, aPntIndx );
mySectionView->pointsRemoved( aSectionId, aPntIndx );
}
+ finishCurveModification( QList<int>() );
}
-bool CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
+void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
const int theY )
{
OCCViewer_Viewer* aViewer = getOCCViewer();
if ( !aViewer )
- return false;
+ return;
int aPoint1 = -1, aPoint2 = -1;
-
gp_Pnt aPoint;
bool isFoundPoint = false;
Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext();
isFoundPoint = pointOnObject( anAIS, theX, theY, aPoint, aPoint1, aPoint2 );
}
}
- // insert the point to the model curve
bool isDone = false;
- if ( isFoundPoint && aPoint1 >= 0 && aPoint2 >= 0 ) {
- int aSection = 0;
- CurveCreator::Coordinates aCoords;
- aCoords.push_back( aPoint.X() );
- aCoords.push_back( aPoint.Y() );
+ if ( !isFoundPoint || aPoint1 < 0 || aPoint2 < 0 )
+ return;
+
+ // insert the point to the model curve
+ QList<int> aSelPoints;
+ startCurveModification( aSelPoints );
- int anInsertPos = aPoint1 < aPoint2 ? aPoint1 + 1 : aPoint2 + 1;
- myCurve->addPoints( aCoords, aSection, anInsertPos );
- mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
+ int aSection = 0;
+ CurveCreator::Coordinates aCoords;
+ aCoords.push_back( aPoint.X() );
+ aCoords.push_back( aPoint.Y() );
- isDone = true;
+ int anInsertPos = -1;
+ int aLastPoint = myCurve->getNbPoints( 0/*SectionId*/ )-1;
+ if ( ( aPoint1 == aLastPoint && aPoint2 == 0 ) ||
+ ( aPoint2 == aLastPoint && aPoint1 == 0 ) )
+ anInsertPos = -1; // if the section happens between first and last points
+ else
+ anInsertPos = aPoint1 < aPoint2 ? aPoint1 + 1 : aPoint2 + 1;
+
+ myCurve->addPoints( aCoords, aSection, anInsertPos );
+ mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
+
+ finishCurveModification( aSelPoints );
+
+ setSelectedPonts( 0 );
+ updateUndoRedo();
+}
+
+void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
+ const int theYPosition )
+{
+ OCCViewer_Viewer* aViewer = getOCCViewer();
+ if ( !aViewer )
+ return;
+
+ QList<int> aPoints;
+ startCurveModification( aPoints, false );
+
+ OCCViewer_ViewWindow* aWindow =
+ (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView();
+ gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(),
+ myDragStartPosition.y(),
+ aWindow->getViewPort()->getView() );
+ gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition,
+ aWindow->getViewPort()->getView() );
+ double aXDelta = aStartPnt.X() - anEndPnt.X();
+ double anYDelta = aStartPnt.Y() - anEndPnt.Y();
+
+ int aSectionId = 0;
+ int aPointId;
+ std::deque<float> aChangedPos;
+ for ( int i = 0, aNb = myDragPoints.size(); i < aNb; i++ ) {
+ aPointId = myDragPoints[i];
+ aChangedPos = myCurve->getPoint( aSectionId, aPointId );
+ if ( aChangedPos.size() < 2 )
+ continue;
+ aChangedPos[0] = aChangedPos[0] - aXDelta;
+ aChangedPos[1] = aChangedPos[1] - anYDelta;
+ myCurve->setPoint( aSectionId, aPointId, aChangedPos );
}
- return isDone;
+ finishCurveModification( myDragPoints );
}
void CurveCreator_Widget::updateLocalPointView()
myLocalPointView->blockSignals(isBlocked);
}
-void CurveCreator_Widget::setLocalPointContext( const bool theOpen )
+/**
+ *
+ */
+void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable )
{
OCCViewer_Viewer* aViewer = getOCCViewer();
if ( !aViewer )
}
}
else {
- ic->CloseAllContexts();
+ if ( ic->HasOpenedContext() )
+ ic->CloseAllContexts();
+ if ( isUpdateTable )
+ updateLocalPointView();
}
}
*/
void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
{
- myDragStarted = theState;
- if ( myDragStarted ) {
- myDragStartPosition = thePoint;
+ if ( !theState ) {
+ myDragStarted = false;
+ myDragPoints.clear();
+ }
+ else {
getSelectedPonts( 0, myDragPoints );
+ myDragStarted = myDragPoints.size();
+ myDragStartPosition = thePoint;
}
}
updateLocalPointView();
}
+/**
+ * Get viewer information before perform the curve modification.
+ * Take a list of selected cuve points an close local context.
+ * The context should be closed because the curve presentation is
+ * redisplayed and if it is not closed, when we close the local context
+ * later, the presentation shown in the local context is disappeared.
+ * \param thePoints an output list of curve selected points
+ * \param theFillPoints a flag whether the selection list should be filled
+ */
+void CurveCreator_Widget::startCurveModification( QList<int>& thePoints, const bool theFillPoints )
+{
+ if ( theFillPoints ) {
+ thePoints.clear();
+ int aSectionId = 0;
+ getSelectedPonts( aSectionId, thePoints );
+ }
+ setLocalPointContext( false );
+}
+
+/**
+ * Restore the viewer state after the curve modification is done.
+ * Open local context and select given points inside it.
+ * \param thePoints a list of curve selected points
+ */
+void CurveCreator_Widget::finishCurveModification( const QList<int>& thePoints )
+{
+ setLocalPointContext( true );
+ int aSectionId = 0;
+ setSelectedPonts( aSectionId, thePoints );
+}
+
/**
* Returns a point index in the model curve by the point coordinates in the viewer
* \param theX the X coordinate of the point