~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/main/toolsystem/toolcontroller.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-10-24 21:28:17 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131024212817-ej1skb9og09d3ht6
Tags: 3.5.0.1137.31+dfsg-1
New upstream release [October 2013]

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  $Id: toolcontroller.cpp $
4
4
 *  Ginkgo CADx Project
5
5
 *
6
 
 *  Copyright 2008-12 MetaEmotion S.L. All rights reserved.
 
6
 *  Copyright 2008-14 MetaEmotion S.L. All rights reserved.
7
7
 *  http://ginkgo-cadx.com
8
8
 *
9
9
 *  This file is licensed under LGPL v3 license.
24
24
#include <api/toolsystem/itoolsregistry.h>
25
25
#include <api/controllers/icontroladorlog.h>
26
26
#include <api/controllers/ieventscontroller.h>
27
 
#include <eventos/toolevents.h>
 
27
#include <eventos/toolevents.h>
28
28
#include <api/icontract.h>
29
29
#include <api/ientorno.h>
30
30
 
 
31
#include <wx/aui/auibar.h>
 
32
 
31
33
namespace GNC {
32
34
        namespace GUI {
33
35
                const wxEventType wxEVT_ACTIVATE_TOOL_ASYNC = wxNewEventType();
200
202
 
201
203
void GNC::ToolController::AddTool(long idTool, GNC::GCS::IContract* pContract)
202
204
{
203
 
        GNC::GCS::ITool* pTool = GNC::GCS::IToolsRegistry::Instance()->NewTool(idTool);
204
 
        if (pTool != NULL && pTool->IsReady()) {
205
 
                GNC::GCS::IContractable* pContractableTool = dynamic_cast<GNC::GCS::IContractable*>(pTool);
206
 
                if (pContractableTool) {
207
 
                        if (pContractableTool->IsValidContract(pContract)) {                            
208
 
                                pContractableTool->Register(pContract);
209
 
                        }
210
 
                        else {
211
 
                                LOG_WARN("ToolControler", "The tool \"" << pTool->Name.c_str() << "\" is not compatible with the specified contract");
212
 
                                return;
213
 
                        }
214
 
                }
215
 
                pTool->SetToolBar(this);
216
 
                m_tools[idTool] = pTool;
 
205
        GNC::GCS::ITool* pTool = GNC::GCS::IToolsRegistry::Instance()->NewTool(idTool);
 
206
        if (pTool != NULL && pTool->IsReady()) {
 
207
                GNC::GCS::IContractable* pContractableTool = dynamic_cast<GNC::GCS::IContractable*>(pTool);
 
208
                if (pContractableTool) {
 
209
                        if (pContractableTool->IsValidContract(pContract)) {                            
 
210
                                pContractableTool->Register(pContract);
 
211
                        }
 
212
                        else {
 
213
                                LOG_WARN("ToolControler", "The tool \"" << pTool->Name.c_str() << "\" is not compatible with the specified contract");
 
214
                                return;
 
215
                        }
 
216
                }
 
217
                pTool->SetToolBar(this);
 
218
                m_tools[idTool] = pTool;
217
219
        } else if (pTool != NULL) {
218
220
                delete pTool;
219
221
        }
249
251
        if (!alignLeft) {
250
252
                pToolController->AddStretchSpacer(1);
251
253
        }
252
 
        for (TToolMap::iterator it = m_tools.begin(); it != m_tools.end(); ++it) 
253
 
        {
254
 
                GNC::GCS::ITool*& pTool = (*it).second;
255
 
                if (pTool->GetFamily() == family && pTool->IsReady()) {
256
 
                        pTool->AppendToolIn(pToolController);
257
 
                }
258
 
        }
 
254
        AppendsToolsInToolBar(pToolController, family);
259
255
        pToolController->Realize();
260
256
        return pToolController;
261
257
}
262
258
 
263
259
wxWindow* GNC::ToolController::CreateNewToolBar(wxWindow* pParent, const GNC::GCS::IToolController::TIdList& toolsToInclude, bool alignLeft)
264
260
{
265
 
        std::set<long> setOfIds;
266
 
        setOfIds.insert(toolsToInclude.begin(), toolsToInclude.end());
267
 
 
268
261
        GNC::GUI::wxGinkgoToolBar* pToolController = new GNC::GUI::wxGinkgoToolBar(pParent, this, GNC::GCS::ITool::TFamiliaGlobal);
269
262
        if (!alignLeft) {
270
263
                pToolController->AddStretchSpacer(1);
271
264
        }
272
 
        for (TToolMap::iterator it = m_tools.begin(); it != m_tools.end(); ++it) 
273
 
        {
274
 
                GNC::GCS::ITool*& pTool = (*it).second;
275
 
                if (setOfIds.find(pTool->ID) != setOfIds.end() && pTool->IsReady()) {
276
 
                        pTool->AppendToolIn(pToolController);
277
 
                }
278
 
        }
 
265
 
 
266
        AppendsToolsInToolBar(pToolController, toolsToInclude);
 
267
        
279
268
        pToolController->Realize();
280
269
        return pToolController;
281
270
}
345
334
        }
346
335
}
347
336
 
 
337
void GNC::ToolController::AppendsToolsInToolBar(wxAuiToolBar* pToolBar, GNC::GCS::ITool::TToolFamily family)
 
338
{
 
339
        for (TToolMap::iterator it = m_tools.begin(); it != m_tools.end(); ++it) 
 
340
        {
 
341
                GNC::GCS::ITool*& pTool = (*it).second;
 
342
                if (pTool->GetFamily() == family && pTool->IsReady()) {
 
343
                        pTool->AppendToolIn(pToolBar);
 
344
                }
 
345
        }
 
346
}
 
347
 
 
348
void GNC::ToolController::AppendsToolsInToolBar(wxAuiToolBar* pToolBar, const GNC::GCS::IToolController::TIdList& toolsToInclude)
 
349
{
 
350
        std::set<long> setOfIds;
 
351
        setOfIds.insert(toolsToInclude.begin(), toolsToInclude.end());
 
352
 
 
353
        for (TToolMap::iterator it = m_tools.begin(); it != m_tools.end(); ++it) 
 
354
        {
 
355
                GNC::GCS::ITool*& pTool = (*it).second;
 
356
                if (pTool != NULL && setOfIds.find(pTool->ID) != setOfIds.end() && pTool->IsReady()) {
 
357
                        pTool->AppendToolIn(pToolBar);
 
358
                }
 
359
        }
 
360
}
 
361
 
348
362
void GNC::ToolController::OnKeyAccelerator(GNC::GCS::Events::EventoTeclado& evento, wxWindow* pWindow)
349
363
{
350
364
        if (evento.ControlDown() || evento.GetKeyCode() == WXK_ESCAPE) {