Mercurial > hg > orthanc-stone
diff Samples/Sdl/TrackerSampleApp.cpp @ 761:07adcffba38c
truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
shortcut: 'm')
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Thu, 23 May 2019 10:25:48 +0200 |
parents | 92c400a09f1b |
children | 1a28fce57ff3 |
line wrap: on
line diff
--- a/Samples/Sdl/TrackerSampleApp.cpp Wed May 22 18:34:06 2019 +0200 +++ b/Samples/Sdl/TrackerSampleApp.cpp Thu May 23 10:25:48 2019 +0200 @@ -71,6 +71,11 @@ return controller_->GetScene(); } + Scene2DConstPtr TrackerSampleApp::GetScene() const + { + return controller_->GetScene(); + } + void TrackerSampleApp::SelectNextTool() { currentTool_ = static_cast<GuiTool>(currentTool_ + 1); @@ -153,15 +158,76 @@ GetScene()->DeleteLayer(FLOATING_INFOTEXT_LAYER_ZINDEX); } + ScenePoint2D TrackerSampleApp::GetRandomPointInScene() const + { + unsigned int w = compositor_->GetCanvasWidth(); + LOG(TRACE) << "compositor_->GetCanvasWidth() = " << + compositor_->GetCanvasWidth(); + unsigned int h = compositor_->GetCanvasHeight(); + LOG(TRACE) << "compositor_->GetCanvasHeight() = " << + compositor_->GetCanvasHeight(); + + if ((w >= RAND_MAX) || (h >= RAND_MAX)) + LOG(WARNING) << "Canvas is too big : tools will not be randomly placed"; + + int x = rand() % w; + int y = rand() % h; + LOG(TRACE) << "random x = " << x << "random y = " << y; + + ScenePoint2D p = compositor_->GetPixelCenterCoordinates(x, y); + LOG(TRACE) << "--> p.GetX() = " << p.GetX() << " p.GetY() = " << p.GetY(); + + ScenePoint2D r = p.Apply(GetScene()->GetCanvasToSceneTransform()); + LOG(TRACE) << "--> r.GetX() = " << r.GetX() << " r.GetY() = " << r.GetY(); + return r; + } + + void TrackerSampleApp::CreateRandomMeasureTool() + { + static bool srandCalled = false; + if (!srandCalled) + { + srand(42); + srandCalled = true; + } + + int i = rand() % 2; + LOG(TRACE) << "random i = " << i; + switch (i) + { + case 0: + // line measure + { + CreateLineMeasureCommandPtr cmd = + boost::make_shared<CreateLineMeasureCommand>( + IObserver::GetBroker(), + controller_, + GetRandomPointInScene()); + cmd->SetEnd(GetRandomPointInScene()); + controller_->PushCommand(cmd); + } + break; + case 1: + // angle measure + { + CreateAngleMeasureCommandPtr cmd = + boost::make_shared<CreateAngleMeasureCommand>( + IObserver::GetBroker(), + controller_, + GetRandomPointInScene()); + cmd->SetCenter(GetRandomPointInScene()); + cmd->SetSide2End(GetRandomPointInScene()); + controller_->PushCommand(cmd); + } + break; + } + } + void TrackerSampleApp::HandleApplicationEvent( const SDL_Event & event) { DisplayInfoText(); - // we seed the random number generator for random measure tool - // generation - srand(42); - if (event.type == SDL_MOUSEMOTION) { int scancodeCount = 0; @@ -192,8 +258,8 @@ //LOG(TRACE) << "event.button.x = " << event.button.x << " " << // "event.button.y = " << event.button.y; - //LOG(TRACE) << "activeTracker_->PointerMove(e); " << - // e.GetMainPosition().GetX() << " " << e.GetMainPosition().GetY(); + LOG(TRACE) << "activeTracker_->PointerMove(e); " << + e.GetMainPosition().GetX() << " " << e.GetMainPosition().GetY(); activeTracker_->PointerMove(e); if (!activeTracker_->IsAlive()) @@ -254,22 +320,20 @@ break; case SDLK_m: - // let's create a random measuring tool - - - + CreateRandomMeasureTool(); + break; case SDLK_s: controller_->FitContent(compositor_->GetCanvasWidth(), compositor_->GetCanvasHeight()); break; case SDLK_z: - LOG(INFO) << "SDLK_z has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; + LOG(TRACE) << "SDLK_z has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; if (event.key.keysym.mod & KMOD_CTRL) { if (controller_->CanUndo()) { - LOG(INFO) << "Undoing..."; + LOG(TRACE) << "Undoing..."; controller_->Undo(); } else @@ -280,12 +344,12 @@ break; case SDLK_y: - LOG(INFO) << "SDLK_y has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; + LOG(TRACE) << "SDLK_y has been pressed. event.key.keysym.mod == " << event.key.keysym.mod; if (event.key.keysym.mod & KMOD_CTRL) { if (controller_->CanRedo()) { - LOG(INFO) << "Redoing..."; + LOG(TRACE) << "Redoing..."; controller_->Redo(); } else