Graphics-VTK
view release on metacpan or search on metacpan
Tk/pTk/mTk/vtkTcl/vtkXRenderWindowTclInteractor.cxx view on Meta::CPAN
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkXRenderWindowTclInteractor.cxx,v $
Language: C++
Date: $Date: 2002/11/05 19:35:21 $
Version: $Revision: 1.6 $
Copyright (c) 1993-2000 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
of any contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
* Modified source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Arg X11_Arg
#include <X11/X.h>
#include <X11/keysym.h>
#include "vtkXRenderWindowTclInteractor.h"
#include "vtkInteractorStyle.h"
#include "vtkXOpenGLRenderWindow.h"
#include "vtkActor.h"
#include <X11/Shell.h>
#include <math.h>
#include "vtkTkport.h"
#include "tkPort.h"
#include "tkInt.h"
#include "tkVMacro.h"
#include "vtkActorCollection.h"
#include "vtkPoints.h"
#include "vtkOldStyleCallbackCommand.h"
#include "vtkObjectFactory.h"
//------------------------------------------------------------------------------
vtkXRenderWindowTclInteractor* vtkXRenderWindowTclInteractor::New()
{
// First try to create the object from the vtkObjectFactory
vtkObject* ret = vtkObjectFactory::CreateInstance("vtkXRenderWindowTclInteractor");
if(ret)
{
return (vtkXRenderWindowTclInteractor*)ret;
}
// If the factory was unable to create the object, then create it here.
return new vtkXRenderWindowTclInteractor;
}
// returns 1 if done
static int vtkTclEventProc(XtPointer clientData,XEvent *event)
{
Boolean ctd;
vtkXOpenGLRenderWindow *rw;
rw = (vtkXOpenGLRenderWindow *)
(((vtkXRenderWindowTclInteractor *)clientData)->GetRenderWindow());
if (rw->GetWindowId() == (reinterpret_cast<XAnyEvent *>(event))->window)
{
vtkXRenderWindowTclInteractorCallback((Widget)NULL,clientData, event, &ctd);
ctd = 0;
}
else
{
ctd = 1;
}
return !ctd;
}
static void vtkXTclTimerProc(ClientData clientData)
{
XtIntervalId id;
vtkXRenderWindowTclInteractorTimer((XtPointer)clientData,&id);
}
// Construct object so that light follows camera motion.
vtkXRenderWindowTclInteractor::vtkXRenderWindowTclInteractor()
{
this->App = 0;
this->top = 0;
Tk/pTk/mTk/vtkTcl/vtkXRenderWindowTclInteractor.cxx view on Meta::CPAN
// create and set distinct DisplayID for each vtkRenderWindow. Using the same
// display ID without setting the parent widgets will cause the display to be
// reinitialized every time an interactor is initialized), do not set the
// widgets (so the render windows would be in their own windows), and do
// not set TopLevelShell (each has its own top level shell already)
void vtkXRenderWindowTclInteractor::SetTopLevelShell(Widget topLevel)
{
this->TopLevelShell = topLevel;
}
static void vtkBreakTclLoop(void *iren)
{
((vtkXRenderWindowTclInteractor*)iren)->SetBreakLoopFlag(1);
}
void vtkXRenderWindowTclInteractor::Start()
{
// Let the compositing handle the event loop if it wants to.
if (this->HasObserver(vtkCommand::StartEvent))
{
this->InvokeEvent(vtkCommand::StartEvent,NULL);
return;
}
if ( this->ExitTag )
{
this->RemoveObserver(this->ExitTag);
}
vtkOldStyleCallbackCommand *cbc = vtkOldStyleCallbackCommand::New();
cbc->Callback = vtkBreakTclLoop;
cbc->ClientData = this;
this->ExitTag = this->AddObserver(vtkCommand::ExitEvent,cbc);
cbc->Delete();
this->BreakLoopFlag = 0;
while(this->BreakLoopFlag == 0)
{
Tcl_DoOneEvent(0);
}
this->RemoveObserver(this->ExitTag);
}
// Initializes the event handlers
void vtkXRenderWindowTclInteractor::Initialize(XtAppContext app)
{
this->App = app;
this->Initialize();
}
// Begin processing keyboard strokes.
void vtkXRenderWindowTclInteractor::Initialize()
{
vtkXOpenGLRenderWindow *ren;
int *size;
// make sure we have a RenderWindow and camera
if ( ! this->RenderWindow)
{
vtkErrorMacro(<<"No renderer defined!");
return;
}
this->Initialized = 1;
ren = (vtkXOpenGLRenderWindow *)(this->RenderWindow);
// use the same display as tcl/tk
#if ((TK_MAJOR_VERSION <= 4)||((TK_MAJOR_VERSION == 8)&&(TK_MINOR_VERSION == 0)))
ren->SetDisplayId(Tk_Display(tkMainWindowList->winPtr));
#else
ren->SetDisplayId(Tk_Display(TkGetMainInfoList()->winPtr));
#endif
this->DisplayId = ren->GetDisplayId();
// get the info we need from the RenderingWindow
size = ren->GetSize();
size = ren->GetSize();
ren->Start();
this->WindowId = ren->GetWindowId();
size = ren->GetSize();
this->Size[0] = size[0];
this->Size[1] = size[1];
this->Enable();
// Set the event handler
Tk_CreateGenericHandler((Tk_GenericProc *)vtkTclEventProc,(ClientData)this);
}
void vtkXRenderWindowTclInteractor::Enable()
{
// avoid cycles of calling Initialize() and Enable()
if (this->Enabled)
{
return;
}
// Select the events that we want to respond to
// (Multiple calls to XSelectInput overrides the previous settings)
XSelectInput(this->DisplayId,this->WindowId,
KeyPressMask | ButtonPressMask | ExposureMask |
StructureNotifyMask | ButtonReleaseMask | EnterWindowMask |
PointerMotionMask);
this->Enabled = 1;
this->Modified();
}
void vtkXRenderWindowTclInteractor::Disable()
{
if (!this->Enabled)
{
return;
}
// Remove the all the events that we registered for EXCEPT for
( run in 1.253 second using v1.01-cache-2.11-cpan-39bf76dae61 )