| 232 | } |
| 233 | |
| 234 | std::shared_ptr<SurfacePointWidget> PickPointManager::createPickWidget_( const std::shared_ptr<MR::VisualObject>& obj, const PickedPoint& pt ) |
| 235 | { |
| 236 | auto newPoint = std::make_shared<SurfacePointWidget>(); |
| 237 | newPoint->setAutoHover( false ); |
| 238 | newPoint->setParameters( params.surfacePointParams ); |
| 239 | newPoint->setBaseColor( params.ordinaryPointColor ); |
| 240 | newPoint->create( obj, pt ); |
| 241 | |
| 242 | newPoint->setCanMoveCallback( [this, obj = obj] ( SurfacePointWidget& pointWidget, const PickedPoint& )->bool |
| 243 | { |
| 244 | const int index = getPointIndex( obj, pointWidget ); |
| 245 | if ( index < 0 ) |
| 246 | { |
| 247 | assert( false ); |
| 248 | return false; |
| 249 | } |
| 250 | if ( params.canMovePoint ) |
| 251 | return params.canMovePoint( obj, index ); |
| 252 | return true; |
| 253 | } ); |
| 254 | |
| 255 | newPoint->setStartMoveCallback( [this, obj = obj] ( SurfacePointWidget & pointWidget, const PickedPoint& point ) |
| 256 | { |
| 257 | const int index = getPointIndex( obj, pointWidget ); |
| 258 | if ( index < 0 ) |
| 259 | { |
| 260 | assert( false ); |
| 261 | return; |
| 262 | } |
| 263 | moveClosedPoint_ = false; |
| 264 | const auto& contour = pickedPoints_[obj]; |
| 265 | if ( isClosedContour( obj ) ) |
| 266 | moveClosedPoint_ = &pointWidget == contour[0].get(); |
| 267 | if ( params.writeHistory ) |
| 268 | { |
| 269 | SCOPED_HISTORY( "Move Point" + params.historyNameSuffix ); |
| 270 | AppendHistory<MovePointHistoryAction>( *this, obj, point, index ); |
| 271 | if ( moveClosedPoint_ ) |
| 272 | AppendHistory<MovePointHistoryAction>( *this, obj, point, int( contour.size() ) - 1 ); |
| 273 | } |
| 274 | assert( hoveredPointWidget_ == &pointWidget ); |
| 275 | draggedPointWidget_ = &pointWidget; |
| 276 | if ( params.onPointMoveStart ) |
| 277 | params.onPointMoveStart( obj, index ); |
| 278 | |
| 279 | } ); |
| 280 | |
| 281 | newPoint->setOnMoveCallback( [this, obj = obj] ( SurfacePointWidget & pointWidget, const PickedPoint& point ) |
| 282 | { |
| 283 | if ( moveClosedPoint_ ) |
| 284 | { |
| 285 | const auto& contour = pickedPoints_[obj]; |
| 286 | if ( &pointWidget == contour[0].get() ) |
| 287 | contour.back()->setCurrentPosition( point ); |
| 288 | } |
| 289 | assert( draggedPointWidget_ == &pointWidget ); |
| 290 | if ( params.onPointMove ) |
| 291 | { |
nothing calls this directly
no test coverage detected