don't include fcurve modifiers when getting an actions frame range.
[blender-staging.git] / intern / ghost / intern / GHOST_NDOFManager.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): none yet.
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file ghost/intern/GHOST_NDOFManager.cpp
24  *  \ingroup GHOST
25  */
26
27
28 #include <stdio.h> /* just for printf */
29
30 #include "GHOST_NDOFManager.h"
31
32
33 // the variable is outside the class because it must be accessed from plugin
34 static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
35
36 #if !defined(_WIN32) && !defined(__APPLE__)
37 #include "GHOST_SystemX11.h"
38 #endif
39
40 namespace
41 {
42     GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
43     GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
44     GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
45 }
46
47 GHOST_NDOFManager::GHOST_NDOFManager()
48 {
49     m_DeviceHandle = 0;
50
51     // discover the API from the plugin
52     ndofLibraryInit = 0;
53     ndofLibraryShutdown = 0;
54     ndofDeviceOpen = 0;
55 }
56
57 GHOST_NDOFManager::~GHOST_NDOFManager()
58 {
59     if (ndofLibraryShutdown)
60         ndofLibraryShutdown(m_DeviceHandle);
61
62     m_DeviceHandle = 0;
63 }
64
65
66 int
67 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
68         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
69         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
70         GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
71 {
72         int Pid;
73         
74     ndofLibraryInit = setNdofLibraryInit;
75     ndofLibraryShutdown = setNdofLibraryShutdown;
76     ndofDeviceOpen = setNdofDeviceOpen;
77
78     if (ndofLibraryInit  && ndofDeviceOpen)
79     {
80         Pid= ndofLibraryInit();
81 #if 0
82         printf("%i client \n", Pid);
83 #endif
84                 #if defined(WITH_HEADLESS)
85                         /* do nothing */
86                 #elif defined(_WIN32) || defined(__APPLE__)
87                         m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
88                 #elif defined(WITH_GHOST_SDL)
89                         /* do nothing */
90                 #else
91                         GHOST_SystemX11 *sys;
92                         sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
93                         void *ndofInfo = sys->prepareNdofInfo(&currentNdofValues);
94                         m_DeviceHandle = ndofDeviceOpen(ndofInfo);
95                 #endif
96                  return (Pid > 0) ? 0 : 1;
97                         
98         } else
99                 return 1;
100 }
101
102
103 bool 
104 GHOST_NDOFManager::available() const
105
106     return m_DeviceHandle != 0; 
107 }
108
109 bool 
110 GHOST_NDOFManager::event_present() const
111
112     if( currentNdofValues.changed >0) {
113                 printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n"  ,                       
114                                 currentNdofValues.time,         currentNdofValues.buttons,
115                                 currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
116                                 currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
117         return true;
118         }else
119         return false;
120
121 }
122
123 void        GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
124 {
125         datas.tx = currentNdofValues.tx;
126         datas.ty = currentNdofValues.ty;
127         datas.tz = currentNdofValues.tz;
128         datas.rx = currentNdofValues.rx;
129         datas.ry = currentNdofValues.ry;
130         datas.rz = currentNdofValues.rz;
131         datas.buttons = currentNdofValues.buttons;
132         datas.client = currentNdofValues.client;
133         datas.address = currentNdofValues.address;
134         datas.time = currentNdofValues.time;
135         datas.delta = currentNdofValues.delta;
136 }