~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/main/tools/copyimagetoclipboardtool.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*  
 
3
*  $Id: resettool.cpp $
 
4
*  Ginkgo CADx Project
 
5
*
 
6
*  Copyright 2008-12 MetaEmotion S.L. All rights reserved.
 
7
*  http://ginkgo-cadx.com
 
8
*
 
9
*  This file is licensed under LGPL v3 license.
 
10
*  See License.txt for details
 
11
*
 
12
*
 
13
*/
 
14
 
 
15
#include "copyimagetoclipboardtool.h"
 
16
#include <export/contracts/iwidgetscontract.h>
 
17
#include <api/controllers/ieventscontroller.h>
 
18
#include <eventos/modificacionimagen.h>
 
19
#include <eventos/render.h>
 
20
#include <api/iwidgetsmanager.h>
 
21
#include <main/entorno.h>
 
22
#include <main/controllers/commandcontroller.h>
 
23
 
 
24
#ifdef __DEPRECATED
 
25
#undef __DEPRECATED
 
26
#endif
 
27
 
 
28
#include <vtk/vtkginkgoimageviewer.h>
 
29
 
 
30
#include <vtkPolyDataMapper.h>
 
31
#include <vtkActor.h>
 
32
#include <vtkSmartPointer.h>
 
33
#include <vtkRenderWindow.h>
 
34
#include <vtkRenderer.h>
 
35
#include <vtkRenderWindowInteractor.h>
 
36
#include <vtkPolyData.h>
 
37
#include <vtkSphereSource.h>
 
38
#include <vtkWindowToImageFilter.h>
 
39
#include <vtkJPEGWriter.h>
 
40
 
 
41
#include <resources/ginkgoresourcesmanager.h>
 
42
 
 
43
#include <wx/bitmap.h>
 
44
#include <wx/image.h>
 
45
#include <wx/dataobj.h>
 
46
#include <wx/clipbrd.h>
 
47
 
 
48
GNC::GCS::ITool* GNC::CopyImageToClipboardTool::NewTool()
 
49
{
 
50
        return new GNC::CopyImageToClipboardTool();
 
51
}
 
52
 
 
53
GNC::CopyImageToClipboardTool::CopyImageToClipboardTool()
 
54
{
 
55
}
 
56
GNC::CopyImageToClipboardTool::~CopyImageToClipboardTool()
 
57
{
 
58
}
 
59
 
 
60
bool GNC::CopyImageToClipboardTool::ExecuteAction()
 
61
{       
 
62
        std::string tempName = GNC::Entorno::Instance()->CreateGinkgoTempFile();
 
63
        {
 
64
                vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = 
 
65
                        vtkSmartPointer<vtkWindowToImageFilter>::New();
 
66
                windowToImageFilter->SetInput(WidgetsContract->GetViewerActivo()->GetRenderWindow());
 
67
                windowToImageFilter->SetInputBufferTypeToRGB(); //also record the alpha (transparency) channel
 
68
                windowToImageFilter->Update();
 
69
                //copy image to wx...
 
70
                // put the pixels into a wxImage ...
 
71
                vtkSmartPointer<vtkImageData> timg = windowToImageFilter->GetOutput();
 
72
                unsigned char *pVtkPix = (unsigned char *)timg->GetScalarPointer();
 
73
                
 
74
                unsigned long imgsize = timg->GetDimensions()[0] * timg->GetDimensions()[1] * sizeof(unsigned char) * 3;
 
75
                unsigned char* data = new unsigned char[imgsize];
 
76
                int linesize = timg->GetDimensions()[0] *3;
 
77
                for (int y = 0; y < timg->GetDimensions()[1]; ++y) {
 
78
                        int offsetWx = imgsize - (linesize * (y +1));
 
79
                        int offsetVtk = y*linesize;
 
80
                        for (int x = 0; x < linesize; ++x) {
 
81
                                data[offsetWx+x] = pVtkPix[offsetVtk+x];
 
82
                        }
 
83
                }
 
84
 
 
85
                wxImage image(timg->GetDimensions()[0], timg->GetDimensions()[1],data,false);
 
86
                // ... and send the image to the clipboard
 
87
                if (wxTheClipboard->Open())
 
88
                {
 
89
                   wxTheClipboard->SetData( new wxBitmapDataObject(wxBitmap(image)) );
 
90
                   wxTheClipboard->Close();
 
91
                }
 
92
                
 
93
        }
 
94
 
 
95
        return true;
 
96
}