comparison Framework/Scene2DViewport/LineMeasureTool.cpp @ 722:28b9e3a54200

Undo mechanism implemented (not connected to UI yet). Undo stack and measuring tools are now handled by the ViewportController. Multi-touch does not crash trackers anymore.
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 21 May 2019 10:27:54 +0200
parents 8b6adfb62a2f
children 712ff6ff3c19
comparison
equal deleted inserted replaced
721:af0aa0c149fa 722:28b9e3a54200
83 return concreteLayer; 83 return concreteLayer;
84 } 84 }
85 85
86 void LineMeasureTool::RefreshScene() 86 void LineMeasureTool::RefreshScene()
87 { 87 {
88 if (IsEnabled()) 88 if (IsSceneAlive())
89 { 89 {
90 if (!layersCreated) 90 if (IsEnabled())
91 { 91 {
92 // Create the layers if need be 92 if (!layersCreated)
93 93 {
94 assert(textZIndex_ == -1); 94 // Create the layers if need be
95 { 95
96 polylineZIndex_ = GetScene()->GetMaxDepth() + 100; 96 assert(textZIndex_ == -1);
97 //LOG(INFO) << "set polylineZIndex_ to: " << polylineZIndex_; 97 {
98 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer()); 98 polylineZIndex_ = GetScene()->GetMaxDepth() + 100;
99 GetScene()->SetLayer(polylineZIndex_, layer.release()); 99 //LOG(INFO) << "set polylineZIndex_ to: " << polylineZIndex_;
100 } 100 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer());
101 { 101 GetScene()->SetLayer(polylineZIndex_, layer.release());
102 textZIndex_ = GetScene()->GetMaxDepth() + 100; 102 }
103 //LOG(INFO) << "set textZIndex_ to: " << textZIndex_; 103 {
104 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer()); 104 textZIndex_ = GetScene()->GetMaxDepth() + 100;
105 GetScene()->SetLayer(textZIndex_, layer.release()); 105 //LOG(INFO) << "set textZIndex_ to: " << textZIndex_;
106 } 106 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer());
107 layersCreated = true; 107 GetScene()->SetLayer(textZIndex_, layer.release());
108 }
109 layersCreated = true;
110 }
111 else
112 {
113 assert(GetScene()->HasLayer(polylineZIndex_));
114 assert(GetScene()->HasLayer(textZIndex_));
115 }
116 {
117 // Fill the polyline layer with the measurement line
118
119 PolylineSceneLayer* polylineLayer = GetPolylineLayer();
120 polylineLayer->ClearAllChains();
121 polylineLayer->SetColor(0, 223, 21);
122
123 {
124 PolylineSceneLayer::Chain chain;
125 chain.push_back(start_);
126 chain.push_back(end_);
127 polylineLayer->AddChain(chain, false);
128 }
129
130 // handles
131 {
132 //void AddSquare(PolylineSceneLayer::Chain& chain,const Scene2D& scene,const ScenePoint2D& centerS,const double& sideLength)
133
134 {
135 PolylineSceneLayer::Chain chain;
136 AddSquare(chain, *GetScene(), start_, 10.0); //TODO: take DPI into account
137 polylineLayer->AddChain(chain, true);
138 }
139
140 {
141 PolylineSceneLayer::Chain chain;
142 AddSquare(chain, *GetScene(), end_, 10.0); //TODO: take DPI into account
143 polylineLayer->AddChain(chain, true);
144 }
145
146 //ScenePoint2D startC = start_.Apply(GetScene()->GetSceneToCanvasTransform());
147 //double squareSize = 10.0;
148 //double startHandleLX = startC.GetX() - squareSize/2;
149 //double startHandleTY = startC.GetY() - squareSize / 2;
150 //double startHandleRX = startC.GetX() + squareSize / 2;
151 //double startHandleBY = startC.GetY() + squareSize / 2;
152 //ScenePoint2D startLTC(startHandleLX, startHandleTY);
153 //ScenePoint2D startRTC(startHandleRX, startHandleTY);
154 //ScenePoint2D startRBC(startHandleRX, startHandleBY);
155 //ScenePoint2D startLBC(startHandleLX, startHandleBY);
156
157 //ScenePoint2D startLT = startLTC.Apply(GetScene()->GetCanvasToSceneTransform());
158 //ScenePoint2D startRT = startRTC.Apply(GetScene()->GetCanvasToSceneTransform());
159 //ScenePoint2D startRB = startRBC.Apply(GetScene()->GetCanvasToSceneTransform());
160 //ScenePoint2D startLB = startLBC.Apply(GetScene()->GetCanvasToSceneTransform());
161
162 //PolylineSceneLayer::Chain chain;
163 //chain.push_back(startLT);
164 //chain.push_back(startRT);
165 //chain.push_back(startRB);
166 //chain.push_back(startLB);
167 //polylineLayer->AddChain(chain, true);
168 }
169
170 }
171 {
172 // Set the text layer proporeties
173
174 TextSceneLayer* textLayer = GetTextLayer();
175 double deltaX = end_.GetX() - start_.GetX();
176 double deltaY = end_.GetY() - start_.GetY();
177 double squareDist = deltaX * deltaX + deltaY * deltaY;
178 double dist = sqrt(squareDist);
179 char buf[64];
180 sprintf(buf, "%0.02f units", dist);
181 textLayer->SetText(buf);
182 textLayer->SetColor(0, 223, 21);
183
184 // TODO: for now we simply position the text overlay at the middle
185 // of the measuring segment
186 double midX = 0.5 * (end_.GetX() + start_.GetX());
187 double midY = 0.5 * (end_.GetY() + start_.GetY());
188 textLayer->SetPosition(midX, midY);
189 }
108 } 190 }
109 else 191 else
110 { 192 {
111 assert(GetScene()->HasLayer(polylineZIndex_)); 193 if (layersCreated)
112 assert(GetScene()->HasLayer(textZIndex_)); 194 {
113 } 195 RemoveFromScene();
114 { 196 layersCreated = false;
115 // Fill the polyline layer with the measurement line 197 }
116
117 PolylineSceneLayer* polylineLayer = GetPolylineLayer();
118 polylineLayer->ClearAllChains();
119 polylineLayer->SetColor(0, 223, 21);
120
121 {
122 PolylineSceneLayer::Chain chain;
123 chain.push_back(start_);
124 chain.push_back(end_);
125 polylineLayer->AddChain(chain, false);
126 }
127
128 // handles
129 {
130 //void AddSquare(PolylineSceneLayer::Chain& chain,const Scene2D& scene,const ScenePoint2D& centerS,const double& sideLength)
131
132 {
133 PolylineSceneLayer::Chain chain;
134 AddSquare(chain, *GetScene(), start_, 10.0); //TODO: take DPI into account
135 polylineLayer->AddChain(chain, true);
136 }
137
138 {
139 PolylineSceneLayer::Chain chain;
140 AddSquare(chain, *GetScene(), end_, 10.0); //TODO: take DPI into account
141 polylineLayer->AddChain(chain, true);
142 }
143
144 //ScenePoint2D startC = start_.Apply(GetScene()->GetSceneToCanvasTransform());
145 //double squareSize = 10.0;
146 //double startHandleLX = startC.GetX() - squareSize/2;
147 //double startHandleTY = startC.GetY() - squareSize / 2;
148 //double startHandleRX = startC.GetX() + squareSize / 2;
149 //double startHandleBY = startC.GetY() + squareSize / 2;
150 //ScenePoint2D startLTC(startHandleLX, startHandleTY);
151 //ScenePoint2D startRTC(startHandleRX, startHandleTY);
152 //ScenePoint2D startRBC(startHandleRX, startHandleBY);
153 //ScenePoint2D startLBC(startHandleLX, startHandleBY);
154
155 //ScenePoint2D startLT = startLTC.Apply(GetScene()->GetCanvasToSceneTransform());
156 //ScenePoint2D startRT = startRTC.Apply(GetScene()->GetCanvasToSceneTransform());
157 //ScenePoint2D startRB = startRBC.Apply(GetScene()->GetCanvasToSceneTransform());
158 //ScenePoint2D startLB = startLBC.Apply(GetScene()->GetCanvasToSceneTransform());
159
160 //PolylineSceneLayer::Chain chain;
161 //chain.push_back(startLT);
162 //chain.push_back(startRT);
163 //chain.push_back(startRB);
164 //chain.push_back(startLB);
165 //polylineLayer->AddChain(chain, true);
166 }
167
168 }
169 {
170 // Set the text layer proporeties
171
172 TextSceneLayer* textLayer = GetTextLayer();
173 double deltaX = end_.GetX() - start_.GetX();
174 double deltaY = end_.GetY() - start_.GetY();
175 double squareDist = deltaX * deltaX + deltaY * deltaY;
176 double dist = sqrt(squareDist);
177 char buf[64];
178 sprintf(buf, "%0.02f units", dist);
179 textLayer->SetText(buf);
180 textLayer->SetColor(0, 223, 21);
181
182 // TODO: for now we simply position the text overlay at the middle
183 // of the measuring segment
184 double midX = 0.5*(end_.GetX() + start_.GetX());
185 double midY = 0.5*(end_.GetY() + start_.GetY());
186 textLayer->SetPosition(midX, midY);
187 } 198 }
188 } 199 }
189 else 200 }
190 {
191 if (layersCreated)
192 {
193 RemoveFromScene();
194 layersCreated = false;
195 }
196 }
197 }
198
199
200 } 201 }