Mercurial > hg > orthanc-stone
diff Framework/Scene2DViewport/LineMeasureTool.cpp @ 1203:f3bb9a6dd949 broker
locking abstraction in IViewport
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 Nov 2019 21:22:21 +0100 |
parents | e146743f6cdc |
children | 86a8266b8888 |
line wrap: on
line diff
--- a/Framework/Scene2DViewport/LineMeasureTool.cpp Fri Nov 29 11:03:41 2019 +0100 +++ b/Framework/Scene2DViewport/LineMeasureTool.cpp Fri Nov 29 21:22:21 2019 +0100 @@ -108,8 +108,10 @@ LineMeasureTool::LineHighlightArea LineMeasureTool::LineHitTest(ScenePoint2D p) const { + std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock()); + const double pixelToScene = - GetController()->GetScene().GetCanvasToSceneTransform().ComputeZoom(); + lock->GetScene().GetCanvasToSceneTransform().ComputeZoom(); const double SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD = pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD * pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD; const double sqDistanceFromStart = ScenePoint2D::SquaredDistancePtPt(p, start_); @@ -134,8 +136,10 @@ boost::shared_ptr<IFlexiblePointerTracker> LineMeasureTool::CreateEditionTracker(const PointerEvent& e) { + std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock()); + ScenePoint2D scenePos = e.GetMainPosition().Apply( - GetController()->GetScene().GetCanvasToSceneTransform()); + lock->GetScene().GetCanvasToSceneTransform()); if (!HitTest(scenePos)) return boost::shared_ptr<IFlexiblePointerTracker>(); @@ -176,61 +180,65 @@ { if (IsEnabled()) { + std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock()); + layerHolder_->CreateLayersIfNeeded(); { // Fill the polyline layer with the measurement line PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0); - polylineLayer->ClearAllChains(); - - const Color color(TOOL_LINES_COLOR_RED, - TOOL_LINES_COLOR_GREEN, - TOOL_LINES_COLOR_BLUE); - - const Color highlightColor(TOOL_LINES_HL_COLOR_RED, - TOOL_LINES_HL_COLOR_GREEN, - TOOL_LINES_HL_COLOR_BLUE); - + if (polylineLayer) { - PolylineSceneLayer::Chain chain; - chain.push_back(start_); - chain.push_back(end_); - if(lineHighlightArea_ == LineHighlightArea_Segment) - polylineLayer->AddChain(chain, false, highlightColor); - else - polylineLayer->AddChain(chain, false, color); - } + polylineLayer->ClearAllChains(); - // handles - { - { - PolylineSceneLayer::Chain chain; - - //TODO: take DPI into account - AddSquare(chain, GetController()->GetScene(), start_, - GetController()->GetHandleSideLengthS()); - - if (lineHighlightArea_ == LineHighlightArea_Start) - polylineLayer->AddChain(chain, true, highlightColor); - else - polylineLayer->AddChain(chain, true, color); - } + const Color color(TOOL_LINES_COLOR_RED, + TOOL_LINES_COLOR_GREEN, + TOOL_LINES_COLOR_BLUE); + + const Color highlightColor(TOOL_LINES_HL_COLOR_RED, + TOOL_LINES_HL_COLOR_GREEN, + TOOL_LINES_HL_COLOR_BLUE); { PolylineSceneLayer::Chain chain; + chain.push_back(start_); + chain.push_back(end_); + if(lineHighlightArea_ == LineHighlightArea_Segment) + polylineLayer->AddChain(chain, false, highlightColor); + else + polylineLayer->AddChain(chain, false, color); + } + + // handles + { + { + PolylineSceneLayer::Chain chain; - //TODO: take DPI into account - AddSquare(chain, GetController()->GetScene(), end_, - GetController()->GetHandleSideLengthS()); + //TODO: take DPI into account + AddSquare(chain, lock->GetScene(), start_, + GetController()->GetHandleSideLengthS()); - if (lineHighlightArea_ == LineHighlightArea_End) - polylineLayer->AddChain(chain, true, highlightColor); - else - polylineLayer->AddChain(chain, true, color); + if (lineHighlightArea_ == LineHighlightArea_Start) + polylineLayer->AddChain(chain, true, highlightColor); + else + polylineLayer->AddChain(chain, true, color); + } + + { + PolylineSceneLayer::Chain chain; + + //TODO: take DPI into account + AddSquare(chain, lock->GetScene(), end_, + GetController()->GetHandleSideLengthS()); + + if (lineHighlightArea_ == LineHighlightArea_End) + polylineLayer->AddChain(chain, true, highlightColor); + else + polylineLayer->AddChain(chain, true, color); + } } } - } { // Set the text layer propreties @@ -248,10 +256,10 @@ #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1 SetTextLayerOutlineProperties( - GetController()->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0); + lock->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0); #else SetTextLayerProperties( - GetController()->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0); + lock->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0); #endif } }