comparison Framework/Scene2DViewport/AngleMeasureTool.cpp @ 774:66ac7a2d1e3a

A few renames and cleanups + moved GUI constants to controller + start work on hit tests for measure tools and mouse hover.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 24 May 2019 15:59:51 +0200
parents 712ff6ff3c19
children 61ba4b504e9a
comparison
equal deleted inserted replaced
761:07adcffba38c 774:66ac7a2d1e3a
73 { 73 {
74 side2End_ = pt; 74 side2End_ = pt;
75 RefreshScene(); 75 RefreshScene();
76 } 76 }
77 77
78
79 bool AngleMeasureTool::HitTest(ScenePoint2D p) const
80 {
81 throw std::logic_error("The method or operation is not implemented.");
82 }
83
78 void AngleMeasureTool::SetCenter(ScenePoint2D pt) 84 void AngleMeasureTool::SetCenter(ScenePoint2D pt)
79 { 85 {
80 center_ = pt; 86 center_ = pt;
81 RefreshScene(); 87 RefreshScene();
82 } 88 }
83 89
84 void AngleMeasureTool::RefreshScene() 90 void AngleMeasureTool::RefreshScene()
85 { 91 {
86 if (IsSceneAlive()) 92 if (IsSceneAlive())
87 { 93 {
94 ViewportControllerPtr controller = GetController();
88 if (IsEnabled()) 95 if (IsEnabled())
89 { 96 {
90 // get the scaling factor
91 const double pixelToScene =
92 GetScene()->GetCanvasToSceneTransform().ComputeZoom();
93
94 layerHolder_->CreateLayersIfNeeded(); 97 layerHolder_->CreateLayersIfNeeded();
95 98
96 { 99 {
97 // Fill the polyline layer with the measurement lines 100 // Fill the polyline layer with the measurement lines
98 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0); 101 PolylineSceneLayer* polylineLayer = layerHolder_->GetPolylineLayer(0);
119 // Create the handles 122 // Create the handles
120 { 123 {
121 { 124 {
122 PolylineSceneLayer::Chain chain; 125 PolylineSceneLayer::Chain chain;
123 //TODO: take DPI into account 126 //TODO: take DPI into account
124 AddSquare(chain, GetScene(), side1End_, 10.0 * pixelToScene); 127 AddSquare(chain, GetScene(), side1End_,
128 GetController()->GetHandleSideLengthS());
125 polylineLayer->AddChain(chain, true); 129 polylineLayer->AddChain(chain, true);
126 } 130 }
127 { 131 {
128 PolylineSceneLayer::Chain chain; 132 PolylineSceneLayer::Chain chain;
129 //TODO: take DPI into account 133 //TODO: take DPI into account
130 AddSquare(chain, GetScene(), side2End_, 10.0 * pixelToScene); 134 AddSquare(chain, GetScene(), side2End_,
135 GetController()->GetHandleSideLengthS());
131 polylineLayer->AddChain(chain, true); 136 polylineLayer->AddChain(chain, true);
132 } 137 }
133 } 138 }
134 139
135 // Create the arc 140 // Create the arc
136 { 141 {
137 PolylineSceneLayer::Chain chain; 142 PolylineSceneLayer::Chain chain;
138 143
139 const double ARC_RADIUS_CANVAS_COORD = 30.0;
140 AddShortestArc(chain, side1End_, center_, side2End_, 144 AddShortestArc(chain, side1End_, center_, side2End_,
141 ARC_RADIUS_CANVAS_COORD * pixelToScene); 145 controller->GetAngleToolArcRadiusS());
142 polylineLayer->AddChain(chain, false); 146 polylineLayer->AddChain(chain, false);
143 } 147 }
144 } 148 }
145 { 149 {
146 // Set the text layer 150 // Set the text layer
154 side2End_.GetX() - center_.GetX()); 158 side2End_.GetX() - center_.GetX());
155 159
156 double delta = NormalizeAngle(p2cAngle - p1cAngle); 160 double delta = NormalizeAngle(p2cAngle - p1cAngle);
157 double theta = p1cAngle + delta / 2; 161 double theta = p1cAngle + delta / 2;
158 162
159 const double TEXT_CENTER_DISTANCE_CANVAS_COORD = 90; 163 double ox = controller->GetAngleTopTextLabelDistanceS() * cos(theta);
160 164 double oy = controller->GetAngleTopTextLabelDistanceS() * sin(theta);
161 double offsetX = TEXT_CENTER_DISTANCE_CANVAS_COORD * cos(theta); 165
162 double offsetY = TEXT_CENTER_DISTANCE_CANVAS_COORD * sin(theta); 166 double pointX = center_.GetX() + ox;
163 167 double pointY = center_.GetY() + oy;
164 double pointX = center_.GetX() + offsetX * pixelToScene;
165 double pointY = center_.GetY() + offsetY * pixelToScene;
166 168
167 char buf[64]; 169 char buf[64];
168 double angleDeg = RadiansToDegrees(delta); 170 double angleDeg = RadiansToDegrees(delta);
169 171
170 // http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00B0&mode=hex 172 // http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00B0&mode=hex
205 boost::lexical_cast<std::string>(RadiansToDegrees(theta))); 207 boost::lexical_cast<std::string>(RadiansToDegrees(theta)));
206 208
207 TrackerSample_SetInfoDisplayMessage("p2cAngle (deg)", 209 TrackerSample_SetInfoDisplayMessage("p2cAngle (deg)",
208 boost::lexical_cast<std::string>(RadiansToDegrees(p2cAngle))); 210 boost::lexical_cast<std::string>(RadiansToDegrees(p2cAngle)));
209 211
210 TrackerSample_SetInfoDisplayMessage("offsetX (pix)", 212 TrackerSample_SetInfoDisplayMessage("ox (scene)",
211 boost::lexical_cast<std::string>(offsetX)); 213 boost::lexical_cast<std::string>(ox));
212 214
213 TrackerSample_SetInfoDisplayMessage("offsetY (pix)", 215 TrackerSample_SetInfoDisplayMessage("offsetY (scene)",
214 boost::lexical_cast<std::string>(offsetY)); 216 boost::lexical_cast<std::string>(oy));
215 217
216 TrackerSample_SetInfoDisplayMessage("pointX", 218 TrackerSample_SetInfoDisplayMessage("pointX",
217 boost::lexical_cast<std::string>(pointX)); 219 boost::lexical_cast<std::string>(pointX));
218 220
219 TrackerSample_SetInfoDisplayMessage("pointY", 221 TrackerSample_SetInfoDisplayMessage("pointY",