Import Geant4 11.0.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2021-06-25 16:12:29 +02:00
parent c968e26a39
commit 6399a014b6
4200 changed files with 207479 additions and 237366 deletions
File diff suppressed because it is too large Load Diff
+24
View File
@@ -0,0 +1,24 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_metal_session_hm
#define tools_metal_session_hm
#include "../Cocoa/session.hm"
namespace tools {
namespace metal {
class session : public Cocoa::session {
typedef Cocoa::session parent;
public:
session(std::ostream& a_out):parent(a_out){}
virtual ~session() {}
protected:
session(const session& a_from):parent(a_from) {}
session& operator=(const session&){return *this;}
};
}}
#endif
@@ -0,0 +1,147 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_metal_sg_viewer_hm
#define tools_metal_sg_viewer_hm
#include "session.hm"
#if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
@interface tools_metal_sg_viewer_win_delegate : NSObject {
#else
@interface tools_metal_sg_viewer_win_delegate : NSObject<NSWindowDelegate> {
#endif
tools::metal::session* m_session;
}
- (id)init:(tools::metal::session*)a_session;
- (void)dealloc;
- (void)windowWillClose:(NSNotification*)a_not;
@end
@implementation tools_metal_sg_viewer_win_delegate
- (id)init:(tools::metal::session*)a_session {
if(self = [super init]) {}
m_session = a_session;
return self;
}
- (void)dealloc {[super dealloc];}
- (void)windowWillClose:(NSNotification*)a_not {
m_session->set_to_exit();
(void)a_not;
}
@end
#include "view.hm"
#include "render.hm"
namespace tools {
namespace metal {
class sg_viewer : public ui_viewer {
typedef ui_viewer parent;
public:
virtual void win_render() { //ui_viewer::win_render()
if(!m_ww) return;
if(!m_wh) return;
if(!m_win) return;
if(m_mgr_gra.begin_render(0,0,m_ww,m_wh,
m_clear_color.r(),
m_clear_color.g(),
m_clear_color.b(),
m_clear_color.a())) {
render action(m_mgr_gra,m_out,m_ww,m_wh);
action.state().m_use_gsto = m_use_gsto;
m_sg.render(action);
if(!action.end()) { //check that matrices stack are ok.
m_out << "exib::sg::viewer : bad gl_action end." << std::endl;
}
m_mgr_gra.end_render();
}
}
public:
sg_viewer(session& a_session,
int a_x = 0,int a_y = 0,
unsigned int a_width = 500,unsigned int a_height = 500,
const std::string& a_win_title = "")
:parent(a_session.out(),a_width,a_height)
,m_session(a_session)
,m_mgr_gra(a_session.out())
,m_win(0)
,m_view(0)
{
//////////////////////////////////////////////////////////
/// windowing : //////////////////////////////////////////
//////////////////////////////////////////////////////////
m_win = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
if(!m_win) return; //throw
tools_metal_sg_viewer_win_delegate* _win_delegate = [[tools_metal_sg_viewer_win_delegate alloc] init:&a_session];
[m_win setDelegate:_win_delegate];
NSRect rect;
rect = [m_win frame];
rect = [m_win contentRectForFrameRect:rect]; //window content true size.
{int w = rect.size.width;
int h = rect.size.height;
//::printf("debug : sg_viewer::cstor %d %d\n",w,h);
parent::set_size(w,h);}
m_view = [[tools_metal_view alloc] init:rect device:m_mgr_gra.device() viewer:this];
#ifdef TOOLS_METAL_DRAW_WHEN_NEEDED
m_view.paused = true;
m_view.enableSetNeedsDisplay = true;
#endif
//m_view.presentsWithTransaction = true; //it does not help.
m_view.depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
//m_view.clearDepth = -100000;
//m_view.clearStencil = 0;
#ifdef TOOLS_METAL_DRAW_WHEN_NEEDED
#else
tools_metal_view_controller* view_controller = [[tools_metal_view_controller alloc] init];
m_view.delegate = view_controller;
#endif
m_mgr_gra.set_view(m_view);
[m_win setContentView:m_view];
[m_view release];
}
virtual ~sg_viewer() {
if(m_win) {
m_session.delete_window(m_win);
}
}
protected:
sg_viewer(const sg_viewer& a_from)
:parent(a_from)
,m_session(a_from.m_session)
,m_mgr_gra(a_from.m_mgr_gra)
,m_win(a_from.m_win)
{}
sg_viewer& operator=(const sg_viewer& a_from){
parent::operator=(a_from);
m_mgr_gra = a_from.m_mgr_gra;
m_win = a_from.m_win;
return *this;
}
public:
bool has_window() const {return m_win?true:false;} //for SWIG
bool show() {
if(!m_win) return false;
m_session.show_window(m_win);
return true;
}
protected:
session& m_session;
metal::manager m_mgr_gra;
NSWindow* m_win;
tools_metal_view* m_view;
};
}}
#endif
+31
View File
@@ -0,0 +1,31 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_metal_ui_viewer
#define tools_metal_ui_viewer
#include <tools/sg/viewer>
namespace tools {
namespace metal {
class ui_viewer : public tools::sg::viewer {
typedef tools::sg::viewer parent;
public:
virtual void win_render() = 0;
//virtual void set_to_render() {} //for Apple/Metal.
public:
ui_viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height):parent(a_out,a_width,a_height){}
virtual ~ui_viewer(){}
protected:
ui_viewer(const ui_viewer& a_from):parent(a_from){}
ui_viewer& operator=(const ui_viewer& a_from){
if(&a_from==this) return *this;
parent::operator=(a_from);
return *this;
}
};
}}
#endif
+185
View File
@@ -0,0 +1,185 @@
// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file tools.license for terms.
#ifndef tools_metal_view_hm
#define tools_metal_view_hm
#import <MetalKit/MetalKit.h>
#include "ui_viewer"
@interface tools_metal_view : MTKView {
@public tools::metal::ui_viewer* m_viewer;
NSCursor* m_cursor_default;
NSCursor* m_cursor_target;
NSCursor* m_cursor_current;
}
- (BOOL)acceptsFirstResponder;
- (nonnull id)init:(NSRect)a_rect device:(nonnull id<MTLDevice>)a_device viewer:(nonnull tools::metal::ui_viewer*)a_viewer;
- (void)dealloc;
#ifdef TOOLS_METAL_DRAW_WHEN_NEEDED
- (void)drawRect:(NSRect)a_rect;
#endif
- (void)resetCursorRects;
- (void)set_cursor:(tools::sg::cursor_shape)a_cursor;
- (void)mouseDown:(nonnull NSEvent*)a_event;
- (void)mouseUp:(nonnull NSEvent*)a_event;
- (void)mouseDragged:(nonnull NSEvent*)a_event;
@end
@implementation tools_metal_view
- (BOOL)acceptsFirstResponder {return YES;}
- (nonnull id)init:(NSRect)a_rect device:(nonnull id<MTLDevice>)a_device viewer:(nonnull tools::metal::ui_viewer*)a_viewer {
//::printf("debug : tools::metal::tools_metal_view::init\n");
self = [super initWithFrame:a_rect device:a_device];
if(!self) return self;
m_viewer = a_viewer;
m_cursor_default = [NSCursor arrowCursor];
m_cursor_target = [NSCursor crosshairCursor];
m_cursor_current = m_cursor_default;
NSTrackingAreaOptions _options = NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect;
NSTrackingArea* tracking_area =
[[NSTrackingArea alloc] initWithRect:NSZeroRect
options:_options
owner:self userInfo:nil];
[self addTrackingArea:tracking_area];
return self;
}
- (void)dealloc {[super dealloc];}
#ifdef TOOLS_METAL_DRAW_WHEN_NEEDED
- (void)drawRect:(NSRect)a_rect {
[super drawRect:a_rect];
if(!m_viewer) return;
int w = a_rect.size.width;
int h = a_rect.size.height;
::printf("debug : tools::metal::view::drawRect : %d %d\n",w,h);
m_viewer->set_size(w,h);
m_viewer->win_render();
}
#endif
- (void)mouseDown:(nonnull NSEvent*)a_event {
[super mouseDown:a_event];
::printf("debug : tools::metal::view::mouse_down : begin :\n");
//NSPoint p = [a_event locationInWindow];
//(0,0) = bottom left of window.
//NSLog(@"debug : tools_metal_view::mouseDown %g %g",p.x,p.y);
if(!m_viewer) return;
/*
bool to_render = m_viewer->touch_down(p.x,p.y);
if(m_viewer->do_works()) to_render = true;
if(to_render) {
#ifdef TOOLS_METAL_DRAW_WHEN_NEEDED
::printf("debug : tools::metal::view::mouse_down : to render...\n");
m_viewer->win_render();
#else
[self setNeedsDisplay:YES];
#endif
}
::printf("debug : tools::metal::view::mouse_down : end.\n");
*/
}
- (void)mouseUp:(nonnull NSEvent*)a_event {
[super mouseUp:a_event];
::printf("debug : tools::metal::view::mouse_up : begin :\n");
//NSPoint p = [a_event locationInWindow];
//(0,0) = bottom left of window.
//NSLog(@"debug : tools_metal_view::mouseUp %g %g",p.x,p.y);
if(!m_viewer) return;
/*
m_viewer->add_work_check_arm_buttons();
bool to_render = m_viewer->touch_up(p.x,p.y);
//if(m_viewer->do_works()) to_render = true;
if(to_render) {
#ifdef TOOLS_METAL_DRAW_WHEN_NEEDED
::printf("debug : tools::metal::view::mouse_up : to render...\n");
m_viewer->win_render();
#else
[self setNeedsDisplay:YES];
#endif
}
*/
NSRect rect;
rect.origin.x = 0;
rect.origin.y = 0;
rect.size.width = 700;
rect.size.height = 500;
// [self setNeedsDisplayInRect:rect];
[self display];
/*
if(m_viewer->touch_up(p.x,p.y)) {
//m_viewer->win_render();
[self setNeedsDisplay:YES];
}
*/
::printf("debug : tools::metal::view::mouse_up : end.\n");
}
- (void)mouseDragged:(nonnull NSEvent*)a_event {
[super mouseDragged:a_event];
::printf("debug : tools::metal::view::mouse_dragged\n");
//NSPoint p = [a_event locationInWindow];
//(0,0) = bottom left of window.
//NSLog(@"debug : tools_metal_view::mouseDragged %g %g",p.x,p.y);
if(!m_viewer) return;
//if(m_viewer->touch_move(p.x,p.y)) m_viewer->win_render();
}
- (void)resetCursorRects {
[super resetCursorRects];
//NSLog(@"debug : resetCursorRects");
[self discardCursorRects];
[self addCursorRect:self.bounds cursor:m_cursor_default];
[self addCursorRect:self.bounds cursor:m_cursor_target];
[m_cursor_current set];
}
- (void)mouseEntered:(nonnull NSEvent*)a_event {
[super mouseEntered:a_event];
[m_cursor_current set];
}
- (void)set_cursor:(tools::sg::cursor_shape)a_cursor {
if(a_cursor==tools::sg::cursor_default) {
[m_cursor_default set];
m_cursor_current = m_cursor_default;
} else if(a_cursor==tools::sg::cursor_target) {
[m_cursor_target set];
m_cursor_current = m_cursor_target;
}
}
@end
@interface tools_metal_view_controller : NSViewController<MTKViewDelegate>
@end
@implementation tools_metal_view_controller {
}
-(void)drawInMTKView:(nonnull MTKView*)a_view {
//static unsigned int s_count = 0;
//::printf("debug : tools::metal::tools_metal_view_controller::drawInMtkView : %d\n",s_count);s_count++;
tools_metal_view* _view = static_cast<tools_metal_view*>(a_view);
@autoreleasepool {
_view->m_viewer->win_render();
}
}
- (void)mtkView:(nonnull MTKView*)a_view drawableSizeWillChange:(CGSize)a_size {
int w = a_size.width*0.5;
int h = a_size.height*0.5;
//static unsigned int s_count = 0;
//::printf("debug : tools::metal::tools_metal_view_controller::drawableSizeWillChange : %d :%d %d : %d %d\n",
// s_count,(int)a_size.width,(int)a_size.height,w,h);
tools_metal_view* _view = static_cast<tools_metal_view*>(a_view);
@autoreleasepool {
_view->m_viewer->set_size(w,h);
//_view->m_viewer->win_render(); //no.
}
}
@end
#endif