Mercurial > hg > orthanc-stone
comparison Framework/Scene2DViewport/AngleMeasureTool.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 |
---|---|
129 SetAngleHighlightArea(angleHighlightArea); | 129 SetAngleHighlightArea(angleHighlightArea); |
130 } | 130 } |
131 | 131 |
132 AngleMeasureTool::AngleHighlightArea AngleMeasureTool::AngleHitTest(ScenePoint2D p) const | 132 AngleMeasureTool::AngleHighlightArea AngleMeasureTool::AngleHitTest(ScenePoint2D p) const |
133 { | 133 { |
134 std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock()); | |
135 | |
134 const double pixelToScene = | 136 const double pixelToScene = |
135 GetController()->GetScene().GetCanvasToSceneTransform().ComputeZoom(); | 137 lock->GetScene().GetCanvasToSceneTransform().ComputeZoom(); |
136 const double SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD = pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD * pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD; | 138 const double SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD = pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD * pixelToScene * HIT_TEST_MAX_DISTANCE_CANVAS_COORD; |
137 | 139 |
138 { | 140 { |
139 const double sqDistanceFromSide1End = ScenePoint2D::SquaredDistancePtPt(p, side1End_); | 141 const double sqDistanceFromSide1End = ScenePoint2D::SquaredDistancePtPt(p, side1End_); |
140 if (sqDistanceFromSide1End <= SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD) | 142 if (sqDistanceFromSide1End <= SQUARED_HIT_TEST_MAX_DISTANCE_SCENE_COORD) |
174 } | 176 } |
175 | 177 |
176 | 178 |
177 boost::shared_ptr<IFlexiblePointerTracker> AngleMeasureTool::CreateEditionTracker(const PointerEvent& e) | 179 boost::shared_ptr<IFlexiblePointerTracker> AngleMeasureTool::CreateEditionTracker(const PointerEvent& e) |
178 { | 180 { |
181 std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock()); | |
182 | |
179 ScenePoint2D scenePos = e.GetMainPosition().Apply( | 183 ScenePoint2D scenePos = e.GetMainPosition().Apply( |
180 GetController()->GetScene().GetCanvasToSceneTransform()); | 184 lock->GetScene().GetCanvasToSceneTransform()); |
181 | 185 |
182 if (!HitTest(scenePos)) | 186 if (!HitTest(scenePos)) |
183 return boost::shared_ptr<IFlexiblePointerTracker>(); | 187 return boost::shared_ptr<IFlexiblePointerTracker>(); |
184 | 188 |
185 /** | 189 /** |
206 if (IsSceneAlive()) | 210 if (IsSceneAlive()) |
207 { | 211 { |
208 boost::shared_ptr<ViewportController> controller = GetController(); | 212 boost::shared_ptr<ViewportController> controller = GetController(); |
209 if (IsEnabled()) | 213 if (IsEnabled()) |
210 { | 214 { |
215 std::auto_ptr<IViewport::ILock> lock(GetController()->GetViewport().Lock()); | |
216 | |
211 layerHolder_->CreateLayersIfNeeded(); | 217 layerHolder_->CreateLayersIfNeeded(); |
212 | 218 |
213 { | 219 { |
214 // Fill the polyline layer with the measurement lines | 220 // Fill the polyline layer with the measurement lines |
215 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0); | 221 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0); |
216 polylineLayer->ClearAllChains(); | 222 if (polylineLayer) |
217 | |
218 const Color color(TOOL_ANGLE_LINES_COLOR_RED, TOOL_ANGLE_LINES_COLOR_GREEN, TOOL_ANGLE_LINES_COLOR_BLUE); | |
219 const Color highlightColor(TOOL_ANGLE_LINES_HL_COLOR_RED, TOOL_ANGLE_LINES_HL_COLOR_GREEN, TOOL_ANGLE_LINES_HL_COLOR_BLUE); | |
220 | |
221 // sides | |
222 { | 223 { |
224 polylineLayer->ClearAllChains(); | |
225 | |
226 const Color color(TOOL_ANGLE_LINES_COLOR_RED, TOOL_ANGLE_LINES_COLOR_GREEN, TOOL_ANGLE_LINES_COLOR_BLUE); | |
227 const Color highlightColor(TOOL_ANGLE_LINES_HL_COLOR_RED, TOOL_ANGLE_LINES_HL_COLOR_GREEN, TOOL_ANGLE_LINES_HL_COLOR_BLUE); | |
228 | |
229 // sides | |
230 { | |
231 { | |
232 PolylineSceneLayer::Chain chain; | |
233 chain.push_back(side1End_); | |
234 chain.push_back(center_); | |
235 | |
236 if ((angleHighlightArea_ == AngleHighlightArea_Side1) || (angleHighlightArea_ == AngleHighlightArea_Side2)) | |
237 polylineLayer->AddChain(chain, false, highlightColor); | |
238 else | |
239 polylineLayer->AddChain(chain, false, color); | |
240 } | |
241 { | |
242 PolylineSceneLayer::Chain chain; | |
243 chain.push_back(side2End_); | |
244 chain.push_back(center_); | |
245 if ((angleHighlightArea_ == AngleHighlightArea_Side1) || (angleHighlightArea_ == AngleHighlightArea_Side2)) | |
246 polylineLayer->AddChain(chain, false, highlightColor); | |
247 else | |
248 polylineLayer->AddChain(chain, false, color); | |
249 } | |
250 } | |
251 | |
252 // Create the handles | |
253 { | |
254 { | |
255 PolylineSceneLayer::Chain chain; | |
256 //TODO: take DPI into account | |
257 AddSquare(chain, lock->GetScene(), side1End_, | |
258 GetController()->GetHandleSideLengthS()); | |
259 | |
260 if (angleHighlightArea_ == AngleHighlightArea_Side1End) | |
261 polylineLayer->AddChain(chain, true, highlightColor); | |
262 else | |
263 polylineLayer->AddChain(chain, true, color); | |
264 | |
265 } | |
266 { | |
267 PolylineSceneLayer::Chain chain; | |
268 //TODO: take DPI into account | |
269 AddSquare(chain, lock->GetScene(), side2End_, | |
270 GetController()->GetHandleSideLengthS()); | |
271 | |
272 if (angleHighlightArea_ == AngleHighlightArea_Side2End) | |
273 polylineLayer->AddChain(chain, true, highlightColor); | |
274 else | |
275 polylineLayer->AddChain(chain, true, color); | |
276 } | |
277 } | |
278 | |
279 // Create the arc | |
223 { | 280 { |
224 PolylineSceneLayer::Chain chain; | 281 PolylineSceneLayer::Chain chain; |
225 chain.push_back(side1End_); | 282 |
226 chain.push_back(center_); | 283 AddShortestArc(chain, side1End_, center_, side2End_, |
227 | 284 controller->GetAngleToolArcRadiusS()); |
228 if ((angleHighlightArea_ == AngleHighlightArea_Side1) || (angleHighlightArea_ == AngleHighlightArea_Side2)) | 285 if (angleHighlightArea_ == AngleHighlightArea_Center) |
229 polylineLayer->AddChain(chain, false, highlightColor); | |
230 else | |
231 polylineLayer->AddChain(chain, false, color); | |
232 } | |
233 { | |
234 PolylineSceneLayer::Chain chain; | |
235 chain.push_back(side2End_); | |
236 chain.push_back(center_); | |
237 if ((angleHighlightArea_ == AngleHighlightArea_Side1) || (angleHighlightArea_ == AngleHighlightArea_Side2)) | |
238 polylineLayer->AddChain(chain, false, highlightColor); | 286 polylineLayer->AddChain(chain, false, highlightColor); |
239 else | 287 else |
240 polylineLayer->AddChain(chain, false, color); | 288 polylineLayer->AddChain(chain, false, color); |
241 } | 289 } |
242 } | 290 } |
243 | |
244 // Create the handles | |
245 { | |
246 { | |
247 PolylineSceneLayer::Chain chain; | |
248 //TODO: take DPI into account | |
249 AddSquare(chain, GetController()->GetScene(), side1End_, | |
250 GetController()->GetHandleSideLengthS()); | |
251 | |
252 if (angleHighlightArea_ == AngleHighlightArea_Side1End) | |
253 polylineLayer->AddChain(chain, true, highlightColor); | |
254 else | |
255 polylineLayer->AddChain(chain, true, color); | |
256 | |
257 } | |
258 { | |
259 PolylineSceneLayer::Chain chain; | |
260 //TODO: take DPI into account | |
261 AddSquare(chain, GetController()->GetScene(), side2End_, | |
262 GetController()->GetHandleSideLengthS()); | |
263 | |
264 if (angleHighlightArea_ == AngleHighlightArea_Side2End) | |
265 polylineLayer->AddChain(chain, true, highlightColor); | |
266 else | |
267 polylineLayer->AddChain(chain, true, color); | |
268 } | |
269 } | |
270 | |
271 // Create the arc | |
272 { | |
273 PolylineSceneLayer::Chain chain; | |
274 | |
275 AddShortestArc(chain, side1End_, center_, side2End_, | |
276 controller->GetAngleToolArcRadiusS()); | |
277 if (angleHighlightArea_ == AngleHighlightArea_Center) | |
278 polylineLayer->AddChain(chain, false, highlightColor); | |
279 else | |
280 polylineLayer->AddChain(chain, false, color); | |
281 } | |
282 } | 291 } |
283 { | 292 { |
284 // Set the text layer | 293 // Set the text layer |
285 | 294 |
286 double p1cAngle = atan2( | 295 double p1cAngle = atan2( |
306 // http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00B0&mode=hex | 315 // http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00B0&mode=hex |
307 sprintf(buf, "%0.02f\xc2\xb0", angleDeg); | 316 sprintf(buf, "%0.02f\xc2\xb0", angleDeg); |
308 | 317 |
309 #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1 | 318 #if ORTHANC_STONE_ENABLE_OUTLINED_TEXT == 1 |
310 SetTextLayerOutlineProperties( | 319 SetTextLayerOutlineProperties( |
311 GetController()->GetScene(), layerHolder_, buf, ScenePoint2D(pointX, pointY), 0); | 320 lock->GetScene(), layerHolder_, buf, ScenePoint2D(pointX, pointY), 0); |
312 #else | 321 #else |
313 SetTextLayerProperties( | 322 SetTextLayerProperties( |
314 GetController()->GetScene(), layerHolder_, buf, ScenePoint2D(pointX, pointY) , 0); | 323 lock->GetScene(), layerHolder_, buf, ScenePoint2D(pointX, pointY) , 0); |
315 #endif | 324 #endif |
316 | 325 |
317 #if 0 | 326 #if 0 |
318 // TODO:make it togglable | 327 // TODO:make it togglable |
319 bool enableInfoDisplay = true; | 328 bool enableInfoDisplay = true; |