comparison 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
comparison
equal deleted inserted replaced
1200:54cbffabdc45 1203:f3bb9a6dd949
106 SetLineHighlightArea(lineHighlightArea); 106 SetLineHighlightArea(lineHighlightArea);
107 } 107 }
108 108
109 LineMeasureTool::LineHighlightArea LineMeasureTool::LineHitTest(ScenePoint2D p) const 109 LineMeasureTool::LineHighlightArea LineMeasureTool::LineHitTest(ScenePoint2D p) const
110 { 110 {
111 std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock());
112
111 const double pixelToScene = 113 const double pixelToScene =
112 GetController()->GetScene().GetCanvasToSceneTransform().ComputeZoom(); 114 lock->GetScene().GetCanvasToSceneTransform().ComputeZoom();
113 const double SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD = pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD * pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD; 115 const double SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD = pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD * pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD;
114 116
115 const double sqDistanceFromStart = ScenePoint2D::SquaredDistancePtPt(p, start_); 117 const double sqDistanceFromStart = ScenePoint2D::SquaredDistancePtPt(p, start_);
116 if (sqDistanceFromStart <= SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD) 118 if (sqDistanceFromStart <= SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD)
117 return LineHighlightArea_Start; 119 return LineHighlightArea_Start;
132 return LineHitTest(p) != LineHighlightArea_None; 134 return LineHitTest(p) != LineHighlightArea_None;
133 } 135 }
134 136
135 boost::shared_ptr<IFlexiblePointerTracker> LineMeasureTool::CreateEditionTracker(const PointerEvent& e) 137 boost::shared_ptr<IFlexiblePointerTracker> LineMeasureTool::CreateEditionTracker(const PointerEvent& e)
136 { 138 {
139 std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock());
140
137 ScenePoint2D scenePos = e.GetMainPosition().Apply( 141 ScenePoint2D scenePos = e.GetMainPosition().Apply(
138 GetController()->GetScene().GetCanvasToSceneTransform()); 142 lock->GetScene().GetCanvasToSceneTransform());
139 143
140 if (!HitTest(scenePos)) 144 if (!HitTest(scenePos))
141 return boost::shared_ptr<IFlexiblePointerTracker>(); 145 return boost::shared_ptr<IFlexiblePointerTracker>();
142 146
143 /** 147 /**
174 { 178 {
175 if (IsSceneAlive()) 179 if (IsSceneAlive())
176 { 180 {
177 if (IsEnabled()) 181 if (IsEnabled())
178 { 182 {
183 std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock());
184
179 layerHolder_->CreateLayersIfNeeded(); 185 layerHolder_->CreateLayersIfNeeded();
180 186
181 { 187 {
182 // Fill the polyline layer with the measurement line 188 // Fill the polyline layer with the measurement line
183 189
184 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0); 190 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0);
185 polylineLayer->ClearAllChains(); 191 if (polylineLayer)
186
187 const Color color(TOOL_LINES_COLOR_RED,
188 TOOL_LINES_COLOR_GREEN,
189 TOOL_LINES_COLOR_BLUE);
190
191 const Color highlightColor(TOOL_LINES_HL_COLOR_RED,
192 TOOL_LINES_HL_COLOR_GREEN,
193 TOOL_LINES_HL_COLOR_BLUE);
194
195 { 192 {
196 PolylineSceneLayer::Chain chain; 193 polylineLayer->ClearAllChains();
197 chain.push_back(start_); 194
198 chain.push_back(end_); 195 const Color color(TOOL_LINES_COLOR_RED,
199 if(lineHighlightArea_ == LineHighlightArea_Segment) 196 TOOL_LINES_COLOR_GREEN,
200 polylineLayer->AddChain(chain, false, highlightColor); 197 TOOL_LINES_COLOR_BLUE);
201 else 198
202 polylineLayer->AddChain(chain, false, color); 199 const Color highlightColor(TOOL_LINES_HL_COLOR_RED,
203 } 200 TOOL_LINES_HL_COLOR_GREEN,
204 201 TOOL_LINES_HL_COLOR_BLUE);
205 // handles 202
206 {
207 { 203 {
208 PolylineSceneLayer::Chain chain; 204 PolylineSceneLayer::Chain chain;
209 205 chain.push_back(start_);
210 //TODO: take DPI into account 206 chain.push_back(end_);
211 AddSquare(chain, GetController()->GetScene(), start_, 207 if(lineHighlightArea_ == LineHighlightArea_Segment)
212 GetController()->GetHandleSideLengthS()); 208 polylineLayer->AddChain(chain, false, highlightColor);
213
214 if (lineHighlightArea_ == LineHighlightArea_Start)
215 polylineLayer->AddChain(chain, true, highlightColor);
216 else 209 else
217 polylineLayer->AddChain(chain, true, color); 210 polylineLayer->AddChain(chain, false, color);
218 } 211 }
219 212
213 // handles
220 { 214 {
221 PolylineSceneLayer::Chain chain; 215 {
222 216 PolylineSceneLayer::Chain chain;
223 //TODO: take DPI into account 217
224 AddSquare(chain, GetController()->GetScene(), end_, 218 //TODO: take DPI into account
225 GetController()->GetHandleSideLengthS()); 219 AddSquare(chain, lock->GetScene(), start_,
226 220 GetController()->GetHandleSideLengthS());
227 if (lineHighlightArea_ == LineHighlightArea_End) 221
228 polylineLayer->AddChain(chain, true, highlightColor); 222 if (lineHighlightArea_ == LineHighlightArea_Start)
229 else 223 polylineLayer->AddChain(chain, true, highlightColor);
230 polylineLayer->AddChain(chain, true, color); 224 else
225 polylineLayer->AddChain(chain, true, color);
226 }
227
228 {
229 PolylineSceneLayer::Chain chain;
230
231 //TODO: take DPI into account
232 AddSquare(chain, lock->GetScene(), end_,
233 GetController()->GetHandleSideLengthS());
234
235 if (lineHighlightArea_ == LineHighlightArea_End)
236 polylineLayer->AddChain(chain, true, highlightColor);
237 else
238 polylineLayer->AddChain(chain, true, color);
239 }
231 } 240 }
232 } 241 }
233
234 } 242 }
235 { 243 {
236 // Set the text layer propreties 244 // Set the text layer propreties
237 double deltaX = end_.GetX() - start_.GetX(); 245 double deltaX = end_.GetX() - start_.GetX();
238 double deltaY = end_.GetY() - start_.GetY(); 246 double deltaY = end_.GetY() - start_.GetY();
246 double midX = 0.5 * (end_.GetX() + start_.GetX()); 254 double midX = 0.5 * (end_.GetX() + start_.GetX());
247 double midY = 0.5 * (end_.GetY() + start_.GetY()); 255 double midY = 0.5 * (end_.GetY() + start_.GetY());
248 256
249 #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1 257 #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1
250 SetTextLayerOutlineProperties( 258 SetTextLayerOutlineProperties(
251 GetController()->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0); 259 lock->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0);
252 #else 260 #else
253 SetTextLayerProperties( 261 SetTextLayerProperties(
254 GetController()->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0); 262 lock->GetScene(), layerHolder_, buf, ScenePoint2D(midX, midY), 0);
255 #endif 263 #endif
256 } 264 }
257 } 265 }
258 else 266 else
259 { 267 {